Skip to content

Commit 8d5acc1

Browse files
Add separate labels for namespace
1 parent 83467cd commit 8d5acc1

File tree

9 files changed

+44
-28
lines changed

9 files changed

+44
-28
lines changed

pkg/controller/queuejobresources/genericresource/genericresource.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545

4646
var appwrapperJobLabelName = "appwrapper.mcad.ibm.com"
4747
var resourceName = "resourceName"
48+
var resourceNamespace = "resourceNamespace"
4849
var appWrapperKind = arbv1.SchemeGroupVersion.WithKind("AppWrapper")
4950

5051
type 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

test/e2e-kuttl-deployment-01/steps/01-assert.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ metadata:
1616
app: no-quota-deployment-01
1717
appwrapper.mcad.ibm.com: no-quota-deployment-01
1818
resourceName: no-quota-deployment-01
19+
resourceNamespace: start-up
1920
status:
2021
availableReplicas: 1
2122
observedGeneration: 1

test/e2e-kuttl-deployment-01/steps/03-assert.yaml

+17-14
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,29 @@ metadata:
1414
labels:
1515
appwrapper.mcad.ibm.com: hold-completion-job-03
1616
resourceName: hold-completion-job-03-01
17+
resourceNamespace: start-up
1718
status:
1819
conditions:
1920
- status: "True"
2021
type: Complete
2122
succeeded: 1
2223
---
23-
apiVersion: v1
24-
kind: Pod
25-
metadata:
24+
apiVersion: v1
25+
kind: Pod
26+
metadata:
2627
namespace: start-up
27-
labels:
28-
appwrapper.mcad.ibm.com: hold-completion-job-03
29-
job-name: hold-completion-job-03-01
30-
resourceName: hold-completion-job-03-01
28+
labels:
29+
appwrapper.mcad.ibm.com: hold-completion-job-03
30+
job-name: hold-completion-job-03-01
31+
resourceName: hold-completion-job-03-01
32+
resourceNamespace: start-up
3133
---
32-
apiVersion: v1
33-
kind: Pod
34-
metadata:
34+
apiVersion: v1
35+
kind: Pod
36+
metadata:
3537
namespace: start-up
36-
labels:
37-
appwrapper.mcad.ibm.com: hold-completion-job-03
38-
job-name: hold-completion-job-03-02
39-
resourceName: hold-completion-job-03-02
38+
labels:
39+
appwrapper.mcad.ibm.com: hold-completion-job-03
40+
job-name: hold-completion-job-03-02
41+
resourceName: hold-completion-job-03-02
42+
resourceNamespace: start-up

test/e2e-kuttl-deployment-01/steps/07-assert.yaml

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ metadata:
77
status:
88
state: Running
99
---
10-
apiVersion: v1
11-
kind: Pod
12-
metadata:
10+
apiVersion: v1
11+
kind: Pod
12+
metadata:
1313
namespace: start-up
14-
labels:
15-
appwrapper.mcad.ibm.com: no-quota-job-06
16-
job-name: no-quota-job-06
14+
labels:
15+
appwrapper.mcad.ibm.com: no-quota-job-06
16+
job-name: no-quota-job-06
1717
resourceName: no-quota-job-06
18+
resourceNamespace: start-up
1819

test/e2e-kuttl-deployment-02/steps/02-assert.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ metadata:
1616
app: no-quota-deployment-02
1717
appwrapper.mcad.ibm.com: no-quota-deployment-02
1818
resourceName: no-quota-deployment-02
19+
resourceNamespace: start-up-02
1920
status:
2021
availableReplicas: 1
2122
observedGeneration: 1

test/e2e-kuttl-deployment-03/steps/02-assert.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ metadata:
1616
app: no-quota-deployment-02
1717
appwrapper.mcad.ibm.com: no-quota-deployment-02
1818
resourceName: no-quota-deployment-02
19+
resourceNamespace: start-up-03
1920
status:
2021
availableReplicas: 1

test/e2e-kuttl/quota-errors/03-assert.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ metadata:
1818
labels:
1919
app: deployment-silver-lo-pri-1replica
2020
appwrapper.mcad.ibm.com: deployment-silver-lo-pri-1replica
21-
resourceName: deployment-silver-lo-pri-1replica
21+
resourceName: deployment-silver-lo-pri-1replica
22+
resourceNamespace: quota-errors
2223
status:
2324
availableReplicas: 1
2425
observedGeneration: 1

test/e2e-kuttl/quota-forest/06-assert.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ kind: Pod
1515
metadata:
1616
name: job-gold-high-pri-1replica-0
1717
namespace: test
18+
labels:
19+
appwrapper.mcad.ibm.com: job-gold-high-pri-1replica
20+
job-name: job-gold-high-pri-1replica
21+
resourceName: job-gold-high-pri-1replica
22+
resourceNamespace: test
1823
---
1924
apiVersion: workload.codeflare.dev/v1beta1
2025
kind: AppWrapper

test/e2e/util.go

+1
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,7 @@ func createGenericServiceAWWithNoStatus(context *context, name string) *arbv1.Ap
15131513
"labels": {
15141514
"appwrapper.mcad.ibm.com": "test-dep-job-item",
15151515
"resourceName": "test-dep-job-item-svc"
1516+
"resourceNamespace": "test"
15161517
},
15171518
"name": "test-dep-job-item-svc",
15181519
"namespace": "test"

0 commit comments

Comments
 (0)