@@ -134,6 +134,8 @@ func (r *CoderProvisionerReconciler) Reconcile(ctx context.Context, req ctrl.Req
134134 keyNameDrift := status .ProvisionerKeyName != "" && status .ProvisionerKeyName != keyName
135135 tagsDrift := status .TagsHash != "" && status .TagsHash != desiredTagsHash
136136 driftDetected := orgDrift || keyNameDrift || tagsDrift
137+ appliedOrgName := provisioner .Status .OrganizationName
138+ appliedTagsHash := provisioner .Status .TagsHash
137139
138140 // Check whether a usable provisioner key secret already exists.
139141 // The secret is considered "usable" only if the Secret object exists
@@ -205,6 +207,8 @@ func (r *CoderProvisionerReconciler) Reconcile(ctx context.Context, req ctrl.Req
205207 if keyMaterial == "" {
206208 return ctrl.Result {}, fmt .Errorf ("assertion failed: provisioner key returned empty material after drift rotation" )
207209 }
210+ appliedOrgName = organizationName
211+ appliedTagsHash = desiredTagsHash
208212 } else if ! secretUsable {
209213 response , ensureErr := r .BootstrapClient .EnsureProvisionerKey (ctx , coderbootstrap.EnsureProvisionerKeyRequest {
210214 CoderURL : controlPlane .Status .URL ,
@@ -263,6 +267,8 @@ func (r *CoderProvisionerReconciler) Reconcile(ctx context.Context, req ctrl.Req
263267 return ctrl.Result {}, fmt .Errorf ("assertion failed: provisioner key %q returned empty key material after rotation" , keyName )
264268 }
265269 }
270+ appliedOrgName = organizationName
271+ appliedTagsHash = desiredTagsHash
266272 }
267273 setCondition (
268274 provisioner ,
@@ -328,10 +334,10 @@ func (r *CoderProvisionerReconciler) Reconcile(ctx context.Context, req ctrl.Req
328334 deployment ,
329335 secretRef ,
330336 organizationID ,
331- organizationName ,
337+ appliedOrgName ,
332338 provisionerKeyID ,
333339 provisionerKeyName ,
334- desiredTagsHash ,
340+ appliedTagsHash ,
335341 ); err != nil {
336342 return ctrl.Result {}, err
337343 }
@@ -842,7 +848,20 @@ func provisionerKeyConfig(provisioner *coderv1alpha1.CoderProvisioner) (string,
842848
843849 secretName := provisioner .Spec .Key .SecretName
844850 if secretName == "" {
845- secretName = fmt .Sprintf ("%s-provisioner-key" , provisioner .Name )
851+ const secretNameSuffix = "-provisioner-key"
852+ candidate := provisioner .Name + secretNameSuffix
853+ if len (candidate ) <= 253 {
854+ secretName = candidate
855+ } else {
856+ hasher := fnv .New32a ()
857+ _ , _ = hasher .Write ([]byte (provisioner .Name ))
858+ suffix := fmt .Sprintf ("%08x" , hasher .Sum32 ())
859+ available := 253 - len (secretNameSuffix ) - len (suffix ) - 1
860+ if available < 1 {
861+ available = 1
862+ }
863+ secretName = fmt .Sprintf ("%s-%s%s" , provisioner .Name [:available ], suffix , secretNameSuffix )
864+ }
846865 }
847866
848867 secretKey := provisioner .Spec .Key .SecretKey
0 commit comments