@@ -31,6 +31,7 @@ import (
31
31
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
32
32
"sigs.k8s.io/cluster-api/controlplane/kubeadm/internal/etcd"
33
33
fake2 "sigs.k8s.io/cluster-api/controlplane/kubeadm/internal/etcd/fake"
34
+ "sigs.k8s.io/cluster-api/util/yaml"
34
35
"sigs.k8s.io/controller-runtime/pkg/client"
35
36
"sigs.k8s.io/controller-runtime/pkg/client/fake"
36
37
)
@@ -45,36 +46,44 @@ func TestUpdateEtcdVersionInKubeadmConfigMap(t *testing.T) {
45
46
}{
46
47
{
47
48
name : "it should set etcd version when local etcd" ,
48
- clusterConfigurationData : "apiVersion: kubeadm.k8s.io/v1beta2\n " +
49
- "kind: ClusterConfiguration\n " +
50
- "etcd:\n " +
51
- " local: {}\n " ,
49
+ clusterConfigurationData : yaml .Raw (`
50
+ apiVersion: kubeadm.k8s.io/v1beta2
51
+ kind: ClusterConfiguration
52
+ etcd:
53
+ local: {}
54
+ ` ),
52
55
newImageRepository : "example.com/k8s" ,
53
56
newImageTag : "v1.6.0" ,
54
- wantClusterConfiguration : "apiServer: {}\n " +
55
- "apiVersion: kubeadm.k8s.io/v1beta2\n " +
56
- "controllerManager: {}\n " +
57
- "dns: {}\n " +
58
- "etcd:\n " +
59
- " local:\n " +
60
- " imageRepository: example.com/k8s\n " +
61
- " imageTag: v1.6.0\n " +
62
- "kind: ClusterConfiguration\n " +
63
- "networking: {}\n " +
64
- "scheduler: {}\n " ,
57
+ wantClusterConfiguration : yaml .Raw (`
58
+ apiServer: {}
59
+ apiVersion: kubeadm.k8s.io/v1beta2
60
+ controllerManager: {}
61
+ dns: {}
62
+ etcd:
63
+ local:
64
+ imageRepository: example.com/k8s
65
+ imageTag: v1.6.0
66
+ kind: ClusterConfiguration
67
+ networking: {}
68
+ scheduler: {}
69
+ ` ),
65
70
},
66
71
{
67
72
name : "no op when external etcd" ,
68
- clusterConfigurationData : "apiVersion: kubeadm.k8s.io/v1beta2\n " +
69
- "kind: ClusterConfiguration\n " +
70
- "etcd:\n " +
71
- " external: {}\n " ,
73
+ clusterConfigurationData : yaml .Raw (`
74
+ apiVersion: kubeadm.k8s.io/v1beta2
75
+ kind: ClusterConfiguration
76
+ etcd:
77
+ external: {}
78
+ ` ),
72
79
newImageRepository : "example.com/k8s" ,
73
80
newImageTag : "v1.6.0" ,
74
- wantClusterConfiguration : "apiVersion: kubeadm.k8s.io/v1beta2\n " +
75
- "kind: ClusterConfiguration\n " +
76
- "etcd:\n " +
77
- " external: {}\n " ,
81
+ wantClusterConfiguration : yaml .Raw (`
82
+ apiVersion: kubeadm.k8s.io/v1beta2
83
+ kind: ClusterConfiguration
84
+ etcd:
85
+ external: {}
86
+ ` ),
78
87
},
79
88
}
80
89
@@ -442,19 +451,21 @@ func TestReconcileEtcdMembers(t *testing.T) {
442
451
Namespace : metav1 .NamespaceSystem ,
443
452
},
444
453
Data : map [string ]string {
445
- clusterStatusKey : "apiEndpoints:\n " +
446
- " ip-10-0-0-1.ec2.internal:\n " +
447
- " advertiseAddress: 10.0.0.1\n " +
448
- " bindPort: 6443\n " +
449
- " ip-10-0-0-2.ec2.internal:\n " +
450
- " advertiseAddress: 10.0.0.2\n " +
451
- " bindPort: 6443\n " +
452
- " someFieldThatIsAddedInTheFuture: bar\n " +
453
- " ip-10-0-0-3.ec2.internal:\n " +
454
- " advertiseAddress: 10.0.0.3\n " +
455
- " bindPort: 6443\n " +
456
- "apiVersion: kubeadm.k8s.io/v1beta2\n " +
457
- "kind: ClusterStatus\n " ,
454
+ clusterStatusKey : yaml .Raw (`
455
+ apiEndpoints:
456
+ ip-10-0-0-1.ec2.internal:
457
+ advertiseAddress: 10.0.0.1
458
+ bindPort: 6443
459
+ ip-10-0-0-2.ec2.internal:
460
+ advertiseAddress: 10.0.0.2
461
+ bindPort: 6443
462
+ someFieldThatIsAddedInTheFuture: bar
463
+ ip-10-0-0-3.ec2.internal:
464
+ advertiseAddress: 10.0.0.3
465
+ bindPort: 6443
466
+ apiVersion: kubeadm.k8s.io/v1beta2
467
+ kind: ClusterStatus
468
+ ` ),
458
469
},
459
470
}
460
471
kubeadmConfigWithoutClusterStatus := kubeadmConfig .DeepCopy ()
@@ -516,16 +527,18 @@ func TestReconcileEtcdMembers(t *testing.T) {
516
527
client.ObjectKey {Name : kubeadmConfigKey , Namespace : metav1 .NamespaceSystem },
517
528
& actualConfig ,
518
529
)).To (Succeed ())
519
-
520
- g .Expect (actualConfig .Data [clusterStatusKey ]).To (Equal ("apiEndpoints:\n " +
521
- " ip-10-0-0-1.ec2.internal:\n " +
522
- " advertiseAddress: 10.0.0.1\n " +
523
- " bindPort: 6443\n " +
524
- " ip-10-0-0-2.ec2.internal:\n " +
525
- " advertiseAddress: 10.0.0.2\n " +
526
- " bindPort: 6443\n " +
527
- "apiVersion: kubeadm.k8s.io/v1beta2\n " +
528
- "kind: ClusterStatus\n " ))
530
+ expectedOutput := yaml .Raw (`
531
+ apiEndpoints:
532
+ ip-10-0-0-1.ec2.internal:
533
+ advertiseAddress: 10.0.0.1
534
+ bindPort: 6443
535
+ ip-10-0-0-2.ec2.internal:
536
+ advertiseAddress: 10.0.0.2
537
+ bindPort: 6443
538
+ apiVersion: kubeadm.k8s.io/v1beta2
539
+ kind: ClusterStatus
540
+ ` )
541
+ g .Expect (actualConfig .Data [clusterStatusKey ]).To (Equal (expectedOutput ))
529
542
},
530
543
},
531
544
{
@@ -606,37 +619,45 @@ func TestRemoveNodeFromKubeadmConfigMap(t *testing.T) {
606
619
{
607
620
name : "removes the api endpoint" ,
608
621
apiEndpoint : "ip-10-0-0-2.ec2.internal" ,
609
- clusterStatusData : "apiEndpoints:\n " +
610
- " ip-10-0-0-1.ec2.internal:\n " +
611
- " advertiseAddress: 10.0.0.1\n " +
612
- " bindPort: 6443\n " +
613
- " ip-10-0-0-2.ec2.internal:\n " +
614
- " advertiseAddress: 10.0.0.2\n " +
615
- " bindPort: 6443\n " +
616
- "apiVersion: kubeadm.k8s.io/v1beta2\n " +
617
- "kind: ClusterStatus\n " ,
618
- wantClusterStatus : "apiEndpoints:\n " +
619
- " ip-10-0-0-1.ec2.internal:\n " +
620
- " advertiseAddress: 10.0.0.1\n " +
621
- " bindPort: 6443\n " +
622
- "apiVersion: kubeadm.k8s.io/v1beta2\n " +
623
- "kind: ClusterStatus\n " ,
622
+ clusterStatusData : yaml .Raw (`
623
+ apiEndpoints:
624
+ ip-10-0-0-1.ec2.internal:
625
+ advertiseAddress: 10.0.0.1
626
+ bindPort: 6443
627
+ ip-10-0-0-2.ec2.internal:
628
+ advertiseAddress: 10.0.0.2
629
+ bindPort: 6443
630
+ apiVersion: kubeadm.k8s.io/v1beta2
631
+ kind: ClusterStatus
632
+ ` ),
633
+ wantClusterStatus : yaml .Raw (`
634
+ apiEndpoints:
635
+ ip-10-0-0-1.ec2.internal:
636
+ advertiseAddress: 10.0.0.1
637
+ bindPort: 6443
638
+ apiVersion: kubeadm.k8s.io/v1beta2
639
+ kind: ClusterStatus
640
+ ` ),
624
641
},
625
642
{
626
643
name : "no op if the api endpoint does not exists" ,
627
644
apiEndpoint : "ip-10-0-0-2.ec2.internal" ,
628
- clusterStatusData : "apiEndpoints:\n " +
629
- " ip-10-0-0-1.ec2.internal:\n " +
630
- " advertiseAddress: 10.0.0.1\n " +
631
- " bindPort: 6443\n " +
632
- "apiVersion: kubeadm.k8s.io/v1beta2\n " +
633
- "kind: ClusterStatus\n " ,
634
- wantClusterStatus : "apiEndpoints:\n " +
635
- " ip-10-0-0-1.ec2.internal:\n " +
636
- " advertiseAddress: 10.0.0.1\n " +
637
- " bindPort: 6443\n " +
638
- "apiVersion: kubeadm.k8s.io/v1beta2\n " +
639
- "kind: ClusterStatus\n " ,
645
+ clusterStatusData : yaml .Raw (`
646
+ apiEndpoints:
647
+ ip-10-0-0-1.ec2.internal:
648
+ advertiseAddress: 10.0.0.1
649
+ bindPort: 6443
650
+ apiVersion: kubeadm.k8s.io/v1beta2
651
+ kind: ClusterStatus
652
+ ` ),
653
+ wantClusterStatus : yaml .Raw (`
654
+ apiEndpoints:
655
+ ip-10-0-0-1.ec2.internal:
656
+ advertiseAddress: 10.0.0.1
657
+ bindPort: 6443
658
+ apiVersion: kubeadm.k8s.io/v1beta2
659
+ kind: ClusterStatus
660
+ ` ),
640
661
},
641
662
}
642
663
for _ , tt := range tests {
0 commit comments