Skip to content

Commit

Permalink
Add separate labels for namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianZaccaria committed Oct 4, 2023
1 parent 83467cd commit 719dea1
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (

var appwrapperJobLabelName = "appwrapper.mcad.ibm.com"
var resourceName = "resourceName"
var resourceNamespace = "resourceNamespace"
var appWrapperKind = arbv1.SchemeGroupVersion.WithKind("AppWrapper")

type GenericResources struct {
Expand Down Expand Up @@ -163,7 +164,7 @@ func (gr *GenericResources) Cleanup(aw *arbv1.AppWrapper, awr *arbv1.AppWrapperG
}

// Get the resource to see if it exists
labelSelector := fmt.Sprintf("%s=%s, %s=%s", appwrapperJobLabelName, aw.Name, resourceName, unstruct.GetNamespace() + "-" + unstruct.GetName())
labelSelector := fmt.Sprintf("%s=%s, %s=%s, %s/%s", appwrapperJobLabelName, aw.Name, resourceName, unstruct.GetName(), resourceNamespace, unstruct.GetNamespace())
inEtcd, err := dclient.Resource(rsrc).List(context.Background(), metav1.ListOptions{LabelSelector: labelSelector})
if err != nil {
return name, gvk, err
Expand All @@ -172,8 +173,8 @@ func (gr *GenericResources) Cleanup(aw *arbv1.AppWrapper, awr *arbv1.AppWrapperG
// Check to see if object already exists in etcd, if not, create the object.
if inEtcd != nil || len(inEtcd.Items) > 0 {
newName := name
if len(newName + namespace) > 63 {
newName = newName[:len(newName) - (len(newName) + len(namespace) - 63)]
if len(newName) > 63 {
newName = newName[:63]
}

err = deleteObject(namespaced, namespace, newName, rsrc, dclient)
Expand Down Expand Up @@ -292,7 +293,8 @@ func (gr *GenericResources) SyncQueueJob(aw *arbv1.AppWrapper, awr *arbv1.AppWra
labels = unstruct.GetLabels()
}
labels[appwrapperJobLabelName] = aw.Name
labels[resourceName] = unstruct.GetNamespace() + "-" + unstruct.GetName()
labels[resourceName] = unstruct.GetName()
labels[resourceNamespace] = unstruct.GetNamespace()
unstruct.SetLabels(labels)

// Add labels to pod template if one exists.
Expand All @@ -302,7 +304,7 @@ func (gr *GenericResources) SyncQueueJob(aw *arbv1.AppWrapper, awr *arbv1.AppWra
}

// Get the resource to see if it exists
labelSelector := fmt.Sprintf("%s=%s, %s=%s", appwrapperJobLabelName, aw.Name, resourceName, unstruct.GetNamespace() + "-" + unstruct.GetName())
labelSelector := fmt.Sprintf("%s=%s, %s=%s, %s=%s", appwrapperJobLabelName, aw.Name, resourceName, unstruct.GetName(), resourceNamespace, unstruct.GetNamespace())
inEtcd, err := dclient.Resource(rsrc).List(context.Background(), metav1.ListOptions{LabelSelector: labelSelector})
if err != nil {
return []*v1.Pod{}, err
Expand All @@ -311,8 +313,8 @@ func (gr *GenericResources) SyncQueueJob(aw *arbv1.AppWrapper, awr *arbv1.AppWra
// Check to see if object already exists in etcd, if not, create the object.
if inEtcd == nil || len(inEtcd.Items) < 1 {
newName := name
if len(newName + namespace) > 63 {
newName = newName[:len(newName) - (len(newName) + len(namespace) - 63)]
if len(newName) > 63 {
newName = newName[:63]
}
unstruct.SetName(newName)
//Asumption object is always namespaced
Expand Down
1 change: 1 addition & 0 deletions test/e2e-kuttl-deployment-01/steps/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ metadata:
app: no-quota-deployment-01
appwrapper.mcad.ibm.com: no-quota-deployment-01
resourceName: no-quota-deployment-01
resourceNamespace: start-up
status:
availableReplicas: 1
observedGeneration: 1
Expand Down
31 changes: 17 additions & 14 deletions test/e2e-kuttl-deployment-01/steps/03-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,29 @@ metadata:
labels:
appwrapper.mcad.ibm.com: hold-completion-job-03
resourceName: hold-completion-job-03-01
resourceNamespace: start-up
status:
conditions:
- status: "True"
type: Complete
succeeded: 1
---
apiVersion: v1
kind: Pod
metadata:
apiVersion: v1
kind: Pod
metadata:
namespace: start-up
labels:
appwrapper.mcad.ibm.com: hold-completion-job-03
job-name: hold-completion-job-03-01
resourceName: hold-completion-job-03-01
labels:
appwrapper.mcad.ibm.com: hold-completion-job-03
job-name: hold-completion-job-03-01
resourceName: hold-completion-job-03-01
resourceNamespace: start-up
---
apiVersion: v1
kind: Pod
metadata:
apiVersion: v1
kind: Pod
metadata:
namespace: start-up
labels:
appwrapper.mcad.ibm.com: hold-completion-job-03
job-name: hold-completion-job-03-02
resourceName: hold-completion-job-03-02
labels:
appwrapper.mcad.ibm.com: hold-completion-job-03
job-name: hold-completion-job-03-02
resourceName: hold-completion-job-03-02
resourceNamespace: start-up
13 changes: 7 additions & 6 deletions test/e2e-kuttl-deployment-01/steps/07-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ metadata:
status:
state: Running
---
apiVersion: v1
kind: Pod
metadata:
apiVersion: v1
kind: Pod
metadata:
namespace: start-up
labels:
appwrapper.mcad.ibm.com: no-quota-job-06
job-name: no-quota-job-06
labels:
appwrapper.mcad.ibm.com: no-quota-job-06
job-name: no-quota-job-06
resourceName: no-quota-job-06
resourceNamespace: start-up

1 change: 1 addition & 0 deletions test/e2e-kuttl-deployment-02/steps/02-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ metadata:
app: no-quota-deployment-02
appwrapper.mcad.ibm.com: no-quota-deployment-02
resourceName: no-quota-deployment-02
resourceNamespace: start-up-02
status:
availableReplicas: 1
observedGeneration: 1
Expand Down
1 change: 1 addition & 0 deletions test/e2e-kuttl-deployment-03/steps/02-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ metadata:
app: no-quota-deployment-02
appwrapper.mcad.ibm.com: no-quota-deployment-02
resourceName: no-quota-deployment-02
resourceNamespace: start-up-03
status:
availableReplicas: 1
3 changes: 2 additions & 1 deletion test/e2e-kuttl/quota-errors/03-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ metadata:
labels:
app: deployment-silver-lo-pri-1replica
appwrapper.mcad.ibm.com: deployment-silver-lo-pri-1replica
resourceName: deployment-silver-lo-pri-1replica
resourceName: deployment-silver-lo-pri-1replica
resourceNamespace: quota-errors
status:
availableReplicas: 1
observedGeneration: 1
Expand Down
1 change: 1 addition & 0 deletions test/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,7 @@ func createGenericServiceAWWithNoStatus(context *context, name string) *arbv1.Ap
"labels": {
"appwrapper.mcad.ibm.com": "test-dep-job-item",
"resourceName": "test-dep-job-item-svc"
"resourceNamespace": "test"
},
"name": "test-dep-job-item-svc",
"namespace": "test"
Expand Down

0 comments on commit 719dea1

Please sign in to comment.