Skip to content

Commit f2a6a24

Browse files
committed
Reintroduce KCP/CABPK ClusterConfiguration controlPlaneEndpoint
Signed-off-by: Stefan Büringer buringerst@vmware.com
1 parent 07db0a3 commit f2a6a24

27 files changed

+148
-65
lines changed

api/bootstrap/kubeadm/v1beta1/conversion_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ func spokeClusterConfiguration(in *ClusterConfiguration, c randfill.Continue) {
143143
in.Networking.PodSubnet = ""
144144
in.Networking.DNSDomain = ""
145145
in.KubernetesVersion = ""
146-
in.ControlPlaneEndpoint = ""
147146
in.ClusterName = ""
148147
}
149148

api/bootstrap/kubeadm/v1beta1/zz_generated.conversion.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/bootstrap/kubeadm/v1beta2/kubeadm_types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ type ClusterConfiguration struct {
122122
// +optional
123123
Etcd Etcd `json:"etcd,omitempty"`
124124

125+
// controlPlaneEndpoint sets a stable IP address or DNS name for the control plane; it
126+
// can be a valid IP address or a RFC-1123 DNS subdomain, both with optional TCP port.
127+
// In case the ControlPlaneEndpoint is not specified, the AdvertiseAddress + BindPort
128+
// are used; in case the ControlPlaneEndpoint is specified but without a TCP port,
129+
// the BindPort is used.
130+
// Possible usages are:
131+
// e.g. In a cluster with more than one control plane instances, this field should be
132+
// assigned the address of the external load balancer in front of the
133+
// control plane instances.
134+
// e.g. in environments with enforced node recycling, the ControlPlaneEndpoint
135+
// could be used for assigning a stable DNS to the control plane.
136+
// NB: This value defaults to the first value in the Cluster object status.apiEndpoints array.
137+
// +optional
138+
// +kubebuilder:validation:MinLength=1
139+
// +kubebuilder:validation:MaxLength=512
140+
ControlPlaneEndpoint string `json:"controlPlaneEndpoint,omitempty"`
141+
125142
// apiServer contains extra settings for the API server control plane component
126143
// +optional
127144
APIServer APIServer `json:"apiServer,omitempty"`

api/controlplane/kubeadm/v1beta1/conversion_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ func spokeClusterConfiguration(in *bootstrapv1beta1.ClusterConfiguration, c rand
222222
in.Networking.PodSubnet = ""
223223
in.Networking.DNSDomain = ""
224224
in.KubernetesVersion = ""
225-
in.ControlPlaneEndpoint = ""
226225
in.ClusterName = ""
227226
}
228227

bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ func (r *KubeadmConfigReconciler) handleClusterNotInitialized(ctx context.Contex
546546
scope.Config.Spec.InitConfiguration = &bootstrapv1.InitConfiguration{}
547547
}
548548

549-
additionalData := r.computeClusterConfigurationAdditionalData(scope.Cluster, machine, scope.Config.Spec.InitConfiguration)
549+
additionalData := r.computeClusterConfigurationAndAdditionalData(scope.Cluster, machine, scope.Config.Spec.ClusterConfiguration, scope.Config.Spec.InitConfiguration)
550550

551551
clusterdata, err := kubeadmtypes.MarshalClusterConfigurationForVersion(scope.Config.Spec.ClusterConfiguration, parsedVersion, additionalData)
552552
if err != nil {
@@ -1313,15 +1313,16 @@ func (r *KubeadmConfigReconciler) reconcileDiscoveryFile(ctx context.Context, cl
13131313
return ctrl.Result{}, nil
13141314
}
13151315

1316-
// computeClusterConfigurationAdditionalData computes additional data that must go in kubeadm's ClusterConfiguration, but exists
1316+
// computeClusterConfigurationAndAdditionalData computes additional data that must go in kubeadm's ClusterConfiguration, but exists
13171317
// in different Cluster API objects, like e.g. the Cluster object.
1318-
func (r *KubeadmConfigReconciler) computeClusterConfigurationAdditionalData(cluster *clusterv1.Cluster, machine *clusterv1.Machine, initConfiguration *bootstrapv1.InitConfiguration) *upstream.AdditionalData {
1318+
func (r *KubeadmConfigReconciler) computeClusterConfigurationAndAdditionalData(cluster *clusterv1.Cluster, machine *clusterv1.Machine, clusterConfiguration *bootstrapv1.ClusterConfiguration, initConfiguration *bootstrapv1.InitConfiguration) *upstream.AdditionalData {
13191319
data := &upstream.AdditionalData{}
13201320

1321-
// If there is a ControlPlaneEndpoint defined at Cluster level (e.g. the load balancer endpoint),
1321+
// If there is no ControlPlaneEndpoint defined in ClusterConfiguration but
1322+
// there is a ControlPlaneEndpoint defined at Cluster level (e.g. the load balancer endpoint),
13221323
// then use Cluster's ControlPlaneEndpoint as a control plane endpoint for the Kubernetes cluster.
1323-
if cluster.Spec.ControlPlaneEndpoint.IsValid() {
1324-
data.ControlPlaneEndpoint = ptr.To(cluster.Spec.ControlPlaneEndpoint.String())
1324+
if clusterConfiguration.ControlPlaneEndpoint == "" && cluster.Spec.ControlPlaneEndpoint.IsValid() {
1325+
clusterConfiguration.ControlPlaneEndpoint = cluster.Spec.ControlPlaneEndpoint.String()
13251326
}
13261327

13271328
// Use Cluster.Name

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,7 @@ func TestKubeadmConfigReconciler_Reconcile_DiscoveryReconcileFailureBehaviors(t
18281828
}
18291829

18301830
// Set cluster configuration defaults based on dynamic values from the cluster object.
1831-
func TestKubeadmConfigReconciler_computeClusterConfigurationAdditionalData(t *testing.T) {
1831+
func TestKubeadmConfigReconciler_computeClusterConfigurationAndAdditionalData(t *testing.T) {
18321832
k := &KubeadmConfigReconciler{}
18331833

18341834
testcases := []struct {
@@ -1870,9 +1870,10 @@ func TestKubeadmConfigReconciler_computeClusterConfigurationAdditionalData(t *te
18701870
t.Run(tc.name, func(t *testing.T) {
18711871
g := NewWithT(t)
18721872

1873-
gotData := k.computeClusterConfigurationAdditionalData(tc.cluster, tc.machine, tc.initConfiguration)
1873+
clusterConfiguration := &bootstrapv1.ClusterConfiguration{}
1874+
gotData := k.computeClusterConfigurationAndAdditionalData(tc.cluster, tc.machine, clusterConfiguration, tc.initConfiguration)
1875+
g.Expect(clusterConfiguration.ControlPlaneEndpoint).To(Equal("myControlPlaneEndpoint:6443"))
18741876
g.Expect(gotData.KubernetesVersion).To(Equal(ptr.To("v1.23.0")))
1875-
g.Expect(gotData.ControlPlaneEndpoint).To(Equal(ptr.To("myControlPlaneEndpoint:6443")))
18761877
g.Expect(gotData.ClusterName).To(Equal(ptr.To("mycluster")))
18771878
g.Expect(gotData.PodSubnet).To(Equal(ptr.To("myPodSubnet")))
18781879
g.Expect(gotData.ServiceSubnet).To(Equal(ptr.To("myServiceSubnet")))

bootstrap/kubeadm/types/upstream/upstream.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ type AdditionalDataGetter interface {
3535
// in different Cluster API objects, like e.g. the Cluster object.
3636
type AdditionalData struct {
3737
// Data from Cluster API's Cluster object.
38-
KubernetesVersion *string
39-
ClusterName *string
40-
ControlPlaneEndpoint *string
41-
DNSDomain *string
42-
ServiceSubnet *string
43-
PodSubnet *string
38+
KubernetesVersion *string
39+
ClusterName *string
40+
DNSDomain *string
41+
ServiceSubnet *string
42+
PodSubnet *string
4443

4544
// Data migrated from ClusterConfiguration to InitConfiguration in kubeadm's v1beta4 API version.
4645
// Note: Corresponding Cluster API types are aligned with kubeadm's v1beta4 API version.
@@ -52,7 +51,6 @@ func (a *AdditionalData) Clone() *AdditionalData {
5251
return &AdditionalData{
5352
KubernetesVersion: a.KubernetesVersion,
5453
ClusterName: a.ClusterName,
55-
ControlPlaneEndpoint: a.ControlPlaneEndpoint,
5654
DNSDomain: a.DNSDomain,
5755
ServiceSubnet: a.ServiceSubnet,
5856
PodSubnet: a.PodSubnet,

bootstrap/kubeadm/types/upstreamv1beta3/conversion.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,6 @@ func (src *ClusterConfiguration) SetAdditionalData(data upstream.AdditionalData)
193193
if data.ClusterName != nil {
194194
src.ClusterName = *data.ClusterName
195195
}
196-
if data.ControlPlaneEndpoint != nil {
197-
src.ControlPlaneEndpoint = *data.ControlPlaneEndpoint
198-
}
199196
if data.DNSDomain != nil {
200197
src.Networking.DNSDomain = *data.DNSDomain
201198
}
@@ -226,9 +223,6 @@ func (src *ClusterConfiguration) GetAdditionalData(data *upstream.AdditionalData
226223
if src.ClusterName != "" {
227224
data.ClusterName = ptr.To(src.ClusterName)
228225
}
229-
if src.ControlPlaneEndpoint != "" {
230-
data.ControlPlaneEndpoint = ptr.To(src.ControlPlaneEndpoint)
231-
}
232226
if src.Networking.DNSDomain != "" {
233227
data.DNSDomain = ptr.To(src.Networking.DNSDomain)
234228
}

0 commit comments

Comments
 (0)