Skip to content

Commit

Permalink
add annotations and labels to object (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
pasha-codefresh authored Sep 11, 2023
1 parent 01f52e8 commit 6138725
Show file tree
Hide file tree
Showing 17 changed files with 1,124 additions and 687 deletions.
14 changes: 14 additions & 0 deletions assets/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -8415,6 +8415,13 @@
"type": "object",
"title": "ResourceNode contains information about live resource and its children\nTODO: describe members of this type",
"properties": {
"annotations": {
"type": "object",
"title": "available for managed resource without k8s-last-applied-configuration",
"additionalProperties": {
"type": "string"
}
},
"createdAt": {
"$ref": "#/definitions/v1Time"
},
Expand All @@ -8433,6 +8440,13 @@
"$ref": "#/definitions/v1alpha1InfoItem"
}
},
"labels": {
"type": "object",
"title": "available for managed resource",
"additionalProperties": {
"type": "string"
}
},
"networkingInfo": {
"$ref": "#/definitions/v1alpha1ResourceNetworkingInfo"
},
Expand Down
13 changes: 11 additions & 2 deletions controller/appcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,24 @@ func (ctrl *ApplicationController) getResourceTree(a *appv1.Application, managed
}

if live == nil {
nodes = append(nodes, appv1.ResourceNode{
newNode := appv1.ResourceNode{
ResourceRef: appv1.ResourceRef{
Version: target.GroupVersionKind().Version,
Name: managedResource.Name,
Kind: managedResource.Kind,
Group: managedResource.Group,
Namespace: managedResource.Namespace,
},
})
}

if targetLabels := target.GetLabels(); targetLabels != nil {
newNode.Labels = targetLabels
}
if targetAnnotations := target.GetAnnotations(); targetAnnotations != nil {
newNode.Annotations = targetAnnotations
}

nodes = append(nodes, newNode)
} else {
err := ctrl.stateCache.IterateHierarchy(a.Spec.Destination.Server, kube.GetResourceKey(live), func(child appv1.ResourceNode, appName string) bool {
permitted, _ := proj.IsResourcePermitted(schema.GroupKind{Group: child.ResourceRef.Group, Kind: child.ResourceRef.Kind}, child.Namespace, a.Spec.Destination, func(project string) ([]*appv1.Cluster, error) {
Expand Down
3 changes: 3 additions & 0 deletions controller/appcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,9 @@ func TestGetResourceTree_HasOrphanedResources(t *testing.T) {

managedDeploy := v1alpha1.ResourceNode{
ResourceRef: v1alpha1.ResourceRef{Group: "apps", Kind: "Deployment", Namespace: "default", Name: "nginx-deployment", Version: "v1"},
Labels: map[string]string{
"app": "nginx",
},
}
orphanedDeploy1 := v1alpha1.ResourceNode{
ResourceRef: v1alpha1.ResourceRef{Group: "apps", Kind: "Deployment", Namespace: "default", Name: "deploy1"},
Expand Down
14 changes: 13 additions & 1 deletion controller/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func asResourceNode(r *clustercache.Resource) appv1.ResourceNode {
if resourceInfo.Health != nil {
resHealth = &appv1.HealthStatus{Status: resourceInfo.Health.Status, Message: resourceInfo.Health.Message}
}
return appv1.ResourceNode{
result := appv1.ResourceNode{
ResourceRef: appv1.ResourceRef{
UID: string(r.Ref.UID),
Name: r.Ref.Name,
Expand All @@ -265,6 +265,18 @@ func asResourceNode(r *clustercache.Resource) appv1.ResourceNode {
Health: resHealth,
CreatedAt: r.CreationTimestamp,
}

if r.Resource != nil {
if labels := r.Resource.GetLabels(); labels != nil {
result.Labels = labels
}
if annotations := r.Resource.GetAnnotations(); annotations != nil {
delete(annotations, "kubectl.kubernetes.io/last-applied-configuration")
result.Annotations = annotations
}
}

return result
}

func resInfo(r *clustercache.Resource) *ResourceInfo {
Expand Down
2 changes: 1 addition & 1 deletion manifests/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Kustomization
images:
- name: quay.io/argoproj/argocd
newName: quay.io/codefresh/argocd
newTag: v2.8.1-cap-CR-19754-deletion-fix
newTag: latest
resources:
- ./application-controller
- ./dex
Expand Down
6 changes: 3 additions & 3 deletions manifests/core-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19577,7 +19577,7 @@ spec:
value: /helm-working-dir
- name: HELM_DATA_HOME
value: /helm-working-dir
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
livenessProbe:
failureThreshold: 3
Expand Down Expand Up @@ -19629,7 +19629,7 @@ spec:
- -n
- /usr/local/bin/argocd
- /var/run/argocd/argocd-cmp-server
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
name: copyutil
securityContext:
allowPrivilegeEscalation: false
Expand Down Expand Up @@ -19847,7 +19847,7 @@ spec:
key: controller.kubectl.parallelism.limit
name: argocd-cmd-params-cm
optional: true
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
name: argocd-application-controller
ports:
Expand Down
2 changes: 1 addition & 1 deletion manifests/core-install/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ resources:
images:
- name: quay.io/argoproj/argocd
newName: quay.io/codefresh/argocd
newTag: v2.8.1-cap-CR-19754-deletion-fix
newTag: latest
2 changes: 1 addition & 1 deletion manifests/ha/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ patches:
images:
- name: quay.io/argoproj/argocd
newName: quay.io/codefresh/argocd
newTag: v2.8.1-cap-CR-19754-deletion-fix
newTag: latest
resources:
- ../../base/application-controller
- ../../base/applicationset-controller
Expand Down
10 changes: 5 additions & 5 deletions manifests/ha/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20543,7 +20543,7 @@ spec:
- -n
- /usr/local/bin/argocd
- /shared/argocd-dex
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
name: copyutil
securityContext:
Expand Down Expand Up @@ -20855,7 +20855,7 @@ spec:
value: /helm-working-dir
- name: HELM_DATA_HOME
value: /helm-working-dir
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
livenessProbe:
failureThreshold: 3
Expand Down Expand Up @@ -20907,7 +20907,7 @@ spec:
- -n
- /usr/local/bin/argocd
- /var/run/argocd/argocd-cmp-server
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
name: copyutil
securityContext:
allowPrivilegeEscalation: false
Expand Down Expand Up @@ -21202,7 +21202,7 @@ spec:
key: server.enable.proxy.extension
name: argocd-cmd-params-cm
optional: true
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
livenessProbe:
httpGet:
Expand Down Expand Up @@ -21450,7 +21450,7 @@ spec:
key: controller.kubectl.parallelism.limit
name: argocd-cmd-params-cm
optional: true
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
name: argocd-application-controller
ports:
Expand Down
10 changes: 5 additions & 5 deletions manifests/ha/namespace-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,7 @@ spec:
- -n
- /usr/local/bin/argocd
- /shared/argocd-dex
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
name: copyutil
securityContext:
Expand Down Expand Up @@ -1956,7 +1956,7 @@ spec:
value: /helm-working-dir
- name: HELM_DATA_HOME
value: /helm-working-dir
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
livenessProbe:
failureThreshold: 3
Expand Down Expand Up @@ -2008,7 +2008,7 @@ spec:
- -n
- /usr/local/bin/argocd
- /var/run/argocd/argocd-cmp-server
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
name: copyutil
securityContext:
allowPrivilegeEscalation: false
Expand Down Expand Up @@ -2303,7 +2303,7 @@ spec:
key: server.enable.proxy.extension
name: argocd-cmd-params-cm
optional: true
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
livenessProbe:
httpGet:
Expand Down Expand Up @@ -2551,7 +2551,7 @@ spec:
key: controller.kubectl.parallelism.limit
name: argocd-cmd-params-cm
optional: true
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
name: argocd-application-controller
ports:
Expand Down
10 changes: 5 additions & 5 deletions manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19644,7 +19644,7 @@ spec:
- -n
- /usr/local/bin/argocd
- /shared/argocd-dex
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
name: copyutil
securityContext:
Expand Down Expand Up @@ -19910,7 +19910,7 @@ spec:
value: /helm-working-dir
- name: HELM_DATA_HOME
value: /helm-working-dir
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
livenessProbe:
failureThreshold: 3
Expand Down Expand Up @@ -19962,7 +19962,7 @@ spec:
- -n
- /usr/local/bin/argocd
- /var/run/argocd/argocd-cmp-server
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
name: copyutil
securityContext:
allowPrivilegeEscalation: false
Expand Down Expand Up @@ -20248,7 +20248,7 @@ spec:
key: server.enable.proxy.extension
name: argocd-cmd-params-cm
optional: true
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
livenessProbe:
httpGet:
Expand Down Expand Up @@ -20494,7 +20494,7 @@ spec:
key: controller.kubectl.parallelism.limit
name: argocd-cmd-params-cm
optional: true
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
name: argocd-application-controller
ports:
Expand Down
10 changes: 5 additions & 5 deletions manifests/namespace-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ spec:
- -n
- /usr/local/bin/argocd
- /shared/argocd-dex
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
name: copyutil
securityContext:
Expand Down Expand Up @@ -1011,7 +1011,7 @@ spec:
value: /helm-working-dir
- name: HELM_DATA_HOME
value: /helm-working-dir
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
livenessProbe:
failureThreshold: 3
Expand Down Expand Up @@ -1063,7 +1063,7 @@ spec:
- -n
- /usr/local/bin/argocd
- /var/run/argocd/argocd-cmp-server
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
name: copyutil
securityContext:
allowPrivilegeEscalation: false
Expand Down Expand Up @@ -1349,7 +1349,7 @@ spec:
key: server.enable.proxy.extension
name: argocd-cmd-params-cm
optional: true
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
livenessProbe:
httpGet:
Expand Down Expand Up @@ -1595,7 +1595,7 @@ spec:
key: controller.kubectl.parallelism.limit
name: argocd-cmd-params-cm
optional: true
image: quay.io/codefresh/argocd:v2.8.1-cap-CR-19754-deletion-fix
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
name: argocd-application-controller
ports:
Expand Down
Loading

0 comments on commit 6138725

Please sign in to comment.