@@ -392,7 +392,13 @@ func (k *K8sClient) GetClusterRoleInformation(clusterRoleName string, allowedClu
392392 "Deleted unlabeled Trident cluster role; replacing it with a labeled Trident cluster role." )
393393 }
394394 } else if shouldUpdate {
395- unwantedClusterRoles = clusterRoles
395+ // During updates, only delete the specific cluster role being processed, not siblings with same label
396+ for _ , clusterRole := range clusterRoles {
397+ if clusterRole .Name == clusterRoleName {
398+ // This is the one we're updating - mark for deletion and recreation
399+ unwantedClusterRoles = append (unwantedClusterRoles , clusterRole )
400+ }
401+ }
396402 } else {
397403 // Processing cluster roles with selective deletion logic:
398404 // 1. Keep cluster roles that match names in allowedClusterRoleNames (e.g., trident-controller,
@@ -540,6 +546,13 @@ func (k *K8sClient) PutClusterRole(currentClusterRole *rbacv1.ClusterRole, creat
540546
541547 if currentClusterRole != nil {
542548 clusterRoleName = currentClusterRole .Name
549+ } else {
550+ // get cluster role from newClusterRoleYAML
551+ var clusterRoleFromYAML rbacv1.ClusterRole
552+ if err := yaml .Unmarshal ([]byte (newClusterRoleYAML ), & clusterRoleFromYAML ); err != nil {
553+ return fmt .Errorf ("could not unmarshal new cluster role YAML; %v" , err )
554+ }
555+ clusterRoleName = clusterRoleFromYAML .Name
543556 }
544557
545558 logFields := LogFields {
@@ -566,7 +579,7 @@ func (k *K8sClient) PutClusterRole(currentClusterRole *rbacv1.ClusterRole, creat
566579
567580 // Apply the patch to the current Cluster Role
568581 patchType := types .MergePatchType
569- if err = k .PatchClusterRoleByLabel (appLabel , patchBytes , patchType ); err != nil {
582+ if err = k .PatchClusterRoleByLabelAndName (appLabel , currentClusterRole . Name , patchBytes , patchType ); err != nil {
570583 return fmt .Errorf ("could not patch Trident Cluster role; %v" , err )
571584 }
572585
@@ -701,7 +714,13 @@ func (k *K8sClient) GetClusterRoleBindingInformation(clusterRoleBindingName stri
701714 "Deleted unlabeled Trident cluster role binding; replacing it with a labeled Trident cluster role binding." )
702715 }
703716 } else if shouldUpdate {
704- unwantedClusterRoleBindings = clusterRoleBindings
717+ // During updates, only delete the specific cluster role binding being processed, not siblings with same label
718+ for _ , clusterRoleBinding := range clusterRoleBindings {
719+ if clusterRoleBinding .Name == clusterRoleBindingName {
720+ // This is the one we're updating - mark for deletion and recreation
721+ unwantedClusterRoleBindings = append (unwantedClusterRoleBindings , clusterRoleBinding )
722+ }
723+ }
705724 } else {
706725 // Processing cluster role bindings with selective deletion logic:
707726 // 1. Keep cluster role bindings that match names in allowedClusterRoleBindingNames (e.g., trident-controller,
@@ -743,6 +762,13 @@ func (k *K8sClient) PutClusterRoleBinding(currentClusterRoleBinding *rbacv1.Clus
743762
744763 if currentClusterRoleBinding != nil {
745764 clusterRoleBindingName = currentClusterRoleBinding .Name
765+ } else {
766+ // get cluster role from newClusterRoleYAML
767+ var clusterRoleBindingYAML rbacv1.ClusterRole
768+ if err := yaml .Unmarshal ([]byte (newClusterRoleBindingYAML ), & clusterRoleBindingYAML ); err != nil {
769+ return fmt .Errorf ("could not unmarshal new cluster role YAML; %v" , err )
770+ }
771+ clusterRoleBindingName = clusterRoleBindingYAML .Name
746772 }
747773
748774 logFields := LogFields {
@@ -769,7 +795,8 @@ func (k *K8sClient) PutClusterRoleBinding(currentClusterRoleBinding *rbacv1.Clus
769795
770796 // Apply the patch to the current Cluster Role Binding
771797 patchType := types .MergePatchType
772- if err = k .PatchClusterRoleBindingByLabel (appLabel , patchBytes , patchType ); err != nil {
798+ if err = k .PatchClusterRoleBindingByLabelAndName (appLabel , currentClusterRoleBinding .Name , patchBytes ,
799+ patchType ); err != nil {
773800 return fmt .Errorf ("could not patch cluster role binding; %v" , err )
774801 }
775802
0 commit comments