@@ -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 (
0 commit comments