Skip to content

Commit 3eb9c7f

Browse files
committed
capi: refactor bootstrap building to use shared ConfigBuilder
The intent is that the ConfigBuilder from bare-metal support is reusable.
1 parent a0b1202 commit 3eb9c7f

File tree

4 files changed

+85
-248
lines changed

4 files changed

+85
-248
lines changed

clusterapi/controlplane/kops/api/v1beta1/kopscontrolplane_types.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,35 @@ type KopsControlPlaneInitializationStatus struct {
6060
ControlPlaneInitialized *bool `json:"controlPlaneInitialized,omitempty"`
6161
}
6262

63+
// SystemEndpointType identifies the service that the SystemEndpoint is describing.
64+
type SystemEndpointType string
65+
66+
const (
67+
// SystemEndpointTypeKubeAPIServer indicates that the endpoint is for the Kubernetes API server.
68+
SystemEndpointTypeKubeAPIServer SystemEndpointType = "kube-apiserver"
69+
// SystemEndpointTypeKopsController indicates that the endpoint is for the kops-controller.
70+
SystemEndpointTypeKopsController SystemEndpointType = "kops-controller"
71+
)
72+
73+
// SystemEndpointScope describes whether an endpoint is intended for internal or external use.
74+
type SystemEndpointScope string
75+
76+
const (
77+
// SystemEndpointScopeInternal indicates that the endpoint is intended for internal use.
78+
SystemEndpointScopeInternal SystemEndpointScope = "internal"
79+
// SystemEndpointScopeExternal indicates that the endpoint is intended for external use.
80+
SystemEndpointScopeExternal SystemEndpointScope = "external"
81+
)
82+
6383
// SystemEndpoint represents a reachable Kubernetes API endpoint.
6484
type SystemEndpoint struct {
65-
// The hostname on which the API server is serving.
66-
Host string `json:"host"`
67-
// The hostname on which the API server is serving.
68-
Type string `json:"type"`
69-
Scope string `json:"scope"`
85+
// The type of the endpoint
86+
Type SystemEndpointType `json:"type"`
87+
88+
// The hostname or IP on which the API server is serving.
89+
Endpoint string `json:"endpoint"`
90+
91+
Scope SystemEndpointScope `json:"scope"`
7092
}
7193

7294
// +kubebuilder:object:root=true

pkg/commands/toolbox_enroll.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,11 @@ type BootstrapData struct {
423423
// ConfigBuilder builds bootstrap configuration for a node.
424424
type ConfigBuilder struct {
425425
// ClusterName is the name of the cluster to build.
426-
// Required.
426+
// Required (unless Cluster is set).
427427
ClusterName string
428428

429429
// InstanceGroupName is the name of the InstanceGroup we are building configuration for.
430-
// Required.
430+
// Required (unless InstanceGroup is set).
431431
InstanceGroupName string
432432

433433
// Clientset is the clientset to use to query for clusters / instancegroups etc

pkg/controllers/clusterapi/cluster_controller.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import (
3131
"sigs.k8s.io/controller-runtime/pkg/client"
3232
"sigs.k8s.io/controller-runtime/pkg/manager"
3333
"sigs.k8s.io/yaml"
34+
35+
capikops "k8s.io/kops/clusterapi/controlplane/kops/api/v1beta1"
3436
)
3537

3638
// NewClusterReconciler is the constructor for an ClusterReconciler
@@ -163,7 +165,7 @@ func (s *clusterScope) applyGCPCluster(ctx context.Context, kube client.Client)
163165
return nil
164166
}
165167

166-
func (s *clusterScope) findSystemEndpoints(ctx context.Context) ([]map[string]any, error) {
168+
func (s *clusterScope) findSystemEndpoints(ctx context.Context) ([]capikops.SystemEndpoint, error) {
167169
cluster := s.Cluster
168170

169171
clusterInternal := &kops.Cluster{}
@@ -183,38 +185,38 @@ func (s *clusterScope) findSystemEndpoints(ctx context.Context) ([]map[string]an
183185
return nil, fmt.Errorf("error getting ingress status: %v", err)
184186
}
185187

186-
var targets []map[string]any
188+
var targets []capikops.SystemEndpoint
187189

188190
for _, ingress := range ingresses {
189-
target := make(map[string]any)
191+
var target capikops.SystemEndpoint
190192
if ingress.Hostname != "" {
191-
target["host"] = ingress.Hostname
193+
target.Endpoint = ingress.Hostname
192194
}
193195
if ingress.IP != "" {
194-
target["host"] = ingress.IP
196+
target.Endpoint = ingress.IP
195197
}
196-
target["type"] = "kops-controller"
198+
target.Type = capikops.SystemEndpointTypeKopsController
197199
if ingress.InternalEndpoint {
198-
target["scope"] = "internal"
200+
target.Scope = capikops.SystemEndpointScopeInternal
199201
} else {
200-
target["scope"] = "global"
202+
target.Scope = capikops.SystemEndpointScopeExternal
201203
}
202204
targets = append(targets, target)
203205
}
204206

205207
for _, ingress := range ingresses {
206-
target := make(map[string]any)
208+
var target capikops.SystemEndpoint
207209
if ingress.Hostname != "" {
208-
target["host"] = ingress.Hostname
210+
target.Endpoint = ingress.Hostname
209211
}
210212
if ingress.IP != "" {
211-
target["host"] = ingress.IP
213+
target.Endpoint = ingress.IP
212214
}
213-
target["type"] = "kube-apiserver"
215+
target.Type = capikops.SystemEndpointTypeKubeAPIServer
214216
if ingress.InternalEndpoint {
215-
target["scope"] = "internal"
217+
target.Scope = capikops.SystemEndpointScopeInternal
216218
} else {
217-
target["scope"] = "global"
219+
target.Scope = capikops.SystemEndpointScopeExternal
218220
}
219221
targets = append(targets, target)
220222
}
@@ -234,17 +236,17 @@ func (s *clusterScope) createKopsControlPlane(ctx context.Context, kube client.C
234236
// TODO: cloud-provider-gcp should not assume cluster name is a valid prefix
235237
name := gce.SafeClusterName(s.Cluster.GetName())
236238

237-
status := map[string]any{}
239+
status := capikops.KopsControlPlaneStatus{}
238240

239241
systemEndpoints, err := s.findSystemEndpoints(ctx)
240242
if err != nil {
241243
return err
242244
}
243-
status["systemEndpoints"] = systemEndpoints
245+
status.SystemEndpoints = systemEndpoints
244246

245-
status["initialization"] = map[string]any{
246-
"controlPlaneInitialized": true,
247-
}
247+
status.Initialization = capikops.KopsControlPlaneInitializationStatus{}
248+
controlPlaneInitialized := true
249+
status.Initialization.ControlPlaneInitialized = &controlPlaneInitialized
248250

249251
// Create secret
250252
{

0 commit comments

Comments
 (0)