Skip to content

Commit 3d59525

Browse files
committed
test(e2e): amend according to new conditions
1 parent 3c77914 commit 3d59525

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

test/e2e/clusterdeployment/validate_deployed.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2929
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3030
"k8s.io/apimachinery/pkg/util/intstr"
31+
clusterapiv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
3132

3233
"github.com/K0rdent/kcm/test/e2e/kubeclient"
3334
validationutil "github.com/K0rdent/kcm/test/util/validation"
@@ -56,7 +57,11 @@ func validateCluster(ctx context.Context, kc *kubeclient.KubeClient, clusterName
5657
Fail(err.Error())
5758
}
5859

59-
return validationutil.ValidateConditionsTrue(cluster)
60+
return validationutil.ValidateConditionsTrue(cluster,
61+
clusterapiv1.AvailableCondition,
62+
clusterapiv1.ClusterControlPlaneMachinesReadyCondition,
63+
clusterapiv1.ClusterWorkerMachinesReadyReason,
64+
)
6065
}
6166

6267
func validateMachines(ctx context.Context, kc *kubeclient.KubeClient, clusterName string) error {
@@ -80,7 +85,7 @@ func validateMachines(ctx context.Context, kc *kubeclient.KubeClient, clusterNam
8085
Fail(err.Error())
8186
}
8287

83-
if err := validationutil.ValidateConditionsTrue(&md); err != nil {
88+
if err := validationutil.ValidateConditionsTrue(&md, clusterapiv1.ReadyCondition); err != nil {
8489
return err
8590
}
8691
}
@@ -91,7 +96,7 @@ func validateMachines(ctx context.Context, kc *kubeclient.KubeClient, clusterNam
9196
Fail(err.Error())
9297
}
9398

94-
if err := validationutil.ValidateConditionsTrue(&machine); err != nil {
99+
if err := validationutil.ValidateConditionsTrue(&machine, clusterapiv1.ReadyCondition, clusterapiv1.AvailableCondition); err != nil {
95100
return err
96101
}
97102
}

test/util/validation/validation.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,30 @@ import (
2727

2828
// ValidateConditionsTrue iterates over the conditions of the given
2929
// unstructured object and returns an error if any of the conditions are not
30-
// true. Conditions are expected to be of type metav1.Condition.
31-
func ValidateConditionsTrue(unstrObj *unstructured.Unstructured) error {
30+
// true. Conditions are expected to be of type metav1.Condition.
31+
//
32+
// If includeTypes argument is set, then validation includes only the given,
33+
// otherwise all of the available conditions are up to be tested against Status == True.
34+
func ValidateConditionsTrue(unstrObj *unstructured.Unstructured, includeTypes ...string) error {
3235
objKind, objName := statusutil.ObjKindName(unstrObj)
3336

3437
conditions, err := statusutil.ConditionsFromUnstructured(unstrObj)
3538
if err != nil {
3639
return fmt.Errorf("failed to get conditions from unstructured object: %w", err)
3740
}
3841

39-
var errs error
42+
include := make(map[string]struct{}, len(includeTypes))
43+
for _, v := range includeTypes {
44+
include[v] = struct{}{}
45+
}
4046

47+
var errs error
4148
for _, c := range conditions {
49+
if len(include) > 0 {
50+
if _, ok := include[c.Type]; !ok {
51+
continue
52+
}
53+
}
4254
if c.Status == metav1.ConditionTrue {
4355
continue
4456
}

0 commit comments

Comments
 (0)