Skip to content

Commit 954be1f

Browse files
author
Yuvaraj Kakaraparthi
committed
reset certificate expiry time if not found
1 parent 0a93b4f commit 954be1f

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

internal/controllers/machine/machine_controller_phases.go

+10
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,13 @@ func (r *Reconciler) reconcileCertificateExpiry(ctx context.Context, _ *clusterv
327327
return ctrl.Result{}, nil
328328
}
329329

330+
var expiryInfoFound bool
331+
330332
// Check for certificate expiry information in the machine annotation.
331333
// This should take precedence over other information.
332334
annotations = m.GetAnnotations()
333335
if expiry, ok := annotations[clusterv1.MachineCertificatesExpiryDateAnnotation]; ok {
336+
expiryInfoFound = true
334337
expiryTime, err := time.Parse(time.RFC3339, expiry)
335338
if err != nil {
336339
return ctrl.Result{}, errors.Wrapf(err, "failed to reconcile certificates expiry: failed to parse expiry date from annotation on %s", klog.KObj(m))
@@ -348,6 +351,7 @@ func (r *Reconciler) reconcileCertificateExpiry(ctx context.Context, _ *clusterv
348351
// Check for certificate expiry information in the bootstrap config.
349352
annotations = bootstrapConfig.GetAnnotations()
350353
if expiry, ok := annotations[clusterv1.MachineCertificatesExpiryDateAnnotation]; ok {
354+
expiryInfoFound = true
351355
expiryTime, err := time.Parse(time.RFC3339, expiry)
352356
if err != nil {
353357
return ctrl.Result{}, errors.Wrapf(err, "failed to reconcile certificates expiry: failed to parse expiry date from annotation on %s", klog.KObj(bootstrapConfig))
@@ -357,5 +361,11 @@ func (r *Reconciler) reconcileCertificateExpiry(ctx context.Context, _ *clusterv
357361
}
358362
}
359363

364+
// If the certificates expiry information is not fond on the machine
365+
// and on the bootstrap config then reset machine.status.certificatesExpiryDate.
366+
if !expiryInfoFound {
367+
m.Status.CertificatesExpiryDate = nil
368+
}
369+
360370
return ctrl.Result{}, nil
361371
}

internal/controllers/machine/machine_controller_phases_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,33 @@ func TestReconcileCertificateExpiry(t *testing.T) {
12841284
g.Expect(m.Status.CertificatesExpiryDate).To(Equal(fakeMetaTime2))
12851285
},
12861286
},
1287+
{
1288+
name: "reset certificates expiry information in machine status if the information is not available on the machine and the bootstrap config",
1289+
machine: &clusterv1.Machine{
1290+
ObjectMeta: metav1.ObjectMeta{
1291+
Name: "bootstrap-test-existing",
1292+
Namespace: metav1.NamespaceDefault,
1293+
Labels: map[string]string{
1294+
clusterv1.MachineControlPlaneLabelName: "",
1295+
},
1296+
},
1297+
Spec: clusterv1.MachineSpec{
1298+
Bootstrap: clusterv1.Bootstrap{
1299+
ConfigRef: &corev1.ObjectReference{
1300+
APIVersion: "bootstrap.cluster.x-k8s.io/v1beta1",
1301+
Kind: "GenericBootstrapConfig",
1302+
Name: "bootstrap-config-without-expiry",
1303+
},
1304+
},
1305+
},
1306+
Status: clusterv1.MachineStatus{
1307+
CertificatesExpiryDate: fakeMetaTime,
1308+
},
1309+
},
1310+
expected: func(g *WithT, m *clusterv1.Machine) {
1311+
g.Expect(m.Status.CertificatesExpiryDate).To(BeNil())
1312+
},
1313+
},
12871314
}
12881315

12891316
for _, tc := range tests {

0 commit comments

Comments
 (0)