Skip to content

Commit 9c6df7d

Browse files
authored
[BRE-1272] Adding custom label support for SM operator (#364)
1 parent 428758f commit 9c6df7d

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

.github/workflows/tests.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,32 @@ jobs:
219219
exit 1
220220
fi
221221
222+
echo "*****VERIFYING CUSTOM LABELS*****"
223+
224+
# Array of resource types to check for custom labels
225+
resource_types=("deployment" "service" "serviceaccount" "configmap")
226+
failed_resources=()
227+
228+
# Loop through each resource type and verify custom labels
229+
for resource_type in "${resource_types[@]}"; do
230+
echo "Checking $resource_type for custom labels..."
231+
labels=$(kubectl get "$resource_type" -l app.kubernetes.io/name=sm-operator -o jsonpath='{.items[0].metadata.labels}')
232+
echo "$resource_type labels: $labels"
233+
234+
if ! echo "$labels" | grep -q "test-label"; then
235+
echo "::error::Custom label 'test-label' not found on $resource_type."
236+
failed_resources+=("$resource_type")
237+
fi
238+
done
239+
240+
# Exit if any resources failed the check
241+
if [ ${#failed_resources[@]} -gt 0 ]; then
242+
echo "::error::Custom labels verification failed for: ${failed_resources[*]}"
243+
exit 1
244+
fi
245+
246+
echo "Custom labels verified successfully on all resources!"
247+
222248
echo "*****CREATING AUTH SECRET*****"
223249
kubectl create secret generic bw-auth-token -n bitwarden --from-literal=token="$AUTH_TOKEN"
224250
echo "*****CREATING BW SECRET*****"

charts/sm-operator/ci/test-values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Custom labels to be applied to all resources created by the operator
2+
# These labels are used in CI testing to verify the custom label feature works correctly
3+
commonLabels:
4+
test-label: test-value
5+
16
settings:
27
# How often the secrets synchronize in seconds. Minimum value is 180.
38
bwSecretsManagerRefreshInterval: 300

charts/sm-operator/templates/_helpers.tpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ helm.sh/chart: {{ include "sm-operator.chart" . }}
4040
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
4141
{{- end }}
4242
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- with .Values.commonLabels }}
44+
{{ toYaml . }}
45+
{{- end }}
4346
{{- end }}
4447

4548
{{/*

charts/sm-operator/values.schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema",
33
"properties": {
4+
"commonLabels": {
5+
"type": "object",
6+
"additionalProperties": {
7+
"type": "string"
8+
},
9+
"default": {}
10+
},
411
"containers": {
512
"properties": {
613
"manager": {

charts/sm-operator/values.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ settings:
1414
# The number of operator pod replicas to run. When in doubt, leave at 1
1515
replicas: 1
1616

17+
# Optional: Custom labels to be applied to all resources created by the operator
18+
# This can be used to identify the Bitwarden Secrets Manager project or for any other labeling needs
19+
# Example:
20+
# commonLabels:
21+
# custom-label: custom-label-value
22+
commonLabels: {}
23+
1724
# Settings specific to the pod containers
1825
containers:
1926
manager:

0 commit comments

Comments
 (0)