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