@@ -47,22 +47,20 @@ func NewBootkube(config Config) (*bootkube, error) {
4747 apiServer := apiserver .NewServerRunOptions ()
4848 fs := pflag .NewFlagSet ("apiserver" , pflag .ExitOnError )
4949 apiServer .AddFlags (fs )
50- fs .Parse (makeAPIServerFlags (config ))
50+ flags , err := makeAPIServerFlags (config )
51+ if err != nil {
52+ return nil , err
53+ }
54+ fs .Parse (flags )
5155
5256 cmServer := controller .NewCMServer ()
5357 fs = pflag .NewFlagSet ("controllermanager" , pflag .ExitOnError )
5458 cmServer .AddFlags (fs )
55- fs .Parse ([]string {
56- "--master=" + insecureAPIAddr ,
57- "--service-account-private-key-file=" + filepath .Join (config .AssetDir , asset .AssetPathServiceAccountPrivKey ),
58- "--root-ca-file=" + filepath .Join (config .AssetDir , asset .AssetPathCACert ),
59- "--cluster-signing-cert-file=" + filepath .Join (config .AssetDir , asset .AssetPathCACert ),
60- "--cluster-signing-key-file=" + filepath .Join (config .AssetDir , asset .AssetPathCAKey ),
61- "--allocate-node-cidrs=true" ,
62- "--cluster-cidr=10.2.0.0/16" ,
63- "--configure-cloud-routes=false" ,
64- "--leader-elect=true" ,
65- })
59+ flags , err = makeControllerManagerFlags (config )
60+ if err != nil {
61+ return nil , err
62+ }
63+ fs .Parse (flags )
6664
6765 schedServer := scheduler .NewSchedulerServer ()
6866 fs = pflag .NewFlagSet ("scheduler" , pflag .ExitOnError )
@@ -81,8 +79,12 @@ func NewBootkube(config Config) (*bootkube, error) {
8179 }, nil
8280}
8381
84- func makeAPIServerFlags (config Config ) []string {
85- res := []string {
82+ func makeAPIServerFlags (config Config ) ([]string , error ) {
83+ serviceCIDR , err := detectServiceCIDR (config )
84+ if err != nil {
85+ return []string {}, err
86+ }
87+ return []string {
8688 "--bind-address=0.0.0.0" ,
8789 "--secure-port=443" ,
8890 "--insecure-port=8080" ,
@@ -93,13 +95,30 @@ func makeAPIServerFlags(config Config) []string {
9395 "--token-auth-file=" + filepath .Join (config .AssetDir , asset .AssetPathBootstrapAuthToken ),
9496 "--authorization-mode=RBAC" ,
9597 "--etcd-servers=" + config .EtcdServer .String (),
96- "--service-cluster-ip-range=10.3.0.0/24" ,
98+ "--service-cluster-ip-range=" + serviceCIDR ,
9799 "--service-account-key-file=" + filepath .Join (config .AssetDir , asset .AssetPathServiceAccountPubKey ),
98100 "--admission-control=NamespaceLifecycle,ServiceAccount" ,
99101 "--runtime-config=api/all=true" ,
100102 "--storage-backend=etcd3" ,
103+ }, nil
104+ }
105+
106+ func makeControllerManagerFlags (config Config ) ([]string , error ) {
107+ podCIDR , err := detectPodCIDR (config )
108+ if err != nil {
109+ return []string {}, err
101110 }
102- return res
111+ return []string {
112+ "--master=" + insecureAPIAddr ,
113+ "--service-account-private-key-file=" + filepath .Join (config .AssetDir , asset .AssetPathServiceAccountPrivKey ),
114+ "--root-ca-file=" + filepath .Join (config .AssetDir , asset .AssetPathCACert ),
115+ "--cluster-signing-cert-file=" + filepath .Join (config .AssetDir , asset .AssetPathCACert ),
116+ "--cluster-signing-key-file=" + filepath .Join (config .AssetDir , asset .AssetPathCAKey ),
117+ "--allocate-node-cidrs=true" ,
118+ "--cluster-cidr=" + podCIDR ,
119+ "--configure-cloud-routes=false" ,
120+ "--leader-elect=true" ,
121+ }, nil
103122}
104123
105124func (b * bootkube ) Run () error {
0 commit comments