diff --git a/pkg/controller/queuejobresources/genericresource/genericresource.go b/pkg/controller/queuejobresources/genericresource/genericresource.go index e9944dfc..d64ffd2c 100644 --- a/pkg/controller/queuejobresources/genericresource/genericresource.go +++ b/pkg/controller/queuejobresources/genericresource/genericresource.go @@ -44,6 +44,7 @@ import ( ) var appwrapperJobLabelName = "appwrapper.mcad.ibm.com" +var appwrapperJobLabelNamespace = "appwrapper.mcad.ibm.com/namespace" var resourceName = "resourceName" var appWrapperKind = arbv1.SchemeGroupVersion.WithKind("AppWrapper") @@ -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", appwrapperJobLabelName, aw.Name, appwrapperJobLabelNamespace, aw.Namespace) 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[appwrapperJobLabelNamespace] = aw.Namespace + labels[resourceName] = unstruct.GetName() 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", appwrapperJobLabelName, aw.Name, appwrapperJobLabelNamespace, aw.Namespace) 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 @@ -648,7 +650,7 @@ func (gr *GenericResources) IsItemCompleted(awgr *arbv1.AppWrapperGenericResourc return false } - labelSelector := fmt.Sprintf("%s=%s", appwrapperJobLabelName, appwrapperName) + labelSelector := fmt.Sprintf("%s=%s, %s=%s", appwrapperJobLabelName, appwrapperName, appwrapperJobLabelNamespace, appwrapperNamespace) inEtcd, err := dclient.Resource(rsrc).Namespace(appwrapperNamespace).List(context.Background(), metav1.ListOptions{LabelSelector: labelSelector}) if err != nil { klog.Errorf("[IsItemCompleted] Error listing object: %v", err) diff --git a/test/e2e-kuttl-deployment-01/steps/01-assert.yaml b/test/e2e-kuttl-deployment-01/steps/01-assert.yaml index cbf35849..1d7fc1d1 100644 --- a/test/e2e-kuttl-deployment-01/steps/01-assert.yaml +++ b/test/e2e-kuttl-deployment-01/steps/01-assert.yaml @@ -15,6 +15,7 @@ metadata: labels: app: no-quota-deployment-01 appwrapper.mcad.ibm.com: no-quota-deployment-01 + appwrapper.mcad.ibm.com/namespace: start-up resourceName: no-quota-deployment-01 status: availableReplicas: 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..73d11699 100644 --- a/test/e2e-kuttl-deployment-01/steps/03-assert.yaml +++ b/test/e2e-kuttl-deployment-01/steps/03-assert.yaml @@ -13,6 +13,7 @@ metadata: namespace: start-up labels: appwrapper.mcad.ibm.com: hold-completion-job-03 + appwrapper.mcad.ibm.com/namespace: start-up resourceName: hold-completion-job-03-01 status: conditions: @@ -20,20 +21,22 @@ status: 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 + appwrapper.mcad.ibm.com/namespace: start-up + job-name: hold-completion-job-03-01 + resourceName: hold-completion-job-03-01 --- -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 + appwrapper.mcad.ibm.com/namespace: start-up + job-name: hold-completion-job-03-02 + resourceName: hold-completion-job-03-02 diff --git a/test/e2e-kuttl-deployment-01/steps/07-assert.yaml b/test/e2e-kuttl-deployment-01/steps/07-assert.yaml index dc0ade42..518320cb 100644 --- a/test/e2e-kuttl-deployment-01/steps/07-assert.yaml +++ b/test/e2e-kuttl-deployment-01/steps/07-assert.yaml @@ -7,12 +7,12 @@ 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 + appwrapper.mcad.ibm.com/namespace: start-up + job-name: no-quota-job-06 resourceName: no-quota-job-06 - diff --git a/test/e2e-kuttl-deployment-02/steps/02-assert.yaml b/test/e2e-kuttl-deployment-02/steps/02-assert.yaml index aa9a6f7e..297d1c67 100644 --- a/test/e2e-kuttl-deployment-02/steps/02-assert.yaml +++ b/test/e2e-kuttl-deployment-02/steps/02-assert.yaml @@ -15,6 +15,7 @@ metadata: labels: app: no-quota-deployment-02 appwrapper.mcad.ibm.com: no-quota-deployment-02 + appwrapper.mcad.ibm.com/namespace: start-up-02 resourceName: no-quota-deployment-02 status: availableReplicas: 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..758038ed 100644 --- a/test/e2e-kuttl-deployment-03/steps/02-assert.yaml +++ b/test/e2e-kuttl-deployment-03/steps/02-assert.yaml @@ -15,6 +15,7 @@ metadata: labels: app: no-quota-deployment-02 appwrapper.mcad.ibm.com: no-quota-deployment-02 + appwrapper.mcad.ibm.com/namespace: start-up-03 resourceName: no-quota-deployment-02 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..26c28c55 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 + appwrapper.mcad.ibm.com/namespace: quota-errors + resourceName: deployment-silver-lo-pri-1replica status: availableReplicas: 1 observedGeneration: 1 diff --git a/test/e2e/util.go b/test/e2e/util.go index e517f681..aa91fd6e 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -1512,6 +1512,7 @@ func createGenericServiceAWWithNoStatus(context *context, name string) *arbv1.Ap "metadata": { "labels": { "appwrapper.mcad.ibm.com": "test-dep-job-item", + "appwrapper.mcad.ibm.com/namespace": "test", "resourceName": "test-dep-job-item-svc" }, "name": "test-dep-job-item-svc",