Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(komodor-agent): Support custom labels #320

Merged
merged 3 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .buildkite/tests/values_components_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ def test_override_deployment_pod_annotations():
assert pod_annotations == value, f"Expected {value} in pod annotations {pod_annotations}"


def run_label_test(set_path, value, deployment_name, resource_type):
set_command = f"{set_path}={value}"
results = get_yaml_from_helm_template(set_command, resource_type, deployment_name, "spec.template.metadata.labels.test")
assert results == value, f"Expected {value} in pod labels {results}"


@pytest.mark.parametrize("set_path, value, deployment_name, resource_type", [
("components.komodorAgent.labels.test", "test_value", f"{RELEASE_NAME}-komodor-agent", "Deployment"),
("components.komodorDaemon.labels.test", "test_value", f"{RELEASE_NAME}-komodor-agent-daemon", "DaemonSet"),
("components.komodorDaemonWindows.labels.test", "test_value", f"{RELEASE_NAME}-komodor-agent-daemon-windows", "DaemonSet"),
])
def test_user_labels(set_path, value, deployment_name, resource_type):
run_label_test(set_path, value, deployment_name, resource_type)


def test_override_deployment_tolerations():
values_file = """
components:
Expand Down
7 changes: 5 additions & 2 deletions charts/komodor-agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ The command removes all the Kubernetes components associated with the chart and
| components.komodorAgent | object | See sub-values | Configure the komodor agent components |
| components.komodorAgent.affinity | object | `{}` | Set node affinity for the komodor agent deployment |
| components.komodorAgent.annotations | object | `{}` | Set annotations for the komodor agent deployment |
| components.komodorAgent.labels | object | `{}` | Set custom labels |
| components.komodorAgent.nodeSelector | object | `{}` | Set node selectors for the komodor agent deployment |
| components.komodorAgent.tolerations | list | `[]` | Set tolerations for the komodor agent deployment |
| components.komodorAgent.podAnnotations | object | `{}` | Set pod annotations for the komodor agent deployment |
Expand All @@ -154,7 +155,8 @@ The command removes all the Kubernetes components associated with the chart and
| components.komodorAgent.networkMapper.resources | object | `{}` | Set custom resources to the komodor agent network mapper container |
| components.komodorDaemon | object | See sub-values | Configure the komodor agent components |
| components.komodorDaemon.affinity | object | `{}` | Set node affinity for the komodor agent daemon |
| components.komodorDaemon.annotations | object | `{}` | Adds custom annotations - Example: `--set podAnnotations."app\.komodor\.com/app"="komodor-agent"` |
| components.komodorDaemon.annotations | object | `{}` | Adds custom annotations - Example: `--set annotations."app\.komodor\.com/app"="komodor-agent"` |
| components.komodorDaemon.labels | object | `{}` | Adds custom labels |
| components.komodorDaemon.nodeSelector | object | `{}` | Set node selectors for the komodor agent daemon |
| components.komodorDaemon.tolerations | list | `[]` | Add tolerations to the komodor agent daemon |
| components.komodorDaemon.podAnnotations | object | `{}` | # Add annotations to the komodor agent watcher pod |
Expand All @@ -175,7 +177,8 @@ The command removes all the Kubernetes components associated with the chart and
| components.komodorDaemon.nodeEnricher.extraEnvVars | list | `[]` | List of additional environment variables, Each entry is a key-value pair |
| components.komodorDaemonWindows | object | See sub-values | Configure the komodor agent components |
| components.komodorDaemonWindows.affinity | object | `{}` | Set node affinity for the komodor agent daemon |
| components.komodorDaemonWindows.annotations | object | `{}` | Adds custom annotations - Example: `--set podAnnotations."app\.komodor\.com/app"="komodor-agent"` |
| components.komodorDaemonWindows.annotations | object | `{}` | Adds custom annotations - Example: `--set annotations."app\.komodor\.com/app"="komodor-agent"` |
| components.komodorDaemonWindows.labels | object | `{}` | Adds custom labels |
| components.komodorDaemonWindows.nodeSelector | object | `{}` | Set node selectors for the komodor agent daemon |
| components.komodorDaemonWindows.tolerations | list | `[]` | Add tolerations to the komodor agent daemon |
| components.komodorDaemonWindows.podAnnotations | object | `{}` | # Add annotations to the komodor agent watcher pod |
Expand Down
17 changes: 17 additions & 0 deletions charts/komodor-agent/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,20 @@ app.kubernetes.io/name: {{ include "komodorAgent.name" . }}-daemon-windows
app.kubernetes.io/instance: {{ .Release.Name }}-daemon-windows
{{- end }}

{{- define "KomodorDaemon.user.labels" -}}
{{- if not (empty (((.Values.components).komodorDaemon).labels)) }}
{{ toYaml .Values.components.komodorDaemon.labels }}
{{- end }}
{{- end}}

{{- define "komodorAgent.user.labels" -}}
{{- if not (empty (((.Values.components).komodorAgent).labels)) }}
{{ toYaml .Values.components.komodorAgent.labels }}
{{- end }}
{{- end}}

{{- define "komodorDaemonWindows.user.labels" -}}
{{- if not (empty (((.Values.components).komodorDaemonWindows).labels)) }}
{{ toYaml .Values.components.komodorDaemonWindows.labels }}
{{- end }}
{{- end}}
6 changes: 5 additions & 1 deletion charts/komodor-agent/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ metadata:
name: {{ include "komodorAgent.fullname" . }}-daemon
labels:
{{- include "komodorAgentDaemon.labels" . | nindent 4 }}
{{- include "KomodorDaemon.user.labels" . | nindent 4 }}

{{- if not (empty ((.Values.components).komodorDaemon).annotations) }}
annotations: {{ toYaml ((.Values.components).komodorDaemon).annotations | nindent 4 }}
{{- end }}
Expand All @@ -18,7 +20,9 @@ spec:
{{- if not (empty (((.Values.components).komodorDaemon).podAnnotations)) }}
{{- toYaml .Values.components.komodorDaemon.podAnnotations | trim | nindent 8 }}
{{- end }}
labels: {{- include "komodorAgentDaemon.selectorLabels" . | nindent 8 }}
labels:
{{- include "komodorAgentDaemon.selectorLabels" . | nindent 8 }}
{{- include "KomodorDaemon.user.labels" . | nindent 8 }}
spec:
{{- include "network_mapper.daemonset.network" . | nindent 6 }}

Expand Down
5 changes: 4 additions & 1 deletion charts/komodor-agent/templates/daemonset_windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
name: {{ include "komodorAgent.fullname" . }}-daemon-windows
labels:
{{- include "komodorAgentDaemonWindows.labels" . | nindent 4 }}
{{- include "komodorDaemonWindows.user.labels" . | nindent 4 }}
{{- if not (empty ((.Values.components).komodorDaemonWindows).annotations) }}
annotations: {{ toYaml ((.Values.components).komodorDaemonWindows).annotations | nindent 4 }}
{{- end }}
Expand All @@ -18,7 +19,9 @@ spec:
{{- if not (empty (((.Values.components).komodorDaemonWindows).podAnnotations)) }}
{{- toYaml .Values.components.komodorDaemonWindows.podAnnotations | trim | nindent 8 }}
{{- end }}
labels: {{- include "komodorAgentDaemonWindows.selectorLabels" . | nindent 8 }}
labels:
{{- include "komodorAgentDaemonWindows.selectorLabels" . | nindent 8 }}
{{- include "komodorDaemonWindows.user.labels" . | nindent 8 }}
spec:
terminationGracePeriodSeconds: 0
priorityClassName: {{ .Release.Name }}-daemon-high-priority
Expand Down
2 changes: 2 additions & 0 deletions charts/komodor-agent/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: {{ include "komodorAgent.fullname" . }}
labels:
{{- include "komodorAgent.labels" . | nindent 4 }}
{{- include "komodorAgent.user.labels" . | nindent 4 }}
annotations:
{{ toYaml .Values.components.komodorAgent.annotations | nindent 4 }}
spec:
Expand All @@ -24,6 +25,7 @@ spec:
{{- end }}
labels:
{{- include "komodorAgent.selectorLabels" . | nindent 8 }}
{{- include "komodorAgent.user.labels" . | nindent 8 }}
spec:
priorityClassName: {{ .Release.Name }}-agent-high-priority
serviceAccountName: {{ include "komodorAgent.serviceAccountName" . }}
Expand Down
1 change: 1 addition & 0 deletions charts/komodor-agent/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
name: {{ include "komodorAgent.serviceAccountName" . }}
labels:
{{- include "komodorAgent.labels" . | nindent 4 }}
{{- include "komodorAgent.user.labels" . | nindent 4 }}
annotations:
{{- toYaml .Values.components.komodorAgent.annotations | nindent 4 }}
{{- end }}
Expand Down
10 changes: 8 additions & 2 deletions charts/komodor-agent/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ components:
affinity: {}
# components.komodorAgent.annotations -- Set annotations for the komodor agent deployment
annotations: {}
# components.komodorAgent.labels -- Set custom labels
labels: {}
# components.komodorAgent.nodeSelector -- Set node selectors for the komodor agent deployment
nodeSelector: {}
# components.komodorAgent.tolerations -- Set tolerations for the komodor agent deployment
Expand Down Expand Up @@ -169,8 +171,10 @@ components:
komodorDaemon:
# components.komodorDaemon.affinity -- Set node affinity for the komodor agent daemon
affinity: {}
# components.komodorDaemon.annotations -- Adds custom annotations - Example: `--set podAnnotations."app\.komodor\.com/app"="komodor-agent"`
# components.komodorDaemon.annotations -- Adds custom annotations - Example: `--set annotations."app\.komodor\.com/app"="komodor-agent"`
annotations: {}
# components.komodorDaemon.labels -- Adds custom labels
labels: {}
# components.komodorDaemon.nodeSelector -- Set node selectors for the komodor agent daemon
nodeSelector: {}
# components.komodorDaemon.tolerations -- Add tolerations to the komodor agent daemon
Expand Down Expand Up @@ -241,8 +245,10 @@ components:
komodorDaemonWindows:
# components.komodorDaemonWindows.affinity -- Set node affinity for the komodor agent daemon
affinity: { }
# components.komodorDaemonWindows.annotations -- Adds custom annotations - Example: `--set podAnnotations."app\.komodor\.com/app"="komodor-agent"`
# components.komodorDaemonWindows.annotations -- Adds custom annotations - Example: `--set annotations."app\.komodor\.com/app"="komodor-agent"`
annotations: { }
# components.komodorDaemonWindows.labels -- Adds custom labels
labels: { }
# components.komodorDaemonWindows.nodeSelector -- Set node selectors for the komodor agent daemon
nodeSelector: { }
# components.komodorDaemonWindows.tolerations -- Add tolerations to the komodor agent daemon
Expand Down