@@ -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