Skip to content
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

reconciler/apiexport: don't klog.Fatal #1291

Merged
merged 1 commit into from
Jun 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions pkg/reconciler/apis/apiexport/apiexport_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

jsonpatch "github.com/evanphx/json-patch"
"github.com/google/go-cmp/cmp"
"github.com/kcp-dev/logicalcluster"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -322,10 +323,6 @@ func (c *controller) patchIfNeeded(ctx context.Context, old, obj *apisv1alpha1.A
specOrObjectMetaChanged := !equality.Semantic.DeepEqual(old.Spec, obj.Spec) || !equality.Semantic.DeepEqual(old.ObjectMeta, obj.ObjectMeta)
statusChanged := !equality.Semantic.DeepEqual(old.Status, obj.Status)

if specOrObjectMetaChanged && statusChanged {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put as a comment on the inner apiExportForPatch declaration that the logic will guarantee that only the objectmeta/spec change will be patched first and on the next iteration the spec change.

klog.Fatalf("Programmer error: spec and status changed in same reconcile iteration")
}

if !specOrObjectMetaChanged && !statusChanged {
return nil
}
Expand Down Expand Up @@ -375,7 +372,16 @@ func (c *controller) patchIfNeeded(ctx context.Context, old, obj *apisv1alpha1.A
}

_, err = c.kcpClusterClient.Cluster(clusterName).ApisV1alpha1().APIExports().Patch(ctx, obj.Name, types.MergePatchType, patchBytes, metav1.PatchOptions{}, subresources...)
return err
if err != nil {
return fmt.Errorf("failed to patch APIExport %s|%s: %w", clusterName, name, err)
}

if specOrObjectMetaChanged && statusChanged {
klog.Errorf("Programmer error: spec and status changed in same reconcile iteration:\n%s", cmp.Diff(old, obj))
c.enqueueAPIExport(obj) // enqueue again to take care of the spec change, assuming the patch did nothing
}

return nil
}

func (c *controller) readThroughGetSecret(ctx context.Context, clusterName logicalcluster.Name, ns, name string) (*corev1.Secret, error) {
Expand Down