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

✨ CABPK can now read file contents from a Secret #3083

Merged
merged 4 commits into from
May 26, 2020

Conversation

alexeldeib
Copy link
Contributor

@alexeldeib alexeldeib commented May 21, 2020

What this PR does / why we need it:
related to #1739

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

revised from #3038 after offline discussion

still needs some manual testing

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 21, 2020
@alexeldeib
Copy link
Contributor Author

/hold

for some additional manual testing

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 21, 2020
@alexeldeib alexeldeib force-pushed the ace/from branch 4 times, most recently from 87a85b7 to 039ea98 Compare May 22, 2020 00:18
@alexeldeib
Copy link
Contributor Author

/test pull-cluster-api-e2e

Comment on lines 133 to 137
func Convert_v1alpha3_File_To_v1alpha2_File(in *kubeadmbootstrapv1alpha3.File, out *File, s apiconversion.Scope) error {
// We don't implement manual conversion for types using contentFrom
return autoConvert_v1alpha3_File_To_v1alpha2_File(in, out, s)
}
Copy link
Member

Choose a reason for hiding this comment

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

We should still restore it when we go v1alpha3 -> v1alpha2 -> v1alpha3, there is an example in other files, or I can help tomorrow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will add

Comment on lines 186 to 187
// +optional
Secret *SecretFileSource `json:"secret,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be optional I think? If one specifies a FileSource in file.contentFrom: {} it should fail validation saying that secret is required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we only have one I was thinking if in the future we change this from required to optional it'd be breaking? But I think you mentioned today it's fine, and I concur that makes sense. Will make required.

The webhook does validate the stricter scenario already, I think you're correct regardless.

bootstrap/kubeadm/controllers/kubeadmconfig_controller.go Outdated Show resolved Hide resolved
@vincepri
Copy link
Member

/test pull-cluster-api-test

@vincepri
Copy link
Member

Only reviewed ~40% for now, will continue later

@alexeldeib alexeldeib force-pushed the ace/from branch 2 times, most recently from 5c977e8 to d006bc0 Compare May 22, 2020 02:46
@alexeldeib
Copy link
Contributor Author

I tried to reorder commits so all the functional stuff is in one because it's fairly small compared to total changes. Moved the rest into separate Go/yaml commits, hope that's easier to review.

@alexeldeib
Copy link
Contributor Author

How this looks for Azure now, if anyone is interested:

apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
kind: KubeadmConfigTemplate
metadata:
  name: ${CLUSTER_NAME}-md-0
spec:
  template:
    spec:
      files:
      - contentFrom:
          secret:
            name: azure-secret
            key: azure.json
        owner: root:root
        path: /etc/kubernetes/azure.json
        permissions: "0644"
      joinConfiguration:
        nodeRegistration:
          kubeletExtraArgs:
            cloud-config: /etc/kubernetes/azure.json
            cloud-provider: azure
          name: '{{ ds.meta_data["local_hostname"] }}'
---
apiVersion: v1
kind: Secret
metadata:
  name: azure-secret
data:
  "azure.json": |
    ${AZURE_JSON_B64}

definitely nicer than the previous example IMO

@@ -39,6 +39,7 @@ func (src *KubeadmConfig) ConvertTo(dstRaw conversion.Hub) error {
dst.Status.DataSecretName = restored.Status.DataSecretName
dst.Spec.Verbosity = restored.Spec.Verbosity
dst.Spec.UseExperimentalRetryJoin = restored.Spec.UseExperimentalRetryJoin
dst.Spec.Files = restored.Spec.Files
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is what we want? Otherwise we have to match files based on some property field to match array items?

Copy link
Member

Choose a reason for hiding this comment

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

We should only restore the files that have ContentFrom populated (non-nil)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this because the restored version might be stale where conversion was possible?

Copy link
Member

Choose a reason for hiding this comment

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

Correct, in case a v1alpha2 controller modified some of the files (even though unlikely because bootstrap should only happen once), we need to make sure to restore those that have the new schema.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I follow what this is doing... we're setting dst.Spec.Files to restored.Spec.Files and then appending some of the restored files to dst.Spec.Files? Isn't that going to result in duplicates?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch.

I think the first line dst.Spec.Files = restores.Spec.Files is leftover from my first revision, it should only be the loop. The intent is to look at restored files with contentFrom and append them. We shouldn’t append restored files with content set.

Will PR shortly

@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 May 22, 2020
return nil
}

func (c *KubeadmConfig) validate() error {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func (c *KubeadmConfig) validate() error {
func (c *KubeadmConfigSpec) validate() error {

If we add this method to KubeadmConfigSpec instead of KubeadmConfig we should be able to call it from the webhooks defined under controlplane/kubeadm as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

better?

bootstrap/kubeadm/controllers/kubeadmconfig_controller.go Outdated Show resolved Hide resolved
bootstrap/kubeadm/controllers/kubeadmconfig_controller.go Outdated Show resolved Hide resolved
bootstrap/kubeadm/controllers/kubeadmconfig_controller.go Outdated Show resolved Hide resolved
bootstrap/kubeadm/controllers/kubeadmconfig_controller.go Outdated Show resolved Hide resolved
bootstrap/kubeadm/controllers/kubeadmconfig_controller.go Outdated Show resolved Hide resolved
bootstrap/kubeadm/controllers/kubeadmconfig_controller.go Outdated Show resolved Hide resolved
@alexeldeib alexeldeib force-pushed the ace/from branch 2 times, most recently from 89831eb to 5c3a0f2 Compare May 22, 2020 22:42
@alexeldeib
Copy link
Contributor Author

/retest

@alexeldeib
Copy link
Contributor Author

/retest

@alexeldeib alexeldeib force-pushed the ace/from branch 4 times, most recently from 8f5f288 to 2cff638 Compare May 22, 2020 23:46
Signed-off-by: Alexander Eldeib <[email protected]>
Co-authored-by: Vince Prignano <[email protected]>
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.

One other thing that came to mind when I was reading the conversion is that today files has no checks on whether the path for each added file is actually unique.

Would that cause a configuration error?

Comment on lines +562 to +564
in.ContentFrom = nil
in.Content = string(data)
collected[i] = in
Copy link
Member

Choose a reason for hiding this comment

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

Just to double check, this logic is only changing the content of the struct at runtime, but it won't be stored in the KubeadmConfig at the end when we patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the intent. I could probably make this a little bit more explicit by newing up a slice, copying, and returning? Plus comments

@vincepri
Copy link
Member

/milestone v0.3.7

@k8s-ci-robot k8s-ci-robot added this to the v0.3.7 milestone May 25, 2020
@alexeldeib
Copy link
Contributor Author

alexeldeib commented May 25, 2020

Files not validating path uniqueness is a problem, yes. This PR matches the existing behavior in files which is effectively "last file wins". I can validate uniqueness on path and adjust the conversion logic to account?

The main effect of this right now is loss of conversion fidelity: conversion from v1a3 to v1a2, then adding a raw content file with the same path as a contentFrom file and then converting back to v1a3 would prefer the contentFrom file, even though the raw content file is newer.

@alexeldeib
Copy link
Contributor Author

We should probably also validate that via webhooks at create time

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.

@alexeldeib I like very much this new approach
Only one minor not from my side, otherwise lgtm

@vincepri
Copy link
Member

@alexeldeib I'm fine doing the validation in a different PR / later

@vincepri
Copy link
Member

/retitle ✨ CABPK can now read file contents from a Secret

@k8s-ci-robot k8s-ci-robot changed the title ✨ enable capbk to read secrets ✨ CABPK can now read file contents from a Secret May 26, 2020
@fabriziopandini
Copy link
Member

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexeldeib, fabriziopandini

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 May 26, 2020
@alexeldeib
Copy link
Contributor Author

alexeldeib commented May 26, 2020

@vincepri I'm happy either way. Might make more sense to snapshot as-is and iterate, but the additional code change isn't too big. I'll have a chance to wrap up the additional changes today/tomorrow.

@fabriziopandini thanks for review! 👍

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

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 26, 2020
@k8s-ci-robot k8s-ci-robot merged commit f0a0230 into kubernetes-sigs:master May 26, 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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants