@@ -17,15 +17,18 @@ limitations under the License.
17
17
package internal
18
18
19
19
import (
20
+ "strings"
20
21
"testing"
21
22
23
+ "github.com/google/go-cmp/cmp"
22
24
. "github.com/onsi/gomega"
23
25
corev1 "k8s.io/api/core/v1"
24
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25
27
"k8s.io/utils/ptr"
26
28
27
29
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
28
30
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
31
+ "sigs.k8s.io/cluster-api/controlplane/kubeadm/internal/etcd"
29
32
"sigs.k8s.io/cluster-api/util/collections"
30
33
"sigs.k8s.io/cluster-api/util/conditions"
31
34
)
@@ -252,6 +255,75 @@ func TestHasHealthyMachineStillProvisioning(t *testing.T) {
252
255
})
253
256
}
254
257
258
+ func TestStatusToLogKeyAndValues (t * testing.T ) {
259
+ healthyMachine := & clusterv1.Machine {
260
+ ObjectMeta : metav1.ObjectMeta {Name : "healthy" },
261
+ Status : clusterv1.MachineStatus {
262
+ NodeRef : & corev1.ObjectReference {Name : "healthy-node" },
263
+ Conditions : []clusterv1.Condition {
264
+ {Type : controlplanev1 .MachineAPIServerPodHealthyCondition , Status : corev1 .ConditionTrue },
265
+ {Type : controlplanev1 .MachineControllerManagerPodHealthyCondition , Status : corev1 .ConditionTrue },
266
+ {Type : controlplanev1 .MachineSchedulerPodHealthyCondition , Status : corev1 .ConditionTrue },
267
+ {Type : controlplanev1 .MachineEtcdPodHealthyCondition , Status : corev1 .ConditionTrue },
268
+ {Type : controlplanev1 .MachineEtcdMemberHealthyCondition , Status : corev1 .ConditionTrue },
269
+ },
270
+ },
271
+ }
272
+
273
+ machineWithoutNode := & clusterv1.Machine {
274
+ ObjectMeta : metav1.ObjectMeta {Name : "without-node" },
275
+ Status : clusterv1.MachineStatus {
276
+ NodeRef : nil ,
277
+ Conditions : []clusterv1.Condition {
278
+ {Type : controlplanev1 .MachineAPIServerPodHealthyCondition , Status : corev1 .ConditionUnknown },
279
+ {Type : controlplanev1 .MachineControllerManagerPodHealthyCondition , Status : corev1 .ConditionUnknown },
280
+ {Type : controlplanev1 .MachineSchedulerPodHealthyCondition , Status : corev1 .ConditionUnknown },
281
+ {Type : controlplanev1 .MachineEtcdPodHealthyCondition , Status : corev1 .ConditionUnknown },
282
+ {Type : controlplanev1 .MachineEtcdMemberHealthyCondition , Status : corev1 .ConditionFalse }, // not a real use case, but used to test a code branch.
283
+ },
284
+ },
285
+ }
286
+
287
+ machineJustCreated := & clusterv1.Machine {ObjectMeta : metav1.ObjectMeta {Name : "just-created" }}
288
+
289
+ machineJustDeleted := healthyMachine .DeepCopy ()
290
+ machineJustDeleted .Name = "just-deleted"
291
+
292
+ machineNotUpToDate := healthyMachine .DeepCopy ()
293
+ machineNotUpToDate .Name = "not-up-to-date"
294
+
295
+ machineMarkedForRemediation := healthyMachine .DeepCopy ()
296
+ machineMarkedForRemediation .Name = "marked-for-remediation"
297
+ machineMarkedForRemediation .Status .Conditions = append (machineMarkedForRemediation .Status .Conditions ,
298
+ clusterv1.Condition {Type : clusterv1 .MachineHealthCheckSucceededCondition , Status : corev1 .ConditionFalse },
299
+ clusterv1.Condition {Type : clusterv1 .MachineOwnerRemediatedCondition , Status : corev1 .ConditionFalse },
300
+ )
301
+
302
+ g := NewWithT (t )
303
+ c := & ControlPlane {
304
+ KCP : & controlplanev1.KubeadmControlPlane {},
305
+ Machines : collections .FromMachines (healthyMachine , machineWithoutNode , machineJustDeleted , machineNotUpToDate , machineMarkedForRemediation ),
306
+ machinesNotUptoDate : collections .FromMachines (machineNotUpToDate ),
307
+ EtcdMembers : []* etcd.Member {{Name : "m1" }, {Name : "m2" }, {Name : "m3" }},
308
+ }
309
+
310
+ got := c .StatusToLogKeyAndValues (machineJustCreated , machineJustDeleted )
311
+
312
+ g .Expect (got ).To ((HaveLen (4 )))
313
+ g .Expect (got [0 ]).To (Equal ("machines" ))
314
+ machines := strings .Join ([]string {
315
+ "healthy" ,
316
+ "just-created (just created)" ,
317
+ "just-deleted (just deleted)" ,
318
+ "marked-for-remediation (marked for remediation)" ,
319
+ "not-up-to-date (not up-to-date)" ,
320
+ "without-node (status.nodeRef not set, APIServerPod health unknown, ControllerManagerPod health unknown, SchedulerPod health unknown, EtcdPod health unknown, EtcdMember not healthy)" ,
321
+ }, ", " )
322
+ g .Expect (got [1 ]).To (Equal (machines ), cmp .Diff (got [1 ], machines ))
323
+ g .Expect (got [2 ]).To (Equal ("etcdMembers" ))
324
+ g .Expect (got [3 ]).To (Equal ("m1, m2, m3" ))
325
+ }
326
+
255
327
type machineOpt func (* clusterv1.Machine )
256
328
257
329
func failureDomain (controlPlane bool ) clusterv1.FailureDomainSpec {
0 commit comments