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

🌱 test/framework: improve the way we inject the ci-artifacts script #4420

Conversation

sbueringer
Copy link
Member

@sbueringer sbueringer commented Apr 1, 2021

What this PR does / why we need it:

This PR changes the way we patch the ci-artifacts.sh script. Up until now we used strategic merge patch. This overwrote the files and preKubeadmCommands arrays. That was the reason this functionality could not be reused in CAPO and CAPZ (kubernetes-sigs/cluster-api-provider-azure#1018 (comment)). The new version is implemented with JSON patch and just appends the script to the arrays. Because we append the script, it's also possible to run some provider-specific scripts before.

Further improvements:

  • only download control plane images on control plane nodes
  • use wget to download artifacts instead of gsutil so save a few minutes because we don't have to install gsutil

Some more details on the linked issue.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #4386

Notes:

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 1, 2021
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 1, 2021
@sbueringer sbueringer force-pushed the pr-improve-inject-debian-script branch from 0f420ff to 8c42b45 Compare April 1, 2021 07:00
DEBIAN_FRONTEND=noninteractive apt-get install -y apt-transport-https curl
export DEBIAN_FRONTEND=noninteractive
# sometimes the network is not immediately available, so we have to retry the apt-get update
retry 10 5 "apt-get update"
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 had to do this because the network did not immediately work after boot in our case. It's fine if we don't want this in the main repo, I can move it to a provider-specific script which is run before in CAPO.

//go:embed data/kustomization.yaml
kustomizationYamlBytes []byte
//go:embed data/debian_injection_script_control_plane.envsubst.sh
debianInjectionScriptControlPlaneBytes string
Copy link
Member Author

Choose a reason for hiding this comment

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

An alternative to duplicating the script would have been to template the images we pull (that's the only difference between the two scripts). I just thought another layer of templating would be a bad idea.

I'm not sure if there is a good way to auto-discover if the script runs on a control plane or worker node.

// * scriptPath: is the path where the script will be stored at
// * scriptContent: content of the script
func generateInjectScriptJSONPatch(sourceTemplate []byte, objectKind, objectName, jsonPatchPathPrefix, scriptPath, scriptContent string) ([]byte, error) {
filesPathExists, preKubeadmCommandsPathExists, err := checkIfArraysAlreadyExist(sourceTemplate, objectKind, objectName, jsonPatchPathPrefix)
Copy link
Member Author

Choose a reason for hiding this comment

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

This is where it gets pretty hacky. I couldn't find a way via JSON patch to just "create an array if it isn't there". That's why I have to check first if the arrays already exist and only add them if they don't exist before.

I could have always set the arrays to an empty array but this would have overwritten every preexisting array elements.

I thought about just parsing the relevant objects, changing them and generating a JSON patch for the diff, maybe that would be better.

What do you think?

@sbueringer sbueringer force-pushed the pr-improve-inject-debian-script branch from 8c42b45 to c552b88 Compare April 1, 2021 07:10
@sbueringer sbueringer changed the title [WIP] 🌱 test/framework: improves the way we inject the debian script 🌱 test/framework: improves the way we inject the debian script Apr 1, 2021
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 1, 2021
@sbueringer sbueringer changed the title 🌱 test/framework: improves the way we inject the debian script 🌱 test/framework: improve the way we inject the ci-artifacts script Apr 1, 2021
@sbueringer sbueringer force-pushed the pr-improve-inject-debian-script branch from c552b88 to 90a96a2 Compare April 1, 2021 07:23
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 1, 2021
@CecileRobertMichon
Copy link
Contributor

cc @chewong @jackfrancis

@sbueringer sbueringer force-pushed the pr-improve-inject-debian-script branch 2 times, most recently from 36a0f59 to 2eb0e2b Compare May 7, 2021 19:09
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 7, 2021
Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/lgtm
/assign @fabriziopandini

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 11, 2021
@sbueringer
Copy link
Member Author

sbueringer commented May 11, 2021

Would be also good to get a review from some CAPA folks as CAPA is using the old version of this util at the moment.

P.S. Fyi, I'm using a 100% exact copy of this package in CAPO on the main branch and it works fine there.

@sbueringer
Copy link
Member Author

sbueringer commented May 24, 2021

@fabriziopandini @vincepri @CecileRobertMichon What do you think we should do to get this PR merged? :) Anyone to cc/ping for further review?

@vincepri
Copy link
Member

@CecileRobertMichon
Copy link
Contributor

lgtm

waiting for someone from CAPA to review

@sedefsavas
Copy link

@sbueringer
My only comment is debian_injection_script_control_plane.envsubst.sh and debian_injection_script_worker.envsubst.sh are exactly same except this difference:

declare -a CONTAINERS_TO_TEST=("kube-proxy")
declare -a CONTAINERS_TO_TEST=("kube-apiserver" "kube-controller-manager" "kube-proxy" "kube-scheduler")

For the sake of maintaining them easier, is there a way to combine these?

@randomvariable
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 13, 2021
@randomvariable
Copy link
Member

Let's rebase on top of #4922 and then I can test it again.

@sbueringer sbueringer force-pushed the pr-improve-inject-debian-script branch from ba9c0a5 to 0c3182f Compare July 13, 2021 11:15
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 13, 2021
@sbueringer
Copy link
Member Author

Included the changes from #4922 and squashed.

@randomvariable
Copy link
Member

testing now

@randomvariable
Copy link
Member

randomvariable commented Jul 13, 2021

Seems to be working

I would amend your commit to add @jackfrancis as a co-author and then can lgtm.

@randomvariable
Copy link
Member

Here's the generated CAPA template https://gist.github.com/randomvariable/0b8e4d4334fcaf120c2ad902b1ff4510

@sbueringer sbueringer force-pushed the pr-improve-inject-debian-script branch 2 times, most recently from b816733 to 5f95ba2 Compare July 13, 2021 13:20
Signed-off-by: Stefan Büringer buringerst@vmware.com

Co-authored-by: Jack Francis <jack.francis@microsoft.com>
@sbueringer sbueringer force-pushed the pr-improve-inject-debian-script branch from 5f95ba2 to b2d9539 Compare July 13, 2021 13:22
@sbueringer
Copy link
Member Author

Seems to be working

I would amend your commit to add @jackfrancis as a co-author and then can lgtm.

Good point, should be correct now.

@randomvariable
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 13, 2021
Copy link
Contributor

@CecileRobertMichon CecileRobertMichon left a comment

Choose a reason for hiding this comment

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

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CecileRobertMichon

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 13, 2021
@k8s-ci-robot k8s-ci-robot merged commit 38fabab into kubernetes-sigs:master Jul 13, 2021
@k8s-ci-robot k8s-ci-robot added this to the v0.4 milestone Jul 13, 2021
@sbueringer sbueringer deleted the pr-improve-inject-debian-script branch July 13, 2021 16:59
@spiffxp
Copy link
Member

spiffxp commented Jul 16, 2021

ref: kubernetes/k8s.io#2318

If you're not going to use gsutil anymore, I've got another suggestion I'll PR up shortly

@spiffxp
Copy link
Member

spiffxp commented Jul 16, 2021

Opened #4958 (not using gsutil means we don't need to reference GCS bucket names anymore, which would be awesome)

@sbueringer
Copy link
Member Author

sbueringer commented Jul 17, 2021

ref: kubernetes/k8s.io#2318

If you're not going to use gsutil anymore, I've got another suggestion I'll PR up shortly

Nice, I removed gsutil because it took a bit long to install, so that wasn't really worth it. Good to see that it also helps with getting rid of references to the bucket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve the way we inject ci-artifacts.sh
9 participants