@@ -759,6 +759,20 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out, errout io.Write
759
759
Name : "system:router" ,
760
760
},
761
761
},
762
+ & authapi.ClusterRoleBinding {
763
+ ObjectMeta : metav1.ObjectMeta {Name : generateAuthRoleBindingName (cfg .Name )},
764
+ Subjects : []kapi.ObjectReference {
765
+ {
766
+ Kind : "ServiceAccount" ,
767
+ Name : cfg .ServiceAccount ,
768
+ Namespace : namespace ,
769
+ },
770
+ },
771
+ RoleRef : kapi.ObjectReference {
772
+ Kind : "ClusterRole" ,
773
+ Name : "system:auth-delegator" ,
774
+ },
775
+ },
762
776
)
763
777
764
778
objects = append (objects , & appsapi.DeploymentConfig {
@@ -833,7 +847,7 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out, errout io.Write
833
847
834
848
levelPrefixFilter := func (e error ) string {
835
849
// Avoid failing when service accounts or role bindings already exist.
836
- if ignoreError (e , cfg .ServiceAccount , generateRoleBindingName (cfg .Name )) {
850
+ if ignoreError (e , cfg .ServiceAccount , generateRoleBindingName (cfg .Name ), generateAuthRoleBindingName ( cfg . Name ) ) {
837
851
return "warning"
838
852
}
839
853
return "error"
@@ -850,9 +864,9 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out, errout io.Write
850
864
}
851
865
852
866
// ignoreError will return true if the error is an already exists status error and
853
- // 1. it is for a cluster role binding named roleBindingName , or
854
- // 2. it is for a service account name saName
855
- func ignoreError (e error , saName string , roleBindingName string ) bool {
867
+ // 1. it is for a cluster role binding matching in roleBindingNames , or
868
+ // 2. it is for a service account named saName
869
+ func ignoreError (e error , saName string , roleBindingNames ... string ) bool {
856
870
if ! errors .IsAlreadyExists (e ) {
857
871
return false
858
872
}
@@ -864,9 +878,17 @@ func ignoreError(e error, saName string, roleBindingName string) bool {
864
878
if details == nil {
865
879
return false
866
880
}
867
- return (details .Kind == "serviceaccounts" && details .Name == saName ) ||
868
- (details .Kind == "clusterrolebinding" /*pre-3.7*/ && details .Name == roleBindingName ) ||
869
- (details .Kind == "clusterrolebindings" /*3.7+*/ && details .Name == roleBindingName )
881
+ if details .Kind == "serviceaccounts" {
882
+ return details .Name == saName
883
+ }
884
+ if details .Kind == "clusterrolebinding" /*pre-3.7*/ || details .Kind == "clusterrolebindings" /*3.7+*/ {
885
+ for _ , name := range roleBindingNames {
886
+ if details .Name == name {
887
+ return true
888
+ }
889
+ }
890
+ }
891
+ return false
870
892
}
871
893
872
894
// generateRoleBindingName generates a name for the rolebinding object if it is
@@ -875,6 +897,10 @@ func generateRoleBindingName(name string) string {
875
897
return fmt .Sprintf ("router-%s-role" , name )
876
898
}
877
899
900
+ func generateAuthRoleBindingName (name string ) string {
901
+ return fmt .Sprintf ("router-%s-auth-role" , name )
902
+ }
903
+
878
904
// generateStatsPassword creates a random password.
879
905
func generateStatsPassword () string {
880
906
rand := rand .New (rand .NewSource (time .Now ().UTC ().UnixNano ()))
0 commit comments