Skip to content

Commit 5fdc668

Browse files
committed
Progress in machine controller.
1 parent e450a1c commit 5fdc668

9 files changed

+248
-89
lines changed

api/v1alpha1/metalstackcluster_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ type MetalStackClusterStatus struct {
105105
// Conditions defines current service state of the MetalStackCluster.
106106
// +optional
107107
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
108+
109+
// NodeCIDR is set as soon as the node network was created
110+
// +optional
111+
NodeCIDR *string `json:"nodeCIDR,omitempty"`
112+
// NodeNetworkID is set as soon as the node network was created
113+
// +optional
114+
NodeNetworkID *string `json:"nodeNetworkID,omitempty"`
108115
}
109116

110117
// +kubebuilder:object:root=true

api/v1alpha1/metalstackmachine_types.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ import (
2525
const (
2626
// MachineFinalizer allows to clean up resources associated with before removing it from the apiserver.
2727
MachineFinalizer = "metal-stack.infrastructure.cluster.x-k8s.io/machine"
28+
29+
TagInfraMachineID = "metal-stack.infrastructure.cluster.x-k8s.io/machine-id"
30+
31+
ProviderMachineCreated clusterv1.ConditionType = "MachineCreated"
32+
ProviderMachineHealthy clusterv1.ConditionType = "MachineHealthy"
2833
)
2934

3035
// MetalStackMachineSpec defines the desired state of MetalStackMachine.
@@ -42,21 +47,21 @@ type MetalStackMachineSpec struct {
4247

4348
// MetalStackMachineStatus defines the observed state of MetalStackMachine.
4449
type MetalStackMachineStatus struct {
45-
// Ready denotes that the cluster is ready.
50+
// Ready denotes that the machine is ready.
4651
Ready bool `json:"ready"`
4752

4853
// FailureReason indicates that there is a fatal problem reconciling the
4954
// state, and will be set to a token value suitable for
5055
// programmatic interpretation.
5156
// +optional
52-
FailureReason *capierrors.ClusterStatusError `json:"failureReason,omitempty"`
57+
FailureReason *capierrors.MachineStatusError `json:"failureReason,omitempty"`
5358

5459
// FailureMessage indicates that there is a fatal problem reconciling the
5560
// state, and will be set to a descriptive error message.
5661
// +optional
5762
FailureMessage *string `json:"failureMessage,omitempty"`
5863

59-
// Conditions defines current service state of the MetalStackCluster.
64+
// Conditions defines current service state of the MetalStackMachine.
6065
// +optional
6166
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
6267

@@ -88,3 +93,13 @@ type MetalStackMachineList struct {
8893
func init() {
8994
SchemeBuilder.Register(&MetalStackMachine{}, &MetalStackMachineList{})
9095
}
96+
97+
// GetConditions returns the list of conditions.
98+
func (c *MetalStackMachine) GetConditions() clusterv1.Conditions {
99+
return c.Status.Conditions
100+
}
101+
102+
// SetConditions will set the given conditions.
103+
func (c *MetalStackMachine) SetConditions(conditions clusterv1.Conditions) {
104+
c.Status.Conditions = conditions
105+
}

api/v1alpha1/zz_generated.deepcopy.go

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

config/crd/bases/infrastructure.cluster.x-k8s.io_inframachinetemplates.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ spec:
110110
type: array
111111
conditions:
112112
description: Conditions defines current service state of the
113-
MetalStackCluster.
113+
MetalStackMachine.
114114
items:
115115
description: Condition defines an observation of a Cluster
116116
API resource operational state.
@@ -167,7 +167,7 @@ spec:
167167
programmatic interpretation.
168168
type: string
169169
ready:
170-
description: Ready denotes that the cluster is ready.
170+
description: Ready denotes that the machine is ready.
171171
type: boolean
172172
required:
173173
- ready

config/crd/bases/infrastructure.cluster.x-k8s.io_metalstackclusters.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ spec:
193193
state, and will be set to a token value suitable for
194194
programmatic interpretation.
195195
type: string
196+
nodeCIDR:
197+
description: NodeCIDR is set as soon as the node network was created
198+
type: string
199+
nodeNetworkID:
200+
description: NodeNetworkID is set as soon as the node network was
201+
created
202+
type: string
196203
ready:
197204
description: Ready denotes that the cluster is ready.
198205
type: boolean

config/crd/bases/infrastructure.cluster.x-k8s.io_metalstackmachines.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ spec:
7575
type: object
7676
type: array
7777
conditions:
78-
description: Conditions defines current service state of the MetalStackCluster.
78+
description: Conditions defines current service state of the MetalStackMachine.
7979
items:
8080
description: Condition defines an observation of a Cluster API resource
8181
operational state.
@@ -131,7 +131,7 @@ spec:
131131
programmatic interpretation.
132132
type: string
133133
ready:
134-
description: Ready denotes that the cluster is ready.
134+
description: Ready denotes that the machine is ready.
135135
type: boolean
136136
required:
137137
- ready

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ require (
99
github.com/metal-stack/metal-lib v0.18.4
1010
github.com/onsi/ginkgo/v2 v2.20.2
1111
github.com/onsi/gomega v1.34.2
12+
golang.org/x/sync v0.8.0
13+
k8s.io/api v0.31.0
1214
k8s.io/apimachinery v0.31.0
1315
k8s.io/client-go v0.31.0
16+
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
1417
sigs.k8s.io/cluster-api v1.8.4
1518
sigs.k8s.io/controller-runtime v0.19.0
1619
)
@@ -103,7 +106,6 @@ require (
103106
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
104107
golang.org/x/net v0.30.0 // indirect
105108
golang.org/x/oauth2 v0.23.0 // indirect
106-
golang.org/x/sync v0.8.0 // indirect
107109
golang.org/x/sys v0.26.0 // indirect
108110
golang.org/x/term v0.25.0 // indirect
109111
golang.org/x/text v0.19.0 // indirect
@@ -117,13 +119,11 @@ require (
117119
gopkg.in/inf.v0 v0.9.1 // indirect
118120
gopkg.in/yaml.v2 v2.4.0 // indirect
119121
gopkg.in/yaml.v3 v3.0.1 // indirect
120-
k8s.io/api v0.31.0 // indirect
121122
k8s.io/apiextensions-apiserver v0.31.0 // indirect
122123
k8s.io/apiserver v0.31.0 // indirect
123124
k8s.io/component-base v0.31.0 // indirect
124125
k8s.io/klog/v2 v2.130.1 // indirect
125126
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
126-
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
127127
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 // indirect
128128
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
129129
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect

internal/controller/metalstackcluster_controller.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ func (r *MetalStackClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
144144
}
145145

146146
func (r *MetalStackClusterReconciler) reconcile(ctx context.Context, log logr.Logger, infraCluster *v1alpha1.MetalStackCluster) error {
147-
148147
nodeCIDR, err := r.ensureNodeNetwork(ctx, infraCluster)
149148
if err != nil {
150149
return fmt.Errorf("unable to ensure node network: %w", err)
@@ -361,15 +360,12 @@ func (r *MetalStackClusterReconciler) deleteFirewallDeployment(ctx context.Conte
361360

362361
func (r *MetalStackClusterReconciler) status(ctx context.Context, infraCluster *v1alpha1.MetalStackCluster) error {
363362
var (
364-
g, _ = errgroup.WithContext(ctx)
365-
status = &v1alpha1.MetalStackClusterStatus{
366-
Ready: true,
367-
}
363+
g, _ = errgroup.WithContext(ctx)
368364
conditionUpdates = make(chan func())
369365

370366
// TODO: probably there is a helper for this available somewhere?
371367
allConditionsTrue = func() bool {
372-
for _, c := range status.Conditions {
368+
for _, c := range infraCluster.Status.Conditions {
373369
if c.Status != corev1.ConditionTrue {
374370
return false
375371
}
@@ -396,6 +392,13 @@ func (r *MetalStackClusterReconciler) status(ctx context.Context, infraCluster *
396392
case 0:
397393
conditions.MarkFalse(infraCluster, v1alpha1.ClusterNodeNetworkEnsured, "NotCreated", clusterv1.ConditionSeverityError, "node network was not yet created")
398394
case 1:
395+
nw := nws[0]
396+
397+
if len(nw.Prefixes) > 0 {
398+
infraCluster.Status.NodeCIDR = &nw.Prefixes[0]
399+
}
400+
infraCluster.Status.NodeNetworkID = nw.ID
401+
399402
conditions.MarkTrue(infraCluster, v1alpha1.ClusterNodeNetworkEnsured)
400403
default:
401404
conditions.MarkFalse(infraCluster, v1alpha1.ClusterNodeNetworkEnsured, "InternalError", clusterv1.ConditionSeverityError, "more than a single node network exists for this cluster, operator investigation is required")
@@ -445,7 +448,7 @@ func (r *MetalStackClusterReconciler) status(ctx context.Context, infraCluster *
445448

446449
groupErr := g.Wait()
447450
if groupErr == nil && allConditionsTrue() {
448-
status.Ready = true
451+
infraCluster.Status.Ready = true
449452
}
450453

451454
err := r.Client.Status().Update(ctx, infraCluster)

0 commit comments

Comments
 (0)