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

🐛 avoid in-place capbk mutation, duplicate files #3473

Merged
merged 1 commit into from
Aug 18, 2020

Conversation

alexeldeib
Copy link
Contributor

What this PR does / why we need it:

we write the certificate files twice into cloud init, once as writeFiles and again as additionalFiles which get written back to writeFiles.

we also mutate the kubeadm config spec in place when converting contentFrom -> content. avoid doing that.

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

/hold

for some tests

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 11, 2020
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Aug 11, 2020

for i := range merge {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this unit tested?

Copy link
Contributor

Choose a reason for hiding this comment

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

edit: just saw you have a hold for tests, nvm

Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

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

Good catch!
Wondering if we can remove the merge parameter from resolveFiles, since it seems it is never used now.

Additional question, from a quick glance at this feauture, it seems to me that the AdditionalFiles are never added to cloud-init for a joining control plane node. see

input.WriteFiles = input.Certificates.AsFiles()
input.WriteFiles = append(input.WriteFiles, input.AdditionalFiles...)

vs
input.WriteFiles = input.Certificates.AsFiles()

Is this intentional or another potential bug hidden by the duplication of files?

@alexeldeib
Copy link
Contributor Author

I think for the join case, we take


and plumb it through to
if err := input.prepare(); err != nil {
return nil, err
}
which handles the same logic for us:
input.WriteFiles = append(input.WriteFiles, input.AdditionalFiles...)

will see if I can align these, or if there's a reason not to 👍

@alexeldeib
Copy link
Contributor Author

I guess prepare() only really makes sense for join, since this code isn't helpful for init:

input.KubeadmCommand = fmt.Sprintf(standardJoinCommand, input.KubeadmVerbosity)
if input.UseExperimentalRetry {
input.KubeadmCommand = retriableJoinScriptName
joinScriptFile, err := generateBootstrapScript(input)
if err != nil {
return errors.Wrap(err, "failed to generate user data for machine joining control plane")
}
input.WriteFiles = append(input.WriteFiles, *joinScriptFile)
}

@fabriziopandini
Copy link
Member

@alexeldeib thanks for investigating this.
I think we are ok with prepare for join (eventually fixing this is out of scope of this PR)

@@ -578,20 +578,35 @@ func (r *KubeadmConfigReconciler) joinControlplane(ctx context.Context, scope *S
// resolveFiles maps .Spec.Files into cloudinit.Files, resolving any object references
// along the way.
func (r *KubeadmConfigReconciler) resolveFiles(ctx context.Context, cfg *bootstrapv1.KubeadmConfig, merge ...bootstrapv1.File) ([]bootstrapv1.File, error) {
collected := append(cfg.Spec.Files, merge...)
collected := make([]bootstrapv1.File, len(cfg.Spec.Files)+len(merge))
Copy link
Member

@vincepri vincepri Aug 18, 2020

Choose a reason for hiding this comment

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

Suggested change
collected := make([]bootstrapv1.File, len(cfg.Spec.Files)+len(merge))
collected := make([]bootstrapv1.File, 0, len(cfg.Spec.Files)+len(merge))

Then we don't need index, but we can just append()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not actually merging anything anymore, so got rid of this altogether and switched to append

@vincepri
Copy link
Member

/milestone v0.3.9

@k8s-ci-robot k8s-ci-robot added this to the v0.3.9 milestone Aug 18, 2020
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 18, 2020
@alexeldeib
Copy link
Contributor Author

@CecileRobertMichon added tests

@alexeldeib
Copy link
Contributor Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 18, 2020
},
objects: []runtime.Object{testSecret},
},
"multiple files should work correctly": {
Copy link
Contributor

Choose a reason for hiding this comment

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

was about to hit enter on a comment asking exactly for this :D

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.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 18, 2020
Signed-off-by: Alexander Eldeib <alexeldeib@gmail.com>
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 18, 2020
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.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 18, 2020
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.

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vincepri

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 Aug 18, 2020
@k8s-ci-robot k8s-ci-robot merged commit 57a1c7e into kubernetes-sigs:master Aug 18, 2020
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.

5 participants