Skip to content

Commit 7e3eb61

Browse files
committed
fix: populate status metadata when secret exists but status is empty
1 parent bb7df6c commit 7e3eb61

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

internal/controller/coderprovisioner_controller.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,41 @@ func (r *CoderProvisionerReconciler) Reconcile(ctx context.Context, req ctrl.Req
307307
"ProvisionerKeyReady",
308308
"Provisioner key is available in coderd",
309309
)
310+
} else if status.OrganizationName == "" || status.TagsHash == "" {
311+
// Secret is usable and no drift detected, but status metadata
312+
// is empty (e.g. upgrade from older version). Call EnsureProvisionerKey
313+
// to populate IDs/name and establish the baseline for future drift detection.
314+
// The key material will be empty (already exists), but that's OK.
315+
response, ensureErr := r.BootstrapClient.EnsureProvisionerKey(ctx, coderbootstrap.EnsureProvisionerKeyRequest{
316+
CoderURL: controlPlane.Status.URL,
317+
SessionToken: sessionToken,
318+
OrganizationName: organizationName,
319+
KeyName: keyName,
320+
Tags: provisioner.Spec.Tags,
321+
})
322+
if ensureErr != nil {
323+
log.Info("failed to verify provisioner key metadata, will retry",
324+
"keyName", keyName, "error", ensureErr)
325+
} else {
326+
if response.OrganizationID != uuid.Nil {
327+
organizationID = response.OrganizationID.String()
328+
}
329+
if response.KeyID != uuid.Nil {
330+
provisionerKeyID = response.KeyID.String()
331+
}
332+
if response.KeyName != "" {
333+
provisionerKeyName = response.KeyName
334+
}
335+
appliedOrgName = organizationName
336+
appliedTagsHash = desiredTagsHash
337+
setCondition(
338+
provisioner,
339+
coderv1alpha1.CoderProvisionerConditionProvisionerKeyReady,
340+
metav1.ConditionTrue,
341+
"ProvisionerKeyReady",
342+
"Provisioner key is available in coderd",
343+
)
344+
}
310345
}
311346

312347
provisionerKeySecret, err := r.ensureProvisionerKeySecret(ctx, provisioner, keySecretName, keySecretKey, keyMaterial)

internal/controller/coderprovisioner_controller_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,10 @@ func TestCoderProvisionerReconciler_ExistingSecret(t *testing.T) {
354354
reconcileProvisioner(ctx, t, reconciler, namespacedName)
355355
reconcileProvisioner(ctx, t, reconciler, namespacedName)
356356

357-
require.Equal(t, 0, bootstrapClient.provisionerKeyCalls)
357+
// The first real reconcile triggers a metadata-only EnsureProvisionerKey
358+
// call because status.OrganizationName and status.TagsHash are empty.
359+
// The second reconcile skips since metadata is now populated.
360+
require.Equal(t, 1, bootstrapClient.provisionerKeyCalls)
358361
require.Equal(t, 0, bootstrapClient.deleteKeyCalls)
359362

360363
reconciledSecret := &corev1.Secret{}

0 commit comments

Comments
 (0)