From 434a076e8b52d9fae208d29c2b3213ee9b7a8a92 Mon Sep 17 00:00:00 2001 From: Travis Hall Date: Thu, 9 Jul 2020 22:54:09 -0700 Subject: [PATCH] Allow KCP users to mutate node registration options --- ...strap.cluster.x-k8s.io_kubeadmconfigs.yaml | 16 ++++++++--- ...uster.x-k8s.io_kubeadmconfigtemplates.yaml | 20 ++++++++++--- bootstrap/kubeadm/types/v1beta1/types.go | 8 ++++-- .../v1alpha3/kubeadm_control_plane_webhook.go | 5 ++++ .../kubeadm_control_plane_webhook_test.go | 28 ++++++++++++++++++- ...cluster.x-k8s.io_kubeadmcontrolplanes.yaml | 10 +++++-- 6 files changed, 74 insertions(+), 13 deletions(-) diff --git a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml index e4c353d5a99c..cfdf1fe17216 100644 --- a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml +++ b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml @@ -483,7 +483,9 @@ spec: type: object nodeRegistration: description: NodeRegistration holds fields that relate to registering - the new control-plane node to the cluster + the new control-plane node to the cluster. When used in the + context of control plane nodes, NodeRegistration should remain + consistent across both InitConfiguration and JoinConfiguration properties: criSocket: description: CRISocket is used to retrieve container runtime @@ -662,7 +664,9 @@ spec: type: string nodeRegistration: description: NodeRegistration holds fields that relate to registering - the new control-plane node to the cluster + the new control-plane node to the cluster. When used in the + context of control plane nodes, NodeRegistration should remain + consistent across both InitConfiguration and JoinConfiguration properties: criSocket: description: CRISocket is used to retrieve container runtime @@ -1391,7 +1395,9 @@ spec: type: object nodeRegistration: description: NodeRegistration holds fields that relate to registering - the new control-plane node to the cluster + the new control-plane node to the cluster. When used in the + context of control plane nodes, NodeRegistration should remain + consistent across both InitConfiguration and JoinConfiguration properties: criSocket: description: CRISocket is used to retrieve container runtime @@ -1570,7 +1576,9 @@ spec: type: string nodeRegistration: description: NodeRegistration holds fields that relate to registering - the new control-plane node to the cluster + the new control-plane node to the cluster. When used in the + context of control plane nodes, NodeRegistration should remain + consistent across both InitConfiguration and JoinConfiguration properties: criSocket: description: CRISocket is used to retrieve container runtime diff --git a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml index cda86e295cdb..191310ed0c5b 100644 --- a/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml +++ b/bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml @@ -514,7 +514,10 @@ spec: type: object nodeRegistration: description: NodeRegistration holds fields that relate - to registering the new control-plane node to the cluster + to registering the new control-plane node to the cluster. + When used in the context of control plane nodes, NodeRegistration + should remain consistent across both InitConfiguration + and JoinConfiguration properties: criSocket: description: CRISocket is used to retrieve container @@ -703,7 +706,10 @@ spec: type: string nodeRegistration: description: NodeRegistration holds fields that relate - to registering the new control-plane node to the cluster + to registering the new control-plane node to the cluster. + When used in the context of control plane nodes, NodeRegistration + should remain consistent across both InitConfiguration + and JoinConfiguration properties: criSocket: description: CRISocket is used to retrieve container @@ -1461,7 +1467,10 @@ spec: type: object nodeRegistration: description: NodeRegistration holds fields that relate - to registering the new control-plane node to the cluster + to registering the new control-plane node to the cluster. + When used in the context of control plane nodes, NodeRegistration + should remain consistent across both InitConfiguration + and JoinConfiguration properties: criSocket: description: CRISocket is used to retrieve container @@ -1650,7 +1659,10 @@ spec: type: string nodeRegistration: description: NodeRegistration holds fields that relate - to registering the new control-plane node to the cluster + to registering the new control-plane node to the cluster. + When used in the context of control plane nodes, NodeRegistration + should remain consistent across both InitConfiguration + and JoinConfiguration properties: criSocket: description: CRISocket is used to retrieve container diff --git a/bootstrap/kubeadm/types/v1beta1/types.go b/bootstrap/kubeadm/types/v1beta1/types.go index 897f3866957f..6e2c58ee29a6 100644 --- a/bootstrap/kubeadm/types/v1beta1/types.go +++ b/bootstrap/kubeadm/types/v1beta1/types.go @@ -33,7 +33,9 @@ type InitConfiguration struct { // +optional BootstrapTokens []BootstrapToken `json:"bootstrapTokens,omitempty"` - // NodeRegistration holds fields that relate to registering the new control-plane node to the cluster + // NodeRegistration holds fields that relate to registering the new control-plane node to the cluster. + // When used in the context of control plane nodes, NodeRegistration should remain consistent + // across both InitConfiguration and JoinConfiguration // +optional NodeRegistration NodeRegistrationOptions `json:"nodeRegistration,omitempty"` @@ -325,7 +327,9 @@ type ExternalEtcd struct { type JoinConfiguration struct { metav1.TypeMeta `json:",inline"` - // NodeRegistration holds fields that relate to registering the new control-plane node to the cluster + // NodeRegistration holds fields that relate to registering the new control-plane node to the cluster. + // When used in the context of control plane nodes, NodeRegistration should remain consistent + // across both InitConfiguration and JoinConfiguration // +optional NodeRegistration NodeRegistrationOptions `json:"nodeRegistration,omitempty"` diff --git a/controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_webhook.go b/controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_webhook.go index 8cd653f0e15c..7b4008eb788a 100644 --- a/controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_webhook.go +++ b/controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_webhook.go @@ -80,6 +80,9 @@ const ( spec = "spec" kubeadmConfigSpec = "kubeadmConfigSpec" clusterConfiguration = "clusterConfiguration" + initConfiguration = "initConfiguration" + joinConfiguration = "joinConfiguration" + nodeRegistration = "nodeRegistration" preKubeadmCommands = "preKubeadmCommands" postKubeadmCommands = "postKubeadmCommands" files = "files" @@ -96,6 +99,8 @@ func (in *KubeadmControlPlane) ValidateUpdate(old runtime.Object) error { {spec, kubeadmConfigSpec, clusterConfiguration, "dns", "imageRepository"}, {spec, kubeadmConfigSpec, clusterConfiguration, "dns", "imageTag"}, {spec, kubeadmConfigSpec, clusterConfiguration, "imageRepository"}, + {spec, kubeadmConfigSpec, initConfiguration, nodeRegistration, "*"}, + {spec, kubeadmConfigSpec, joinConfiguration, nodeRegistration, "*"}, {spec, kubeadmConfigSpec, preKubeadmCommands}, {spec, kubeadmConfigSpec, postKubeadmCommands}, {spec, kubeadmConfigSpec, files}, diff --git a/controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_webhook_test.go b/controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_webhook_test.go index 3afb02b1f591..d53d61d24cce 100644 --- a/controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_webhook_test.go +++ b/controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_webhook_test.go @@ -175,6 +175,9 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) { AdvertiseAddress: "127.0.0.1", BindPort: int32(443), }, + NodeRegistration: kubeadmv1beta1.NodeRegistrationOptions{ + Name: "test", + }, }, ClusterConfiguration: &kubeadmv1beta1.ClusterConfiguration{ ClusterName: "test", @@ -186,6 +189,11 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) { }, }, JoinConfiguration: &kubeadmv1beta1.JoinConfiguration{ + Discovery: kubeadmv1beta1.Discovery{ + Timeout: &metav1.Duration{ + Duration: 10 * time.Minute, + }, + }, NodeRegistration: kubeadmv1beta1.NodeRegistrationOptions{ Name: "test", }, @@ -209,11 +217,17 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) { invalidUpdateKubeadmConfigInit := before.DeepCopy() invalidUpdateKubeadmConfigInit.Spec.KubeadmConfigSpec.InitConfiguration = &kubeadmv1beta1.InitConfiguration{} + validUpdateKubeadmConfigInit := before.DeepCopy() + validUpdateKubeadmConfigInit.Spec.KubeadmConfigSpec.InitConfiguration.NodeRegistration = kubeadmv1beta1.NodeRegistrationOptions{} + invalidUpdateKubeadmConfigCluster := before.DeepCopy() invalidUpdateKubeadmConfigCluster.Spec.KubeadmConfigSpec.ClusterConfiguration = &kubeadmv1beta1.ClusterConfiguration{} + invalidUpdateKubeadmConfigJoin := before.DeepCopy() + invalidUpdateKubeadmConfigJoin.Spec.KubeadmConfigSpec.JoinConfiguration = &kubeadmv1beta1.JoinConfiguration{} + validUpdateKubeadmConfigJoin := before.DeepCopy() - validUpdateKubeadmConfigJoin.Spec.KubeadmConfigSpec.JoinConfiguration = &kubeadmv1beta1.JoinConfiguration{} + validUpdateKubeadmConfigJoin.Spec.KubeadmConfigSpec.JoinConfiguration.NodeRegistration = kubeadmv1beta1.NodeRegistrationOptions{} validUpdate := before.DeepCopy() validUpdate.Labels = map[string]string{"blue": "green"} @@ -429,6 +443,12 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) { before: before, kcp: invalidUpdateKubeadmConfigInit, }, + { + name: "should not return an error when trying to mutate the kubeadmconfigspec initconfiguration noderegistration", + expectErr: false, + before: before, + kcp: validUpdateKubeadmConfigInit, + }, { name: "should return error when trying to mutate the kubeadmconfigspec clusterconfiguration", expectErr: true, @@ -439,6 +459,12 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) { name: "should return error when trying to mutate the kubeadmconfigspec joinconfiguration", expectErr: true, before: before, + kcp: invalidUpdateKubeadmConfigJoin, + }, + { + name: "should not return an error when trying to mutate the kubeadmconfigspec joinconfiguration noderegistration", + expectErr: false, + before: before, kcp: validUpdateKubeadmConfigJoin, }, { diff --git a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml index 6bd128ba3887..b676025582e9 100644 --- a/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml +++ b/controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml @@ -671,7 +671,10 @@ spec: type: object nodeRegistration: description: NodeRegistration holds fields that relate to - registering the new control-plane node to the cluster + registering the new control-plane node to the cluster. When + used in the context of control plane nodes, NodeRegistration + should remain consistent across both InitConfiguration and + JoinConfiguration properties: criSocket: description: CRISocket is used to retrieve container runtime @@ -855,7 +858,10 @@ spec: type: string nodeRegistration: description: NodeRegistration holds fields that relate to - registering the new control-plane node to the cluster + registering the new control-plane node to the cluster. When + used in the context of control plane nodes, NodeRegistration + should remain consistent across both InitConfiguration and + JoinConfiguration properties: criSocket: description: CRISocket is used to retrieve container runtime