@@ -150,21 +150,24 @@ func (gr *GenericResources) Cleanup(aw *arbv1.AppWrapper, awr *arbv1.AppWrapperG
150150 }
151151
152152 unstruct .Object = blob .(map [string ]interface {}) // set object to the content of the blob after Unmarshalling
153- namespace := ""
153+ namespace := aw . Namespace // only delete resources from AppWrapper namespace
154154 if md , ok := unstruct .Object ["metadata" ]; ok {
155155
156156 metadata := md .(map [string ]interface {})
157157 if objectName , ok := metadata ["name" ]; ok {
158158 name = objectName .(string )
159159 }
160160 if objectns , ok := metadata ["namespace" ]; ok {
161- namespace = objectns .(string )
161+ if objectns .(string ) != namespace {
162+ err := fmt .Errorf ("[Cleanup] resource namespace \" %s\" is different from AppWrapper namespace \" %s\" " , objectns .(string ), namespace )
163+ return name , gvk , err
164+ }
162165 }
163166 }
164167
165- // Get the resource to see if it exists
168+ // Get the resource to see if it exists in the AppWrapper namespace
166169 labelSelector := fmt .Sprintf ("%s=%s, %s=%s" , appwrapperJobName , aw .Name , resourceName , unstruct .GetName ())
167- inEtcd , err := dclient .Resource (rsrc ).List (context .Background (), metav1.ListOptions {LabelSelector : labelSelector })
170+ inEtcd , err := dclient .Resource (rsrc ).Namespace ( aw . Namespace ). List (context .Background (), metav1.ListOptions {LabelSelector : labelSelector })
168171 if err != nil {
169172 return name , gvk , err
170173 }
@@ -273,7 +276,7 @@ func (gr *GenericResources) SyncQueueJob(aw *arbv1.AppWrapper, awr *arbv1.AppWra
273276 ownerRef := metav1 .NewControllerRef (aw , appWrapperKind )
274277 unstruct .Object = blob .(map [string ]interface {}) // set object to the content of the blob after Unmarshalling
275278 unstruct .SetOwnerReferences (append (unstruct .GetOwnerReferences (), * ownerRef ))
276- namespace := "default"
279+ namespace := aw . Namespace // only create resources in AppWrapper namespace
277280 name := ""
278281 if md , ok := unstruct .Object ["metadata" ]; ok {
279282
@@ -282,7 +285,10 @@ func (gr *GenericResources) SyncQueueJob(aw *arbv1.AppWrapper, awr *arbv1.AppWra
282285 name = objectName .(string )
283286 }
284287 if objectns , ok := metadata ["namespace" ]; ok {
285- namespace = objectns .(string )
288+ if objectns .(string ) != namespace {
289+ err := fmt .Errorf ("[SyncQueueJob] resource namespace \" %s\" is different from AppWrapper namespace \" %s\" " , objectns .(string ), namespace )
290+ return []* v1.Pod {}, err
291+ }
286292 }
287293 }
288294 labels := map [string ]string {}
0 commit comments