Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit cfe0f05

Browse files
committed
fix: unit tests for patching kubeadmconfigtemplate with containerd restart
1 parent 853f918 commit cfe0f05

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import (
1717
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors"
1818
)
1919

20-
type globalMirrorPatchHandler struct{}
20+
type containerdRestartPatchHandler struct{}
2121

22-
func NewPatch() *globalMirrorPatchHandler {
23-
return &globalMirrorPatchHandler{}
22+
func NewPatch() *containerdRestartPatchHandler {
23+
return &containerdRestartPatchHandler{}
2424
}
2525

26-
func (h *globalMirrorPatchHandler) Mutate(
26+
func (h *containerdRestartPatchHandler) Mutate(
2727
ctx context.Context,
2828
obj *unstructured.Unstructured,
2929
vars map[string]apiextensionsv1.JSON,

pkg/handlers/generic/mutation/containerdrestart/tests/generate_patches.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88

99
"github.com/onsi/gomega"
10+
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
1011

1112
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation"
1213
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest"
@@ -46,12 +47,22 @@ func TestGeneratePatches(
4647
},
4748
},
4849
capitest.PatchTestDef{
49-
Name: "restart script and command added to worker node kubeadm config template",
50-
RequestItem: request.NewKubeadmControlPlaneTemplateRequestItem(""),
50+
Name: "restart script and command added to worker node kubeadm config template",
51+
Vars: []runtimehooksv1.Variable{
52+
capitest.VariableWithValue(
53+
"builtin",
54+
map[string]any{
55+
"machineDeployment": map[string]any{
56+
"class": "*",
57+
},
58+
},
59+
),
60+
},
61+
RequestItem: request.NewKubeadmConfigTemplateRequestItem(""),
5162
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{
5263
{
5364
Operation: "add",
54-
Path: "/spec/template/spec/kubeadmConfigSpec/files",
65+
Path: "/spec/template/spec/files",
5566
ValueMatcher: gomega.ContainElements(
5667
gomega.HaveKeyWithValue(
5768
"path", containerdrestart.ContainerdRestartScriptOnRemote,
@@ -60,7 +71,7 @@ func TestGeneratePatches(
6071
},
6172
{
6273
Operation: "add",
63-
Path: "/spec/template/spec/kubeadmConfigSpec/preKubeadmCommands",
74+
Path: "/spec/template/spec/preKubeadmCommands",
6475
ValueMatcher: gomega.ContainElements(
6576
containerdrestart.ContainerdRestartScriptOnRemoteCommand,
6677
),

0 commit comments

Comments
 (0)