in kinder/pkg/cluster/manager/actions/kubeadm-config.go [59:135]
func KubeadmConfig(c *status.Cluster, kubeadmConfigVersion string, copyCertsMode CopyCertsMode, discoveryMode DiscoveryMode, featureGate string, nodes ...*status.Node) error {
cp1 := c.BootstrapControlPlane()
// get installed kubernetes version from the node image
kubeVersion, err := cp1.KubeVersion()
if err != nil {
return errors.Wrap(err, "failed to get kubernetes version from node")
}
// gets the IP of the bootstrap control plane node
controlPlaneIP, controlPlaneIPV6, err := c.BootstrapControlPlane().IP()
if err != nil {
return errors.Wrapf(err, "failed to get IP for node: %s", c.BootstrapControlPlane().Name())
}
// get the control plane endpoint, in case the cluster has an external load balancer in
// front of the control-plane nodes
controlPlaneEndpoint, controlPlaneEndpointIPv6, ControlPlanePort, err := getControlPlaneAddress(c)
if err != nil {
return err
}
// configure the right protocol addresses
if c.Settings.IPFamily == status.IPv6Family {
controlPlaneIP = controlPlaneIPV6
controlPlaneEndpoint = controlPlaneEndpointIPv6
}
featureGateName := ""
featureGateValue := ""
// We remove the leading and trailing double or single quotes because the
// feature-gate could be set as
// --kubeadm-feature-gate="RootlessControlPlane=true" or
// --kubeadm-feature-gate='RootlessControlPlane=true', so the value
// of featureGate string would be "\"RootlessControlPlane=true"\" or "RootlessControlPlane=true'" respectively.
// Once we trim the value double or single quotes the value will be "RootlessControlPlane=true".
trimmedFeatureGate := strings.Trim(featureGate, "\"'")
if len(trimmedFeatureGate) > 0 {
split := strings.Split(trimmedFeatureGate, "=")
if len(split) != 2 {
return errors.New("feature gate must be formatted as 'key=value'")
}
featureGateName = split[0]
featureGateValue = split[1]
}
// create configData with all the configurations supported by the kubeadm config template implemented in kind
configData := kubeadm.ConfigData{
ClusterName: c.Name(),
KubernetesVersion: kubeVersion,
ControlPlaneEndpoint: fmt.Sprintf("%s:%d", controlPlaneEndpoint, ControlPlanePort),
APIBindPort: constants.APIServerPort,
APIServerAddress: controlPlaneIP,
Token: constants.Token,
PodSubnet: "192.168.0.0/16", // default for kindnet
ControlPlane: true,
IPv6: c.Settings.IPFamily == status.IPv6Family,
FeatureGateName: featureGateName,
FeatureGateValue: featureGateValue,
}
// create configOptions with all the kinder flags that impact on the kubeadm config generation
configOptions := kubeadmConfigOptions{
configVersion: kubeadmConfigVersion,
copyCertsMode: copyCertsMode,
discoveryMode: discoveryMode,
}
// writs the kubeadm config file on all the K8s nodes.
for _, node := range nodes {
if err := writeKubeadmConfig(c, node, configData, configOptions); err != nil {
return err
}
}
return nil
}