@@ -236,13 +236,9 @@ func (r *CoderProvisionerReconciler) reconcileDeletion(ctx context.Context, prov
236236
237237 log := ctrl .LoggerFrom (ctx )
238238
239- // Prefer persisted identity from status (reflects what was actually
240- // created in coderd) over the current spec values, which may have been
241- // edited after initial provisioning.
242- organizationName := provisioner .Status .OrganizationID
243- if organizationName == "" {
244- organizationName = provisionerOrganizationName (provisioner .Spec .OrganizationName )
245- }
239+ // DeleteProvisionerKey resolves organizations by name, so always pass the
240+ // spec-derived organization name here instead of the persisted organization ID.
241+ organizationName := provisionerOrganizationName (provisioner .Spec .OrganizationName )
246242 keyName := provisioner .Status .ProvisionerKeyName
247243 if keyName == "" {
248244 keyName , _ , _ = provisionerKeyConfig (provisioner )
@@ -688,7 +684,20 @@ func provisionerInstanceLabelValue(name string) string {
688684}
689685
690686func provisionerServiceAccountName (name string ) string {
691- return fmt .Sprintf ("%s%s" , name , provisionerServiceAccountSuffix )
687+ candidate := fmt .Sprintf ("%s%s" , name , provisionerServiceAccountSuffix )
688+ if len (candidate ) <= 63 {
689+ return candidate
690+ }
691+
692+ hasher := fnv .New32a ()
693+ _ , _ = hasher .Write ([]byte (name ))
694+ suffix := fmt .Sprintf ("%08x" , hasher .Sum32 ())
695+ available := 63 - len (provisionerServiceAccountSuffix ) - len (suffix ) - 1
696+ if available < 1 {
697+ available = 1
698+ }
699+
700+ return fmt .Sprintf ("%s-%s%s" , name [:available ], suffix , provisionerServiceAccountSuffix )
692701}
693702
694703func provisionerOrganizationName (name string ) string {
0 commit comments