Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pkg/controller/installation/core_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ func (r *ReconcileInstallation) Reconcile(ctx context.Context, request reconcile
}
if len(needsCleanup) > 0 {
// Add a component to remove the finalizers from the objects that need it.
reqLogger.Info("Removing finalizers from objects that are wronly marked for deletion")
reqLogger.Info("Removing finalizers from objects that are wrongly marked for deletion")
components = append(components, render.NewPassthrough(needsCleanup...))
}
}
Expand Down
22 changes: 21 additions & 1 deletion pkg/controller/utils/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,34 @@ func (c *componentHandler) createOrUpdateObject(ctx context.Context, obj client.
logCtx.V(2).Info("Failed converting object", "obj", obj)
return fmt.Errorf("failed converting object %+v", obj)
}
// Check to see if the object exists or not.

// Check to see if the object exists or not - this determines whether we should create or update.
err := c.client.Get(ctx, key, cur)
if err != nil {
if !errors.IsNotFound(err) {
// Anything other than "Not found" we should retry.
return err
}

// Check to see if the object's Namespace exists, and whether the Namespace
// is currently terminating. We cannot create objects in a terminating Namespace.
namespaceTerminating := false
if ns := cur.GetNamespace(); ns != "" {
nsKey := client.ObjectKey{Name: ns}
namespace, err := GetIfExists[v1.Namespace](ctx, nsKey, c.client)
if err != nil {
logCtx.WithValues("key", nsKey).Error(err, "Failed to get Namespace.")
return err
}
if namespace != nil {
namespaceTerminating = namespace.GetDeletionTimestamp() != nil
}
}
if namespaceTerminating {
logCtx.Info("Object's Namespace is terminating, skipping creation.")
return nil
}

// Otherwise, if it was not found, we should create it and move on.
logCtx.V(2).Info("Object does not exist, creating it", "error", err)
if multipleOwners {
Expand Down
Loading
Loading