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

🐛validation for not having both local and external etcd in control plane #2598

Merged
merged 1 commit into from
Mar 9, 2020

Conversation

nader-ziada
Copy link
Contributor

What this PR does / why we need it:

  • add validation in webhook to check that only one of local and external etcd is set

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 #2580

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 9, 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
/assign @chuckha

@vincepri
Copy link
Member

vincepri commented Mar 9, 2020

/milestone v0.3.0

@k8s-ci-robot k8s-ci-robot added this to the v0.3.0 milestone Mar 9, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nader-ziada, 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 Mar 9, 2020
)
}

if in.Spec.KubeadmConfigSpec.InitConfiguration.Etcd.External != nil && in.Spec.KubeadmConfigSpec.InitConfiguration.Etcd.Local != nil {
Copy link
Member

@fabriziopandini fabriziopandini Mar 9, 2020

Choose a reason for hiding this comment

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

not blocking for this PR, but the "real" kubeadm configuration/v1alpha3 does not have embedded ClusterConfiguration; wondering why we are doing this in the bootstrap provider...

Copy link
Member

Choose a reason for hiding this comment

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

PR: #2605

Copy link
Contributor

Choose a reason for hiding this comment

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

This case can be removed as well as the first two cases will cover all the checks we need.

The only reason this check would ever get triggered is if someone first deletes the local configuration and then tries to update both local and external at the same time. I don't think we need to handle this edge case right now.

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

Copy link
Contributor

@chuckha chuckha left a comment

Choose a reason for hiding this comment

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

One minor change in semantics, but this is 90% of the way there

@fabriziopandini it's likely just an oversight. The details of kubeadm sometimes get lost when thinking too much about cluster api. If you have suggestions, we are all ears!

@@ -293,6 +291,23 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) {
scaleToEvenExternalEtcdCluster := beforeExternalEtcdCluster.DeepCopy()
scaleToEvenExternalEtcdCluster.Spec.Replicas = pointer.Int32Ptr(2)

beforeInvalidEtcdCluster := before.DeepCopy()
beforeInvalidEtcdCluster.Spec.KubeadmConfigSpec.ClusterConfiguration = &kubeadmv1beta1.ClusterConfiguration{
Copy link
Contributor

Choose a reason for hiding this comment

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

This is testing a slightly different use case than what the issue describes. This test cases is for an object that is invalid to start with won't accept any updates.

Could you modify this test so that the before configuration has local and then the after is trying to add an external configuration?

@@ -229,6 +231,30 @@ func (in *KubeadmControlPlane) validateCommon() (allErrs field.ErrorList) {
return allErrs
}

func (in *KubeadmControlPlane) validateEtcd() (allErrs field.ErrorList) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will need to accept prev as an argument to do a check between previous and new

Copy link
Contributor

Choose a reason for hiding this comment

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

actually, what exists should be sufficient, just the test would need updating

Copy link
Contributor

@chuckha chuckha Mar 9, 2020

Choose a reason for hiding this comment

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

ok sorry for the back and forth haha, i'm thinking about various use cases.

But I've got an example that this should cover:

If an existing config defines local
then the user manually removes the local config and supplies an external config in the same transaction

the check that only looks at in's configuration is not sufficient and will need to see if previous had either local or external and ensure that the incoming structure does not define the opposite while removing the old one.

Does that make sense? That felt hard to explain so I'd be happy to hop on a call to explain further if necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chuckha please take a look

@nader-ziada
Copy link
Contributor Author

/test pull-cluster-api-capd-e2e

)
}

if in.Spec.KubeadmConfigSpec.ClusterConfiguration.Etcd.External != nil && in.Spec.KubeadmConfigSpec.ClusterConfiguration.Etcd.Local != nil {
Copy link
Contributor

@chuckha chuckha Mar 9, 2020

Choose a reason for hiding this comment

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

This shouldn't reference the ClusterConfiguration, please see: https://github.com/kubernetes-sigs/cluster-api/pull/2605/files

This can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, didn't see that other PR :D

Copy link
Contributor

@chuckha chuckha left a comment

Choose a reason for hiding this comment

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

few minor updates

)
}

if in.Spec.KubeadmConfigSpec.InitConfiguration.Etcd.External != nil && in.Spec.KubeadmConfigSpec.InitConfiguration.Etcd.Local != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This case can be removed as well as the first two cases will cover all the checks we need.

The only reason this check would ever get triggered is if someone first deletes the local configuration and then tries to update both local and external at the same time. I don't think we need to handle this edge case right now.

allErrs = append(
allErrs,
field.Forbidden(
field.NewPath("spec", "kubeadmConfigSpec", "clusterConfiguration", "etcd", "external"),
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be local instead of external

External: &kubeadmv1beta1.ExternalEtcd{
Endpoints: []string{"127.0.0.1"},
},
Local: &kubeadmv1beta1.LocalEtcd{
Copy link
Contributor

Choose a reason for hiding this comment

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

this local should be undefined in this struct. The incoming would only have the external defined and our validations should catch that there is already local defined and we're trying to also define an external configuration.

allErrs = append(
allErrs,
field.Forbidden(
field.NewPath("spec", "kubeadmConfigSpec", "initConfiguration", "etcd", "local"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, this one should be "external" instead of "local".

The reason is that this field is the thing that gets bubbled up to the user and the field on the in type is the one that the user tried to change. So if they change external but then we tell them local is forbidden that's a pretty confusing error message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense

@chuckha
Copy link
Contributor

chuckha commented Mar 9, 2020

That failure is a known flake, please see #2593 for more information.

This looks good, thanks

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 9, 2020
@nader-ziada
Copy link
Contributor Author

/test pull-cluster-api-capd-e2e

@k8s-ci-robot k8s-ci-robot merged commit 96ccd37 into kubernetes-sigs:master Mar 9, 2020
@nader-ziada nader-ziada deleted the etcd branch April 3, 2020 14:56
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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[kubeadm control plane] ensure etcd settings are correct
6 participants