Created
April 19, 2023 16:38
-
-
Save pivotaljohn/221cd4961a4f1ab6c5ad1386f1504554 to your computer and use it in GitHub Desktop.
Purge labels from multiple paths
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kind: Widget | |
metadata: | |
name: foo-with-more-than-all-labels | |
labels: | |
label0: value0 | |
label1: value1 | |
label2: value2 | |
label3: value3 | |
label4: value4 | |
--- | |
kind: Widget | |
metadata: | |
name: foo-with-all-labels | |
labels: | |
label1: value1 | |
label2: value2 | |
label3: value3 | |
--- | |
kind: Widget | |
metadata: | |
name: foo-with-some-labels | |
labels: | |
label2: value2 | |
label3: value3 | |
--- | |
kind: Widget | |
metadata: | |
name: foo-with-none-of-labels | |
labels: | |
labelX: valueX | |
labelY: valueY | |
--- | |
kind: Widget | |
metadata: | |
name: foo-without-labels | |
--- | |
kind: Service | |
metadata: | |
name: bar-with-more-than-all-labels | |
spec: | |
selector: | |
matchLabels: | |
label0: value0 | |
label1: value1 | |
label2: value2 | |
label3: value3 | |
label4: value4 | |
--- | |
kind: Service | |
metadata: | |
name: bar-with-all-labels | |
spec: | |
selector: | |
matchLabels: | |
label1: value1 | |
label2: value2 | |
label3: value3 | |
--- | |
kind: Service | |
metadata: | |
name: bar-with-some-labels | |
spec: | |
selector: | |
matchLabels: | |
label2: value2 | |
label3: value3 | |
--- | |
kind: Service | |
metadata: | |
name: bar-with-none-of-labels | |
spec: | |
selector: | |
matchLabels: | |
labelX: valueX | |
labelY: valueY | |
--- | |
kind: Service | |
metadata: | |
name: bar-without-labels | |
spec: | |
selector: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@ load("@ytt:overlay", "overlay") | |
#@ def remove_labels(): | |
#@overlay/remove | |
label1: | |
#@overlay/remove | |
label2: | |
#@overlay/remove | |
label3: | |
#@ end | |
#@overlay/match by=overlay.all, expects="1+" | |
#@overlay/match-child-defaults when=1 | |
--- | |
metadata: | |
labels: #@ remove_labels() | |
spec: | |
selector: | |
matchLabels: #@ remove_labels() | |
#! Remove empty collections of labels | |
#@ is_empty=lambda _, left, __: len(left) == 0 | |
#@overlay/match by=overlay.all, expects="1+" | |
#@overlay/match-child-defaults when=1 | |
--- | |
metadata: | |
#@overlay/match by=is_empty | |
#@overlay/remove | |
labels: | |
spec: | |
selector: | |
#@overlay/match by=is_empty | |
#@overlay/remove | |
matchLabels: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment