Skip to content

Instantly share code, notes, and snippets.

@rpothier
Created November 14, 2017 21:14
Show Gist options
  • Save rpothier/5a087d9943e5791d17af48321cbe2f36 to your computer and use it in GitHub Desktop.
Save rpothier/5a087d9943e5791d17af48321cbe2f36 to your computer and use it in GitHub Desktop.
// EnsureProxyAddon creates the kube-proxy addons
func EnsureProxyAddon(cfg *kubeadmapi.MasterConfiguration, client clientset.Interface) error {
if err := CreateServiceAccount(client); err != nil {
return fmt.Errorf("error when creating kube-proxy service account: %v", err)
}
// Generate Master Enpoint kubeconfig file
masterEndpoint, err := kubeadmutil.GetMasterEndpoint(cfg)
if err != nil {
return err
}
ip := net.ParseIP(cfg.API.AdvertiseAddress)
if ip.To4() == nil && ip.To16() != nil {
//bindAddress = "\"::\""
cfg.KubeProxy.Config.BindAddress = "::"
//} else {
// bindAddress = "0.0.0.0"
}
// Validate the kube-proxy bind address
bindAddress := cfg.KubeProxy.Config.BindAddress
//if net.ParseIP(bindAddress) == nil {
// return fmt.Errorf("kube-proxy bind address '%s' is not a valid IP address", bindAddress)
//}
// If the bind address begins with a ':' (e.g. the IPv6 address '::'),
// then wrap it in double quotes; otherwise the config parser will
// consider it a syntax error.
if bindAddress[0] == ':' {
bindAddress = "\"" + bindAddress + "\""
}
ser, err := kubeadmutil.MarshalToYaml(&cfg.KubeProxy.Config, v1.SchemeGroupVersion)
if err != nil {
return fmt.Errorf("error when marshaling: %v", err)
}
proxyConfigMapBytes, err := kubeadmutil.ParseTemplate(KubeProxyConfigMap,
struct {
MasterEndpoint string
Config []byte
}{
MasterEndpoint: masterEndpoint,
Config: ser,
})
if err != nil {
return fmt.Errorf("error when parsing kube-proxy configmap template: %v", err)
}
proxyDaemonSetBytes, err := kubeadmutil.ParseTemplate(KubeProxyDaemonSet, struct{ ImageRepository, Arch, Version, ImageOverride, ExtraParams, ClusterCIDR, MasterTaintKey, CloudTaintKey string }{
ImageRepository: cfg.GetControlPlaneImageRepository(),
Arch: runtime.GOARCH,
Version: kubeadmutil.KubernetesVersionToImageTag(cfg.KubernetesVersion),
ImageOverride: cfg.UnifiedControlPlaneImage,
ExtraParams: getParams(cfg.FeatureGates),
ClusterCIDR: getClusterCIDR(cfg.Networking.PodSubnet),
MasterTaintKey: kubeadmconstants.LabelNodeRoleMaster,
CloudTaintKey: algorithm.TaintExternalCloudProvider,
})
if err != nil {
return fmt.Errorf("error when parsing kube-proxy daemonset template: %v", err)
}
if err := createKubeProxyAddon(proxyConfigMapBytes, proxyDaemonSetBytes, client); err != nil {
return err
}
if err := CreateRBACRules(client); err != nil {
return fmt.Errorf("error when creating kube-proxy RBAC rules: %v", err)
}
fmt.Println("[addons] Applied essential addon: kube-proxy")
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment