kapp-controller icon indicating copy to clipboard operation
kapp-controller copied to clipboard

`kctrl`: ytt overlay flags

Open 100mik opened this issue 3 years ago • 2 comments

What this PR does / why we need it:

Add flags which allow overlaying of package content while creating package installs.

Which issue(s) this PR fixes:

Fixes #674

Does this PR introduce a user-facing change?

Introduce ytt overlay flags
- `--ytt-overlays` (boolean) decides whether or not ytt overlays are added/kept.
- `--ytt-overlay-file` files can be used to supply ytt overlay file paths or paths to directories wioth ytt overlays.

Additional Notes for your reviewer:

Review Checklist:
  • [x] Follows the developer guidelines
  • [ ] Relevant tests are added or updated
  • [x] Relevant docs in this repo added or updated
  • [ ] Relevant carvel.dev docs added or updated in a separate PR and there's a link to that PR
  • [x] Code is at least as readable and maintainable as it was before this change

Additional documentation e.g., Proposal, usage docs, etc.:


100mik avatar Jun 07 '22 19:06 100mik

Right now a secret created by the command:

kctrl package installed update --ytt-overlay-file overlay-file.yaml --ytt-overlay-file /overlays-folder

Will look something like:

apiVersion: v1
kind: Secret
metadata:
  annotations:
    packaging.carvel.dev/package: test-default
  creationTimestamp: "2022-06-21T11:23:11Z"
  name: test-default-overlays
  namespace: default
  resourceVersion: "398587"
  uid: 4a29b5a5-65c4-407e-8cc8-fe1f2adaf7fd
type: Opaque
data:
  0000-overlay-file.yaml: I0AgbG9hZCgiQHl0dDpvd #truncated......
  0001-_Users_soumikm_Documents_playground_kctrloverlays_overlays-folder_a-overlay.yml: I0AgbG9hZCgiQHl0dDpvdm #truncated...
  0001-_Users_soumikm_Documents_playground_kctrloverlays_overlays-folder_b-overlay.yaml: I0AgbG9hZCgiQHl0dDpvdmVy #truncated...

One caveat could be folders with names which have characters that are not permitted in secret data keys. Working on making sure the filepaths are as short as they need to be (relative file path)

100mik avatar Jun 21 '22 11:06 100mik

To illustrate further, lets say a folder kctrloverlays has the following files,

├── overlays
│   ├── first
│   │   └── overlay.yml
│   └── second
│       ├── a-overlay.yml
│       └── b-overlay.yml
└── rep-overlay.yaml

On running the command:

$ kctrl package install -i hello -p hello-app.corp.com --version 1.0.0 --ytt-overlay-file kctrloverlays/rep-overlay.yaml --ytt-overlay-file kctrloverlays/overlays

Would result in a secret like,

apiVersion: v1
data:
  0000-rep-overlay.yaml: I0AgbG9hZCgiQHl0dD...
  0001-first_overlay.yml: I0AgbG9hZCgiQHl0dDpv....
  0001-second_a-overlay.yml: I0AgbG9hZCgiQ....
  0001-second_b-overlay.yml: I0AgbG9hZCgiQ....
kind: Secret
metadata:
  annotations:
    packaging.carvel.dev/package: hello-default
  creationTimestamp: "2022-06-28T07:54:22Z"
  name: hello-default-overlays
  namespace: default
  resourceVersion: "4193758"
  uid: e9288fe4-fe51-4ac5-bfeb-1447be45cbac
type: Opaque

The first flag is given priority by the suffix 0000 All files in the overlays folder get the suffix 0001 and are ordered by ytt alphabetically by their file paths

100mik avatar Jun 28 '22 08:06 100mik

Looks good to me other than the switch conditions which are almost similar, but I couldn't think of a better way to have those conditions.

praveenrewar avatar Sep 14 '22 11:09 praveenrewar

Spent some time on it as well, but most ways around it seem to just be moving the same conditionals elsewhere :(

100mik avatar Sep 14 '22 11:09 100mik