Skip to content

Commit ffa0cfc

Browse files
committed
fixup! refactor: run a script to configure kube-vip
1 parent e505fd3 commit ffa0cfc

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,11 @@ func (h *ControlPlaneVirtualIP) Mutate(
134134
selectors.ControlPlane(),
135135
log,
136136
func(obj *controlplanev1.KubeadmControlPlaneTemplate) error {
137-
virtualIPProviderFiles, preKubeadmCommands, postKubeadmCommands, generateErr :=
138-
virtualIPProvider.GenerateFilesAndCommands(
139-
ctx,
140-
controlPlaneEndpointVar,
141-
cluster,
142-
)
137+
files, preKubeadmCommands, postKubeadmCommands, generateErr := virtualIPProvider.GenerateFilesAndCommands(
138+
ctx,
139+
controlPlaneEndpointVar,
140+
cluster,
141+
)
143142
if generateErr != nil {
144143
return generateErr
145144
}
@@ -153,7 +152,7 @@ func (h *ControlPlaneVirtualIP) Mutate(
153152
))
154153
obj.Spec.Template.Spec.KubeadmConfigSpec.Files = append(
155154
obj.Spec.Template.Spec.KubeadmConfigSpec.Files,
156-
virtualIPProviderFiles...,
155+
files...,
157156
)
158157

159158
if len(preKubeadmCommands) > 0 {

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ var (
3030
configureForKubeVIPScriptOnRemote = common.ConfigFilePathOnRemote(
3131
"configure-for-kube-vip.sh")
3232

33-
configureForKubeVIPScriptOnRemotePreKubeadmCommand = "/bin/bash " + configureForKubeVIPScriptOnRemote + " use-super-admin.conf"
34-
configureForKubeVIPScriptOnRemotePostKubeadmCommand = "/bin/bash " + configureForKubeVIPScriptOnRemote + " use-admin.conf"
33+
configureForKubeVIPScriptOnRemotePreKubeadmCommand = "/bin/bash " +
34+
configureForKubeVIPScriptOnRemote + " use-super-admin.conf"
35+
configureForKubeVIPScriptOnRemotePostKubeadmCommand = "/bin/bash " +
36+
configureForKubeVIPScriptOnRemote + " use-admin.conf"
3537

3638
setHostAliasesScriptOnRemoteCommand = "/bin/bash " + configureForKubeVIPScriptOnRemote + " set-host-aliases"
3739
)
3840

39-
var (
40-
//go:embed templates/configure-for-kube-vip.sh
41-
configureForKubeVIPScript []byte
42-
)
41+
//go:embed templates/configure-for-kube-vip.sh
42+
var configureForKubeVIPScript []byte
4343

4444
type kubeVIPFromConfigMapProvider struct {
4545
client client.Reader
@@ -72,7 +72,7 @@ func (p *kubeVIPFromConfigMapProvider) GenerateFilesAndCommands(
7272
ctx context.Context,
7373
spec v1alpha1.ControlPlaneEndpointSpec,
7474
cluster *clusterv1.Cluster,
75-
) ([]bootstrapv1.File, []string, []string, error) {
75+
) (files []bootstrapv1.File, preKubeadmCommands, postKubeadmCommands []string, err error) {
7676
data, err := getTemplateFromConfigMap(ctx, p.client, p.configMapKey)
7777
if err != nil {
7878
return nil, nil, nil, fmt.Errorf("failed getting template data: %w", err)
@@ -83,7 +83,7 @@ func (p *kubeVIPFromConfigMapProvider) GenerateFilesAndCommands(
8383
return nil, nil, nil, fmt.Errorf("failed templating static Pod: %w", err)
8484
}
8585

86-
files := []bootstrapv1.File{
86+
files = []bootstrapv1.File{
8787
{
8888
Content: kubeVIPStaticPod,
8989
Owner: kubeVIPFileOwner,
@@ -114,7 +114,10 @@ func (p *kubeVIPFromConfigMapProvider) GenerateFilesAndCommands(
114114
// See https://github.com/kubernetes/kubernetes/issues/122420#issuecomment-1864609518
115115
needCommands, err := needHackCommands(cluster)
116116
if err != nil {
117-
return nil, nil, nil, fmt.Errorf("failed to determine if kube-vip commands are needed: %w", err)
117+
return nil, nil, nil, fmt.Errorf(
118+
"failed to determine if kube-vip commands are needed: %w",
119+
err,
120+
)
118121
}
119122
if !needCommands {
120123
return files, nil, nil, nil
@@ -129,11 +132,11 @@ func (p *kubeVIPFromConfigMapProvider) GenerateFilesAndCommands(
129132
},
130133
)
131134

132-
preKubeadmCommands := []string{
135+
preKubeadmCommands = []string{
133136
setHostAliasesScriptOnRemoteCommand,
134137
configureForKubeVIPScriptOnRemotePreKubeadmCommand,
135138
}
136-
postKubeadmCommands := []string{configureForKubeVIPScriptOnRemotePostKubeadmCommand}
139+
postKubeadmCommands = []string{configureForKubeVIPScriptOnRemotePostKubeadmCommand}
137140

138141
return files, preKubeadmCommands, postKubeadmCommands, nil
139142
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,11 @@ func Test_GenerateFilesAndCommands(t *testing.T) {
118118
configMapKey: client.ObjectKeyFromObject(tt.configMap),
119119
}
120120

121-
files, preKubeadmCommands, postKubeadmCommands, err :=
122-
provider.GenerateFilesAndCommands(
123-
context.TODO(),
124-
tt.controlPlaneEndpointSpec,
125-
tt.cluster,
126-
)
121+
files, preKubeadmCommands, postKubeadmCommands, err := provider.GenerateFilesAndCommands(
122+
context.TODO(),
123+
tt.controlPlaneEndpointSpec,
124+
tt.cluster,
125+
)
127126
require.Equal(t, tt.expectedErr, err)
128127
assert.Equal(t, tt.expectedFiles, files)
129128
assert.Equal(t, tt.expectedPreKubeadmCommands, preKubeadmCommands)

0 commit comments

Comments
 (0)