Skip to content

Commit fba03e5

Browse files
msoderberglinghaoSu
authored andcommitted
feat: optionally propagate node labels to application pod view (argoproj#15274) (argoproj#23260)
Signed-off-by: Marcus Söderberg <[email protected]> Co-authored-by: Linghao Su <[email protected]> Signed-off-by: enneitex <[email protected]>
1 parent 53a5cbe commit fba03e5

File tree

18 files changed

+1100
-772
lines changed

18 files changed

+1100
-772
lines changed

assets/swagger.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controller/appcontroller.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,16 @@ func (ctrl *ApplicationController) getAppHosts(destCluster *appv1.Cluster, a *ap
774774
sort.Slice(resourcesInfo, func(i, j int) bool {
775775
return resourcesInfo[i].ResourceName < resourcesInfo[j].ResourceName
776776
})
777-
hosts = append(hosts, appv1.HostInfo{Name: nodeName, SystemInfo: node.SystemInfo, ResourcesInfo: resourcesInfo})
777+
778+
allowedNodeLabels := ctrl.settingsMgr.GetAllowedNodeLabels()
779+
nodeLabels := make(map[string]string)
780+
for _, label := range allowedNodeLabels {
781+
if val, ok := node.Labels[label]; ok {
782+
nodeLabels[label] = val
783+
}
784+
}
785+
786+
hosts = append(hosts, appv1.HostInfo{Name: nodeName, SystemInfo: node.SystemInfo, ResourcesInfo: resourcesInfo, Labels: nodeLabels})
778787
}
779788
ts.AddCheckpoint("process_app_pods_by_node_ms")
780789
return hosts, nil

controller/appcontroller_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,9 @@ func TestGetAppHosts(t *testing.T) {
22032203
Server: test.FakeClusterURL,
22042204
Revision: "abc123",
22052205
},
2206+
configMapData: map[string]string{
2207+
"application.allowedNodeLabels": "label1,label2",
2208+
},
22062209
}
22072210
ctrl := newFakeController(data, nil)
22082211
mockStateCache := &mockstatecache.LiveStateCache{}
@@ -2214,6 +2217,7 @@ func TestGetAppHosts(t *testing.T) {
22142217
Name: "minikube",
22152218
SystemInfo: corev1.NodeSystemInfo{OSImage: "debian"},
22162219
Capacity: map[corev1.ResourceName]resource.Quantity{corev1.ResourceCPU: resource.MustParse("5")},
2220+
Labels: map[string]string{"label1": "value1", "label2": "value2"},
22172221
}})
22182222

22192223
// app pod
@@ -2251,6 +2255,7 @@ func TestGetAppHosts(t *testing.T) {
22512255
ResourceName: corev1.ResourceCPU, Capacity: 5000, RequestedByApp: 1000, RequestedByNeighbors: 2000,
22522256
},
22532257
},
2258+
Labels: map[string]string{"label1": "value1", "label2": "value2"},
22542259
}}, hosts)
22552260
}
22562261

controller/cache/cache.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ type NodeInfo struct {
169169
Name string
170170
Capacity corev1.ResourceList
171171
SystemInfo corev1.NodeSystemInfo
172+
Labels map[string]string
172173
}
173174

174175
type ResourceInfo struct {

controller/cache/info.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ func populateHostNodeInfo(un *unstructured.Unstructured, res *ResourceInfo) {
472472
Name: node.Name,
473473
Capacity: node.Status.Capacity,
474474
SystemInfo: node.Status.NodeInfo,
475+
Labels: node.Labels,
475476
}
476477
}
477478

controller/cache/info_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,8 @@ apiVersion: v1
890890
kind: Node
891891
metadata:
892892
name: minikube
893+
labels:
894+
foo: bar
893895
spec: {}
894896
status:
895897
capacity:
@@ -907,6 +909,7 @@ status:
907909
Name: "minikube",
908910
Capacity: corev1.ResourceList{corev1.ResourceMemory: resource.MustParse("6091320Ki"), corev1.ResourceCPU: resource.MustParse("6")},
909911
SystemInfo: corev1.NodeSystemInfo{Architecture: "amd64", OperatingSystem: "linux", OSImage: "Ubuntu 20.04 LTS"},
912+
Labels: map[string]string{"foo": "bar"},
910913
}, info.NodeInfo)
911914
}
912915

121 KB
Loading

docs/operator-manual/argocd-cm.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ data:
277277
# If omitted, Argo CD injects the app name into the label: 'app.kubernetes.io/instance'
278278
application.instanceLabelKey: mycompany.com/appname
279279

280+
# An optional comma-separated list of node labels to propagate to the application pod view.
281+
application.allowedNodeLabels: topology.kubernetes.io/zone,node.kubernetes.io/instance-type
282+
280283
# You can change the resource tracking method Argo CD uses by changing the
281284
# setting application.resourceTrackingMethod to the desired method.
282285
# The following methods are available:

docs/operator-manual/ui-customization.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,15 @@ By default, the Application Details will show the `Tree` view.
66

77
This can be configured on an Application basis, by setting the `pref.argocd.argoproj.io/default-view` annotation, accepting one of: `tree`, `pods`, `network`, `list` as values.
88

9-
For the Pods view, the default grouping mechanism can be configured using the `pref.argocd.argoproj.io/default-pod-sort` annotation, accepting one of: `node`, `parentResource`, `topLevelResource` as values.
9+
For the Pods view, the default grouping mechanism can be configured using the `pref.argocd.argoproj.io/default-pod-sort` annotation, accepting one of: `node`, `parentResource`, `topLevelResource` as values.
10+
11+
## Node Labels in Pod View
12+
13+
It's possible to propagate node labels to node information in the pod view by configuring `applications.allowedNodeLabels` in the [argocd-cm](argocd-cm-yaml.md) ConfigMap.
14+
15+
The following configuration:
16+
```yaml
17+
application.allowedNodeLabels: topology.kubernetes.io/zone,karpenter.sh/capacity-type
18+
```
19+
Would result in:
20+
![Node Labels in Pod View](../assets/application-pod-view-node-labels.png)

0 commit comments

Comments
 (0)