Skip to content

Commit 1deece7

Browse files
Address comments
1 parent f3e1d84 commit 1deece7

File tree

7 files changed

+41
-80
lines changed

7 files changed

+41
-80
lines changed

api/v1beta1/machine_types.go

+21-22
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,29 @@ const (
8989
// Machine's Available condition and corresponding reasons that will be used in v1Beta2 API version.
9090
const (
9191
// MachineAvailableV1Beta2Condition is true if the machine is Ready for at least MinReadySeconds, as defined by the Machine's MinReadySeconds field.
92+
// Note: MinReadySeconds is assumed 0 until it will be implemented in v1beta2 API.
9293
MachineAvailableV1Beta2Condition = AvailableV1Beta2Condition
9394

94-
// MachineNotReadyV1Beta2Reason surfaces when a machine is not yet ready (and thus not yet available).
95+
// MachineNotReadyV1Beta2Reason surfaces when a machine is not ready (and thus not available).
9596
MachineNotReadyV1Beta2Reason = "NotReady"
9697

97-
// MachineWaitingForMinReadySecondsV1Beta2Reason surfaces when a machine is ready for less then MinReadySeconds (and thus not yet available).
98+
// MachineWaitingForMinReadySecondsV1Beta2Reason surfaces when a machine is ready for less than MinReadySeconds (and thus not yet available).
9899
MachineWaitingForMinReadySecondsV1Beta2Reason = "WaitingForMinReadySeconds"
99100

100101
// MachineReadyNotYetReportedV1Beta2Reason surfaces when a machine ready is not reported yet.
101102
// Note: this should never happen and it is a signal of some internal error.
102103
MachineReadyNotYetReportedV1Beta2Reason = "ReadyNotYetReported"
103104

104-
// MachineAvailableV1Beta2Reason surfaces when a machine ready for at least MinReadySeconds.
105+
// MachineAvailableV1Beta2Reason surfaces when a machine is ready for at least MinReadySeconds.
106+
// Note: MinReadySeconds is assumed 0 until it will be implemented in v1beta2 API.
105107
MachineAvailableV1Beta2Reason = "MachineAvailable"
106108
)
107109

108110
// Machine's Ready condition and corresponding reasons that will be used in v1Beta2 API version.
109111
// Note: when possible, Ready condition will use reasons from the conditions it summarizes.
110112
const (
111-
// MachineReadyV1Beta2Condition is true if the Machine is not deleted, Machine's BootstrapConfigReady, InfrastructureReady,
112-
// NodeHealthy and HealthCheckSucceeded (if present) are true; if other conditions are defined in spec.readinessGates,
113+
// MachineReadyV1Beta2Condition is true if the Machine's deletionTimestamp is not set, Machine's BootstrapConfigReady, InfrastructureReady,
114+
// NodeHealthy and HealthCheckSucceeded (if present) conditions are true; if other conditions are defined in spec.readinessGates,
113115
// these conditions must be true as well.
114116
MachineReadyV1Beta2Condition = ReadyV1Beta2Condition
115117

@@ -132,12 +134,9 @@ const (
132134
// MachineBootstrapConfigReadyV1Beta2Condition condition mirrors the corresponding Ready condition from the Machine's BootstrapConfig resource.
133135
MachineBootstrapConfigReadyV1Beta2Condition = BootstrapConfigReadyV1Beta2Condition
134136

135-
// MachineBootstrapDataSecretDataSecretUserProvidedV1Beta2Reason surfaces when a bootstrap data secret is provided by the user (without a ConfigRef).
136-
MachineBootstrapDataSecretDataSecretUserProvidedV1Beta2Reason = "DataSecretUserProvided"
137-
138-
// MachineBootstrapInvalidConfigV1Beta2Reason surfaces when Machine's spec.bootstrap doesn't have configRef nor a
139-
// dataSecretName set.
140-
MachineBootstrapInvalidConfigV1Beta2Reason = "InvalidConfig"
137+
// MachineBootstrapDataSecretProvidedV1Beta2Reason surfaces when a bootstrap data secret is provided (not originated
138+
// from a BoostrapConfig object referenced from the machine).
139+
MachineBootstrapDataSecretProvidedV1Beta2Reason = "DataSecretProvided"
141140

142141
// MachineBootstrapConfigInvalidConditionReportedV1Beta2Reason surfaces a BootstrapConfig Ready condition (read from a bootstrap config object) which is invalid.
143142
// (e.g. it is status is missing).
@@ -150,13 +149,13 @@ const (
150149
MachineBootstrapConfigInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
151150

152151
// MachineBootstrapConfigDoesNotExistV1Beta2Reason surfaces when a referenced bootstrap config object does not exist.
153-
// Note: this could happen when creating the machine. However, this state should be treated as an error if it last indefinitely.
154-
MachineBootstrapConfigDoesNotExistV1Beta2Reason = RefObjectDoesNotExistV1Beta2Reason
152+
// Note: this could happen when creating the machine. However, this state should be treated as an error if it lasts indefinitely.
153+
MachineBootstrapConfigDoesNotExistV1Beta2Reason = ObjectDoesNotExistV1Beta2Reason
155154

156155
// MachineBootstrapConfigDeletedV1Beta2Reason surfaces when a referenced bootstrap config object has been deleted.
157-
// Note: controllers can't identify if the deletion process has been initiated by the controller itself, e.g.
156+
// Note: controllers can't identify if the bootstrap config object was deleted the controller itself, e.g.
158157
// during the deletion workflow, or by a users.
159-
MachineBootstrapConfigDeletedV1Beta2Reason = RefObjectDeletedV1Beta2Reason
158+
MachineBootstrapConfigDeletedV1Beta2Reason = ObjectDeletedV1Beta2Reason
160159
)
161160

162161
// Machine's InfrastructureReady condition and corresponding reasons that will be used in v1Beta2 API version.
@@ -172,17 +171,17 @@ const (
172171
// MachineInfrastructureReadyNoV1Beta2ReasonReported applies to a infrastructure Ready condition (read from an infra machine object) that reports no reason.
173172
MachineInfrastructureReadyNoV1Beta2ReasonReported = NoV1Beta2ReasonReported
174173

175-
// MachineInfrastructureInternalErrorV1Beta2Reason surfaces unexpected failures when reading a BootstrapConfig object.
174+
// MachineInfrastructureInternalErrorV1Beta2Reason surfaces unexpected failures when reading a infra machine object.
176175
MachineInfrastructureInternalErrorV1Beta2Reason = InternalErrorV1Beta2Reason
177176

178177
// MachineInfrastructureDoesNotExistV1Beta2Reason surfaces when a referenced infrastructure object does not exist.
179-
// Note: this could happen when creating the machine. However, this state should be treated as an error if it last indefinitely.
180-
MachineInfrastructureDoesNotExistV1Beta2Reason = RefObjectDoesNotExistV1Beta2Reason
178+
// Note: this could happen when creating the machine. However, this state should be treated as an error if it lasts indefinitely.
179+
MachineInfrastructureDoesNotExistV1Beta2Reason = ObjectDoesNotExistV1Beta2Reason
181180

182181
// MachineInfrastructureDeletedV1Beta2Reason surfaces when a referenced infrastructure object has been deleted.
183-
// Note: controllers can't identify if the deletion process has been initiated by the controller itself, e.g.
182+
// Note: controllers can't identify if the infrastructure object was deleted by the controller itself, e.g.
184183
// during the deletion workflow, or by a users.
185-
MachineInfrastructureDeletedV1Beta2Reason = RefObjectDeletedV1Beta2Reason
184+
MachineInfrastructureDeletedV1Beta2Reason = ObjectDeletedV1Beta2Reason
186185
)
187186

188187
// Machine's NodeHealthy and NodeReady conditions and corresponding reasons that will be used in v1Beta2 API version.
@@ -198,11 +197,11 @@ const (
198197
MachineNodeConditionNotYetReportedV1Beta2Reason = "NodeConditionNotYetReported"
199198

200199
// MachineNodeNotFoundV1Beta2Reason surfaces when the node hosted on the machine cannot be found.
201-
// Note: this could happen when creating the machine. However, this state should be treated as an error if it last indefinitely.
200+
// Note: this could happen when creating the machine. However, this state should be treated as an error if it lasts indefinitely.
202201
MachineNodeNotFoundV1Beta2Reason = "NodeNotFound"
203202

204203
// MachineNodeDeletedV1Beta2Reason surfaces when the node hosted on the machine has been deleted.
205-
// Note: controllers can't identify if the deletion process has been initiated by the controller itself, e.g.
204+
// Note: controllers can't identify if the Node was deleted by the controller itself, e.g.
206205
// during the deletion workflow, or by a users.
207206
MachineNodeDeletedV1Beta2Reason = "NodeDeleted"
208207
)

api/v1beta1/v1beta2_condition_consts.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ const (
9999
// In most cases, it will be required to look at controllers logs to proper triage those issues.
100100
InternalErrorV1Beta2Reason = "InternalError"
101101

102-
// RefObjectDoesNotExistV1Beta2Reason surfaces when a referenced object does not exist.
103-
RefObjectDoesNotExistV1Beta2Reason = "RefObjectDoesNotExist"
102+
// ObjectDoesNotExistV1Beta2Reason surfaces when a referenced object does not exist.
103+
ObjectDoesNotExistV1Beta2Reason = "ObjectDoesNotExist"
104104

105-
// RefObjectDeletedV1Beta2Reason surfaces when a referenced object has been deleted.
106-
// Note: controllers can't identify if the deletion process has been initiated by the controller itself, e.g.
105+
// ObjectDeletedV1Beta2Reason surfaces when a referenced object has been deleted.
106+
// Note: controllers can't identify if the object was deleted by the controller itself, e.g.
107107
// during the deletion workflow, or by a users.
108-
RefObjectDeletedV1Beta2Reason = "RefObjectDeleted"
108+
ObjectDeletedV1Beta2Reason = "ObjectDeleted"
109109

110110
// NotPausedV1Beta2Reason surfaces when an object is not paused.
111111
NotPausedV1Beta2Reason = "NotPaused"

internal/controllers/machine/machine_controller.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -345,22 +345,22 @@ type scope struct {
345345
// Machine. It is set after reconcileInfrastructure is called.
346346
infraMachine *unstructured.Unstructured
347347

348-
// infraMachineNotFound is true if getting the infra machine object failed with an IsNotFound err
348+
// infraMachineNotFound is true if getting the infra machine object failed with an NotFound err
349349
infraMachineIsNotFound bool
350350

351351
// bootstrapConfig is the BootstrapConfig object that is referenced by the
352352
// Machine. It is set after reconcileBootstrap is called.
353353
bootstrapConfig *unstructured.Unstructured
354354

355-
// bootstrapConfigNotFound is true if getting the BootstrapConfig object failed with an IsNotFound err
355+
// bootstrapConfigNotFound is true if getting the BootstrapConfig object failed with an NotFound err
356356
bootstrapConfigIsNotFound bool
357357

358358
// node is the Kubernetes node hosted on the machine.
359359
node *corev1.Node
360360
}
361361

362362
func (r *Reconciler) reconcileMachineOwnerAndLabels(_ context.Context, s *scope) (ctrl.Result, error) {
363-
// If the machine is a stand-alone one, meaning not originated from a MachineDeployment, then set it as directly
363+
// If the machine is a stand-alone Machine, then set it as directly
364364
// owned by the Cluster (if not already present).
365365
if r.shouldAdopt(s.machine) {
366366
s.machine.SetOwnerReferences(util.EnsureOwnerRef(s.machine.GetOwnerReferences(), metav1.OwnerReference{
@@ -882,7 +882,7 @@ func (r *Reconciler) reconcileDeleteBootstrap(ctx context.Context, s *scope) (bo
882882
if err := r.Client.Delete(ctx, s.bootstrapConfig); err != nil && !apierrors.IsNotFound(err) {
883883
return false, errors.Wrapf(err,
884884
"failed to delete %v %q for Machine %q in namespace %q",
885-
s.bootstrapConfig.GroupVersionKind(), s.bootstrapConfig.GetName(), s.machine.Name, s.machine.Namespace)
885+
s.bootstrapConfig.GroupVersionKind().Kind, s.bootstrapConfig.GetName(), s.machine.Name, s.machine.Namespace)
886886
}
887887
}
888888

@@ -899,7 +899,7 @@ func (r *Reconciler) reconcileDeleteInfrastructure(ctx context.Context, s *scope
899899
if err := r.Client.Delete(ctx, s.infraMachine); err != nil && !apierrors.IsNotFound(err) {
900900
return false, errors.Wrapf(err,
901901
"failed to delete %v %q for Machine %q in namespace %q",
902-
s.infraMachine.GroupVersionKind(), s.infraMachine.GetName(), s.machine.Name, s.machine.Namespace)
902+
s.infraMachine.GroupVersionKind().Kind, s.infraMachine.GetName(), s.machine.Name, s.machine.Namespace)
903903
}
904904
}
905905

internal/controllers/machine/machine_controller_status.go

+3-14
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,10 @@ func (r *Reconciler) reconcileStatus(ctx context.Context, s *scope) {
8686

8787
func setBootstrapReadyCondition(_ context.Context, machine *clusterv1.Machine, bootstrapConfig *unstructured.Unstructured, bootstrapConfigIsNotFound bool) {
8888
if machine.Spec.Bootstrap.ConfigRef == nil {
89-
if ptr.Deref(machine.Spec.Bootstrap.DataSecretName, "") != "" {
90-
v1beta2conditions.Set(machine, metav1.Condition{
91-
Type: clusterv1.MachineBootstrapConfigReadyV1Beta2Condition,
92-
Status: metav1.ConditionTrue,
93-
Reason: clusterv1.MachineBootstrapDataSecretDataSecretUserProvidedV1Beta2Reason,
94-
})
95-
return
96-
}
97-
98-
// Note: validation web hooks should prevent invalid configuration to happen.
9989
v1beta2conditions.Set(machine, metav1.Condition{
100-
Type: clusterv1.MachineBootstrapConfigReadyV1Beta2Condition,
101-
Status: metav1.ConditionFalse,
102-
Reason: clusterv1.MachineBootstrapInvalidConfigV1Beta2Reason,
103-
Message: "Either spec.bootstrap.configRef must be set or spec.bootstrap.dataSecretName must not be empty",
90+
Type: clusterv1.MachineBootstrapConfigReadyV1Beta2Condition,
91+
Status: metav1.ConditionTrue,
92+
Reason: clusterv1.MachineBootstrapDataSecretProvidedV1Beta2Reason,
10493
})
10594
return
10695
}

internal/controllers/machine/machine_controller_status_test.go

+1-25
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,7 @@ func TestSetBootstrapReadyCondition(t *testing.T) {
8080
expectCondition: metav1.Condition{
8181
Type: clusterv1.MachineBootstrapConfigReadyV1Beta2Condition,
8282
Status: metav1.ConditionTrue,
83-
Reason: clusterv1.MachineBootstrapDataSecretDataSecretUserProvidedV1Beta2Reason,
84-
},
85-
},
86-
{
87-
name: "machine without bootstrap config ref and with dataSecretName not set",
88-
machine: func() *clusterv1.Machine {
89-
m := defaultMachine.DeepCopy()
90-
m.Spec.Bootstrap.ConfigRef = nil
91-
return m
92-
}(),
93-
bootstrapConfig: &unstructured.Unstructured{Object: map[string]interface{}{
94-
"kind": "GenericBootstrapConfig",
95-
"apiVersion": "bootstrap.cluster.x-k8s.io/v1beta1",
96-
"metadata": map[string]interface{}{
97-
"name": "bootstrap-config1",
98-
"namespace": metav1.NamespaceDefault,
99-
},
100-
"status": map[string]interface{}{},
101-
}},
102-
bootstrapConfigIsNotFound: false,
103-
expectCondition: metav1.Condition{
104-
Type: clusterv1.MachineBootstrapConfigReadyV1Beta2Condition,
105-
Status: metav1.ConditionFalse,
106-
Reason: clusterv1.MachineBootstrapInvalidConfigV1Beta2Reason,
107-
Message: "Either spec.bootstrap.configRef must be set or spec.bootstrap.dataSecretName must not be empty",
83+
Reason: clusterv1.MachineBootstrapDataSecretProvidedV1Beta2Reason,
10884
},
10985
},
11086
{

internal/webhooks/machine_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ func TestMachineBootstrapValidation(t *testing.T) {
6969
bootstrap: clusterv1.Bootstrap{ConfigRef: nil, DataSecretName: ptr.To("test")},
7070
expectErr: false,
7171
},
72+
{
73+
name: "should not return error if dataSecretName is set",
74+
bootstrap: clusterv1.Bootstrap{ConfigRef: nil, DataSecretName: ptr.To("")},
75+
expectErr: false,
76+
},
7277
{
7378
name: "should not return error if config ref is set",
7479
bootstrap: clusterv1.Bootstrap{ConfigRef: &corev1.ObjectReference{}, DataSecretName: nil},

util/conditions/v1beta2/getter.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,8 @@ func validateAndFixConvertedCondition(c *metav1.Condition) error {
177177
default:
178178
return errors.Errorf("status for the %s condition must be one of %s, %s, %s", c.Type, metav1.ConditionTrue, metav1.ConditionFalse, metav1.ConditionUnknown)
179179
}
180-
181180
if c.Reason == "" {
182-
switch c.Status {
183-
case metav1.ConditionFalse: // When using old Cluster API condition utils, for conditions with Status false, Reason can be empty only when a condition has negative polarity (means "good")
184-
c.Reason = NoReasonReported
185-
case metav1.ConditionTrue: // When using old Cluster API condition utils, for conditions with Status true, Reason can be empty only when a condition has positive polarity (means "good").
186-
c.Reason = NoReasonReported
187-
case metav1.ConditionUnknown:
188-
return errors.Errorf("reason must be set for the %s condition, status unknown", c.Type)
189-
}
181+
c.Reason = NoReasonReported
190182
}
191183

192184
// NOTE: Empty LastTransitionTime is tolerated because it will be set when assigning the newly generated mirror condition to an object.

0 commit comments

Comments
 (0)