-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: patch instead of update and bugfix #2059
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,6 +236,8 @@ func (mr *monoVertexReconciler) orchestratePods(ctx context.Context, monoVtx *df | |
monoVtx.Status.CurrentHash = monoVtx.Status.UpdateHash | ||
} else { // Update scenario | ||
if updatedReplicas >= desiredReplicas { | ||
monoVtx.Status.UpdatedReplicas = uint32(desiredReplicas) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixing 4.) |
||
monoVtx.Status.CurrentHash = monoVtx.Status.UpdateHash | ||
return nil | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ package pipeline | |
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
@@ -40,6 +39,7 @@ import ( | |
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
"sigs.k8s.io/yaml" | ||
|
||
dfv1 "github.com/numaproj/numaflow/pkg/apis/numaflow/v1alpha1" | ||
daemonclient "github.com/numaproj/numaflow/pkg/daemon/client" | ||
|
@@ -51,6 +51,8 @@ import ( | |
|
||
const ( | ||
finalizerName = dfv1.ControllerPipeline | ||
|
||
pauseTimestampPath = `/metadata/annotations/numaflow.numaproj.io~1pause-timestamp` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
) | ||
|
||
// pipelineReconciler reconciles a pipeline object. | ||
|
@@ -85,9 +87,10 @@ func (r *pipelineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c | |
log.Errorw("Reconcile error", zap.Error(reconcileErr)) | ||
} | ||
plCopy.Status.LastUpdated = metav1.Now() | ||
if needsUpdate(pl, plCopy) { | ||
// Update with a DeepCopy because .Status will be cleaned up. | ||
if err := r.client.Update(ctx, plCopy.DeepCopy()); err != nil { | ||
if needsToPatchFinalizers(pl, plCopy) { | ||
patchYaml := "metadata:\n finalizers: [" + strings.Join(plCopy.Finalizers, ",") + "]" | ||
patchJson, _ := yaml.YAMLToJSON([]byte(patchYaml)) | ||
if err := r.client.Patch(ctx, pl, client.RawPatch(types.MergePatchType, []byte(patchJson))); err != nil { | ||
return result, err | ||
} | ||
} | ||
|
@@ -292,7 +295,9 @@ func (r *pipelineReconciler) reconcileFixedResources(ctx context.Context, pl *df | |
r.recorder.Eventf(pl, corev1.EventTypeNormal, "CreateVertexSuccess", "Created vertex %s successfully", vertexName) | ||
} else { | ||
if oldObj.GetAnnotations()[dfv1.KeyHash] != newObj.GetAnnotations()[dfv1.KeyHash] { // need to update | ||
originReplicas := oldObj.Spec.Replicas | ||
oldObj.Spec = newObj.Spec | ||
oldObj.Spec.Replicas = originReplicas | ||
oldObj.Annotations[dfv1.KeyHash] = newObj.GetAnnotations()[dfv1.KeyHash] | ||
if err := r.client.Update(ctx, &oldObj); err != nil { | ||
r.recorder.Eventf(pl, corev1.EventTypeWarning, "UpdateVertexFailed", "Failed to update vertex: %w", err.Error()) | ||
|
@@ -588,9 +593,9 @@ func (r *pipelineReconciler) cleanUpBuffers(ctx context.Context, pl *dfv1.Pipeli | |
return nil | ||
} | ||
|
||
func needsUpdate(old, new *dfv1.Pipeline) bool { | ||
if old == nil { | ||
return true | ||
func needsToPatchFinalizers(old, new *dfv1.Pipeline) bool { | ||
if old == nil { // This is a weird scenario, nothing we can do. Theoretically it will never happen. | ||
return false | ||
} | ||
if !equality.Semantic.DeepEqual(old.Finalizers, new.Finalizers) { | ||
return true | ||
|
@@ -814,7 +819,7 @@ func (r *pipelineReconciler) updateDesiredState(ctx context.Context, pl *dfv1.Pi | |
func (r *pipelineReconciler) resumePipeline(ctx context.Context, pl *dfv1.Pipeline) (bool, error) { | ||
// reset pause timestamp | ||
if pl.GetAnnotations()[dfv1.KeyPauseTimestamp] != "" { | ||
err := r.client.Patch(ctx, pl, client.RawPatch(types.JSONPatchType, []byte(dfv1.RemovePauseTimestampPatch))) | ||
err := r.client.Patch(ctx, pl, client.RawPatch(types.JSONPatchType, []byte(`[{"op": "remove", "path": "`+pauseTimestampPath+`"}]`))) | ||
if err != nil { | ||
if apierrors.IsNotFound(err) { | ||
return false, nil // skip pipeline if it can't be found | ||
|
@@ -837,13 +842,8 @@ func (r *pipelineReconciler) resumePipeline(ctx context.Context, pl *dfv1.Pipeli | |
func (r *pipelineReconciler) pausePipeline(ctx context.Context, pl *dfv1.Pipeline) (bool, error) { | ||
// check that annotations / pause timestamp annotation exist | ||
if pl.GetAnnotations() == nil || pl.GetAnnotations()[dfv1.KeyPauseTimestamp] == "" { | ||
pl.SetAnnotations(map[string]string{dfv1.KeyPauseTimestamp: time.Now().Format(time.RFC3339)}) | ||
body, err := json.Marshal(pl) | ||
if err != nil { | ||
return false, err | ||
} | ||
err = r.client.Patch(ctx, pl, client.RawPatch(types.MergePatchType, body)) | ||
if err != nil && !apierrors.IsNotFound(err) { | ||
patchJson := `[{"op": "add", "path": "` + pauseTimestampPath + `", "value": "` + time.Now().Format(time.RFC3339) + `"}]` | ||
if err := r.client.Patch(ctx, pl, client.RawPatch(types.JSONPatchType, []byte(patchJson))); err != nil && !apierrors.IsNotFound(err) { | ||
return true, err | ||
} | ||
} | ||
|
@@ -924,12 +924,8 @@ func (r *pipelineReconciler) scaleVertex(ctx context.Context, pl *dfv1.Pipeline, | |
} | ||
} | ||
} | ||
vertex.Spec.Replicas = ptr.To[int32](scaleTo) | ||
body, err := json.Marshal(vertex) | ||
if err != nil { | ||
return false, err | ||
} | ||
err = r.client.Patch(ctx, &vertex, client.RawPatch(types.MergePatchType, body)) | ||
patchJson := fmt.Sprintf(`{"spec":{"replicas":%d}}`, scaleTo) | ||
err = r.client.Patch(ctx, &vertex, client.RawPatch(types.MergePatchType, []byte(patchJson))) | ||
if err != nil && !apierrors.IsNotFound(err) { | ||
return false, err | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,6 +259,8 @@ func (r *vertexReconciler) orchestratePods(ctx context.Context, vertex *dfv1.Ver | |
vertex.Status.CurrentHash = vertex.Status.UpdateHash | ||
} else { // Update scenario | ||
if updatedReplicas >= desiredReplicas { | ||
vertex.Status.UpdatedReplicas = uint32(desiredReplicas) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixing 4.) |
||
vertex.Status.CurrentHash = vertex.Status.UpdateHash | ||
return nil | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since it is a weird scenario should be log so it might help whoever is debugging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaned it up since there's no need to add this function.