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 23, 2023
1 parent 83467cd commit 441402a
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")

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", 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
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[appwrapperJobLabelNamespace] = aw.Namespace
labels[resourceName] = unstruct.GetName()
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", 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
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 Expand Up @@ -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)
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 @@ -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
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 @@ -13,27 +13,30 @@ 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:
- 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
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
14 changes: 7 additions & 7 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,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

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 @@ -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
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 @@ -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
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
appwrapper.mcad.ibm.com/namespace: quota-errors
resourceName: deployment-silver-lo-pri-1replica
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 @@ -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",
Expand Down

0 comments on commit 441402a

Please sign in to comment.