Skip to content

Commit a86c0be

Browse files
Don't install resources into terminating Namespaces
1 parent bf9a816 commit a86c0be

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

pkg/controller/installation/core_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ func (r *ReconcileInstallation) Reconcile(ctx context.Context, request reconcile
13551355
}
13561356
if len(needsCleanup) > 0 {
13571357
// Add a component to remove the finalizers from the objects that need it.
1358-
reqLogger.Info("Removing finalizers from objects that are wronly marked for deletion")
1358+
reqLogger.Info("Removing finalizers from objects that are wrongly marked for deletion")
13591359
components = append(components, render.NewPassthrough(needsCleanup...))
13601360
}
13611361
}

pkg/controller/utils/component.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,34 @@ func (c *componentHandler) createOrUpdateObject(ctx context.Context, obj client.
132132
logCtx.V(2).Info("Failed converting object", "obj", obj)
133133
return fmt.Errorf("failed converting object %+v", obj)
134134
}
135-
// Check to see if the object exists or not.
135+
// Check to see if the object's Namespace exists, and whether the Namespace
136+
// is currently terminating. We cannot create objects in a terminating Namespace.
137+
namespaceTerminating := false
138+
if ns := cur.GetNamespace(); ns != "" {
139+
nsKey := client.ObjectKey{Name: ns}
140+
namespace, err := GetIfExists[v1.Namespace](ctx, nsKey, c.client)
141+
if err != nil {
142+
logCtx.WithValues("key", nsKey).Error(err, "Failed to get Namespace.")
143+
return err
144+
}
145+
if namespace != nil {
146+
namespaceTerminating = namespace.GetDeletionTimestamp() != nil
147+
}
148+
}
149+
150+
// Check to see if the object exists or not - this determines whether we should create or update.
136151
err := c.client.Get(ctx, key, cur)
137152
if err != nil {
138153
if !errors.IsNotFound(err) {
139154
// Anything other than "Not found" we should retry.
140155
return err
141156
}
142157

158+
if namespaceTerminating {
159+
logCtx.Info("Object's Namespace is terminating, skipping creation.")
160+
return nil
161+
}
162+
143163
// Otherwise, if it was not found, we should create it and move on.
144164
logCtx.V(2).Info("Object does not exist, creating it", "error", err)
145165
if multipleOwners {

0 commit comments

Comments
 (0)