@@ -575,8 +575,14 @@ func createRoles(ctx context.Context, c KubeClient, serviceAccountName, serviceA
575
575
if telemetryClusterRoles {
576
576
clusterRoleTelemetry := buildClusterRoleTelemetry ()
577
577
_ , err = c .RbacV1 ().ClusterRoles ().Create (ctx , & clusterRoleTelemetry , metav1.CreateOptions {})
578
- if ! errors .IsAlreadyExists (err ) && err != nil {
579
- return xerrors .Errorf ("error creating cluster role: %w" , err )
578
+ if err != nil {
579
+ if errors .IsAlreadyExists (err ) {
580
+ if _ , err := c .RbacV1 ().ClusterRoles ().Update (ctx , & clusterRoleTelemetry , metav1.UpdateOptions {}); err != nil {
581
+ return xerrors .Errorf ("error updating role: %w" , err )
582
+ }
583
+ } else {
584
+ return xerrors .Errorf ("error creating cluster role: %w" , err )
585
+ }
580
586
}
581
587
fmt .Printf ("created clusterrole: %s\n " , clusterRoleTelemetry .Name )
582
588
if err = createClusterRoleBinding (ctx , c , serviceAccountName , serviceAccountNamespace , DefaultOperatorName + "-multi-telemetry-cluster-role-binding" , clusterRoleTelemetry ); err != nil {
@@ -594,7 +600,7 @@ func createRoles(ctx context.Context, c KubeClient, serviceAccountName, serviceA
594
600
}
595
601
596
602
_ , err = c .RbacV1 ().Roles (namespace ).Create (ctx , & role , metav1.CreateOptions {})
597
- if ! errors . IsAlreadyExists ( err ) && err != nil {
603
+ if err != nil {
598
604
if errors .IsAlreadyExists (err ) {
599
605
if _ , err := c .RbacV1 ().Roles (namespace ).Update (ctx , & role , metav1.UpdateOptions {}); err != nil {
600
606
return xerrors .Errorf ("error updating role: %w" , err )
@@ -641,8 +647,14 @@ func createRoles(ctx context.Context, c KubeClient, serviceAccountName, serviceA
641
647
func createClusterRoleBinding (ctx context.Context , c KubeClient , serviceAccountName string , serviceAccountNamespace string , clusterRoleBindingName string , clusterRole rbacv1.ClusterRole ) error {
642
648
clusterRoleBinding := buildClusterRoleBinding (clusterRole , serviceAccountName , serviceAccountNamespace , clusterRoleBindingName )
643
649
_ , err := c .RbacV1 ().ClusterRoleBindings ().Create (ctx , & clusterRoleBinding , metav1.CreateOptions {})
644
- if ! errors .IsAlreadyExists (err ) && err != nil {
645
- return xerrors .Errorf ("error creating cluster role binding: %w" , err )
650
+ if err != nil {
651
+ if errors .IsAlreadyExists (err ) {
652
+ if _ , err := c .RbacV1 ().ClusterRoleBindings ().Update (ctx , & clusterRoleBinding , metav1.UpdateOptions {}); err != nil {
653
+ return xerrors .Errorf ("error updating role: %w" , err )
654
+ }
655
+ } else {
656
+ return xerrors .Errorf ("error creating cluster role binding: %w" , err )
657
+ }
646
658
}
647
659
fmt .Printf ("created clusterrolebinding: %s\n " , clusterRoleBinding .Name )
648
660
return nil
0 commit comments