@@ -45,6 +45,7 @@ import (
4545
4646var appwrapperJobLabelName = "appwrapper.mcad.ibm.com"
4747var resourceName = "resourceName"
48+ var resourceNamespace = "resourceNamespace"
4849var appWrapperKind = arbv1 .SchemeGroupVersion .WithKind ("AppWrapper" )
4950
5051type GenericResources struct {
@@ -163,7 +164,7 @@ func (gr *GenericResources) Cleanup(aw *arbv1.AppWrapper, awr *arbv1.AppWrapperG
163164 }
164165
165166 // Get the resource to see if it exists
166- labelSelector := fmt .Sprintf ("%s=%s, %s=%s" , appwrapperJobLabelName , aw .Name , resourceName , unstruct .GetNamespace () + "-" + unstruct .GetName ())
167+ labelSelector := fmt .Sprintf ("%s=%s, %s=%s, %s/%s " , appwrapperJobLabelName , aw .Name , resourceName , unstruct .GetName (), resourceNamespace , unstruct .GetNamespace ())
167168 inEtcd , err := dclient .Resource (rsrc ).List (context .Background (), metav1.ListOptions {LabelSelector : labelSelector })
168169 if err != nil {
169170 return name , gvk , err
@@ -172,8 +173,8 @@ func (gr *GenericResources) Cleanup(aw *arbv1.AppWrapper, awr *arbv1.AppWrapperG
172173 // Check to see if object already exists in etcd, if not, create the object.
173174 if inEtcd != nil || len (inEtcd .Items ) > 0 {
174175 newName := name
175- if len (newName + namespace ) > 63 {
176- newName = newName [:len ( newName ) - ( len ( newName ) + len ( namespace ) - 63 ) ]
176+ if len (newName ) > 63 {
177+ newName = newName [:63 ]
177178 }
178179
179180 err = deleteObject (namespaced , namespace , newName , rsrc , dclient )
@@ -292,7 +293,8 @@ func (gr *GenericResources) SyncQueueJob(aw *arbv1.AppWrapper, awr *arbv1.AppWra
292293 labels = unstruct .GetLabels ()
293294 }
294295 labels [appwrapperJobLabelName ] = aw .Name
295- labels [resourceName ] = unstruct .GetNamespace () + "-" + unstruct .GetName ()
296+ labels [resourceName ] = unstruct .GetName ()
297+ labels [resourceNamespace ] = unstruct .GetNamespace ()
296298 unstruct .SetLabels (labels )
297299
298300 // Add labels to pod template if one exists.
@@ -302,7 +304,7 @@ func (gr *GenericResources) SyncQueueJob(aw *arbv1.AppWrapper, awr *arbv1.AppWra
302304 }
303305
304306 // Get the resource to see if it exists
305- labelSelector := fmt .Sprintf ("%s=%s, %s=%s" , appwrapperJobLabelName , aw .Name , resourceName , unstruct .GetNamespace () + "-" + unstruct .GetName ())
307+ labelSelector := fmt .Sprintf ("%s=%s, %s=%s, %s=%s " , appwrapperJobLabelName , aw .Name , resourceName , unstruct .GetName (), resourceNamespace , unstruct .GetNamespace ())
306308 inEtcd , err := dclient .Resource (rsrc ).List (context .Background (), metav1.ListOptions {LabelSelector : labelSelector })
307309 if err != nil {
308310 return []* v1.Pod {}, err
@@ -311,8 +313,8 @@ func (gr *GenericResources) SyncQueueJob(aw *arbv1.AppWrapper, awr *arbv1.AppWra
311313 // Check to see if object already exists in etcd, if not, create the object.
312314 if inEtcd == nil || len (inEtcd .Items ) < 1 {
313315 newName := name
314- if len (newName + namespace ) > 63 {
315- newName = newName [:len ( newName ) - ( len ( newName ) + len ( namespace ) - 63 ) ]
316+ if len (newName ) > 63 {
317+ newName = newName [:63 ]
316318 }
317319 unstruct .SetName (newName )
318320 //Asumption object is always namespaced
0 commit comments