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