Skip to content

Commit

Permalink
Implement bundle endpointes backend + UT
Browse files Browse the repository at this point in the history
This commit also extend the MonitoredOperator model to include bundle associations.
Signed-off-by: Eran Cohen <[email protected]>
  • Loading branch information
eranco74 committed Jan 8, 2025
1 parent 24eb5b6 commit 31e1bce
Show file tree
Hide file tree
Showing 20 changed files with 237 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/operators/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"context"

"github.com/lib/pq"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/models"
)
Expand Down Expand Up @@ -55,6 +56,8 @@ type Operator interface {
GetPreflightRequirements(ctx context.Context, cluster *common.Cluster) (*models.OperatorHardwareRequirements, error)
// GetFeatureSupportID returns the operator unique feature-support ID
GetFeatureSupportID() models.FeatureSupportLevelID
// GetBundleLabels returns the bundles associated with the operator
GetBundleLabels() pq.StringArray
}

// Storage Operator provide a generic API for storage operators
Expand Down
15 changes: 15 additions & 0 deletions internal/operators/api/mock_operator_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions internal/operators/authorino/authorino_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"text/template"

"github.com/lib/pq"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/internal/operators/api"
"github.com/openshift/assisted-service/internal/templating"
Expand All @@ -17,6 +18,7 @@ var Operator = models.MonitoredOperator{
OperatorType: models.OperatorTypeOlm,
SubscriptionName: "authorino-operator",
TimeoutSeconds: 30 * 60,
Bundles: pq.StringArray{string(models.BundleOpenshiftai)},
}

// operator is an Authorino AI OLM operator plugin.
Expand Down Expand Up @@ -124,3 +126,8 @@ func (o *operator) GetPreflightRequirements(context context.Context,
func (o *operator) GetFeatureSupportID() models.FeatureSupportLevelID {
return models.FeatureSupportLevelIDAUTHORINO
}

// GetBundleLabels returns the bundle labels for the Authorino operator
func (o *operator) GetBundleLabels() pq.StringArray {
return Operator.Bundles
}
6 changes: 6 additions & 0 deletions internal/operators/cnv/cnv_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strings"

"github.com/lib/pq"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/internal/featuresupport"
"github.com/openshift/assisted-service/internal/hardware/virt"
Expand Down Expand Up @@ -37,6 +38,7 @@ var Operator = models.MonitoredOperator{
OperatorType: models.OperatorTypeOlm,
SubscriptionName: "hco-operatorhub",
TimeoutSeconds: 60 * 60,
Bundles: pq.StringArray{string(models.BundleVirtualization)},
}

// NewCNVOperator creates new instance of a Container Native Virtualization installation plugin
Expand Down Expand Up @@ -333,3 +335,7 @@ func validDiscoverableSNODisk(disks []*models.Disk, installationDiskID string, d
func (o *operator) GetFeatureSupportID() models.FeatureSupportLevelID {
return models.FeatureSupportLevelIDCNV
}

func (o *operator) GetBundleLabels() pq.StringArray {
return Operator.Bundles
}
17 changes: 17 additions & 0 deletions internal/operators/handler/handler_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/go-openapi/runtime/middleware"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/models"
logutil "github.com/openshift/assisted-service/pkg/log"
restoperators "github.com/openshift/assisted-service/restapi/operations/operators"
)
Expand Down Expand Up @@ -36,3 +37,19 @@ func (h *Handler) V2ListSupportedOperators(_ context.Context, _ restoperators.V2
return restoperators.NewV2ListSupportedOperatorsOK().
WithPayload(h.operatorsAPI.GetSupportedOperators())
}

// V2GetBundles Retrieves the list of supported bundles.
func (h *Handler) V2GetBundles(_ context.Context, _ restoperators.V2GetBundlesParams) middleware.Responder {
return restoperators.NewV2GetBundlesOK().WithPayload(h.operatorsAPI.GetBundles())
}

// V2GetBundleOperators Retrieves the list of operators for a specific bundle.
func (h *Handler) V2GetBundleOperators(ctx context.Context, params restoperators.V2GetBundleOperatorsParams) middleware.Responder {
log := logutil.FromContext(ctx, h.log)
operators, err := h.operatorsAPI.GetOperatorsByBundle(models.Bundle(params.BundleName))
if err != nil {
log.Errorf("Failed to get operators for bundle %s: %v", params.BundleName, err)
return common.GenerateErrorResponder(err)
}
return restoperators.NewV2GetBundleOperatorsOK().WithPayload(operators)
}
6 changes: 6 additions & 0 deletions internal/operators/lso/ls_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lso
import (
"context"

"github.com/lib/pq"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/internal/operators/api"
"github.com/openshift/assisted-service/models"
Expand Down Expand Up @@ -103,3 +104,8 @@ func (l *lsOperator) GetPreflightRequirements(context context.Context, cluster *
func (l *lsOperator) GetFeatureSupportID() models.FeatureSupportLevelID {
return models.FeatureSupportLevelIDLSO
}

// GetBundleLabels returns the bundle labels for the LSO operator
func (l *lsOperator) GetBundleLabels() pq.StringArray {
return Operator.Bundles
}
6 changes: 6 additions & 0 deletions internal/operators/lvm/lvm_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/go-openapi/swag"
"github.com/kelseyhightower/envconfig"
"github.com/lib/pq"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/internal/operators/api"
operatorscommon "github.com/openshift/assisted-service/internal/operators/common"
Expand Down Expand Up @@ -215,3 +216,8 @@ func (o *operator) GetPreflightRequirements(context context.Context, cluster *co
func (o *operator) GetFeatureSupportID() models.FeatureSupportLevelID {
return models.FeatureSupportLevelIDLVM
}

// GetBundleLabels returns the bundle labels for the LVM operator
func (o *operator) GetBundleLabels() pq.StringArray {
return Operator.Bundles
}
39 changes: 39 additions & 0 deletions internal/operators/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ type API interface {
GetPreflightRequirementsBreakdownForCluster(ctx context.Context, cluster *common.Cluster) ([]*models.OperatorHardwareRequirements, error)
// EnsureOperatorPrerequisite Ensure that for the given operators has the base prerequisite for installation
EnsureOperatorPrerequisite(cluster *common.Cluster, openshiftVersion string, cpuArchitecture string, operators []*models.MonitoredOperator) error
// GetBundles returns the list of available bundles
GetBundles() []models.Bundle
// GetOperatorsByBundle returns the operators associated with a specific bundle
GetOperatorsByBundle(bundleName models.Bundle) ([]string, error)
}

// GetPreflightRequirementsBreakdownForCluster provides host requirements breakdown for each supported OLM operator
Expand Down Expand Up @@ -514,3 +518,38 @@ func (mgr *Manager) EnsureOperatorPrerequisite(cluster *common.Cluster, openshif

return nil
}

// GetBundles returns a list of available bundles.
func (mgr *Manager) GetBundles() []models.Bundle {
return []models.Bundle{
models.BundleVirtualization,
models.BundleOpenshiftai,
}
}

// GetOperatorsByBundle returns the operators associated with a specific bundle
func (mgr *Manager) GetOperatorsByBundle(bundleName models.Bundle) ([]string, error) {
var operators []string
if !mgr.isBundleValid(bundleName) {
return operators, fmt.Errorf("bundle '%s' is not supported", bundleName)
}
for _, operator := range mgr.olmOperators {
for _, bundleStr := range operator.GetBundleLabels() {
bundle := models.Bundle(bundleStr)
if bundle == bundleName {
operators = append(operators, operator.GetName())
break
}
}
}
return operators, nil
}

func (mgr *Manager) isBundleValid(bundleName models.Bundle) bool {
for _, bundle := range mgr.GetBundles() {
if bundle == bundleName {
return true
}
}
return false
}
47 changes: 47 additions & 0 deletions internal/operators/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/openshift/assisted-service/internal/operators/lvm"
"github.com/openshift/assisted-service/internal/operators/mce"
"github.com/openshift/assisted-service/internal/operators/odf"
"github.com/openshift/assisted-service/internal/operators/openshiftai"
"github.com/openshift/assisted-service/internal/operators/serverless"
"github.com/openshift/assisted-service/models"
"github.com/openshift/assisted-service/pkg/conversions"
"github.com/openshift/assisted-service/pkg/s3wrapper"
Expand Down Expand Up @@ -796,6 +798,51 @@ var _ = Describe("Operators manager", func() {
Expect(err).To(BeEquivalentTo(theError))
})
})

Context("Bundles", func() {
// we use the real operators here, as we want to test the manager's ability to group them into bundles
var (
manager *operators.Manager
cnvOperator, odfOperator, oaiOperator, serverlessOperator, lsoOperator api.Operator
)
BeforeEach(func() {
cfg := cnv.Config{}
cnvOperator = cnv.NewCNVOperator(log, cfg)
// note that odf belongs to both Virtualization and Openshiftai bundles
odfOperator = odf.NewOdfOperator(log)
oaiOperator = openshiftai.NewOpenShiftAIOperator(log)
serverlessOperator = serverless.NewServerLessOperator(log)
// note that lso doesn't belongs to any bundle
lsoOperator = lso.NewLSOperator()

manager = operators.NewManagerWithOperators(log, manifestsAPI, operators.Options{}, nil, cnvOperator, odfOperator, oaiOperator, serverlessOperator, lsoOperator)
})

It("GetBundles should return the list of available bundles", func() {
bundles := manager.GetBundles()
Expect(bundles).To(ConsistOf(
models.BundleVirtualization,
models.BundleOpenshiftai,
))
})

It("GetOperatorsByBundle should return the operators associated with a specific bundle", func() {

operators, err := manager.GetOperatorsByBundle("invalid bundle")
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("bundle 'invalid bundle' is not supported"))
Expect(operators).To(HaveLen(0))
operators, err = manager.GetOperatorsByBundle(models.BundleVirtualization)
Expect(err).ToNot(HaveOccurred())
Expect(operators).To(HaveLen(3))
Expect(operators).To(ContainElements(cnvOperator.GetName(), odfOperator.GetName()))

operators, err = manager.GetOperatorsByBundle(models.BundleOpenshiftai)
Expect(err).ToNot(HaveOccurred())
Expect(operators).To(HaveLen(2))
Expect(operators).To(ContainElements(oaiOperator.GetName(), serverlessOperator.GetName(), odfOperator.GetName()))
})
})
})

func mockOperatorBase(operatorName string) *api.MockOperator {
Expand Down
7 changes: 7 additions & 0 deletions internal/operators/mce/mce_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/hashicorp/go-version"
"github.com/kelseyhightower/envconfig"
"github.com/lib/pq"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/internal/operators/api"
"github.com/openshift/assisted-service/models"
Expand Down Expand Up @@ -53,6 +54,7 @@ func (o *operator) GetName() string {
return Operator.Name
}

// GetFullName reports the full name of the Operator.
func (o *operator) GetFullName() string {
return "multicluster engine"
}
Expand Down Expand Up @@ -215,3 +217,8 @@ func GetMinDiskSizeGB(cluster *models.Cluster) int64 {
}
return lo.Max(lo.Values(storageSizeGi))
}

// GetBundleLabels returns the bundle labels for the MCE operator
func (o *operator) GetBundleLabels() pq.StringArray {
return Operator.Bundles
}
29 changes: 29 additions & 0 deletions internal/operators/mock_operators_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions internal/operators/mtv/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/kelseyhightower/envconfig"
"github.com/lib/pq"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/internal/featuresupport"
"github.com/openshift/assisted-service/internal/operators/api"
Expand All @@ -26,6 +27,7 @@ var Operator = models.MonitoredOperator{
OperatorType: models.OperatorTypeOlm,
SubscriptionName: Subscription,
TimeoutSeconds: 60 * 60,
Bundles: pq.StringArray{string(models.BundleVirtualization)},
}

func NewMTVOperator(log logrus.FieldLogger) *operator {
Expand Down Expand Up @@ -177,3 +179,8 @@ func (o *operator) GenerateManifests(cluster *common.Cluster) (map[string][]byte
func (o *operator) GetFeatureSupportID() models.FeatureSupportLevelID {
return models.FeatureSupportLevelIDMTV
}

// GetBundleLabels returns the bundle labels for the MTV operator
func (o *operator) GetBundleLabels() pq.StringArray {
return Operator.Bundles
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"text/template"

"github.com/kelseyhightower/envconfig"
"github.com/lib/pq"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/internal/operators/api"
"github.com/openshift/assisted-service/internal/templating"
Expand Down Expand Up @@ -137,3 +138,7 @@ func (o *operator) GetPreflightRequirements(context context.Context,
func (o *operator) GetFeatureSupportID() models.FeatureSupportLevelID {
return models.FeatureSupportLevelIDNODEFEATUREDISCOVERY
}

func (o *operator) GetBundleLabels() pq.StringArray {
return Operator.Bundles
}
5 changes: 5 additions & 0 deletions internal/operators/nvidiagpu/nvidia_gpu_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"text/template"

"github.com/kelseyhightower/envconfig"
"github.com/lib/pq"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/internal/operators/api"
"github.com/openshift/assisted-service/internal/operators/nodefeaturediscovery"
Expand Down Expand Up @@ -186,3 +187,7 @@ func (o *operator) GetPreflightRequirements(context context.Context,
func (o *operator) GetFeatureSupportID() models.FeatureSupportLevelID {
return models.FeatureSupportLevelIDNVIDIAGPU
}

func (o *operator) GetBundleLabels() pq.StringArray {
return Operator.Bundles
}
Loading

0 comments on commit 31e1bce

Please sign in to comment.