Skip to content

Commit 43e7a08

Browse files
authored
Merge pull request #6993 from fabriziopandini/improve-machine-provisioning-logs
🌱 improve logging for the machine provisioning workflow
2 parents ba66db7 + db1169e commit 43e7a08

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

internal/controllers/machine/machine_controller_noderef.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (r *Reconciler) reconcileNode(ctx context.Context, cluster *clusterv1.Clust
4646

4747
// Check that the Machine has a valid ProviderID.
4848
if machine.Spec.ProviderID == nil || *machine.Spec.ProviderID == "" {
49-
log.Info("Cannot reconcile Machine's Node, no valid ProviderID yet")
49+
log.Info("Waiting for infrastructure provider to report spec.providerID", util.LowerCamelCase(machine.Spec.InfrastructureRef.Kind), klog.KRef(machine.Spec.InfrastructureRef.Namespace, machine.Spec.InfrastructureRef.Name))
5050
conditions.MarkFalse(machine, clusterv1.MachineNodeHealthyCondition, clusterv1.WaitingForNodeRefReason, clusterv1.ConditionSeverityInfo, "")
5151
return ctrl.Result{}, nil
5252
}
@@ -88,7 +88,7 @@ func (r *Reconciler) reconcileNode(ctx context.Context, cluster *clusterv1.Clust
8888
Name: node.Name,
8989
UID: node.UID,
9090
}
91-
log.Info("Set Machine's NodeRef", "noderef", machine.Status.NodeRef.Name)
91+
log.Info("Infrastructure provider reporting spec.providerID, Kubernetes node is now available", util.LowerCamelCase(machine.Spec.InfrastructureRef.Kind), klog.KRef(machine.Spec.InfrastructureRef.Namespace, machine.Spec.InfrastructureRef.Name), "providerID", providerID, "node", klog.KRef("", machine.Status.NodeRef.Name))
9292
r.recorder.Event(machine, corev1.EventTypeNormal, "SuccessfulSetNodeRef", machine.Status.NodeRef.Name)
9393
}
9494

internal/controllers/machine/machine_controller_phases.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (r *Reconciler) reconcileBootstrap(ctx context.Context, cluster *clusterv1.
219219

220220
// If the bootstrap provider is not ready, requeue.
221221
if !ready {
222-
log.Info("Bootstrap provider is not ready, requeuing")
222+
log.Info("Waiting for bootstrap provider to generate data secret and report status.ready", util.LowerCamelCaseKind(bootstrapConfig), klog.KObj(bootstrapConfig))
223223
return ctrl.Result{RequeueAfter: externalReadyWait}, nil
224224
}
225225

@@ -230,8 +230,10 @@ func (r *Reconciler) reconcileBootstrap(ctx context.Context, cluster *clusterv1.
230230
} else if secretName == "" {
231231
return ctrl.Result{}, errors.Errorf("retrieved empty dataSecretName from bootstrap provider for Machine %q in namespace %q", m.Name, m.Namespace)
232232
}
233-
234233
m.Spec.Bootstrap.DataSecretName = pointer.StringPtr(secretName)
234+
if !m.Status.BootstrapReady {
235+
log.Info("Bootstrap provider generated data secret and reports status.ready", util.LowerCamelCaseKind(bootstrapConfig), klog.KObj(bootstrapConfig), "secret", klog.KRef(m.Namespace, secretName))
236+
}
235237
m.Status.BootstrapReady = true
236238
return ctrl.Result{}, nil
237239
}
@@ -271,6 +273,9 @@ func (r *Reconciler) reconcileInfrastructure(ctx context.Context, cluster *clust
271273
if err != nil {
272274
return ctrl.Result{}, err
273275
}
276+
if ready && !m.Status.InfrastructureReady {
277+
log.Info("Infrastructure provider has completed machine infrastructure provisioning and reports status.ready", util.LowerCamelCaseKind(infraConfig), klog.KObj(infraConfig))
278+
}
274279
m.Status.InfrastructureReady = ready
275280

276281
// Report a summary of current status of the infrastructure object defined for this machine.
@@ -281,7 +286,7 @@ func (r *Reconciler) reconcileInfrastructure(ctx context.Context, cluster *clust
281286

282287
// If the infrastructure provider is not ready, return early.
283288
if !ready {
284-
log.Info("Infrastructure provider is not ready, requeuing")
289+
log.Info("Waiting for infrastructure provider to create machine infrastructure and report status.ready", util.LowerCamelCaseKind(infraConfig), klog.KObj(infraConfig))
285290
return ctrl.Result{RequeueAfter: externalReadyWait}, nil
286291
}
287292

util/util.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,14 @@ func IsNil(i interface{}) bool {
608608
// LowerCamelCaseKind mirrors how controller runtime formats the object's kind when used as a logging key
609609
// for the object being reconciled.
610610
func LowerCamelCaseKind(obj runtime.Object) string {
611-
kind := obj.GetObjectKind().GroupVersionKind().Kind
612-
if kind != "" {
613-
return strings.ToLower(kind[:1]) + kind[1:]
611+
return LowerCamelCase(obj.GetObjectKind().GroupVersionKind().Kind)
612+
}
613+
614+
// LowerCamelCase mirrors how controller runtime formats the object's kind when used as a logging key
615+
// for the object being reconciled.
616+
func LowerCamelCase(s string) string {
617+
if s != "" {
618+
return strings.ToLower(s[:1]) + s[1:]
614619
}
615620
return ""
616621
}

0 commit comments

Comments
 (0)