From 719dea11759da122c14089659ba784deefa0f29e Mon Sep 17 00:00:00 2001 From: ChristianZaccaria Date: Wed, 4 Oct 2023 14:00:18 +0100 Subject: [PATCH] Add separate labels for namespace --- .../genericresource/genericresource.go | 16 +++++----- .../steps/01-assert.yaml | 1 + .../steps/03-assert.yaml | 31 ++++++++++--------- .../steps/07-assert.yaml | 13 ++++---- .../steps/02-assert.yaml | 1 + .../steps/02-assert.yaml | 1 + test/e2e-kuttl/quota-errors/03-assert.yaml | 3 +- test/e2e/util.go | 1 + 8 files changed, 39 insertions(+), 28 deletions(-) diff --git a/pkg/controller/queuejobresources/genericresource/genericresource.go b/pkg/controller/queuejobresources/genericresource/genericresource.go index e9944dfc..7c83b28b 100644 --- a/pkg/controller/queuejobresources/genericresource/genericresource.go +++ b/pkg/controller/queuejobresources/genericresource/genericresource.go @@ -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 { @@ -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 @@ -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) @@ -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. @@ -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 @@ -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 diff --git a/test/e2e-kuttl-deployment-01/steps/01-assert.yaml b/test/e2e-kuttl-deployment-01/steps/01-assert.yaml index cbf35849..43ca5432 100644 --- a/test/e2e-kuttl-deployment-01/steps/01-assert.yaml +++ b/test/e2e-kuttl-deployment-01/steps/01-assert.yaml @@ -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 diff --git a/test/e2e-kuttl-deployment-01/steps/03-assert.yaml b/test/e2e-kuttl-deployment-01/steps/03-assert.yaml index fb5d6ba6..2c9d4c37 100644 --- a/test/e2e-kuttl-deployment-01/steps/03-assert.yaml +++ b/test/e2e-kuttl-deployment-01/steps/03-assert.yaml @@ -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 diff --git a/test/e2e-kuttl-deployment-01/steps/07-assert.yaml b/test/e2e-kuttl-deployment-01/steps/07-assert.yaml index dc0ade42..d933f316 100644 --- a/test/e2e-kuttl-deployment-01/steps/07-assert.yaml +++ b/test/e2e-kuttl-deployment-01/steps/07-assert.yaml @@ -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 diff --git a/test/e2e-kuttl-deployment-02/steps/02-assert.yaml b/test/e2e-kuttl-deployment-02/steps/02-assert.yaml index aa9a6f7e..8288e4b8 100644 --- a/test/e2e-kuttl-deployment-02/steps/02-assert.yaml +++ b/test/e2e-kuttl-deployment-02/steps/02-assert.yaml @@ -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 diff --git a/test/e2e-kuttl-deployment-03/steps/02-assert.yaml b/test/e2e-kuttl-deployment-03/steps/02-assert.yaml index 8551bdf6..07c63e7e 100644 --- a/test/e2e-kuttl-deployment-03/steps/02-assert.yaml +++ b/test/e2e-kuttl-deployment-03/steps/02-assert.yaml @@ -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 diff --git a/test/e2e-kuttl/quota-errors/03-assert.yaml b/test/e2e-kuttl/quota-errors/03-assert.yaml index 629127c4..4d32aad0 100644 --- a/test/e2e-kuttl/quota-errors/03-assert.yaml +++ b/test/e2e-kuttl/quota-errors/03-assert.yaml @@ -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 diff --git a/test/e2e/util.go b/test/e2e/util.go index e517f681..bdc83d21 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -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"