Skip to content

Commit

Permalink
Merge pull request #3324 from tvs/allow-config-changes
Browse files Browse the repository at this point in the history
✨Allow KCP users to mutate node registration options
  • Loading branch information
k8s-ci-robot authored Jul 14, 2020
2 parents 4e07b0c + 434a076 commit 846ca08
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions bootstrap/kubeadm/types/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ const (
spec = "spec"
kubeadmConfigSpec = "kubeadmConfigSpec"
clusterConfiguration = "clusterConfiguration"
initConfiguration = "initConfiguration"
joinConfiguration = "joinConfiguration"
nodeRegistration = "nodeRegistration"
preKubeadmCommands = "preKubeadmCommands"
postKubeadmCommands = "postKubeadmCommands"
files = "files"
Expand All @@ -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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
},
Expand All @@ -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"}
Expand Down Expand Up @@ -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,
Expand All @@ -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,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 846ca08

Please sign in to comment.