@@ -20,8 +20,10 @@ const (
2020 scriptBasePath = "/opt/microk8s/scripts/"
2121 installMicrok8sScript = "00-install-microk8s.sh"
2222 upgradeMicrok8sScript = "00-upgrade-microk8s.sh"
23- configureApiServerScript = "10-configure-apiserver.sh"
23+ // configureApiServerScript = "10-configure-apiserver.sh"
24+ configureAltNamesScript = "10-configure-alt-names.sh"
2425 configureCPKubeletScript = "10-configure-cp-kubelet.sh"
26+ configureCalicoScript = "10-configure-calico.sh"
2527 configureClusterAgentPortScript = "10-configure-cluster-agent-port.sh"
2628 configureDqlitePortScript = "10-configure-dqlite-port.sh"
2729 configureDqliteAddressScript = "10-configure-dqlite-address.sh"
@@ -88,12 +90,14 @@ func generateInitStages(cluster clusterplugin.Cluster, token string, userConfig
8890 var installCommands []string
8991 var upgradeCommands []string
9092 installCommands = getBaseInstallCommands (cluster , token , installCommands )
93+ calicoConfigCommand := addCalicoConfigCommands (userConfig )
94+ installCommands = append (installCommands ,fmt .Sprintf ("%s %v" , calicoConfigCommand , true ))
95+
9196 // figure out endpoint type
9297 endpointType := "DNS"
9398 if net .ParseIP (cluster .ControlPlaneHost ) != nil {
9499 endpointType = "IP"
95100 }
96- installCommands = append (installCommands , fmt .Sprintf ("%s %q %q" , scriptPath (configureApiServerScript ), endpointType , cluster .ControlPlaneHost ))
97101
98102 if userConfig .ClusterConfiguration .PortCompatibilityRemap {
99103 installCommands = append (installCommands , fmt .Sprintf ("%s %q" , scriptPath (configureClusterAgentPortScript ), remappedClusterAgentPort ))
@@ -105,14 +109,17 @@ func generateInitStages(cluster clusterplugin.Cluster, token string, userConfig
105109
106110 // add the bootstrap token
107111 installCommands = append (installCommands , fmt .Sprintf ("microk8s add-node --token-ttl %v --token %q" , tokenTTL , token ))
108- installCommands = append (installCommands , scriptPath (configureCPKubeletScript ))
109112 installCommands = append (installCommands , fmt .Sprintf ("%s %v %q" , scriptPath (configureDNSScript ), userConfig .ClusterConfiguration .UseHostDNS , userConfig .ClusterConfiguration .DNS ))
113+ installCommands = append (installCommands , fmt .Sprintf ("%s %q %q" , scriptPath (configureAltNamesScript ), endpointType , cluster .ControlPlaneHost ))
110114
111115 addons := parseAddons (userConfig )
112116 installCommands = append (installCommands , fmt .Sprintf ("%s %s" , scriptPath (microk8sEnableScript ), strings .Join (addons , " " )))
117+ installCommands = append (installCommands , scriptPath (configureCPKubeletScript ))
118+
113119 writeKubeConfigCommand := fmt .Sprintf ("%s %s" , scriptPath (microk8sKubeConfigScript ), userConfig .ClusterConfiguration .WriteKubeconfig )
114120 installCommands = append (installCommands , writeKubeConfigCommand )
115121 upgradeCommands = append (upgradeCommands , scriptPath (upgradeMicrok8sScript ))
122+ upgradeCommands = append (upgradeCommands ,fmt .Sprintf ("%s %v" , calicoConfigCommand , false ))
116123 upgradeCommands = append (upgradeCommands , writeKubeConfigCommand )
117124
118125 return []yip.Stage {
@@ -129,19 +136,22 @@ func generateInitStages(cluster clusterplugin.Cluster, token string, userConfig
129136 }
130137}
131138
139+
140+
132141func generateControlPlaneJoinStages (cluster clusterplugin.Cluster , token string , userConfig MicroK8sSpec ) []yip.Stage {
133142 var installCommands []string
134143 var upgradeCommands []string
135144 var clusterAgentPort string = defaultClusterAgentPort
136145
137146 installCommands = getBaseInstallCommands (cluster , token , installCommands )
147+ calicoConfigCommand := addCalicoConfigCommands (userConfig )
148+ installCommands = append (installCommands , fmt .Sprintf ("%s %v" , calicoConfigCommand , false ))
149+
138150 // figure out endpoint type
139151 endpointType := "DNS"
140152 if net .ParseIP (cluster .ControlPlaneHost ) != nil {
141153 endpointType = "IP"
142154 }
143- installCommands = append (installCommands , fmt .Sprintf ("%s %q %q" , scriptPath (configureApiServerScript ), endpointType , cluster .ControlPlaneHost ))
144-
145155 if userConfig .ClusterConfiguration .PortCompatibilityRemap {
146156 clusterAgentPort = remappedClusterAgentPort
147157 installCommands = append (installCommands , fmt .Sprintf ("%s %q" , scriptPath (configureClusterAgentPortScript ), remappedClusterAgentPort ))
@@ -150,14 +160,20 @@ func generateControlPlaneJoinStages(cluster clusterplugin.Cluster, token string,
150160 if userConfig .ClusterConfiguration .DqliteUseHostIPV4Address {
151161 installCommands = append (installCommands , scriptPath (configureDqliteAddressScript ))
152162 }
153- installCommands = append (installCommands , scriptPath (configureCPKubeletScript ))
154163 // add join command
155164 installCommands = append (installCommands , fmt .Sprintf ("%s %q" , scriptPath (microk8sJoinScript ), fmt .Sprintf ("%s:%s/%s" , cluster .ControlPlaneHost , clusterAgentPort , token )))
165+ //configure after join
166+ installCommands = append (installCommands , fmt .Sprintf ("%s %q %q" , scriptPath (configureAltNamesScript ), endpointType , cluster .ControlPlaneHost ))
167+
156168 // add the bootstrap token
157169 installCommands = append (installCommands , fmt .Sprintf ("microk8s add-node --token-ttl %v --token %q" , tokenTTL , token ))
170+ // label after join
171+ installCommands = append (installCommands , scriptPath (configureCPKubeletScript ))
158172 installCommands = append (installCommands , fmt .Sprintf ("%s %s" , scriptPath (microk8sKubeConfigScript ), userConfig .ClusterConfiguration .WriteKubeconfig ))
159173
160174 upgradeCommands = append (upgradeCommands , scriptPath (upgradeMicrok8sScript ))
175+ upgradeCommands = append (upgradeCommands ,fmt .Sprintf ("%s %v" , calicoConfigCommand , false ))
176+
161177 return []yip.Stage {
162178
163179 {
@@ -172,13 +188,18 @@ func generateControlPlaneJoinStages(cluster clusterplugin.Cluster, token string,
172188 },
173189 }
174190}
191+
175192func generateWorkerJoinStages (cluster clusterplugin.Cluster , token string , userConfig MicroK8sSpec ) []yip.Stage {
176193
177194 var installCommands []string
178195 var upgradeCommands []string
179196 var clusterAgentPort string = defaultClusterAgentPort
180197
181198 installCommands = getBaseInstallCommands (cluster , token , installCommands )
199+ calicoConfigCommand := addCalicoConfigCommands (userConfig )
200+ installCommands = append (installCommands ,fmt .Sprintf ("%s %v" , calicoConfigCommand , false ))
201+
202+
182203 if userConfig .ClusterConfiguration .PortCompatibilityRemap {
183204 clusterAgentPort = remappedClusterAgentPort
184205 installCommands = append (installCommands , fmt .Sprintf ("%s %q" , scriptPath (configureClusterAgentPortScript ), clusterAgentPort ))
@@ -187,6 +208,7 @@ func generateWorkerJoinStages(cluster clusterplugin.Cluster, token string, userC
187208 installCommands = append (installCommands , fmt .Sprintf ("%s %q --worker" , scriptPath (microk8sJoinScript ), fmt .Sprintf ("%s:%s/%s" , cluster .ControlPlaneHost , clusterAgentPort , token )))
188209
189210 upgradeCommands = append (upgradeCommands , scriptPath (upgradeMicrok8sScript ))
211+
190212 return []yip.Stage {
191213
192214 {
@@ -220,6 +242,20 @@ func getBaseInstallCommands(cluster clusterplugin.Cluster, token string, install
220242
221243 return installCommands
222244}
245+ func addCalicoConfigCommands (userConfig MicroK8sSpec ) string {
246+ var calicoConfigCommand string
247+
248+ if userConfig .ClusterConfiguration .CalicoConfiguration != nil {
249+ // need to escape values like cidr for bash scripts
250+ var replacer = strings .NewReplacer (
251+ `/` , `\/` ,
252+ )
253+ calicoConfig := userConfig .ClusterConfiguration .CalicoConfiguration
254+ calicoConfigCommand = fmt .Sprintf ("%s %v %q" , scriptPath (configureCalicoScript ), calicoConfig .CalicoIPinIP , replacer .Replace (calicoConfig .CalicoAutoDetect ))
255+
256+ }
257+ return calicoConfigCommand
258+ }
223259func parseAddons (userConfig MicroK8sSpec ) []string {
224260
225261 addons := make ([]string , 0 , len (userConfig .InitConfiguration .Addons ))
0 commit comments