/
tenant_conditions.go
41 lines (36 loc) · 1.18 KB
/
tenant_conditions.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
package framework
import (
"context"
"fmt"
api "github.com/SAP/stewardci-core/pkg/apis/steward/v1alpha1"
"github.com/SAP/stewardci-core/pkg/k8s"
corev1 "k8s.io/api/core/v1"
knativeapis "knative.dev/pkg/apis"
)
// TenantCheck is a Check for a tenant
type TenantCheck func(*api.Tenant) bool
// CreateTenantCondition creates a WaitCondition for a tenant with a dedicated Check
func CreateTenantCondition(tenant *api.Tenant, Check TenantCheck) WaitConditionFunc {
key := fmt.Sprintf("%s/%s", tenant.GetNamespace(), tenant.GetName())
return func(ctx context.Context) (bool, error) {
fetcher := k8s.NewClientBasedTenantFetcher(GetClientFactory(ctx))
tenant, err := fetcher.ByKey(ctx, key)
if err != nil {
return true, err
}
if tenant == nil {
return true, fmt.Errorf("tenant not found %q", key)
}
return Check(tenant), nil
}
}
// TenantIsReady creates a TenantCheck which Checks if tenant has readyCondition wiht status true
func TenantIsReady() TenantCheck {
return func(tenant *api.Tenant) bool {
readyCondition := tenant.Status.GetCondition(knativeapis.ConditionReady)
if readyCondition == nil {
return false
}
return readyCondition.Status == corev1.ConditionTrue
}
}