Files
open-cluster-management/test/integration/util/assertion.go
Jian Qiu 61c96873b3 Refactor on connecton check in klusterlet (#202)
1. Update observerved generation
2. Code update to clear the logic

Signed-off-by: Jian Qiu <jqiu@redhat.com>
2022-02-14 02:50:36 -05:00

52 lines
1.8 KiB
Go

package util
import (
"context"
"fmt"
"github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
operatorclientset "open-cluster-management.io/api/client/operator/clientset/versioned"
)
const (
eventuallyTimeout = 60 // seconds
eventuallyInterval = 1 // seconds
)
func AssertKlusterletCondition(
name string, operatorClient operatorclientset.Interface, expectedType, expectedReason string, expectedWorkStatus metav1.ConditionStatus) {
gomega.Eventually(func() error {
klusterlet, err := operatorClient.OperatorV1().Klusterlets().Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
return err
}
// check work status condition
if !HasCondition(klusterlet.Status.Conditions, expectedType, expectedReason, expectedWorkStatus) {
return fmt.Errorf("expect have type %s with reason %s and status %s, but got %v",
expectedType, expectedReason, expectedWorkStatus, klusterlet.Status.Conditions)
}
return nil
}, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred())
}
func AssertClusterManagerCondition(
name string, operatorClient operatorclientset.Interface, expectedType, expectedReason string, expectedWorkStatus metav1.ConditionStatus) {
gomega.Eventually(func() error {
clusterManager, err := operatorClient.OperatorV1().ClusterManagers().Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
return err
}
// check work status condition
if !HasCondition(clusterManager.Status.Conditions, expectedType, expectedReason, expectedWorkStatus) {
return fmt.Errorf("expect have type %s with reason %s and status %s, but got %v",
expectedType, expectedReason, expectedWorkStatus, clusterManager.Status.Conditions)
}
return nil
}, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred())
}