diff --git a/main.go b/main.go index 7f9a0b438c9..9984e1471b0 100644 --- a/main.go +++ b/main.go @@ -144,11 +144,12 @@ func main() { //nolint:funlen,maintidx os.Exit(1) } // Get operator platform - platform, err := cluster.GetPlatform(ctx, setupClient) + release, err := cluster.GetRelease(ctx, setupClient) if err != nil { - setupLog.Error(err, "error getting platform") + setupLog.Error(err, "error getting release") os.Exit(1) } + platform := release.Name setupLog.Info("running on", "platform", platform) secretCache := createSecretCacheConfig(platform) diff --git a/pkg/cluster/cluster_config.go b/pkg/cluster/cluster_config.go index a1c462aeeee..402c9f28934 100644 --- a/pkg/cluster/cluster_config.go +++ b/pkg/cluster/cluster_config.go @@ -114,7 +114,7 @@ func detectManagedRHODS(ctx context.Context, cli client.Client) (Platform, error return ManagedRhods, nil } -func GetPlatform(ctx context.Context, cli client.Client) (Platform, error) { +func getPlatform(ctx context.Context, cli client.Client) (Platform, error) { // First check if its addon installation to return 'ManagedRhods, nil' if platform, err := detectManagedRHODS(ctx, cli); err != nil { return Unknown, err @@ -141,7 +141,7 @@ func GetRelease(ctx context.Context, cli client.Client) (Release, error) { }, } // Set platform - platform, err := GetPlatform(ctx, cli) + platform, err := getPlatform(ctx, cli) if err != nil { return initRelease, err } diff --git a/pkg/cluster/cluster_operations_int_test.go b/pkg/cluster/cluster_operations_int_test.go index cd3af3f68a3..52a83780c6f 100644 --- a/pkg/cluster/cluster_operations_int_test.go +++ b/pkg/cluster/cluster_operations_int_test.go @@ -4,8 +4,6 @@ import ( "context" "time" - ofapiv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" - ofapiv2 "github.com/operator-framework/api/pkg/operators/v2" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ctrlruntime "sigs.k8s.io/controller-runtime/pkg/client" @@ -94,89 +92,6 @@ var _ = Describe("Creating cluster resources", func() { }) - Context("Platform detection", func() { - var objectCleaner *envtestutil.Cleaner - operatorNS := "redhat-ods-operator" - - BeforeEach(func(ctx context.Context) { - objectCleaner = envtestutil.CreateCleaner(envTestClient, envTest.Config, timeout, interval) - }) - - It("should run as unknown", func(ctx context.Context) { - // given nothing - // when - platform, err := cluster.GetPlatform(ctx, envTestClient) - Expect(err).ToNot(HaveOccurred()) - - // then - Expect(platform).To(Equal(cluster.Unknown)) - - }) - - It("should run as managed platform", func(ctx context.Context) { - // give catalogsource exists in operator namespace - _, errNs := cluster.CreateNamespace(ctx, envTestClient, operatorNS) - Expect(errNs).ToNot(HaveOccurred()) - - catalogSource := &ofapiv1alpha1.CatalogSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "addon-managed-odh-catalog", - Namespace: operatorNS, - }, - } - Expect(envTestClient.Create(ctx, catalogSource)).To(Succeed()) - - // when - platform, err := cluster.GetPlatform(ctx, envTestClient) - Expect(err).ToNot(HaveOccurred()) - defer objectCleaner.DeleteAll(ctx, catalogSource) - - // then - Expect(platform).To(Equal(cluster.ManagedRhods)) - - }) - - It("should run as self-managed platform", func(ctx context.Context) { - // given rhoai operatorcondition exist - operatorCondition := &ofapiv2.OperatorCondition{ - ObjectMeta: metav1.ObjectMeta{ - Name: "rhods-operator-something", - Namespace: operatorNS, - }, - } - Expect(envTestClient.Create(ctx, operatorCondition)).To(Succeed()) - - // when - platform, err := cluster.GetPlatform(ctx, envTestClient) - Expect(err).ToNot(HaveOccurred()) - defer objectCleaner.DeleteAll(ctx, operatorCondition) - - // then - Expect(platform).To(Equal(cluster.SelfManagedRhods)) - - }) - - It("should run as ODH platform", func(ctx context.Context) { - // given odh operatorcondition exist - operatorCondition := &ofapiv2.OperatorCondition{ - ObjectMeta: metav1.ObjectMeta{ - Name: "opendatahub-operator-something", - Namespace: operatorNS, - }, - } - Expect(envTestClient.Create(ctx, operatorCondition)).To(Succeed()) - - // when - platform, err := cluster.GetPlatform(ctx, envTestClient) - Expect(err).ToNot(HaveOccurred()) - defer objectCleaner.DeleteAll(ctx, operatorCondition) - - // then - Expect(platform).To(Equal(cluster.OpenDataHub)) - - }) - }) - Context("config map manipulation", func() { var ( diff --git a/pkg/cluster/cluster_operations_suite_int_test.go b/pkg/cluster/cluster_operations_suite_int_test.go index 30cbed65312..16ad6324f7d 100644 --- a/pkg/cluster/cluster_operations_suite_int_test.go +++ b/pkg/cluster/cluster_operations_suite_int_test.go @@ -1,11 +1,8 @@ package cluster_test import ( - "path/filepath" "testing" - ofapiv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" - ofapiv2 "github.com/operator-framework/api/pkg/operators/v2" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" @@ -37,19 +34,8 @@ var _ = BeforeSuite(func() { By("Bootstrapping k8s test environment") utilruntime.Must(corev1.AddToScheme(testScheme)) - utilruntime.Must(ofapiv1alpha1.AddToScheme(testScheme)) - utilruntime.Must(ofapiv2.AddToScheme(testScheme)) - envTest = &envtest.Environment{ - CRDInstallOptions: envtest.CRDInstallOptions{ - Scheme: testScheme, - Paths: []string{ - filepath.Join("..", "..", "config", "crd", "external"), - }, - ErrorIfPathMissing: true, - CleanUpAfterUse: false, - }, - } + envTest = &envtest.Environment{} config, err := envTest.Start() Expect(err).NotTo(HaveOccurred())