|
| 1 | +package helpers |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "time" |
| 7 | + |
| 8 | + //nolint:staticcheck // ST1001: dot-imports for readability |
| 9 | + . "github.com/onsi/gomega" |
| 10 | + |
| 11 | + "k8s.io/apimachinery/pkg/api/meta" |
| 12 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 13 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 14 | + |
| 15 | + olmv1 "github.com/operator-framework/operator-controller/api/v1" |
| 16 | + |
| 17 | + "github/operator-framework-operator-controller/openshift/tests-extension/pkg/env" |
| 18 | +) |
| 19 | + |
| 20 | +// NewClusterCatalog returns a new ClusterCatalog object. |
| 21 | +// It sets the image reference as source. |
| 22 | +func NewClusterCatalog(name, imageRef string) *olmv1.ClusterCatalog { |
| 23 | + return &olmv1.ClusterCatalog{ |
| 24 | + ObjectMeta: metav1.ObjectMeta{ |
| 25 | + Name: name, |
| 26 | + }, |
| 27 | + Spec: olmv1.ClusterCatalogSpec{ |
| 28 | + Source: olmv1.CatalogSource{ |
| 29 | + Type: olmv1.SourceTypeImage, |
| 30 | + Image: &olmv1.ImageSource{ |
| 31 | + Ref: imageRef, |
| 32 | + }, |
| 33 | + }, |
| 34 | + }, |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +// ExpectCatalogToBeServing checks that the catalog with the given name is installed |
| 39 | +func ExpectCatalogToBeServing(ctx context.Context, name string) { |
| 40 | + k8sClient := env.Get().K8sClient |
| 41 | + Eventually(func(g Gomega) { |
| 42 | + var catalog olmv1.ClusterCatalog |
| 43 | + err := k8sClient.Get(ctx, client.ObjectKey{Name: name}, &catalog) |
| 44 | + g.Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to get catalog %q", name)) |
| 45 | + |
| 46 | + conditions := catalog.Status.Conditions |
| 47 | + g.Expect(conditions).NotTo(BeEmpty(), fmt.Sprintf("catalog %q has empty status.conditions", name)) |
| 48 | + |
| 49 | + g.Expect(meta.IsStatusConditionPresentAndEqual(conditions, olmv1.TypeServing, metav1.ConditionTrue)). |
| 50 | + To(BeTrue(), fmt.Sprintf("catalog %q is not serving", name)) |
| 51 | + }).WithTimeout(5 * time.Minute).WithPolling(5 * time.Second).Should(Succeed()) |
| 52 | +} |
0 commit comments