-
Notifications
You must be signed in to change notification settings - Fork 263
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 cluster templates with kustomize #1271
🌱 Generate cluster templates with kustomize #1271
Conversation
Skipping CI for Draft Pull Request. |
✅ Deploy Preview for kubernetes-sigs-cluster-api-openstack ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
880086d
to
1c78102
Compare
@@ -469,3 +497,6 @@ verify-gen: generate | |||
.PHONY: compile-e2e | |||
compile-e2e: ## Test e2e compilation | |||
go test -c -o /dev/null -tags=e2e ./test/e2e/suites/conformance | |||
|
|||
.PHONY: FORCE | |||
FORCE: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this target?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not find any way to make the target depend on all files in a directory. A target that depends on a .PHONY target will always be rebuilt. The targets which use FORCE are pattern targets, and AFAIK there is no way to make them directly .PHONY.
Makefile
Outdated
templates/cluster-template-without-lb.yaml \ | ||
templates/cluster-template-external-cloud-provider.yaml | ||
|
||
templates/cluster-template.yaml: kustomize/v1alpha6/default FORCE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails for me with:
$ make templates
hack/tools/bin/kustomize build "kustomize/v1alpha6/default" > "templates/cluster-template.yaml"
bash: line 1: hack/tools/bin/kustomize: No such file or directory
make: *** [Makefile:404: templates/cluster-template.yaml] Error 127
make: *** Deleting file 'templates/cluster-template.yaml'
I would suggest we add the $(KUSTOMIZE)
target as a dependency, so the binary is always available
templates/cluster-template.yaml: kustomize/v1alpha6/default FORCE | |
templates/cluster-template.yaml: kustomize/v1alpha6/default FORCE $(KUSTOMIZE) |
The same applies to targets templates/cluster-template-%.yaml
, $(E2E_TEMPLATES_DIR)/cluster-template.yaml
and $(E2E_TEMPLATES_DIR)/cluster-template-%.yaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated with this change.
1c78102
to
6c7bb72
Compare
/lgtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also validated the changes via
git clone https://github.com/kubernetes-sigs/cluster-api-provider-openstack/ /tmp/cluster-api-provider-openstack
for template in templates/*yaml; do diff -u <(sort $template) <(sort /tmp/cluster-api-provider-openstack/$template); done
Noticed only some quoting and list syntax changes
Edit: btw, there is also a yaml differ called dyff. But as there are multiple yamls inside the manifest dyff is not able to do its proper job 😿
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mdbooth, tobiasgiese The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
But there is ksort.
|
templates/cluster-template*.yaml is now generated from kustomize in the new kustomize/ directory. This makes no functional changes to the release templates. The resulting templates are identical except for the order of the objects.
The e2e cluster templates are now based on the release templates, with explicit modifications for testing using kustomize. The resulting templates are identical to the previous templates except for the order of objects.
6c7bb72
to
122d7c1
Compare
I did something like this against an unmodified repo to create a new directory (k) containing original templates which have been sorted by kustomize: mkdir k
for i in cluster-template*.yaml; do
echo -e "resources:\n- $i" > kustomization.yaml
kustomize build . > k/$i
end Then I diffed the new generated templates against the kustomize-sorted original templates. They are literally identical. Because the original doesn't apply any patches I think this even avoids kustomize pitfalls involving incorrect API definitions, so I'm fairly confident this is a robust test. |
/lgtm |
/hold cancel |
What this PR does / why we need it:
This PR changes the way we generate our cluster templates for both release and e2e tests to use kustomize. We now have the following dependency structure between templates:
Additionally, all the E2E templates now use a common set of patches to uniformly apply configuration we use in tests but not in release. This means that any change in the release templates is now reflected automatically in the E2E tests, which gives us a level of test coverage for changes to the release templates.
That said, in order to keep this PR simple the templates produced by this PR are identical to the previous templates except in the order of the objects and fields. The order difference is an artifact of using kustomize: it picks a consistent order according to its own rules. I have verified that the templates are identical by the following:
For every existing template in /templates and /test/e2e/data/infrastructure-openstack I generated a kustomization.yaml containing only a resources section specifying only the original template file, and then I built the kustomization. i.e. This is the original template whose only transformation is the re-ordering done by kustomize. I then generated templates from the new kustomize and verified that there were no diffs.
Release templates are generated by a new make target:
templates
.E2E templates are generated by a new make target:
e2e-templates
.I have created directories for v1alpha5 and v1alpha6, which are currently identical except for apiVersion, and we should consider adding a directory for v1alpha4 in the future as long as we support it. The intention here is to for reuse when adding tests for supported previous versions.
I have used strategic merge patches in the release templates because I find them more readable. However, in the e2e templates I have used a json patch everywhere we reference an OpenStack object. This allows the patches to be reusable across apiVersions.
/hold