Skip to content

Commit 2609949

Browse files
committed
allow empty object digest generation for annotations
1 parent 1bf14b6 commit 2609949

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

charts/fluent-bit.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ existingConfigMap: fluent-bit
66

77
podAnnotations:
88
checksum/config: '__slot__:salt:metalk8s_kubernetes.get_object_digest(kind="ConfigMap", apiVersion="v1", namespace="metalk8s-logging", name="fluent-bit", path="data:fluent-bit.conf")'
9-
checksum/secret: '__slot__:salt:metalk8s_kubernetes.get_object_digest(kind="Secret", apiVersion="v1", namespace="metalk8s-logging", name="fluent-bit-certs")'
9+
checksum/secret: '__slot__:salt:metalk8s_kubernetes.get_object_digest(kind="Secret", apiVersion="v1", namespace="metalk8s-logging", name="fluent-bit-certs", path="data", allow_empty=True)'
1010

1111
resources: '__var__(fluent_bit.spec.deployment.resources)'
1212

salt/_modules/metalk8s_kubernetes.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def list_objects(
410410
return result.to_dict()["items"]
411411

412412

413-
def get_object_digest(path=None, checksum="sha256", *args, **kwargs):
413+
def get_object_digest(allow_empty=False, path=None, checksum="sha256", *args, **kwargs):
414414
"""
415415
Helper to get the digest of one kubernetes object or from a specific key
416416
of this object using a path
@@ -432,7 +432,11 @@ def get_object_digest(path=None, checksum="sha256", *args, **kwargs):
432432
obj = salt.utils.data.traverse_dict_and_list(obj, path, delimiter=":")
433433

434434
if not obj:
435-
raise CommandExecutionError(f'Unable to find key "{path}" in the object')
435+
if not allow_empty:
436+
raise CommandExecutionError(
437+
f'Unable to find key "{path}" in the object'
438+
)
439+
return ""
436440

437441
if isinstance(obj, dict):
438442
obj = json.dumps(obj, sort_keys=True)

salt/metalk8s/addons/logging/fluent-bit/deployed/chart.sls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,8 @@ spec:
16971697
checksum/config: __slot__:salt:metalk8s_kubernetes.get_object_digest(kind="ConfigMap",
16981698
apiVersion="v1", namespace="metalk8s-logging", name="fluent-bit", path="data:fluent-bit.conf")
16991699
checksum/secret: __slot__:salt:metalk8s_kubernetes.get_object_digest(kind="Secret",
1700-
apiVersion="v1", namespace="metalk8s-logging", name="fluent-bit-certs")
1700+
apiVersion="v1", namespace="metalk8s-logging", name="fluent-bit-certs",
1701+
path="data", allow_empty=True)
17011702
labels:
17021703
app.kubernetes.io/instance: fluent-bit
17031704
app.kubernetes.io/name: fluent-bit

salt/metalk8s/addons/logging/fluent-bit/deployed/secret.sls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Create metalk8s-fluent-bit-certs Secret:
1919
metadata:
2020
name: fluent-bit-certs
2121
namespace: metalk8s-logging
22+
data: {}
2223

2324
{%- else %}
2425

salt/tests/unit/modules/files/test_metalk8s_kubernetes.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,17 @@ get_object_digest:
702702
raises: True
703703
result: 'Unable to find key "metadata:invalid:path" in the object'
704704

705+
# allow_empty = true and path points to an empty dict
706+
- obj:
707+
apiVersion: v1
708+
kind: Secret
709+
metadata:
710+
name: my_secret
711+
data: {}
712+
path: 'data'
713+
allow_empty: True
714+
result: ''
715+
705716
check_object_ready:
706717
# Simple Pod Ready
707718
- obj:

0 commit comments

Comments
 (0)