diff --git a/Makefile b/Makefile index f934d023b0aa..8c67d56bb8d0 100644 --- a/Makefile +++ b/Makefile @@ -228,7 +228,8 @@ generate-go-core: $(CONTROLLER_GEN) $(CONVERSION_GEN) generate-go-kubeadm-bootstrap: $(CONTROLLER_GEN) $(CONVERSION_GEN) ## Runs Go related generate targets for the kubeadm bootstrapper $(CONTROLLER_GEN) \ object:headerFile=./hack/boilerplate/boilerplate.generatego.txt \ - paths=./bootstrap/kubeadm/api/... + paths=./bootstrap/kubeadm/api/... \ + paths=./bootstrap/kubeadm/types/... $(CONVERSION_GEN) \ --input-dirs=./bootstrap/kubeadm/api/v1alpha2 \ --output-file-base=zz_generated.conversion \ diff --git a/bootstrap/kubeadm/types/v1beta1/types.go b/bootstrap/kubeadm/types/v1beta1/types.go index b1146e2f705b..d05a116e6f20 100644 --- a/bootstrap/kubeadm/types/v1beta1/types.go +++ b/bootstrap/kubeadm/types/v1beta1/types.go @@ -28,16 +28,6 @@ import ( type InitConfiguration struct { metav1.TypeMeta `json:",inline"` - // ClusterConfiguration holds the cluster-wide information, and embeds that struct (which can be (un)marshalled separately as well) - // When InitConfiguration is marshalled to bytes in the external version, this information IS NOT preserved (which can be seen from - // the `json:"-"` tag. This is due to that when InitConfiguration is (un)marshalled, it turns into two YAML documents, one for the - // InitConfiguration and ClusterConfiguration. Hence, the information must not be duplicated, and is therefore omitted here. - ClusterConfiguration `json:"-"` - - // `kubeadm init`-only information. These fields are solely used the first time `kubeadm init` runs. - // After that, the information in the fields IS NOT uploaded to the `kubeadm-config` ConfigMap - // that is used by `kubeadm upgrade` for instance. These fields must be omitempty. - // BootstrapTokens is respected at `kubeadm init` time and describes a set of Bootstrap Tokens to create. // This information IS NOT uploaded to the kubeadm cluster configmap, partly because of its sensitive nature BootstrapTokens []BootstrapToken `json:"bootstrapTokens,omitempty"` diff --git a/bootstrap/kubeadm/types/v1beta1/zz_generated.deepcopy.go b/bootstrap/kubeadm/types/v1beta1/zz_generated.deepcopy.go index d6cdfda335a4..622c19612172 100644 --- a/bootstrap/kubeadm/types/v1beta1/zz_generated.deepcopy.go +++ b/bootstrap/kubeadm/types/v1beta1/zz_generated.deepcopy.go @@ -16,20 +16,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by deepcopy-gen. DO NOT EDIT. +// Code generated by controller-gen. DO NOT EDIT. package v1beta1 import ( corev1 "k8s.io/api/core/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *APIEndpoint) DeepCopyInto(out *APIEndpoint) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIEndpoint. @@ -56,7 +55,6 @@ func (in *APIServer) DeepCopyInto(out *APIServer) { *out = new(v1.Duration) **out = **in } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIServer. @@ -96,7 +94,6 @@ func (in *BootstrapToken) DeepCopyInto(out *BootstrapToken) { *out = make([]string, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BootstrapToken. @@ -117,7 +114,6 @@ func (in *BootstrapTokenDiscovery) DeepCopyInto(out *BootstrapTokenDiscovery) { *out = make([]string, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BootstrapTokenDiscovery. @@ -133,7 +129,6 @@ func (in *BootstrapTokenDiscovery) DeepCopy() *BootstrapTokenDiscovery { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BootstrapTokenString) DeepCopyInto(out *BootstrapTokenString) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BootstrapTokenString. @@ -163,7 +158,6 @@ func (in *ClusterConfiguration) DeepCopyInto(out *ClusterConfiguration) { (*out)[key] = val } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterConfiguration. @@ -195,7 +189,6 @@ func (in *ClusterStatus) DeepCopyInto(out *ClusterStatus) { (*out)[key] = val } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterStatus. @@ -231,7 +224,6 @@ func (in *ControlPlaneComponent) DeepCopyInto(out *ControlPlaneComponent) { *out = make([]HostPathMount, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ControlPlaneComponent. @@ -248,7 +240,6 @@ func (in *ControlPlaneComponent) DeepCopy() *ControlPlaneComponent { func (in *DNS) DeepCopyInto(out *DNS) { *out = *in out.ImageMeta = in.ImageMeta - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DNS. @@ -279,7 +270,6 @@ func (in *Discovery) DeepCopyInto(out *Discovery) { *out = new(v1.Duration) **out = **in } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Discovery. @@ -305,7 +295,6 @@ func (in *Etcd) DeepCopyInto(out *Etcd) { *out = new(ExternalEtcd) (*in).DeepCopyInto(*out) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Etcd. @@ -326,7 +315,6 @@ func (in *ExternalEtcd) DeepCopyInto(out *ExternalEtcd) { *out = make([]string, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalEtcd. @@ -342,7 +330,6 @@ func (in *ExternalEtcd) DeepCopy() *ExternalEtcd { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *FileDiscovery) DeepCopyInto(out *FileDiscovery) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FileDiscovery. @@ -358,7 +345,6 @@ func (in *FileDiscovery) DeepCopy() *FileDiscovery { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *HostPathMount) DeepCopyInto(out *HostPathMount) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HostPathMount. @@ -374,7 +360,6 @@ func (in *HostPathMount) DeepCopy() *HostPathMount { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ImageMeta) DeepCopyInto(out *ImageMeta) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ImageMeta. @@ -391,7 +376,6 @@ func (in *ImageMeta) DeepCopy() *ImageMeta { func (in *InitConfiguration) DeepCopyInto(out *InitConfiguration) { *out = *in out.TypeMeta = in.TypeMeta - in.ClusterConfiguration.DeepCopyInto(&out.ClusterConfiguration) if in.BootstrapTokens != nil { in, out := &in.BootstrapTokens, &out.BootstrapTokens *out = make([]BootstrapToken, len(*in)) @@ -401,7 +385,6 @@ func (in *InitConfiguration) DeepCopyInto(out *InitConfiguration) { } in.NodeRegistration.DeepCopyInto(&out.NodeRegistration) out.LocalAPIEndpoint = in.LocalAPIEndpoint - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InitConfiguration. @@ -433,7 +416,6 @@ func (in *JoinConfiguration) DeepCopyInto(out *JoinConfiguration) { *out = new(JoinControlPlane) **out = **in } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JoinConfiguration. @@ -458,7 +440,6 @@ func (in *JoinConfiguration) DeepCopyObject() runtime.Object { func (in *JoinControlPlane) DeepCopyInto(out *JoinControlPlane) { *out = *in out.LocalAPIEndpoint = in.LocalAPIEndpoint - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JoinControlPlane. @@ -492,7 +473,6 @@ func (in *LocalEtcd) DeepCopyInto(out *LocalEtcd) { *out = make([]string, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LocalEtcd. @@ -508,7 +488,6 @@ func (in *LocalEtcd) DeepCopy() *LocalEtcd { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Networking) DeepCopyInto(out *Networking) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Networking. @@ -538,7 +517,6 @@ func (in *NodeRegistrationOptions) DeepCopyInto(out *NodeRegistrationOptions) { (*out)[key] = val } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeRegistrationOptions. diff --git a/bootstrap/kubeadm/types/v1beta2/zz_generated.deepcopy.go b/bootstrap/kubeadm/types/v1beta2/zz_generated.deepcopy.go index 399923a6164d..1125246c9329 100644 --- a/bootstrap/kubeadm/types/v1beta2/zz_generated.deepcopy.go +++ b/bootstrap/kubeadm/types/v1beta2/zz_generated.deepcopy.go @@ -16,20 +16,19 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Code generated by deepcopy-gen. DO NOT EDIT. +// Code generated by controller-gen. DO NOT EDIT. package v1beta2 import ( corev1 "k8s.io/api/core/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *APIEndpoint) DeepCopyInto(out *APIEndpoint) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIEndpoint. @@ -56,7 +55,6 @@ func (in *APIServer) DeepCopyInto(out *APIServer) { *out = new(v1.Duration) **out = **in } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIServer. @@ -96,7 +94,6 @@ func (in *BootstrapToken) DeepCopyInto(out *BootstrapToken) { *out = make([]string, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BootstrapToken. @@ -117,7 +114,6 @@ func (in *BootstrapTokenDiscovery) DeepCopyInto(out *BootstrapTokenDiscovery) { *out = make([]string, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BootstrapTokenDiscovery. @@ -133,7 +129,6 @@ func (in *BootstrapTokenDiscovery) DeepCopy() *BootstrapTokenDiscovery { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BootstrapTokenString) DeepCopyInto(out *BootstrapTokenString) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BootstrapTokenString. @@ -163,7 +158,6 @@ func (in *ClusterConfiguration) DeepCopyInto(out *ClusterConfiguration) { (*out)[key] = val } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterConfiguration. @@ -195,7 +189,6 @@ func (in *ClusterStatus) DeepCopyInto(out *ClusterStatus) { (*out)[key] = val } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterStatus. @@ -231,7 +224,6 @@ func (in *ControlPlaneComponent) DeepCopyInto(out *ControlPlaneComponent) { *out = make([]HostPathMount, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ControlPlaneComponent. @@ -248,7 +240,6 @@ func (in *ControlPlaneComponent) DeepCopy() *ControlPlaneComponent { func (in *DNS) DeepCopyInto(out *DNS) { *out = *in out.ImageMeta = in.ImageMeta - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DNS. @@ -279,7 +270,6 @@ func (in *Discovery) DeepCopyInto(out *Discovery) { *out = new(v1.Duration) **out = **in } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Discovery. @@ -305,7 +295,6 @@ func (in *Etcd) DeepCopyInto(out *Etcd) { *out = new(ExternalEtcd) (*in).DeepCopyInto(*out) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Etcd. @@ -326,7 +315,6 @@ func (in *ExternalEtcd) DeepCopyInto(out *ExternalEtcd) { *out = make([]string, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalEtcd. @@ -342,7 +330,6 @@ func (in *ExternalEtcd) DeepCopy() *ExternalEtcd { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *FileDiscovery) DeepCopyInto(out *FileDiscovery) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FileDiscovery. @@ -358,7 +345,6 @@ func (in *FileDiscovery) DeepCopy() *FileDiscovery { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *HostPathMount) DeepCopyInto(out *HostPathMount) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HostPathMount. @@ -374,7 +360,6 @@ func (in *HostPathMount) DeepCopy() *HostPathMount { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ImageMeta) DeepCopyInto(out *ImageMeta) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ImageMeta. @@ -400,7 +385,6 @@ func (in *InitConfiguration) DeepCopyInto(out *InitConfiguration) { } in.NodeRegistration.DeepCopyInto(&out.NodeRegistration) out.LocalAPIEndpoint = in.LocalAPIEndpoint - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InitConfiguration. @@ -432,7 +416,6 @@ func (in *JoinConfiguration) DeepCopyInto(out *JoinConfiguration) { *out = new(JoinControlPlane) **out = **in } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JoinConfiguration. @@ -457,7 +440,6 @@ func (in *JoinConfiguration) DeepCopyObject() runtime.Object { func (in *JoinControlPlane) DeepCopyInto(out *JoinControlPlane) { *out = *in out.LocalAPIEndpoint = in.LocalAPIEndpoint - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JoinControlPlane. @@ -491,7 +473,6 @@ func (in *LocalEtcd) DeepCopyInto(out *LocalEtcd) { *out = make([]string, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LocalEtcd. @@ -507,7 +488,6 @@ func (in *LocalEtcd) DeepCopy() *LocalEtcd { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Networking) DeepCopyInto(out *Networking) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Networking. @@ -542,7 +522,6 @@ func (in *NodeRegistrationOptions) DeepCopyInto(out *NodeRegistrationOptions) { *out = make([]string, len(*in)) copy(*out, *in) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeRegistrationOptions. diff --git a/controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_webhook.go b/controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_webhook.go index 1dda665f809f..066626252b71 100644 --- a/controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_webhook.go +++ b/controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_webhook.go @@ -197,11 +197,6 @@ func (in *KubeadmControlPlane) validateCommon() (allErrs field.ErrorList) { } externalEtcd := false - if in.Spec.KubeadmConfigSpec.InitConfiguration != nil { - if in.Spec.KubeadmConfigSpec.InitConfiguration.Etcd.External != nil { - externalEtcd = true - } - } if in.Spec.KubeadmConfigSpec.ClusterConfiguration != nil { if in.Spec.KubeadmConfigSpec.ClusterConfiguration.Etcd.External != nil { externalEtcd = true @@ -235,7 +230,7 @@ func (in *KubeadmControlPlane) validateCommon() (allErrs field.ErrorList) { } func (in *KubeadmControlPlane) validateEtcd(prev *KubeadmControlPlane) (allErrs field.ErrorList) { - if in.Spec.KubeadmConfigSpec.InitConfiguration.Etcd.External != nil && prev.Spec.KubeadmConfigSpec.InitConfiguration.Etcd.Local != nil { + if in.Spec.KubeadmConfigSpec.ClusterConfiguration.Etcd.External != nil && prev.Spec.KubeadmConfigSpec.ClusterConfiguration.Etcd.Local != nil { allErrs = append( allErrs, field.Forbidden( @@ -245,7 +240,7 @@ func (in *KubeadmControlPlane) validateEtcd(prev *KubeadmControlPlane) (allErrs ) } - if in.Spec.KubeadmConfigSpec.InitConfiguration.Etcd.Local != nil && prev.Spec.KubeadmConfigSpec.InitConfiguration.Etcd.External != nil { + if in.Spec.KubeadmConfigSpec.ClusterConfiguration.Etcd.Local != nil && prev.Spec.KubeadmConfigSpec.ClusterConfiguration.Etcd.External != nil { allErrs = append( allErrs, field.Forbidden( 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 7835605a9011..dfa3e05b762e 100644 --- a/controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_webhook_test.go +++ b/controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_webhook_test.go @@ -72,11 +72,9 @@ func TestKubeadmControlPlaneValidateCreate(t *testing.T) { evenReplicasExternalEtcd := evenReplicas.DeepCopy() evenReplicasExternalEtcd.Spec.KubeadmConfigSpec = bootstrapv1.KubeadmConfigSpec{ - InitConfiguration: &kubeadmv1beta1.InitConfiguration{ - ClusterConfiguration: kubeadmv1beta1.ClusterConfiguration{ - Etcd: kubeadmv1beta1.Etcd{ - External: &kubeadmv1beta1.ExternalEtcd{}, - }, + ClusterConfiguration: &kubeadmv1beta1.ClusterConfiguration{ + Etcd: kubeadmv1beta1.Etcd{ + External: &kubeadmv1beta1.ExternalEtcd{}, }, }, } @@ -270,19 +268,6 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) { ExtraArgs: map[string]string{"an arg": "a value"}, } - beforeExternalEtcdInit := before.DeepCopy() - beforeExternalEtcdInit.Spec.KubeadmConfigSpec.InitConfiguration = &kubeadmv1beta1.InitConfiguration{ - ClusterConfiguration: kubeadmv1beta1.ClusterConfiguration{ - Etcd: kubeadmv1beta1.Etcd{ - External: &kubeadmv1beta1.ExternalEtcd{ - Endpoints: []string{"127.0.0.1"}, - }, - }, - }, - } - scaleToEvenExternalEtcdInit := beforeExternalEtcdInit.DeepCopy() - scaleToEvenExternalEtcdInit.Spec.Replicas = pointer.Int32Ptr(2) - beforeExternalEtcdCluster := before.DeepCopy() beforeExternalEtcdCluster.Spec.KubeadmConfigSpec.ClusterConfiguration = &kubeadmv1beta1.ClusterConfiguration{ Etcd: kubeadmv1beta1.Etcd{ @@ -295,7 +280,7 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) { scaleToEvenExternalEtcdCluster.Spec.Replicas = pointer.Int32Ptr(2) beforeInvalidEtcdCluster := before.DeepCopy() - beforeInvalidEtcdCluster.Spec.KubeadmConfigSpec.InitConfiguration.ClusterConfiguration.Etcd = kubeadmv1beta1.Etcd{ + beforeInvalidEtcdCluster.Spec.KubeadmConfigSpec.ClusterConfiguration.Etcd = kubeadmv1beta1.Etcd{ Local: &kubeadmv1beta1.LocalEtcd{ ImageMeta: kubeadmv1beta1.ImageMeta{ ImageRepository: "image-repository", @@ -305,7 +290,7 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) { } afterInvalidEtcdCluster := beforeInvalidEtcdCluster.DeepCopy() - afterInvalidEtcdCluster.Spec.KubeadmConfigSpec.InitConfiguration.ClusterConfiguration.Etcd = kubeadmv1beta1.Etcd{ + afterInvalidEtcdCluster.Spec.KubeadmConfigSpec.ClusterConfiguration.Etcd = kubeadmv1beta1.Etcd{ External: &kubeadmv1beta1.ExternalEtcd{ Endpoints: []string{"127.0.0.1"}, }, @@ -365,12 +350,6 @@ func TestKubeadmControlPlaneValidateUpdate(t *testing.T) { before: before, kcp: missingReplicas, }, - { - name: "should succeed when trying to scale to an even number with external etcd defined in InitConfiguration", - expectErr: false, - before: beforeExternalEtcdInit, - kcp: scaleToEvenExternalEtcdInit, - }, { name: "should succeed when trying to scale to an even number with external etcd defined in ClusterConfiguration", expectErr: false,