Skip to content

Commit d7ef1fd

Browse files
jimmidysondkoshkin
authored andcommitted
build: Add update kube-vip manifests script and use kube-vip 0.8.0
1 parent ba7f694 commit d7ef1fd

File tree

8 files changed

+117
-36
lines changed

8 files changed

+117
-36
lines changed

charts/cluster-api-runtime-extensions-nutanix/templates/kube-vip/manifests/kube-vip-configmap.yaml

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Copyright 2023 D2iQ, Inc. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
#=================================================================
5+
# DO NOT EDIT THIS FILE
6+
# IT HAS BEEN GENERATED BY /hack/addons/update-kube-vip-manifests.sh
7+
#=================================================================
48
{{- if .Values.hooks.kubeVip.defaultTemplateConfigMap.create }}
59
apiVersion: v1
610
data:
@@ -12,61 +16,58 @@ data:
1216
namespace: kube-system
1317
spec:
1418
containers:
15-
- name: kube-vip
16-
image: ghcr.io/kube-vip/kube-vip:v0.6.4
17-
imagePullPolicy: IfNotPresent
18-
args:
19+
- args:
1920
- manager
2021
env:
2122
- name: vip_arp
2223
value: "true"
23-
- name: address
24-
value: "{{ `{{ .ControlPlaneEndpoint.Host }}` }}"
2524
- name: port
26-
value: "{{ `{{ .ControlPlaneEndpoint.Port }}` }}"
25+
value: '{{ `{{ .ControlPlaneEndpoint.Port }}` }}'
26+
- name: vip_nodename
27+
valueFrom:
28+
fieldRef:
29+
fieldPath: spec.nodeName
2730
- name: vip_cidr
2831
value: "32"
32+
- name: dns_mode
33+
value: first
2934
- name: cp_enable
3035
value: "true"
3136
- name: cp_namespace
3237
value: kube-system
33-
- name: vip_ddns
34-
value: "false"
3538
- name: vip_leaderelection
3639
value: "true"
40+
- name: vip_leasename
41+
value: plndr-cp-lock
3742
- name: vip_leaseduration
3843
value: "15"
3944
- name: vip_renewdeadline
4045
value: "10"
4146
- name: vip_retryperiod
4247
value: "2"
43-
- name: svc_enable
44-
value: "false"
45-
- name: lb_enable
46-
value: "false"
47-
- name: enableServicesElection
48-
value: "false"
48+
- name: address
49+
value: '{{ `{{ .ControlPlaneEndpoint.Host }}` }}'
50+
image: ghcr.io/kube-vip/kube-vip:v0.8.0
51+
imagePullPolicy: IfNotPresent
52+
name: kube-vip
53+
resources: {}
4954
securityContext:
5055
capabilities:
5156
add:
5257
- NET_ADMIN
53-
- SYS_TIME
5458
- NET_RAW
5559
volumeMounts:
5660
- mountPath: /etc/kubernetes/admin.conf
5761
name: kubeconfig
58-
resources: { }
59-
hostNetwork: true
6062
hostAliases:
6163
- hostnames:
6264
- kubernetes
6365
ip: 127.0.0.1
66+
hostNetwork: true
6467
volumes:
65-
- name: kubeconfig
66-
hostPath:
67-
type: FileOrCreate
68+
- hostPath:
6869
path: /etc/kubernetes/admin.conf
69-
status: {}
70+
name: kubeconfig
7071
kind: ConfigMap
7172
metadata:
7273
creationTimestamp: null
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
readonly SCRIPT_DIR
7+
8+
# shellcheck source=hack/common.sh
9+
source "${SCRIPT_DIR}/../common.sh"
10+
11+
if [ -z "${KUBE_VIP_VERSION:-}" ]; then
12+
echo "Missing argument: KUBE_VIP_VERSION"
13+
exit 1
14+
fi
15+
16+
ASSETS_DIR="$(mktemp -d -p "${TMPDIR:-/tmp}")"
17+
readonly ASSETS_DIR
18+
trap_add "rm -rf ${ASSETS_DIR}" EXIT
19+
20+
readonly FILE_NAME="kube-vip.yaml"
21+
22+
docker container run --rm ghcr.io/kube-vip/kube-vip:"${KUBE_VIP_VERSION}" \
23+
manifest pod \
24+
--arp \
25+
--address='{{ `{{ .ControlPlaneEndpoint.Host }}` }}' \
26+
--port=-99999 \
27+
--controlplane \
28+
--leaderElection \
29+
--leaseDuration=15 \
30+
--leaseRenewDuration=10 \
31+
--leaseRetry=2 \
32+
--prometheusHTTPServer='' |
33+
gojq --yaml-input --yaml-output 'del(.metadata.creationTimestamp, .status) | .spec.containers[].imagePullPolicy |= "IfNotPresent"' |
34+
sed "s/\"-99999\"/'{{ \`{{ .ControlPlaneEndpoint.Port }}\` }}'/" >"${ASSETS_DIR}/${FILE_NAME}"
35+
36+
kubectl create configmap "{{ .Values.hooks.kubeVip.defaultTemplateConfigMap.name }}" --dry-run=client --output yaml \
37+
--from-file "${ASSETS_DIR}/${FILE_NAME}" \
38+
>"${ASSETS_DIR}/kube-vip-configmap.yaml"
39+
40+
# add warning not to edit file directly
41+
cat <<EOF >"${GIT_REPO_ROOT}/charts/cluster-api-runtime-extensions-nutanix/templates/kube-vip/manifests/kube-vip-configmap.yaml"
42+
$(cat "${GIT_REPO_ROOT}/hack/license-header.yaml.txt")
43+
44+
#=================================================================
45+
# DO NOT EDIT THIS FILE
46+
# IT HAS BEEN GENERATED BY /hack/addons/update-kube-vip-manifests.sh
47+
#=================================================================
48+
{{- if .Values.hooks.kubeVip.defaultTemplateConfigMap.create }}
49+
$(cat "${ASSETS_DIR}/kube-vip-configmap.yaml")
50+
{{- end -}}
51+
EOF

make/addons.mk

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ export AWS_CCM_CHART_VERSION_128 := 0.0.8
1717

1818
export NUTANIX_CCM_CHART_VERSION := 0.3.3
1919

20+
export KUBE_VIP_VERSION := v0.8.0
21+
2022
.PHONY: addons.sync
21-
addons.sync: $(addprefix update-addon.,calico cilium nfd cluster-autoscaler aws-ebs-csi aws-ccm.127 aws-ccm.128)
23+
addons.sync: $(addprefix update-addon.,calico cilium nfd cluster-autoscaler aws-ebs-csi aws-ccm.127 aws-ccm.128 kube-vip)
2224

2325
.PHONY: update-addon.calico
2426
update-addon.calico: ; $(info $(M) updating calico manifests)
@@ -44,6 +46,10 @@ update-addon.aws-ebs-csi: ; $(info $(M) updating aws ebs csi manifests)
4446
update-addon.aws-ccm.%: ; $(info $(M) updating aws ccm $* manifests)
4547
./hack/addons/update-aws-ccm.sh $(AWS_CCM_VERSION_$*) $(AWS_CCM_CHART_VERSION_$*)
4648

49+
.PHONY: update-addon.kube-vip
50+
update-addon.kube-vip: ; $(info $(M) updating kube-vip manifests)
51+
./hack/addons/update-kube-vip-manifests.sh
52+
4753
.PHONY: generate-helm-configmap
4854
generate-helm-configmap:
4955
go run hack/tools/helm-cm/main.go -kustomize-directory="./hack/addons/kustomize" -output-file="./charts/cluster-api-runtime-extensions-nutanix/templates/helm-config.yaml"

pkg/handlers/generic/mutation/controlplanevirtualip/inject.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ func (h *ControlPlaneVirtualIP) Mutate(
131131
selectors.ControlPlane(),
132132
log,
133133
func(obj *controlplanev1.KubeadmControlPlaneTemplate) error {
134-
virtualIPProviderFile, getFileErr := virtualIPProvider.GetFile(ctx, controlPlaneEndpointVar)
134+
virtualIPProviderFile, getFileErr := virtualIPProvider.GetFile(
135+
ctx,
136+
controlPlaneEndpointVar,
137+
)
135138
if getFileErr != nil {
136139
return getFileErr
137140
}
@@ -148,7 +151,9 @@ func (h *ControlPlaneVirtualIP) Mutate(
148151
*virtualIPProviderFile,
149152
)
150153

151-
preKubeadmCommands, postKubeadmCommands, getCommandsErr := virtualIPProvider.GetCommands(cluster)
154+
preKubeadmCommands, postKubeadmCommands, getCommandsErr := virtualIPProvider.GetCommands(
155+
cluster,
156+
)
152157
if getCommandsErr != nil {
153158
return getCommandsErr
154159
}

pkg/handlers/generic/mutation/controlplanevirtualip/inject_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ var _ = Describe("Generate ControlPlane virtual IP patches", func() {
6868
gomega.ContainSubstring("value: \"6443\""),
6969
),
7070
gomega.HaveKey("owner"),
71-
gomega.HaveKeyWithValue("path", gomega.ContainSubstring("kube-vip")),
71+
gomega.HaveKeyWithValue(
72+
"path",
73+
gomega.ContainSubstring("kube-vip"),
74+
),
7275
gomega.HaveKey("permissions"),
7376
),
7477
),
@@ -136,7 +139,10 @@ var _ = Describe("Generate ControlPlane virtual IP patches", func() {
136139
gomega.ContainSubstring("value: \"6443\""),
137140
),
138141
gomega.HaveKey("owner"),
139-
gomega.HaveKeyWithValue("path", gomega.ContainSubstring("kube-vip")),
142+
gomega.HaveKeyWithValue(
143+
"path",
144+
gomega.ContainSubstring("kube-vip"),
145+
),
140146
gomega.HaveKey("permissions"),
141147
),
142148
),

pkg/handlers/generic/mutation/controlplanevirtualip/providers/kubevip.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@ func (p *kubeVIPFromConfigMapProvider) GetFile(
7474
}, nil
7575
}
7676

77+
//
7778
//nolint:gocritic // No need for named return values
78-
func (p *kubeVIPFromConfigMapProvider) GetCommands(cluster *clusterv1.Cluster) ([]string, []string, error) {
79+
func (p *kubeVIPFromConfigMapProvider) GetCommands(
80+
cluster *clusterv1.Cluster,
81+
) ([]string, []string, error) {
7982
// The kube-vip static Pod uses admin.conf on the host to connect to the API server.
8083
// But, starting with Kubernetes 1.29, admin.conf first gets created with no RBAC permissions.
8184
// At the same time, 'kubeadm init' command waits for the API server to be reachable on the kube-vip IP.
@@ -102,15 +105,21 @@ type multipleKeysError struct {
102105
}
103106

104107
func (e multipleKeysError) Error() string {
105-
return fmt.Sprintf("found multiple keys in ConfigMap %q, when only 1 is expected", e.configMapKey)
108+
return fmt.Sprintf(
109+
"found multiple keys in ConfigMap %q, when only 1 is expected",
110+
e.configMapKey,
111+
)
106112
}
107113

108114
type emptyValuesError struct {
109115
configMapKey client.ObjectKey
110116
}
111117

112118
func (e emptyValuesError) Error() string {
113-
return fmt.Sprintf("could not find any keys with non-empty vaules in ConfigMap %q", e.configMapKey)
119+
return fmt.Sprintf(
120+
"could not find any keys with non-empty vaules in ConfigMap %q",
121+
e.configMapKey,
122+
)
114123
}
115124

116125
func getTemplateFromConfigMap(

pkg/handlers/generic/mutation/controlplanevirtualip/providers/providers.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ type Provider interface {
2828
GetCommands(cluster *clusterv1.Cluster) ([]string, []string, error)
2929
}
3030

31-
func templateValues(controlPlaneEndpoint v1alpha1.ControlPlaneEndpointSpec, text string) (string, error) {
31+
func templateValues(
32+
controlPlaneEndpoint v1alpha1.ControlPlaneEndpointSpec,
33+
text string,
34+
) (string, error) {
3235
kubeVIPTemplate, err := template.New("").Parse(text)
3336
if err != nil {
3437
return "", fmt.Errorf("failed to parse template: %w", err)

pkg/handlers/options/global.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
package options
55

66
import (
7-
"cmp"
8-
97
"github.com/spf13/pflag"
108
corev1 "k8s.io/api/core/v1"
119
)
1210

1311
func NewGlobalOptions() *GlobalOptions {
14-
return &GlobalOptions{}
12+
return &GlobalOptions{
13+
defaultsNamespace: corev1.NamespaceDefault,
14+
}
1515
}
1616

1717
type GlobalOptions struct {
@@ -23,7 +23,7 @@ func (o *GlobalOptions) AddFlags(flags *pflag.FlagSet) {
2323
flags.StringVar(
2424
&o.defaultsNamespace,
2525
"defaults-namespace",
26-
corev1.NamespaceDefault,
26+
o.defaultsNamespace,
2727
"namespace for default configurations",
2828
)
2929
flags.StringVar(
@@ -35,7 +35,7 @@ func (o *GlobalOptions) AddFlags(flags *pflag.FlagSet) {
3535
}
3636

3737
func (o *GlobalOptions) DefaultsNamespace() string {
38-
return cmp.Or(o.defaultsNamespace, corev1.NamespaceDefault)
38+
return o.defaultsNamespace
3939
}
4040

4141
func (o *GlobalOptions) HelmAddonsConfigMapName() string {

0 commit comments

Comments
 (0)