-
Notifications
You must be signed in to change notification settings - Fork 162
/
verify.go
125 lines (109 loc) · 4.04 KB
/
verify.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package nodeconfig
import (
"context"
"fmt"
o "github.com/onsi/gomega"
scyllav1alpha1 "github.com/scylladb/scylla-operator/pkg/api/scylla/v1alpha1"
"github.com/scylladb/scylla-operator/pkg/naming"
"github.com/scylladb/scylla-operator/test/e2e/framework"
"github.com/scylladb/scylla-operator/test/e2e/utils"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/kubernetes"
)
func verifyDaemonSet(ds *appsv1.DaemonSet) {
o.Expect(ds.DeletionTimestamp).To(o.BeNil())
o.Expect(ds.Status.ObservedGeneration).To(o.Equal(ds.Generation))
o.Expect(ds.Status.UpdatedNumberScheduled).To(o.Equal(ds.Status.DesiredNumberScheduled))
o.Expect(ds.Status.NumberAvailable).To(o.Equal(ds.Status.DesiredNumberScheduled))
}
func verifyNodeConfig(ctx context.Context, kubeClient kubernetes.Interface, nc *scyllav1alpha1.NodeConfig) {
framework.By("Verifying NodeConfig %q", naming.ObjRef(nc))
o.Expect(nc.Status.ObservedGeneration).NotTo(o.BeNil())
daemonSets, err := utils.GetDaemonSetsForNodeConfig(ctx, kubeClient.AppsV1(), nc)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(daemonSets).To(o.HaveLen(1))
ds := daemonSets[0]
verifyDaemonSet(ds)
for i := range nc.Status.Conditions {
c := &nc.Status.Conditions[i]
o.Expect(c.LastTransitionTime).NotTo(o.BeNil())
o.Expect(c.LastTransitionTime.Time.Before(nc.CreationTimestamp.Time)).NotTo(o.BeTrue())
// To be able to compare the statuses we need to remove the random timestamp.
c.LastTransitionTime = metav1.Time{}
}
o.Expect(nc.Status.Conditions).To(o.ConsistOf(func() []interface{} {
var expectedConditions []interface{}
dsPods, err := kubeClient.CoreV1().Pods(ds.Namespace).List(ctx, metav1.ListOptions{LabelSelector: labels.SelectorFromSet(ds.Spec.Selector.MatchLabels).String()})
o.Expect(err).NotTo(o.HaveOccurred())
dsNodeNames := make([]string, 0, len(dsPods.Items))
for _, dsPod := range dsPods.Items {
dsNodeNames = append(dsNodeNames, dsPod.Spec.NodeName)
}
type condValue struct {
condType string
status corev1.ConditionStatus
}
for _, nodeName := range dsNodeNames {
condList := []condValue{
// Node aggregated conditions
{
condType: fmt.Sprintf("Node%sAvailable", nodeName),
status: corev1.ConditionTrue,
},
{
condType: fmt.Sprintf("Node%sProgressing", nodeName),
status: corev1.ConditionFalse,
},
{
condType: fmt.Sprintf("Node%sDegraded", nodeName),
status: corev1.ConditionFalse,
},
// Controller conditions
{
condType: fmt.Sprintf("FilesystemControllerNode%sProgressing", nodeName),
status: corev1.ConditionFalse,
},
{
condType: fmt.Sprintf("FilesystemControllerNode%sDegraded", nodeName),
status: corev1.ConditionFalse,
},
{
condType: fmt.Sprintf("MountControllerNode%sProgressing", nodeName),
status: corev1.ConditionFalse,
},
{
condType: fmt.Sprintf("MountControllerNode%sDegraded", nodeName),
status: corev1.ConditionFalse,
},
{
condType: fmt.Sprintf("RaidControllerNode%sProgressing", nodeName),
status: corev1.ConditionFalse,
},
{
condType: fmt.Sprintf("RaidControllerNode%sDegraded", nodeName),
status: corev1.ConditionFalse,
},
}
for _, item := range condList {
expectedConditions = append(expectedConditions, scyllav1alpha1.NodeConfigCondition{
Type: scyllav1alpha1.NodeConfigConditionType(item.condType),
Status: item.status,
Reason: "AsExpected",
Message: "",
ObservedGeneration: nc.Generation,
})
}
expectedConditions = append(expectedConditions, scyllav1alpha1.NodeConfigCondition{
Type: scyllav1alpha1.NodeConfigReconciledConditionType,
Status: corev1.ConditionTrue,
Reason: "FullyReconciledAndUp",
Message: "All operands are reconciled and available.",
ObservedGeneration: nc.Generation,
})
}
return expectedConditions
}()...))
}