Skip to content

Commit

Permalink
cluster: remove GetPlatform api (#1256)
Browse files Browse the repository at this point in the history
There is no need to maintain the api since GetRelease performs the
call and returns the information.

The extra work GetRelease does (in addition to GetPlatform) is not
important since only one call in startup left.

Since the api removed, tests do not make sense, so revert testing
part of d73b3da ("refactor: get platform calls (#1251)")

Signed-off-by: Yauheni Kaliuta <[email protected]>
  • Loading branch information
ykaliuta authored Sep 23, 2024
1 parent 8d3a6c2 commit d6eda01
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 104 deletions.
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
85 changes: 0 additions & 85 deletions pkg/cluster/cluster_operations_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 (
Expand Down
16 changes: 1 addition & 15 deletions pkg/cluster/cluster_operations_suite_int_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit d6eda01

Please sign in to comment.