Skip to content

Commit 441402a

Browse files
Add separate labels for namespace
1 parent 83467cd commit 441402a

File tree

8 files changed

+40
-30
lines changed

8 files changed

+40
-30
lines changed

pkg/controller/queuejobresources/genericresource/genericresource.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
)
4545

4646
var appwrapperJobLabelName = "appwrapper.mcad.ibm.com"
47+
var appwrapperJobLabelNamespace = "appwrapper.mcad.ibm.com/namespace"
4748
var resourceName = "resourceName"
4849
var appWrapperKind = arbv1.SchemeGroupVersion.WithKind("AppWrapper")
4950

@@ -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", appwrapperJobLabelName, aw.Name, appwrapperJobLabelNamespace, aw.Namespace)
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[appwrapperJobLabelNamespace] = aw.Namespace
297+
labels[resourceName] = unstruct.GetName()
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", appwrapperJobLabelName, aw.Name, appwrapperJobLabelNamespace, aw.Namespace)
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
@@ -648,7 +650,7 @@ func (gr *GenericResources) IsItemCompleted(awgr *arbv1.AppWrapperGenericResourc
648650
return false
649651
}
650652

651-
labelSelector := fmt.Sprintf("%s=%s", appwrapperJobLabelName, appwrapperName)
653+
labelSelector := fmt.Sprintf("%s=%s, %s=%s", appwrapperJobLabelName, appwrapperName, appwrapperJobLabelNamespace, appwrapperNamespace)
652654
inEtcd, err := dclient.Resource(rsrc).Namespace(appwrapperNamespace).List(context.Background(), metav1.ListOptions{LabelSelector: labelSelector})
653655
if err != nil {
654656
klog.Errorf("[IsItemCompleted] Error listing object: %v", err)

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

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ metadata:
1515
labels:
1616
app: no-quota-deployment-01
1717
appwrapper.mcad.ibm.com: no-quota-deployment-01
18+
appwrapper.mcad.ibm.com/namespace: start-up
1819
resourceName: no-quota-deployment-01
1920
status:
2021
availableReplicas: 1

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

+17-14
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,30 @@ metadata:
1313
namespace: start-up
1414
labels:
1515
appwrapper.mcad.ibm.com: hold-completion-job-03
16+
appwrapper.mcad.ibm.com/namespace: start-up
1617
resourceName: hold-completion-job-03-01
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+
appwrapper.mcad.ibm.com/namespace: start-up
31+
job-name: hold-completion-job-03-01
32+
resourceName: hold-completion-job-03-01
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+
appwrapper.mcad.ibm.com/namespace: start-up
41+
job-name: hold-completion-job-03-02
42+
resourceName: hold-completion-job-03-02

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ 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+
appwrapper.mcad.ibm.com/namespace: start-up
17+
job-name: no-quota-job-06
1718
resourceName: no-quota-job-06
18-

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

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ metadata:
1515
labels:
1616
app: no-quota-deployment-02
1717
appwrapper.mcad.ibm.com: no-quota-deployment-02
18+
appwrapper.mcad.ibm.com/namespace: start-up-02
1819
resourceName: no-quota-deployment-02
1920
status:
2021
availableReplicas: 1

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

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ metadata:
1515
labels:
1616
app: no-quota-deployment-02
1717
appwrapper.mcad.ibm.com: no-quota-deployment-02
18+
appwrapper.mcad.ibm.com/namespace: start-up-03
1819
resourceName: no-quota-deployment-02
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+
appwrapper.mcad.ibm.com/namespace: quota-errors
22+
resourceName: deployment-silver-lo-pri-1replica
2223
status:
2324
availableReplicas: 1
2425
observedGeneration: 1

test/e2e/util.go

+1
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,7 @@ func createGenericServiceAWWithNoStatus(context *context, name string) *arbv1.Ap
15121512
"metadata": {
15131513
"labels": {
15141514
"appwrapper.mcad.ibm.com": "test-dep-job-item",
1515+
"appwrapper.mcad.ibm.com/namespace": "test",
15151516
"resourceName": "test-dep-job-item-svc"
15161517
},
15171518
"name": "test-dep-job-item-svc",

0 commit comments

Comments
 (0)