Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate patches for Kustomize to enable storage versioning #1973

Merged
merged 30 commits into from
Nov 19, 2021

Conversation

theunrepentantgeek
Copy link
Member

@theunrepentantgeek theunrepentantgeek commented Nov 15, 2021

What this PR does / why we need it:

Enabling versioning requires the yaml files generated by controller-gen to be modified by Kustomize to inject the required settings.

We modify the existing gen-kustomize mode of our generator to write the required files.

How does this PR make you feel:
gif

Prerequisites:

@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2021

Codecov Report

Merging #1973 (78442d0) into main (bb8f228) will decrease coverage by 0.05%.
The diff coverage is 7.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1973      +/-   ##
==========================================
- Coverage   57.21%   57.16%   -0.06%     
==========================================
  Files         422      425       +3     
  Lines       85624    85709      +85     
==========================================
+ Hits        48993    48998       +5     
- Misses      30368    30448      +80     
  Partials     6263     6263              
Impacted Files Coverage Δ
v2/tools/generator/gen_kustomize.go 0.00% <0.00%> (ø)
...or/internal/kustomization/conversion_patch_file.go 0.00% <0.00%> (ø)
...r/internal/kustomization/crd_kustomization_file.go 0.00% <0.00%> (ø)
...ator/internal/kustomization/resource_definition.go 0.00% <0.00%> (ø)
...2/internal/testcommon/kube_test_context_envtest.go 76.68% <100.00%> (+0.73%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bb8f228...78442d0. Read the comment docs.

Copy link
Member

@babbageclunk babbageclunk left a comment

Choose a reason for hiding this comment

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

Looks mostly great! I think you need to build config/crd rather than config/default as it does too much (in particular name/namespace mangling), and then that has knock-on consequences for the tasks.

Taskfile.yml Outdated Show resolved Hide resolved
@@ -37,7 +37,7 @@ func createSharedEnvTest(cfg testConfig, namespaceResources *namespaceResources)
environment := envtest.Environment{
ErrorIfCRDPathMissing: true,
CRDDirectoryPaths: []string{
"../../config/crd/bases",
"../../config/crd/packed",
Copy link
Member

Choose a reason for hiding this comment

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

Oh, I guess the benefit of putting the patched CRD output somewhere under config/crd is that we can hardcode it here rather than trying to feed it in as a parameter somehow. That makes sense.

v2/tools/generator/gen_kustomize.go Outdated Show resolved Hide resolved
v2/internal/testcommon/kube_test_context_envtest.go Outdated Show resolved Hide resolved
Taskfile.yml Outdated Show resolved Hide resolved
Taskfile.yml Outdated Show resolved Hide resolved
@babbageclunk
Copy link
Member

babbageclunk commented Nov 15, 2021

I've just realised - we'll also need a v2/config/crd/kustomizeconfig.yaml, which needs to be referenced from v2/config/crd/kustomization.yaml. The content of the file can just be the same as v1's config/crd/kustomizeconfig.yaml.

This tells kustomize how to find names and namespaces that need to be updated when it applies the mangling (to put azureserviceoperator- at the start). (An amusing consequence of this being missing is that in fact the config/default-built CRDs don't have mangled conversion config like I thought, but they should - they won't work in a real cluster if the mangling isn't done.)

Some documentation links about this:

@theunrepentantgeek theunrepentantgeek force-pushed the feature/gen-kustomize-patches branch from 48edb50 to 9979cc3 Compare November 17, 2021 01:09
@theunrepentantgeek theunrepentantgeek changed the base branch from main to feature/copy-objectmeta November 17, 2021 01:14
@theunrepentantgeek
Copy link
Member Author

/ok-to-test 9979cc3

@matthchr
Copy link
Member

@theunrepentantgeek I don't think you should need to ok-to-test this PR as it's not from a fork. Is that not what you experienced?

Copy link
Member

@babbageclunk babbageclunk left a comment

Choose a reason for hiding this comment

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

This looks good, but I'm not sure about copying the TypeMeta field - isn't that always determined by the package+type that it's on?

Taskfile.yml Outdated
@@ -373,8 +374,17 @@ tasks:
deps: [controller:generate-kustomize]
dir: "v2/"
cmds:
- mkdir -p bin # in case it doesn’t exist
- kustomize build config/default | sed -e 's@localhost:5000/azureserviceoperator:latest@{{.PUBLIC_REGISTRY}}{{.CONTROLLER_DOCKER_IMAGE}}@g' > bin/azureserviceoperator_{{.VERSION}}.yaml
- mkdir -p bing # in case it doesn't exist
Copy link
Member

Choose a reason for hiding this comment

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

Uh, bing?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I fixed this with my force push. 😊

Copy link
Member

Choose a reason for hiding this comment

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

This doesn't look fixed?

@@ -98,6 +107,9 @@
}
destination.Status = status

// TypeMeta
destination.TypeMeta = person.TypeMeta
Copy link
Member

Choose a reason for hiding this comment

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

I thought you needed to avoid doing this, since it ends up copying the GVK from one version to another?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I had changes that I hadn't pushed. Now fixed.

@theunrepentantgeek theunrepentantgeek force-pushed the feature/gen-kustomize-patches branch from 62bfb54 to e8ca5d3 Compare November 18, 2021 18:29
Base automatically changed from feature/copy-objectmeta to main November 18, 2021 22:04
@babbageclunk
Copy link
Member

/ok-to-test sha=fb727a1

@theunrepentantgeek theunrepentantgeek merged commit 9045d55 into main Nov 19, 2021
@theunrepentantgeek theunrepentantgeek deleted the feature/gen-kustomize-patches branch November 19, 2021 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants