Skip to content

Commit 9ed7cd6

Browse files
committed
fix: capture key material during metadata-only ensure
1 parent 7e3eb61 commit 9ed7cd6

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

internal/controller/coderprovisioner_controller.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ func (r *CoderProvisionerReconciler) Reconcile(ctx context.Context, req ctrl.Req
311311
// Secret is usable and no drift detected, but status metadata
312312
// is empty (e.g. upgrade from older version). Call EnsureProvisionerKey
313313
// 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.
314+
// Typically the key already exists and Key will be empty, but if the
315+
// remote key was deleted we capture the new key material too.
315316
response, ensureErr := r.BootstrapClient.EnsureProvisionerKey(ctx, coderbootstrap.EnsureProvisionerKeyRequest{
316317
CoderURL: controlPlane.Status.URL,
317318
SessionToken: sessionToken,
@@ -332,6 +333,11 @@ func (r *CoderProvisionerReconciler) Reconcile(ctx context.Context, req ctrl.Req
332333
if response.KeyName != "" {
333334
provisionerKeyName = response.KeyName
334335
}
336+
// If coderd created a new key (remote was missing), capture the
337+
// material so ensureProvisionerKeySecret writes it to the Secret.
338+
if response.Key != "" {
339+
keyMaterial = response.Key
340+
}
335341
appliedOrgName = organizationName
336342
appliedTagsHash = desiredTagsHash
337343
setCondition(

internal/controller/coderprovisioner_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func TestCoderProvisionerReconciler_ExistingSecret(t *testing.T) {
345345
OrganizationID: uuid.New(),
346346
KeyID: uuid.New(),
347347
KeyName: provisionerName,
348-
Key: "new-key-material",
348+
Key: "", // Empty: coderd returns no plaintext for existing keys.
349349
}},
350350
}
351351
reconciler := &controller.CoderProvisionerReconciler{Client: k8sClient, Scheme: scheme, BootstrapClient: bootstrapClient}

0 commit comments

Comments
 (0)