Skip to content

Commit dc74518

Browse files
authored
Merge pull request #152 from greut/fix/argocd-labels
feat: allow to customize the blocked labels
2 parents da9b4ee + b051595 commit dc74518

File tree

8 files changed

+39
-20
lines changed

8 files changed

+39
-20
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
IMG_NAMESPACE = flag5
22
IMG_NAME = clustersecret
33
IMG_FQNAME = $(IMG_NAMESPACE)/$(IMG_NAME)
4-
IMG_VERSION = 0.0.12
4+
IMG_VERSION = 0.0.13
55

66
.PHONY: container push clean
77
all: container

charts/cluster-secret/Chart.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ name: cluster-secret
33
description: ClusterSecret Operator
44
kubeVersion: '>= 1.25.0-0'
55
type: application
6-
version: 0.4.5
6+
version: 0.5.0
77
icon: https://clustersecret.com/assets/csninjasmall.png
88
sources:
99
- https://github.com/zakkg3/ClusterSecret
10-
appVersion: "0.0.12"
10+
appVersion: "0.0.13"
1111
maintainers:
1212
1313
name: zakkg3

charts/cluster-secret/templates/deployment.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ spec:
3535
{{- end }}
3636
containers:
3737
- env:
38+
{{- .Values.env | toYaml | nindent 8 }}
3839
- name: KUBERNETES_CLUSTER_DOMAIN
3940
value: {{ .Values.kubernetesClusterDomain }}
4041
- name: CLUSTER_SECRET_VERSION

charts/cluster-secret/values.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ image:
99
# It can also be replaced, just set value to true.
1010
replace_existing: 'false'
1111

12+
env:
13+
- name: BLOCKED_LABELS
14+
value: app.kubernetes.io # a comma (,) separated list
15+
1216
kubernetesClusterDomain: cluster.local
1317

1418
nodeSelector: {}

src/consts.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99

1010
CLUSTER_SECRET_LABEL = "clustersecret.io"
1111

12-
BLACK_LISTED_ANNOTATIONS = ["kopf.zalando.org", "kubectl.kubernetes.io"]
13-
BLACK_LISTED_LABELS = ["app.kubernetes.io"]
12+
BLOCKED_ANNOTATIONS = ["kopf.zalando.org", "kubectl.kubernetes.io"]
13+
14+
BLOCKED_LABELS = ["app.kubernetes.io"]

src/kubernetes_utils.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import kopf
77
from kubernetes.client import CoreV1Api, CustomObjectsApi, exceptions, V1ObjectMeta, rest, V1Secret
88

9-
from os_utils import get_replace_existing, get_version
10-
from consts import CREATE_BY_ANNOTATION, LAST_SYNC_ANNOTATION, VERSION_ANNOTATION, BLACK_LISTED_ANNOTATIONS, \
11-
BLACK_LISTED_LABELS, CREATE_BY_AUTHOR, CLUSTER_SECRET_LABEL
9+
from os_utils import get_blocked_labels, get_replace_existing, get_version
10+
from consts import CREATE_BY_ANNOTATION, LAST_SYNC_ANNOTATION, VERSION_ANNOTATION, BLOCKED_ANNOTATIONS, \
11+
CREATE_BY_AUTHOR, CLUSTER_SECRET_LABEL
1212

1313

1414
def patch_clustersecret_status(
@@ -309,8 +309,8 @@ def filter_dict(
309309
LAST_SYNC_ANNOTATION: datetime.now().isoformat(),
310310
}
311311

312-
_annotations = filter_dict(BLACK_LISTED_ANNOTATIONS, base_annotations, annotations)
313-
_labels = filter_dict(BLACK_LISTED_LABELS, base_labels, labels)
312+
_annotations = filter_dict(BLOCKED_ANNOTATIONS, base_annotations, annotations)
313+
_labels = filter_dict(get_blocked_labels(), base_labels, labels)
314314
return V1ObjectMeta(
315315
name=name,
316316
namespace=namespace,

src/os_utils.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
import os
2+
from functools import cache
23

4+
from consts import BLOCKED_LABELS
35

6+
7+
@cache
48
def get_version() -> str:
59
"""
610
Wrapper for CLUSTER_SECRET_VERSION variable environment
711
"""
812
return os.getenv('CLUSTER_SECRET_VERSION', '0')
913

1014

15+
@cache
1116
def get_replace_existing() -> bool:
12-
1317
replace_existing = os.getenv('REPLACE_EXISTING', 'false')
1418
return replace_existing.lower() == 'true'
1519

1620

21+
@cache
22+
def get_blocked_labels() -> list[str]:
23+
if blocked_labels := os.getenv('BLOCKED_LABELS'):
24+
return [label.strip() for label in blocked_labels.split(',')]
25+
26+
return BLOCKED_LABELS
27+
28+
29+
@cache
1730
def in_cluster() -> bool:
1831
"""
1932
Whether we are running in cluster (on the pod) or outside (debug mode.)

src/tests/test_kubernetes_utils.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
from kubernetes.client import V1ObjectMeta
88

9-
from consts import CREATE_BY_ANNOTATION, LAST_SYNC_ANNOTATION, VERSION_ANNOTATION, BLACK_LISTED_ANNOTATIONS, \
10-
BLACK_LISTED_LABELS, CREATE_BY_AUTHOR, CLUSTER_SECRET_LABEL
9+
from consts import CREATE_BY_ANNOTATION, LAST_SYNC_ANNOTATION, VERSION_ANNOTATION, BLOCKED_ANNOTATIONS, \
10+
CREATE_BY_AUTHOR, CLUSTER_SECRET_LABEL
1111
from kubernetes_utils import get_ns_list, create_secret_metadata
12-
from os_utils import get_version
12+
from os_utils import get_version, get_blocked_labels
1313

1414
USER_NAMESPACE_COUNT = 10
1515
initial_namespaces = ['default', 'kube-node-lease', 'kube-public', 'kube-system']
@@ -99,9 +99,9 @@ def test_create_secret_metadata(self) -> None:
9999
(LAST_SYNC_ANNOTATION, is_iso_format)
100100
]
101101

102-
attributes_black_lists = dict(
103-
labels=BLACK_LISTED_LABELS,
104-
annotations=BLACK_LISTED_ANNOTATIONS,
102+
attributes_blocked_lists = dict(
103+
labels=get_blocked_labels(),
104+
annotations=BLOCKED_ANNOTATIONS,
105105
)
106106

107107
test_cases: list[Tuple[dict[str, str], dict[str, str]]] = [
@@ -140,15 +140,15 @@ def test_create_secret_metadata(self) -> None:
140140

141141
self.assertIsInstance(obj=subject, cls=V1ObjectMeta, msg='returned value has correct type')
142142

143-
for attribute, black_list in attributes_black_lists.items():
143+
for attribute, blocked_list in attributes_blocked_lists.items():
144144
attribute_object = subject.__getattribute__(attribute)
145145
self.assertIsNotNone(obj=attribute_object, msg=f'attribute "{attribute}" is not None')
146146

147147
for key in attribute_object.keys():
148148
self.assertIsInstance(obj=key, cls=str, msg=f'the {attribute} key is a string')
149-
for black_listed_label_prefix in black_list:
149+
for blocked_listed_label_prefix in blocked_list:
150150
self.assertFalse(
151-
expr=key.startswith(black_listed_label_prefix),
151+
expr=key.startswith(blocked_listed_label_prefix),
152152
msg=f'{attribute} key does not match black listed prefix'
153153
)
154154

0 commit comments

Comments
 (0)