Skip to content

Commit

Permalink
Fix publishing function is the service is unavailable
Browse files Browse the repository at this point in the history
OpenFunction#504
Signed-off-by: Bryce-Huang <[email protected]>
  • Loading branch information
Bryce-huang committed Oct 26, 2023
1 parent c01dd1f commit c45a6d6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
47 changes: 43 additions & 4 deletions controllers/core/function_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,18 @@ func (r *FunctionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
if err != nil {
return ctrl.Result{}, err
}

if err = r.createOrUpdateHTTPRoute(&fn); err != nil {
return ctrl.Result{}, err
}

ready, err := r.httpRouteIsReady(&fn)
if err != nil {
return ctrl.Result{}, err
}
if !ready {
return ctrl.Result{RequeueAfter: constants.DefaultGatewayChangeCleanTime}, nil
}
// for canary rollback
if err := r.cleanServing(&fn); err != nil {
log.Error(err, "Failed to clean Serving")
Expand Down Expand Up @@ -238,10 +246,6 @@ func (r *FunctionReconciler) updateCanaryRelease(fn *openfunction.Function) (*ti
log.Error(err, "Failed to update function canary status")
return nil, err
}
if err := r.cleanServing(fn); err != nil {
log.Error(err, "Failed to clean Serving")
return nil, err
}
}

return recheckTime, nil
Expand Down Expand Up @@ -1575,3 +1579,38 @@ func (r *FunctionReconciler) initRolloutStatus(fn *openfunction.Function) error
return nil

}

func (r *FunctionReconciler) httpRouteIsReady(fn *openfunction.Function) (bool, error) {
if fn.Status.Serving == nil ||
fn.Status.Serving.State != openfunction.Running ||
fn.Status.Serving.Service == "" {
return true, nil
}

log := r.Log.WithName("HttpRouteIsReady")
httpRoute := &k8sgatewayapiv1beta1.HTTPRoute{
ObjectMeta: metav1.ObjectMeta{
Name: fn.Name,
Namespace: fn.Namespace,
},
}
if err := r.Get(r.ctx, client.ObjectKeyFromObject(httpRoute), httpRoute); err != nil {
log.Error(err, "Failed to get httpRoute",
"namespace", fn.Namespace, "name", fn.Name)
return false, err
}

for _, parent := range httpRoute.Status.Parents {
for _, condition := range parent.Conditions {
if condition.ObservedGeneration != httpRoute.Generation {
log.Info("httpRoute observedGeneration is not ready", "name", fn.Name, "parent", parent.ParentRef.Name, "type", condition.Type)
return false, nil
}
if condition.Status != "True" {
log.Info("httpRoute status is not ready", "name", fn.Name, "parent", parent.ParentRef.Name, "type", condition.Type)
return false, nil
}
}
}
return true, nil
}
2 changes: 2 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package constants

import (
"sigs.k8s.io/gateway-api/apis/v1beta1"
"time"
)

const (
Expand All @@ -44,6 +45,7 @@ const (
DefaultFunctionServicePort v1beta1.PortNumber = 80
DefaultFuncPort v1beta1.PortNumber = 8080
DefaultInterceptorPort v1beta1.PortNumber = 8080
DefaultGatewayChangeCleanTime = 5 * time.Second

WasmEdgeWorkloadRuntimeName = "wasmedge"
WasmEdgeRuntimeClassName = "openfunction-crun"
Expand Down

0 comments on commit c45a6d6

Please sign in to comment.