Skip to content

Commit

Permalink
Merge pull request #940 from jenkins-x-plugins/accepterror
Browse files Browse the repository at this point in the history
fix: handle alias when adding annotation or label
  • Loading branch information
jenkins-x-bot authored Sep 20, 2023
2 parents 504743a + 69e05df commit 55ac383
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 10 deletions.
3 changes: 1 addition & 2 deletions pkg/cmd/annotate/testpodspec/deploy/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ metadata:
app.kubernetes.io/instance: external-dns
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: external-dns
gitops.jenkins-x.io/pipeline: namespaces
helm.sh/chart: external-dns-6.8.2
name: external-dns
namespace: jx
Expand All @@ -27,8 +26,8 @@ spec:
annotations:
prometheus.io/port: "7979"
prometheus.io/scrape: "true"
wine: 'merlot'
beer: 'stella'
wine: 'merlot'
labels:
app.kubernetes.io/instance: external-dns
app.kubernetes.io/managed-by: Helm
Expand Down
10 changes: 2 additions & 8 deletions pkg/cmd/annotate/testpodspec/deploy/source.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
labels: &test_labels
app.kubernetes.io/instance: external-dns
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: external-dns
gitops.jenkins-x.io/pipeline: namespaces
helm.sh/chart: external-dns-6.8.2
name: external-dns
namespace: jx
Expand All @@ -27,12 +26,7 @@ spec:
annotations:
prometheus.io/port: "7979"
prometheus.io/scrape: "true"
wine: "riesling"
labels:
app.kubernetes.io/instance: external-dns
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: external-dns
helm.sh/chart: external-dns-6.8.2
labels: *test_labels
spec:
affinity:
podAntiAffinity:
Expand Down
104 changes: 104 additions & 0 deletions pkg/cmd/label/testdata/deploy/expected.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/instance: external-dns
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: external-dns
helm.sh/chart: external-dns-6.8.2
beer: 'stella'
wine: 'merlot'
name: external-dns
namespace: jx
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app.kubernetes.io/instance: external-dns
app.kubernetes.io/name: external-dns
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
annotations:
prometheus.io/port: "7979"
prometheus.io/scrape: "true"
labels:
app.kubernetes.io/instance: external-dns
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: external-dns
helm.sh/chart: external-dns-6.8.2
spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/instance: external-dns
app.kubernetes.io/name: external-dns
namespaces:
- jx
topologyKey: kubernetes.io/hostname
weight: 1
containers:
- args:
- --metrics-address=:7979
- --log-level=debug
- --log-format=text
- --domain-filter=aws.ticket.se
- --policy=sync
- --provider=aws
- --registry=txt
- --interval=1m
- --source=ingress
- --source=service
- --aws-api-retries=3
- --aws-zone-type=
- --aws-batch-change-size=1000
env:
- name: AWS_DEFAULT_REGION
value: eu-north-1
image: docker.io/bitnami/external-dns:0.12.2-debian-11-r14
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 2
httpGet:
path: /healthz
port: http
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
name: external-dns
ports:
- containerPort: 7979
name: http
protocol: TCP
readinessProbe:
failureThreshold: 6
httpGet:
path: /healthz
port: http
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext:
fsGroup: 65534
runAsUser: 1001
serviceAccount: external-dns
serviceAccountName: external-dns
terminationGracePeriodSeconds: 30
104 changes: 104 additions & 0 deletions pkg/cmd/label/testdata/deploy/expectednotoverride.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/instance: external-dns
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: external-dns
helm.sh/chart: external-dns-6.8.2
beer: 'stella'
wine: 'merlot'
name: external-dns
namespace: jx
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app.kubernetes.io/instance: external-dns
app.kubernetes.io/name: external-dns
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
annotations:
prometheus.io/port: "7979"
prometheus.io/scrape: "true"
labels:
app.kubernetes.io/instance: external-dns
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: external-dns
helm.sh/chart: external-dns-6.8.2
spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/instance: external-dns
app.kubernetes.io/name: external-dns
namespaces:
- jx
topologyKey: kubernetes.io/hostname
weight: 1
containers:
- args:
- --metrics-address=:7979
- --log-level=debug
- --log-format=text
- --domain-filter=aws.ticket.se
- --policy=sync
- --provider=aws
- --registry=txt
- --interval=1m
- --source=ingress
- --source=service
- --aws-api-retries=3
- --aws-zone-type=
- --aws-batch-change-size=1000
env:
- name: AWS_DEFAULT_REGION
value: eu-north-1
image: docker.io/bitnami/external-dns:0.12.2-debian-11-r14
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 2
httpGet:
path: /healthz
port: http
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
name: external-dns
ports:
- containerPort: 7979
name: http
protocol: TCP
readinessProbe:
failureThreshold: 6
httpGet:
path: /healthz
port: http
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext:
fsGroup: 65534
runAsUser: 1001
serviceAccount: external-dns
serviceAccountName: external-dns
terminationGracePeriodSeconds: 30
98 changes: 98 additions & 0 deletions pkg/cmd/label/testdata/deploy/source.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels: &test_labels
app.kubernetes.io/instance: external-dns
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: external-dns
helm.sh/chart: external-dns-6.8.2
name: external-dns
namespace: jx
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app.kubernetes.io/instance: external-dns
app.kubernetes.io/name: external-dns
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
annotations:
prometheus.io/port: "7979"
prometheus.io/scrape: "true"
labels: *test_labels
spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/instance: external-dns
app.kubernetes.io/name: external-dns
namespaces:
- jx
topologyKey: kubernetes.io/hostname
weight: 1
containers:
- args:
- --metrics-address=:7979
- --log-level=debug
- --log-format=text
- --domain-filter=aws.ticket.se
- --policy=sync
- --provider=aws
- --registry=txt
- --interval=1m
- --source=ingress
- --source=service
- --aws-api-retries=3
- --aws-zone-type=
- --aws-batch-change-size=1000
env:
- name: AWS_DEFAULT_REGION
value: eu-north-1
image: docker.io/bitnami/external-dns:0.12.2-debian-11-r14
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 2
httpGet:
path: /healthz
port: http
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
name: external-dns
ports:
- containerPort: 7979
name: http
protocol: TCP
readinessProbe:
failureThreshold: 6
httpGet:
path: /healthz
port: http
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext:
fsGroup: 65534
runAsUser: 1001
serviceAccount: external-dns
serviceAccountName: external-dns
terminationGracePeriodSeconds: 30
5 changes: 5 additions & 0 deletions pkg/tagging/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func NewCmdUpdateTag(tagVerb, tagType string) (*cobra.Command, *Options) {
// UpdateTagInYamlFiles updates the annotations in yaml files
func (o *Options) UpdateTagInYamlFiles(tagType string, tags []string) error {
modifyFn := func(node *yaml.RNode, path string) (bool, error) {
// The FieldMatcher assumes MappingNode notAliasNode, so need to DeAnchor before going on
err := node.DeAnchor()
if err != nil {
return false, err
}
sort.Strings(tags)
tagNode, err := getTagNode(node, path, tagType, o)
if err != nil {
Expand Down

0 comments on commit 55ac383

Please sign in to comment.