ministryofjustice / cloud-platform

Documentation on the MoJ cloud platform
MIT License
87 stars 44 forks source link

Github Action to detect resource name renaming in yaml #5568

Open poornima-krishnasamy opened 5 months ago

poornima-krishnasamy commented 5 months ago

Background

Users of Cloud Platform sometimes request PR for renaming kubernetes resources created in cloud-platform-environments repo. But the cloud-platform cli only perform kubectl apply -f. This means new resource gets created for the changes but the exiting resource doesnt get deleted.

It might be easier to detect resource deleting/ renaming via contest, take a look at if it's possible in conftest first.

Approach

It is not generally advisable to rename kubernetes resources and instead delete and recreate. Hence, Implement a way to detect these kind of change to the resource names and add a comment in the PR or fail the checks so this is prevented during PR creation.

One of the suggestion to configure conftest to check the resource kind: namespace and if the name is getting changed

Which part of the user docs does this impact

https://github.com/ministryofjustice/cloud-platform-environments

Communicate changes

Questions / Assumptions

Definition of done

Reference

How to write good user stories

tom-j-smith commented 2 months ago

Will work with Jack on Monday on a GO solution - will need to be carried over to next sprint

tom-j-smith commented 1 month ago

Attempted to compare only changes from PR in yaml files to see if .metadata.name is gets changed, this seems to not work as the line diffs break YAML structure and then any name could be seen as a change causing the failed test.

tom-j-smith commented 4 weeks ago

Go script created that pulls YAML from changed files and compares metadata and fails if it detects changes to metadata.name or metadata.namespace