Skip to content

Commit

Permalink
update func canary step
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce-Huang <[email protected]>
  • Loading branch information
Bryce-huang committed Sep 27, 2023
1 parent 8882e05 commit 66ed784
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 143 deletions.
16 changes: 12 additions & 4 deletions config/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39600,10 +39600,18 @@ subjects:
---
apiVersion: v1
data:
controller_manager_config.yaml: "apiVersion: controller-runtime.sigs.k8s.io/v1alpha1\r\nkind:
ControllerManagerConfig\r\nhealth:\r\n healthProbeBindAddress: :8081\r\nmetrics:\r\n
\ bindAddress: 127.0.0.1:8080\r\nwebhook:\r\n port: 9443\r\nleaderElection:\r\n
\ leaderElect: true\r\n resourceName: 79f0111e.openfunction.io\r\n"
controller_manager_config.yaml: |
apiVersion: controller-runtime.sigs.k8s.io/v1alpha1
kind: ControllerManagerConfig
health:
healthProbeBindAddress: :8081
metrics:
bindAddress: 127.0.0.1:8080
webhook:
port: 9443
leaderElection:
leaderElect: true
resourceName: 79f0111e.openfunction.io
kind: ConfigMap
metadata:
name: openfunction-manager-config
Expand Down
30 changes: 24 additions & 6 deletions controllers/core/builder_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
"math"
"time"

"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -112,7 +115,7 @@ func (r *BuilderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
builder.Status.Message = openfunction.Timeout
builder.Status.BuildDuration = builder.Spec.Timeout

if err := r.Status().Update(r.ctx, builder); err != nil {
if err := r.updateStatus(builder); err != nil {
log.Error(err, "Failed to update builder status")
return ctrl.Result{}, err
}
Expand All @@ -136,7 +139,7 @@ func (r *BuilderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct

// Reset builder status.
builder.Status = openfunction.BuilderStatus{}
if err := r.Status().Update(r.ctx, builder); err != nil {
if err := r.updateStatus(builder); err != nil {
log.Error(err, "Failed to reset builder status")
return ctrl.Result{}, err
}
Expand All @@ -148,7 +151,7 @@ func (r *BuilderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct

builder.Status.Phase = openfunction.BuildPhase
builder.Status.State = openfunction.Building
if err := r.Status().Update(r.ctx, builder); err != nil {
if err := r.updateStatus(builder); err != nil {
log.Error(err, "Failed to update builder status")
return ctrl.Result{}, err
}
Expand All @@ -159,7 +162,22 @@ func (r *BuilderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct

return ctrl.Result{}, nil
}

func (r *BuilderReconciler) updateStatus(builder *openfunction.Builder) error {
log := r.Log.WithName("UpdateStatus")
if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
builderClone := builder.DeepCopy()
if err := r.Client.Get(r.ctx, types.NamespacedName{Namespace: builder.Namespace, Name: builder.Name}, builderClone); err != nil {
log.Error(err, fmt.Sprintf("error getting updated builder(%s/%s) from client", builder.Namespace, builder.Name))
return err
}
builderClone.Status = builder.Status
return r.Client.Status().Update(r.ctx, builderClone)
}); err != nil {
log.Error(err, fmt.Sprintf("update builder(%s/%s)", builder.Name, builder.Namespace))
return err
}
return nil
}
func (r *BuilderReconciler) createBuilderRun() core.BuilderRun {

return shipwright.NewBuildRun(r.ctx, r.Client, r.Scheme, r.Log)
Expand Down Expand Up @@ -192,7 +210,7 @@ func (r *BuilderReconciler) getBuilderResult(builder *openfunction.Builder, buil
Duration: metav1.Now().UTC().Sub(builder.CreationTimestamp.UTC()).Truncate(time.Second),
}
}
if err := r.Status().Update(r.ctx, builder); err != nil {
if err := r.updateStatus(builder); err != nil {
return err
}

Expand Down Expand Up @@ -269,7 +287,7 @@ func (r *BuilderReconciler) buildTimeout(builder *openfunction.Builder) error {
b.Status.Reason = openfunction.Timeout
b.Status.Message = openfunction.Timeout
b.Status.BuildDuration = builder.Spec.Timeout
err := r.Status().Update(r.ctx, b)
err := r.updateStatus(b)
if err == nil {
r.recordEvent(builder)
}
Expand Down
Loading

0 comments on commit 66ed784

Please sign in to comment.