Skip to content

Commit af66d24

Browse files
committed
chore: update to match latest CAPI MachinePool ideas
1 parent b1f084f commit af66d24

File tree

3 files changed

+10
-78
lines changed

3 files changed

+10
-78
lines changed

exp/api/v1beta1/gcpmachinepool_types.go

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"k8s.io/apimachinery/pkg/runtime/schema"
2222

2323
capg "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"
24-
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
2524
)
2625

2726
// Constants block.
@@ -50,11 +49,6 @@ type GCPMachinePoolSpec struct {
5049
// // +optional
5150
// AliasIPRanges []infrav1.AliasIPRange `json:"aliasIPRanges,omitempty"`
5251

53-
// Not meaningful for MachinePool
54-
// // ProviderID is the unique identifier as specified by the cloud provider.
55-
// // +optional
56-
// ProviderID *string `json:"providerID,omitempty"`
57-
5852
// ImageFamily is the full reference to a valid image family to be used for this machine.
5953
// +optional
6054
ImageFamily *string `json:"imageFamily,omitempty"`
@@ -184,45 +178,7 @@ type GCPMachinePoolStatus struct {
184178

185179
// Conditions defines current service state of the GCPMachinePool.
186180
// +optional
187-
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
188-
189-
// FailureReason will be set in the event that there is a terminal problem
190-
// reconciling the MachinePool and will contain a succinct value suitable
191-
// for machine interpretation.
192-
//
193-
// This field should not be set for transitive errors that a controller
194-
// faces that are expected to be fixed automatically over
195-
// time (like service outages), but instead indicate that something is
196-
// fundamentally wrong with the MachinePool's spec or the configuration of
197-
// the controller, and that manual intervention is required. Examples
198-
// of terminal errors would be invalid combinations of settings in the
199-
// spec, values that are unsupported by the controller, or the
200-
// responsible controller itself being critically misconfigured.
201-
//
202-
// Any transient errors that occur during the reconciliation of MachinePools
203-
// can be added as events to the MachinePool object and/or logged in the
204-
// controller's output.
205-
// +optional
206-
FailureReason *string `json:"failureReason,omitempty"`
207-
208-
// FailureMessage will be set in the event that there is a terminal problem
209-
// reconciling the MachinePool and will contain a more verbose string suitable
210-
// for logging and human consumption.
211-
//
212-
// This field should not be set for transitive errors that a controller
213-
// faces that are expected to be fixed automatically over
214-
// time (like service outages), but instead indicate that something is
215-
// fundamentally wrong with the MachinePool's spec or the configuration of
216-
// the controller, and that manual intervention is required. Examples
217-
// of terminal errors would be invalid combinations of settings in the
218-
// spec, values that are unsupported by the controller, or the
219-
// responsible controller itself being critically misconfigured.
220-
//
221-
// Any transient errors that occur during the reconciliation of MachinePools
222-
// can be added as events to the MachinePool object and/or logged in the
223-
// controller's output.
224-
// +optional
225-
FailureMessage *string `json:"failureMessage,omitempty"`
181+
Conditions []metav1.Condition `json:"conditions,omitempty"`
226182
}
227183

228184
// +kubebuilder:object:root=true
@@ -255,16 +211,6 @@ func init() {
255211
SchemeBuilder.Register(&GCPMachinePool{}, &GCPMachinePoolList{})
256212
}
257213

258-
// GetConditions returns the observations of the operational state of the GCPMachinePool resource.
259-
func (r *GCPMachinePool) GetConditions() clusterv1.Conditions {
260-
return r.Status.Conditions
261-
}
262-
263-
// SetConditions sets the underlying service state of the GCPMachinePool to the predescribed clusterv1.Conditions.
264-
func (r *GCPMachinePool) SetConditions(conditions clusterv1.Conditions) {
265-
r.Status.Conditions = conditions
266-
}
267-
268214
// GetObjectKind will return the ObjectKind of an GCPMachinePool.
269215
func (r *GCPMachinePool) GetObjectKind() schema.ObjectKind {
270216
return &r.TypeMeta

exp/controllers/gcpmachinepool_controller.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ import (
3838
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3939

4040
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
41+
"sigs.k8s.io/cluster-api/util/annotations"
4142
"sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions"
43+
v1beta1conditions "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions"
4244
"sigs.k8s.io/cluster-api/util/predicates"
4345

4446
infrav1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"
4547
"sigs.k8s.io/cluster-api-provider-gcp/cloud/scope"
4648
"sigs.k8s.io/cluster-api-provider-gcp/cloud/services/compute/instancegroupmanagers"
4749
"sigs.k8s.io/cluster-api-provider-gcp/cloud/services/compute/instancetemplates"
4850
expinfrav1 "sigs.k8s.io/cluster-api-provider-gcp/exp/api/v1beta1"
49-
"sigs.k8s.io/cluster-api-provider-gcp/pkg/capiutils"
51+
exputil "sigs.k8s.io/cluster-api/exp/util"
5052
"sigs.k8s.io/controller-runtime/pkg/log"
5153
)
5254

@@ -78,7 +80,7 @@ func (r *GCPMachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Reque
7880
}
7981

8082
// Fetch the CAPI MachinePool
81-
machinePool, err := getOwnerMachinePool(ctx, r.Client, gcpMachinePool.ObjectMeta)
83+
machinePool, err := exputil.GetOwnerMachinePool(ctx, r.Client, gcpMachinePool.ObjectMeta)
8284
if err != nil {
8385
return reconcile.Result{}, err
8486
}
@@ -96,7 +98,7 @@ func (r *GCPMachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Reque
9698
}
9799
log = log.WithValues("cluster", klog.KObj(clusterObj))
98100

99-
if capiutils.IsPaused(clusterObj, gcpMachinePool) {
101+
if annotations.IsPaused(clusterObj, gcpMachinePool) {
100102
log.Info("GCPMachinePool or linked Cluster is marked as paused. Won't reconcile")
101103
return ctrl.Result{}, nil
102104
}
@@ -125,12 +127,12 @@ func (r *GCPMachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Reque
125127
// Always close the scope when exiting this function so we can persist any GCPMachine changes.
126128
defer func() {
127129
// set Ready condition before GCPMachinePool is patched
128-
conditions.SetSummary(machinePoolScope.GCPMachinePool,
129-
conditions.WithConditions(
130+
v1beta1conditions.SetSummary(machinePoolScope.GCPMachinePool,
131+
v1beta1conditions.WithConditions(
130132
expinfrav1.MIGReadyCondition,
131133
expinfrav1.InstanceTemplateReadyCondition,
132134
),
133-
conditions.WithStepCounterIfOnly(
135+
v1beta1conditions.WithStepCounterIfOnly(
134136
expinfrav1.MIGReadyCondition,
135137
expinfrav1.InstanceTemplateReadyCondition,
136138
),

exp/controllers/gcpmanagedmachinepool_controller.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,6 @@ func getMachinePoolByName(ctx context.Context, c client.Client, namespace, name
199199
return m, nil
200200
}
201201

202-
// getOwnerMachinePool returns the MachinePool object owning the current resource.
203-
func getOwnerMachinePool(ctx context.Context, c client.Client, obj metav1.ObjectMeta) (*clusterv1.MachinePool, error) {
204-
for _, ref := range obj.OwnerReferences {
205-
if ref.Kind != "MachinePool" {
206-
continue
207-
}
208-
gv, err := schema.ParseGroupVersion(ref.APIVersion)
209-
if err != nil {
210-
return nil, errors.WithStack(err)
211-
}
212-
if gv.Group == clusterv1.GroupVersion.Group {
213-
return getMachinePoolByName(ctx, c, obj.Namespace, ref.Name)
214-
}
215-
}
216-
return nil, nil
217-
}
218202

219203
//+kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=gcpmanagedmachinepools,verbs=get;list;watch;create;update;patch;delete
220204
//+kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=gcpmanagedmachinepools/status,verbs=get;update;patch
@@ -241,7 +225,7 @@ func (r *GCPManagedMachinePoolReconciler) Reconcile(ctx context.Context, req ctr
241225
}
242226

243227
// Get the machine pool
244-
machinePool, err := getOwnerMachinePool(ctx, r.Client, gcpManagedMachinePool.ObjectMeta)
228+
machinePool, err := util.GetOwnerMachinePool(ctx, r.Client, gcpManagedMachinePool.ObjectMeta)
245229
if err != nil {
246230
log.Error(err, "Failed to retrieve owner MachinePool from the API Server")
247231
return ctrl.Result{}, err

0 commit comments

Comments
 (0)