Skip to content

Commit 7e6b3d8

Browse files
⚠️ KCP tolerates diff not leading to changes on machines (#12402)
* KCP should tolerate diff not leading to changes on machines * Address feedback
1 parent 2ebc80d commit 7e6b3d8

File tree

3 files changed

+832
-18
lines changed

3 files changed

+832
-18
lines changed

bootstrap/kubeadm/internal/cloudinit/cloudinit_test.go

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,164 @@ func TestNewJoinNodeCommands(t *testing.T) {
324324

325325
g.Expect(out).To(ContainSubstring(expectedRunCmd))
326326
}
327+
328+
func TestOmittableFields(t *testing.T) {
329+
tests := []struct {
330+
name string
331+
A BaseUserData
332+
B BaseUserData
333+
}{
334+
{
335+
name: "No diff between empty or nil additionalFiles", // NOTE: it maps to .Files in the KubeadmConfigSpec
336+
A: BaseUserData{
337+
AdditionalFiles: []bootstrapv1.File{},
338+
},
339+
B: BaseUserData{
340+
AdditionalFiles: nil,
341+
},
342+
},
343+
{
344+
name: "No diff between empty or nil diskSetup.partitions",
345+
A: BaseUserData{
346+
DiskSetup: &bootstrapv1.DiskSetup{
347+
Partitions: []bootstrapv1.Partition{},
348+
},
349+
},
350+
B: BaseUserData{
351+
DiskSetup: &bootstrapv1.DiskSetup{
352+
Partitions: nil,
353+
},
354+
},
355+
},
356+
{
357+
name: "No diff between empty or nil diskSetup.filesystems.extraOpts",
358+
A: BaseUserData{
359+
DiskSetup: &bootstrapv1.DiskSetup{
360+
Filesystems: []bootstrapv1.Filesystem{
361+
{
362+
ExtraOpts: []string{},
363+
},
364+
},
365+
},
366+
},
367+
B: BaseUserData{
368+
DiskSetup: &bootstrapv1.DiskSetup{
369+
Filesystems: []bootstrapv1.Filesystem{
370+
{
371+
ExtraOpts: nil,
372+
},
373+
},
374+
},
375+
},
376+
},
377+
{
378+
name: "No diff between empty or nil diskSetup.filesystems",
379+
A: BaseUserData{
380+
DiskSetup: &bootstrapv1.DiskSetup{
381+
Filesystems: []bootstrapv1.Filesystem{},
382+
},
383+
},
384+
B: BaseUserData{
385+
DiskSetup: &bootstrapv1.DiskSetup{
386+
Filesystems: nil,
387+
},
388+
},
389+
},
390+
{
391+
name: "No diff between empty or nil mounts",
392+
A: BaseUserData{
393+
Mounts: []bootstrapv1.MountPoints{},
394+
},
395+
B: BaseUserData{
396+
Mounts: nil,
397+
},
398+
},
399+
{
400+
name: "No diff between empty or nil bootCommands",
401+
A: BaseUserData{
402+
BootCommands: []string{},
403+
},
404+
B: BaseUserData{
405+
BootCommands: nil,
406+
},
407+
},
408+
{
409+
name: "No diff between empty or nil preKubeadmCommands",
410+
A: BaseUserData{
411+
PreKubeadmCommands: []string{},
412+
},
413+
B: BaseUserData{
414+
PreKubeadmCommands: nil,
415+
},
416+
},
417+
{
418+
name: "No diff between empty or nil postKubeadmCommands",
419+
A: BaseUserData{
420+
PostKubeadmCommands: []string{},
421+
},
422+
B: BaseUserData{
423+
PostKubeadmCommands: nil,
424+
},
425+
},
426+
{
427+
name: "No diff between empty or nil users",
428+
A: BaseUserData{
429+
Users: []bootstrapv1.User{},
430+
},
431+
B: BaseUserData{
432+
Users: nil,
433+
},
434+
},
435+
{
436+
name: "No diff between empty or nil users.sshAuthorizedKeys",
437+
A: BaseUserData{
438+
Users: []bootstrapv1.User{
439+
{
440+
SSHAuthorizedKeys: nil,
441+
},
442+
},
443+
},
444+
B: BaseUserData{
445+
Users: []bootstrapv1.User{
446+
{
447+
SSHAuthorizedKeys: []string{},
448+
},
449+
},
450+
},
451+
},
452+
{
453+
name: "No diff between empty or nil ntp.servers",
454+
A: BaseUserData{
455+
NTP: &bootstrapv1.NTP{
456+
Servers: []string{},
457+
},
458+
},
459+
B: BaseUserData{
460+
NTP: &bootstrapv1.NTP{
461+
Servers: nil,
462+
},
463+
},
464+
},
465+
}
466+
for _, tt := range tests {
467+
t.Run(tt.name, func(t *testing.T) {
468+
g := NewWithT(t)
469+
470+
outA, err := NewInitControlPlane(&ControlPlaneInput{BaseUserData: tt.A})
471+
g.Expect(err).ToNot(HaveOccurred())
472+
473+
outB, err := NewInitControlPlane(&ControlPlaneInput{BaseUserData: tt.B})
474+
g.Expect(err).ToNot(HaveOccurred())
475+
476+
g.Expect(string(outA)).To(Equal(string(outB)))
477+
478+
outA, err = NewJoinControlPlane(&ControlPlaneJoinInput{BaseUserData: tt.A})
479+
g.Expect(err).ToNot(HaveOccurred())
480+
481+
outB, err = NewJoinControlPlane(&ControlPlaneJoinInput{BaseUserData: tt.B})
482+
g.Expect(err).ToNot(HaveOccurred())
483+
484+
g.Expect(string(outA)).To(Equal(string(outB)))
485+
})
486+
}
487+
}

0 commit comments

Comments
 (0)