Skip to content

feat: sort label result#1076

Merged
jenkins-x-bot merged 8 commits into
jenkins-x-plugins:mainfrom
spring-financial-group:feat/sort-label-result
May 28, 2026
Merged

feat: sort label result#1076
jenkins-x-bot merged 8 commits into
jenkins-x-plugins:mainfrom
spring-financial-group:feat/sort-label-result

Conversation

@TSnowden-1311
Copy link
Copy Markdown

Changes

Add a sort in UpdateTagInYamlFiles after labels are added to keep result order consistent

Context

We see a lot of noise in PRs due to reordering of labels.. This is caused by the following scenarios


Scenario 1 — OUTPUT_DIR wiped (change outside helmfiles/)

get-selectors-and-clean.sh detects the change and runs rm -rf ${OUTPUT_DIR}///. Source-repository files are gone. jx gitops repository create writes fresh files — no pipeline label. post-build runs jx gitops label across all files, finds no existing label, calls addField which appends to the bottom.

before wipe (label at top)
labels:
gitops.jenkins-x.io/pipeline: 'namespaces'
owner: spring-financial-group
repository: acme

after post-build (label at bottom)
labels:
owner: spring-financial-group
repository: acme
gitops.jenkins-x.io/pipeline: 'namespaces'


Scenario 2 — OUTPUT_DIR not wiped (helmfiles-only change, selector run)

Source-repository files persist. jx gitops repository create runs — if spec changed, yamls.SaveFile serialises labels alphabetically, label sorts back to top. post-build finds the label, updates in-place.

before (label at bottom from scenario 1)
labels:
owner: spring-financial-group
repository: acme
gitops.jenkins-x.io/pipeline: 'namespaces'

after yamls.SaveFile alphabetical sort (label at top)
labels:
gitops.jenkins-x.io/pipeline: 'namespaces'
owner: spring-financial-group
repository: acme


Result — pipeline run flips the label across all 344 source-repository files, creating ~700 meaningless diff lines per chore: regenerated commit.

@TSnowden-1311
Copy link
Copy Markdown
Author

/cc @Skisocks

@jenkins-x-bot
Copy link
Copy Markdown
Contributor

Hi @TSnowden-1311. Thanks for your PR.

I'm waiting for a jenkins-x-plugins member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the jenkins-x/lighthouse repository.

@jenkins-x-bot jenkins-x-bot requested a review from Skisocks May 28, 2026 10:13
@TSnowden-1311
Copy link
Copy Markdown
Author

/cc @msvticket

@jenkins-x-bot jenkins-x-bot requested a review from msvticket May 28, 2026 10:14
@Skisocks
Copy link
Copy Markdown
Member

/ok-to-test

@TSnowden-1311
Copy link
Copy Markdown
Author

/test pr

@Skisocks
Copy link
Copy Markdown
Member

Failing tests @TSnowden-1311

--- FAIL: TestUpdateAnnotations (0.04s)
		    annotate_test.go:86: generated for file testdata/cert-manager-bug/source.yaml with args []string{"beer=stella", "wine=merlot"} file
		        # Source: cert-manager/templates/cainjector-rbac.yaml
		        # leader election rules
		        apiVersion: rbac.authorization.k8s.io/v1beta1
		        kind: Role
		        metadata:
		          name: cert-manager-cainjector:leaderelection
		          namespace: cert-manager
		          labels:
		            app: cainjector
		            app.kubernetes.io/name: cainjector
		            app.kubernetes.io/instance: cert-manager
		            app.kubernetes.io/managed-by: Helm
		            helm.sh/chart: cert-manager-v0.13.1
		          annotations:
		            beer: 'stella'
		            wine: 'merlot'
		        rules:
		        - # Used for leader election by the controller
		          # TODO: refine the permission to *just* the leader election configmap
		          apiGroups: [""]
		          resources: ["configmaps"]
		          verbs: ["get", "create", "update", "patch"]
		    annotate_test.go:86: generated for file testdata/cluster-role-binding/source.yaml with args []string{"beer=stella", "wine=merlot"} file
		        apiVersion: rbac.authorization.k8s.io/v1
		        kind: ClusterRoleBinding
		        metadata:
		          name: jx-jx
		          namespace: jx
		          annotations:
		            beer: 'stella'
		            wine: 'merlot'
		        roleRef:
		          apiGroup: rbac.authorization.k8s.io
		          kind: ClusterRole
		          name: jx-jx
		        subjects:
		        - kind: ServiceAccount
		          name: jx
		          namespace: jx
		    annotate_test.go:84: Generated Pipeline for file testdata/svc/source.yaml did not match expected:   (
		          	"""
		          	... // 3 identical lines
		          	  name: cheese
		          	  annotations:
		        - 	    beer: 'stella'
		          	    chart: cheese
		        + 	    beer: 'stella'
		          	    wine: 'merlot'
		          	spec:
		          	... // 7 identical lines
		          	"""
		          )
		         for args []string{"beer=stella", "wine=merlot"}
		    annotate_test.go:86: generated for file testdata/svc/source.yaml with args []string{"beer=stella", "wine=merlot"} file
		        apiVersion: v1
		        kind: Service
		        metadata:
		          name: cheese
		          annotations:
		            beer: 'stella'
		            chart: cheese
		            wine: 'merlot'
		        spec:
		          ports:
		          - port: 80
		            targetPort: 8080
		            protocol: TCP
		            name: http
		          selector:
		            app: cheese
		    annotate_test.go:86: generated for file testdata/cert-manager-bug/source.yaml with args []string{"beer=stella", "wine=merlot"} file
		        # Source: cert-manager/templates/cainjector-rbac.yaml
		        # leader election rules
		        apiVersion: rbac.authorization.k8s.io/v1beta1
		        kind: Role
		        metadata:
		          name: cert-manager-cainjector:leaderelection
		          namespace: cert-manager
		          labels:
		            app: cainjector
		            app.kubernetes.io/name: cainjector
		            app.kubernetes.io/instance: cert-manager
		            app.kubernetes.io/managed-by: Helm
		            helm.sh/chart: cert-manager-v0.13.1
		          annotations:
		            beer: 'stella'
		            wine: 'merlot'
		        rules:
		        - # Used for leader election by the controller
		          # TODO: refine the permission to *just* the leader election configmap
		          apiGroups: [""]
		          resources: ["configmaps"]
		          verbs: ["get", "create", "update", "patch"]
		    annotate_test.go:86: generated for file testdata/cluster-role-binding/source.yaml with args []string{"beer=stella", "wine=merlot"} file
		        apiVersion: rbac.authorization.k8s.io/v1
		        kind: ClusterRoleBinding
		        metadata:
		          name: jx-jx
		          namespace: jx
		          annotations:
		            beer: 'stella'
		            wine: 'merlot'
		        roleRef:
		          apiGroup: rbac.authorization.k8s.io
		          kind: ClusterRole
		          name: jx-jx
		        subjects:
		        - kind: ServiceAccount
		          name: jx
		          namespace: jx
		    annotate_test.go:84: Generated Pipeline for file testdata/svc/source.yaml did not match expected:   (
		          	"""
		          	... // 3 identical lines
		          	  name: cheese
		          	  annotations:
		        - 	    beer: 'stella'
		          	    chart: cheese
		        + 	    beer: 'stella'
		          	    wine: 'merlot'
		          	spec:
		          	... // 7 identical lines
		          	"""
		          )
		         for args []string{"beer=stella", "wine=merlot"}
		    annotate_test.go:86: generated for file testdata/svc/source.yaml with args []string{"beer=stella", "wine=merlot"} file
		        apiVersion: v1
		        kind: Service
		        metadata:
		          name: cheese
		          annotations:
		            beer: 'stella'
		            chart: cheese
		            wine: 'merlot'
		        spec:
		          ports:
		          - port: 80
		            targetPort: 8080
		            protocol: TCP
		            name: http
		          selector:
		            app: cheese
		FAIL
		FAIL	github.com/jenkins-x-plugins/jx-gitops/pkg/cmd/annotate	0.094s
		FAIL
		make: *** [Makefile:106: test] Error 1

@TSnowden-1311
Copy link
Copy Markdown
Author

/test pr

@TSnowden-1311
Copy link
Copy Markdown
Author

/test pr

Copy link
Copy Markdown
Contributor

@msvticket msvticket left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a problem I have seen, but if you say so... This will of course make for one big spurious diff after upgrade of jx-gitops.

@jenkins-x-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: msvticket

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jenkins-x-bot jenkins-x-bot merged commit cc5053c into jenkins-x-plugins:main May 28, 2026
5 of 6 checks passed
@jenkins-x-bot
Copy link
Copy Markdown
Contributor

@TSnowden-1311: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
lint 0981577 link /test lint
Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the jenkins-x/lighthouse repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants