Skip to content

Commit

Permalink
Use super-admin Kubeconfig for kube-vip from Kubernetes v1.29 onwards
Browse files Browse the repository at this point in the history
  • Loading branch information
abhay-krishna committed Feb 1, 2024
1 parent 1b03cb1 commit 838b69a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/providers/cloudstack/config/template-cp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ spec:
else echo "{{$dir}} already symlnk";
fi
{{- end}}
{{- $kube_minor_version := (index (splitList "." (trimPrefix "v" .kubernetesVersion)) 1) }}
{{- if (ge (atoi $kube_minor_version) 29) }}
- "if [ -f /run/kubeadm/kubeadm.yaml ]; then sed -i 's#path: /etc/kubernetes/admin.conf#path: /etc/kubernetes/super-admin.conf#' /etc/kubernetes/manifests/kube-vip.yaml; fi"
{{- end }}
{{- if .cloudstackControlPlaneDiskOfferingProvided }}
diskSetup:
filesystems:
Expand Down
4 changes: 4 additions & 0 deletions pkg/providers/nutanix/config/cp-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ spec:
- echo "127.0.0.1 {{`{{ ds.meta_data.hostname }}`}}" >> /etc/hosts
postKubeadmCommands:
- echo export KUBECONFIG=/etc/kubernetes/admin.conf >> /root/.bashrc
{{- $kube_minor_version := (index (splitList "." (trimPrefix "v" .kubernetesVersion)) 1) }}
{{- if (ge (atoi $kube_minor_version) 29) }}
- "if [ -f /run/kubeadm/kubeadm.yaml ]; then sed -i 's#path: /etc/kubernetes/admin.conf#path: /etc/kubernetes/super-admin.conf#' /etc/kubernetes/manifests/kube-vip.yaml; fi"
{{- end }}
useExperimentalRetryJoin: true
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
Expand Down
16 changes: 16 additions & 0 deletions pkg/providers/snow/apibuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/aws/eks-anywhere/pkg/clusterapi"
"github.com/aws/eks-anywhere/pkg/constants"
snowv1 "github.com/aws/eks-anywhere/pkg/providers/snow/api/v1beta1"
"github.com/aws/eks-anywhere/pkg/semver"
)

const (
Expand Down Expand Up @@ -73,6 +74,21 @@ func KubeadmControlPlane(log logr.Logger, clusterSpec *cluster.Spec, snowMachine
kcp.Spec.KubeadmConfigSpec.PreKubeadmCommands = append(kcp.Spec.KubeadmConfigSpec.PreKubeadmCommands,
"/etc/eks/bootstrap.sh",
)
kubeVersionSemver, err := semver.New(string(clusterSpec.Cluster.Spec.KubernetesVersion) + ".0")
if err != nil {
return nil, fmt.Errorf("error converting kubeVersion %v to semver %v", clusterSpec.Cluster.Spec.KubernetesVersion, err)
}

Check warning on line 80 in pkg/providers/snow/apibuilder.go

View check run for this annotation

Codecov / codecov/patch

pkg/providers/snow/apibuilder.go#L79-L80

Added lines #L79 - L80 were not covered by tests

kube129Semver, err := semver.New(string(v1alpha1.Kube129) + ".0")
if err != nil {
return nil, fmt.Errorf("error converting kubeVersion %v to semver %v", v1alpha1.Kube129, err)
}

Check warning on line 85 in pkg/providers/snow/apibuilder.go

View check run for this annotation

Codecov / codecov/patch

pkg/providers/snow/apibuilder.go#L84-L85

Added lines #L84 - L85 were not covered by tests

if kubeVersionSemver.Compare(kube129Semver) != -1 {
kcp.Spec.KubeadmConfigSpec.PreKubeadmCommands = append(kcp.Spec.KubeadmConfigSpec.PreKubeadmCommands,
"if [ -f /run/kubeadm/kubeadm.yaml ]; then sed -i 's#path: /etc/kubernetes/admin.conf#path: /etc/kubernetes/super-admin.conf#' /etc/kubernetes/manifests/kube-vip.yaml; fi",
)
}

Check warning on line 91 in pkg/providers/snow/apibuilder.go

View check run for this annotation

Codecov / codecov/patch

pkg/providers/snow/apibuilder.go#L88-L91

Added lines #L88 - L91 were not covered by tests

if err := clusterapi.SetProxyConfigInKubeadmControlPlaneForUbuntu(kcp, clusterSpec.Cluster); err != nil {
return nil, err
Expand Down
8 changes: 7 additions & 1 deletion pkg/providers/tinkerbell/config/template-cp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,19 @@ spec:
- {{ . }}
{{- end }}
{{- end }}
{{- if and (or .proxyConfig .registryMirrorMap) (ne .format "bottlerocket") }}
{{- $kube_minor_version := (index (splitList "." (trimPrefix "v" .kubernetesVersion)) 1) }}
{{- if and (or .registryMirrorMap .proxyConfig (ge (atoi $kube_minor_version) 29)) (ne .format "bottlerocket") }}
preKubeadmCommands:
{{- if .registryMirrorMap }}
- cat /etc/containerd/config_append.toml >> /etc/containerd/config.toml
{{- end}}
{{- if (or .registryMirrorMap .proxyConfig) }}
- sudo systemctl daemon-reload
- sudo systemctl restart containerd
{{- end}}
{{- if (ge (atoi $kube_minor_version) 29) }}
- "if [ -f /run/kubeadm/kubeadm.yaml ]; then sed -i 's#path: /etc/kubernetes/admin.conf#path: /etc/kubernetes/super-admin.conf#' /etc/kubernetes/manifests/kube-vip.yaml; fi"
{{- end }}
{{- end }}
users:
- name: {{.controlPlaneSshUsername}}
Expand Down
4 changes: 4 additions & 0 deletions pkg/providers/vsphere/config/template-cp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ spec:
- echo "127.0.0.1 localhost" >>/etc/hosts
- echo "127.0.0.1 {{`{{ ds.meta_data.hostname }}`}}" >>/etc/hosts
- echo "{{`{{ ds.meta_data.hostname }}`}}" >/etc/hostname
{{- $kube_minor_version := (index (splitList "." (trimPrefix "v" .kubernetesVersion)) 1) }}
{{- if and (ge (atoi $kube_minor_version) 29) (ne .format "bottlerocket") }}
- "if [ -f /run/kubeadm/kubeadm.yaml ]; then sed -i 's#path: /etc/kubernetes/admin.conf#path: /etc/kubernetes/super-admin.conf#' /etc/kubernetes/manifests/kube-vip.yaml; fi"
{{- end }}
useExperimentalRetryJoin: true
users:
- name: {{.controlPlaneSshUsername}}
Expand Down

0 comments on commit 838b69a

Please sign in to comment.