Skip to content

Commit

Permalink
fold component handling with an interface
Browse files Browse the repository at this point in the history
Signed-off-by: Yauheni Kaliuta <[email protected]>
  • Loading branch information
ykaliuta committed Nov 18, 2024
1 parent acd89b8 commit 653095e
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 121 deletions.
24 changes: 20 additions & 4 deletions controllers/components/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,31 @@ import (

operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

componentsv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
cr "github.com/opendatahub-io/opendatahub-operator/v2/pkg/componentsregistry"
odhdeploy "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/annotations"
)

func Init(platform cluster.Platform) error {
type dashboardComponentHandler struct{}

func init() {
cr.Add(&dashboardComponentHandler{})
}

func (s *dashboardComponentHandler) GetName() string {
return componentsv1.DashboardComponentName
}

func (s *dashboardComponentHandler) GetManagementState(dsc *dscv1.DataScienceCluster) operatorv1.ManagementState {
return dsc.Spec.Components.Dashboard.ManagementState
}

func (s *dashboardComponentHandler) Init(platform cluster.Platform) error {
mi := defaultManifestInfo(platform)

if err := odhdeploy.ApplyParams(mi.String(), imagesMap); err != nil {
Expand All @@ -23,7 +39,7 @@ func Init(platform cluster.Platform) error {
return nil
}

func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.Dashboard {
func (s *dashboardComponentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Object {
dashboardAnnotations := make(map[string]string)

switch dsc.Spec.Components.Dashboard.ManagementState {
Expand All @@ -33,7 +49,7 @@ func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.Dashboard {
dashboardAnnotations[annotations.ManagementStateAnnotation] = "Unknown"
}

return &componentsv1.Dashboard{
return client.Object(&componentsv1.Dashboard{
TypeMeta: metav1.TypeMeta{
Kind: componentsv1.DashboardKind,
APIVersion: componentsv1.GroupVersion.String(),
Expand All @@ -45,5 +61,5 @@ func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.Dashboard {
Spec: componentsv1.DashboardSpec{
DashboardCommonSpec: dsc.Spec.Components.Dashboard.DashboardCommonSpec,
},
}
})
}
26 changes: 20 additions & 6 deletions controllers/components/kueue/kueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (

operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

componentsv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
cr "github.com/opendatahub-io/opendatahub-operator/v2/pkg/componentsregistry"
odhdeploy "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/annotations"
)
Expand All @@ -21,8 +23,21 @@ var (
DefaultPath = odhdeploy.DefaultManifestPath + "/" + ComponentName + "/rhoai" // same path for both odh and rhoai
)

// for DSC to get compoment Kueue's CR.
func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.Kueue {
type componentHandler struct{}

func init() {

Check failure on line 28 in controllers/components/kueue/kueue.go

View workflow job for this annotation

GitHub Actions / golangci-lint

don't use `init` function (gochecknoinits)
cr.Add(&componentHandler{})
}

func (s *componentHandler) GetName() string {
return componentsv1.KueueComponentName
}

func (s *componentHandler) GetManagementState(dsc *dscv1.DataScienceCluster) operatorv1.ManagementState {
return dsc.Spec.Components.Kueue.ManagementState
}

func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Object {

Check failure on line 40 in controllers/components/kueue/kueue.go

View workflow job for this annotation

GitHub Actions / golangci-lint

NewCRObject returns interface (sigs.k8s.io/controller-runtime/pkg/client.Object) (ireturn)
kueueAnnotations := make(map[string]string)
switch dsc.Spec.Components.Kueue.ManagementState {
case operatorv1.Managed, operatorv1.Removed:
Expand All @@ -31,7 +46,7 @@ func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.Kueue {
kueueAnnotations[annotations.ManagementStateAnnotation] = "Unknown"
}

return &componentsv1.Kueue{
return client.Object(&componentsv1.Kueue{
TypeMeta: metav1.TypeMeta{
Kind: componentsv1.KueueKind,
APIVersion: componentsv1.GroupVersion.String(),
Expand All @@ -43,11 +58,10 @@ func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.Kueue {
Spec: componentsv1.KueueSpec{
KueueCommonSpec: dsc.Spec.Components.Kueue.KueueCommonSpec,
},
}
})
}

// Init for set images.
func Init(platform cluster.Platform) error {
func (s *componentHandler) Init(platform cluster.Platform) error {
imageParamMap := map[string]string{
"odh-kueue-controller-image": "RELATED_IMAGE_ODH_KUEUE_CONTROLLER_IMAGE",
}
Expand Down
24 changes: 20 additions & 4 deletions controllers/components/modelregistry/modelregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,31 @@ import (

operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

componentsv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
cr "github.com/opendatahub-io/opendatahub-operator/v2/pkg/componentsregistry"
odhdeploy "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/annotations"
)

func Init(_ cluster.Platform) error {
type componentHandler struct{}

func init() {
cr.Add(&componentHandler{})
}

func (s *componentHandler) GetName() string {
return componentsv1.ModelRegistryComponentName
}

func (s *componentHandler) GetManagementState(dsc *dscv1.DataScienceCluster) operatorv1.ManagementState {
return dsc.Spec.Components.ModelRegistry.ManagementState
}

func (s *componentHandler) Init(_ cluster.Platform) error {
mi := baseManifestInfo(BaseManifestsSourcePath)

params := make(map[string]string)
Expand All @@ -31,7 +47,7 @@ func Init(_ cluster.Platform) error {
return nil
}

func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.ModelRegistry {
func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Object {
componentAnnotations := make(map[string]string)

switch dsc.Spec.Components.ModelRegistry.ManagementState {
Expand All @@ -42,7 +58,7 @@ func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.ModelRegistry {
componentAnnotations[annotations.ManagementStateAnnotation] = "Unknown"
}

return &componentsv1.ModelRegistry{
return client.Object(&componentsv1.ModelRegistry{
TypeMeta: metav1.TypeMeta{
Kind: componentsv1.ModelRegistryKind,
APIVersion: componentsv1.GroupVersion.String(),
Expand All @@ -54,5 +70,5 @@ func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.ModelRegistry {
Spec: componentsv1.ModelRegistrySpec{
ModelRegistryCommonSpec: dsc.Spec.Components.ModelRegistry.ModelRegistryCommonSpec,
},
}
})
}
26 changes: 20 additions & 6 deletions controllers/components/ray/ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (

operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

componentsv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
cr "github.com/opendatahub-io/opendatahub-operator/v2/pkg/componentsregistry"
odhdeploy "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/annotations"
)
Expand All @@ -21,8 +23,21 @@ var (
DefaultPath = odhdeploy.DefaultManifestPath + "/" + ComponentName + "/openshift"
)

// for DSC to get compoment Ray's CR.
func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.Ray {
type componentHandler struct{}

func init() {

Check failure on line 28 in controllers/components/ray/ray.go

View workflow job for this annotation

GitHub Actions / golangci-lint

don't use `init` function (gochecknoinits)
cr.Add(&componentHandler{})
}

func (s *componentHandler) GetName() string {
return componentsv1.ModelRegistryComponentName
}

func (s *componentHandler) GetManagementState(dsc *dscv1.DataScienceCluster) operatorv1.ManagementState {
return dsc.Spec.Components.ModelRegistry.ManagementState
}

func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Object {

Check failure on line 40 in controllers/components/ray/ray.go

View workflow job for this annotation

GitHub Actions / golangci-lint

NewCRObject returns interface (sigs.k8s.io/controller-runtime/pkg/client.Object) (ireturn)
rayAnnotations := make(map[string]string)
switch dsc.Spec.Components.Ray.ManagementState {
case operatorv1.Managed, operatorv1.Removed:
Expand All @@ -31,7 +46,7 @@ func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.Ray {
rayAnnotations[annotations.ManagementStateAnnotation] = "Unknown"
}

return &componentsv1.Ray{
return client.Object(&componentsv1.Ray{
TypeMeta: metav1.TypeMeta{
Kind: componentsv1.RayKind,
APIVersion: componentsv1.GroupVersion.String(),
Expand All @@ -43,11 +58,10 @@ func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.Ray {
Spec: componentsv1.RaySpec{
RayCommonSpec: dsc.Spec.Components.Ray.RayCommonSpec,
},
}
})
}

// Init for set images.
func Init(platform cluster.Platform) error {
func (s *componentHandler) Init(platform cluster.Platform) error {
imageParamMap := map[string]string{
"odh-kuberay-operator-controller-image": "RELATED_IMAGE_ODH_KUBERAY_OPERATOR_CONTROLLER_IMAGE",
}
Expand Down
26 changes: 20 additions & 6 deletions controllers/components/trainingoperator/trainingoperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (

operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"

componentsv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
cr "github.com/opendatahub-io/opendatahub-operator/v2/pkg/componentsregistry"
odhdeploy "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/annotations"
)
Expand All @@ -21,8 +23,21 @@ var (
DefaultPath = odhdeploy.DefaultManifestPath + "/" + ComponentName + "/rhoai"
)

// for DSC to get compoment TrainingOperator's CR.
func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.TrainingOperator {
type componentHandler struct{}

func init() {
cr.Add(&componentHandler{})
}

func (s *componentHandler) GetName() string {
return componentsv1.ModelRegistryComponentName
}

func (s *componentHandler) GetManagementState(dsc *dscv1.DataScienceCluster) operatorv1.ManagementState {
return dsc.Spec.Components.ModelRegistry.ManagementState
}

func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) k8sclient.Object {
trainingoperatorAnnotations := make(map[string]string)
switch dsc.Spec.Components.TrainingOperator.ManagementState {
case operatorv1.Managed, operatorv1.Removed:
Expand All @@ -31,7 +46,7 @@ func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.TrainingOperato
trainingoperatorAnnotations[annotations.ManagementStateAnnotation] = "Unknown"
}

return &componentsv1.TrainingOperator{
return k8sclient.Object(&componentsv1.TrainingOperator{
TypeMeta: metav1.TypeMeta{
Kind: componentsv1.TrainingOperatorKind,
APIVersion: componentsv1.GroupVersion.String(),
Expand All @@ -43,11 +58,10 @@ func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.TrainingOperato
Spec: componentsv1.TrainingOperatorSpec{
TrainingOperatorCommonSpec: dsc.Spec.Components.TrainingOperator.TrainingOperatorCommonSpec,
},
}
})
}

// Init for set images.
func Init(platform cluster.Platform) error {
func (s *componentHandler) Init(platform cluster.Platform) error {
imageParamMap := map[string]string{
"odh-training-operator-controller-image": "RELATED_IMAGE_ODH_TRAINING_OPERATOR_IMAGE",
}
Expand Down
26 changes: 20 additions & 6 deletions controllers/components/trustyai/trustyai.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (

operatorv1 "github.com/openshift/api/operator/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

componentsv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
cr "github.com/opendatahub-io/opendatahub-operator/v2/pkg/componentsregistry"
odhdeploy "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/annotations"
)
Expand All @@ -27,8 +29,21 @@ var (
}
)

// for DSC to get compoment TrustyAI's CR.
func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.TrustyAI {
type componentHandler struct{}

func init() {

Check failure on line 34 in controllers/components/trustyai/trustyai.go

View workflow job for this annotation

GitHub Actions / golangci-lint

don't use `init` function (gochecknoinits)
cr.Add(&componentHandler{})
}

func (s *componentHandler) GetName() string {
return componentsv1.ModelRegistryComponentName
}

func (s *componentHandler) GetManagementState(dsc *dscv1.DataScienceCluster) operatorv1.ManagementState {
return dsc.Spec.Components.ModelRegistry.ManagementState
}

func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Object {

Check failure on line 46 in controllers/components/trustyai/trustyai.go

View workflow job for this annotation

GitHub Actions / golangci-lint

NewCRObject returns interface (sigs.k8s.io/controller-runtime/pkg/client.Object) (ireturn)
trustyaiAnnotations := make(map[string]string)
switch dsc.Spec.Components.TrustyAI.ManagementState {
case operatorv1.Managed, operatorv1.Removed:
Expand All @@ -37,7 +52,7 @@ func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.TrustyAI {
trustyaiAnnotations[annotations.ManagementStateAnnotation] = "Unknown"
}

return &componentsv1.TrustyAI{
return client.Object(&componentsv1.TrustyAI{
TypeMeta: metav1.TypeMeta{
Kind: componentsv1.TrustyAIKind,
APIVersion: componentsv1.GroupVersion.String(),
Expand All @@ -49,11 +64,10 @@ func GetComponentCR(dsc *dscv1.DataScienceCluster) *componentsv1.TrustyAI {
Spec: componentsv1.TrustyAISpec{
TrustyAICommonSpec: dsc.Spec.Components.TrustyAI.TrustyAICommonSpec,
},
}
})
}

// Init for set images.
func Init(platform cluster.Platform) error {
func (s *componentHandler) Init(platform cluster.Platform) error {
imageParamMap := map[string]string{
"trustyaiServiceImage": "RELATED_IMAGE_ODH_TRUSTYAI_SERVICE_IMAGE",
"trustyaiOperatorImage": "RELATED_IMAGE_ODH_TRUSTYAI_SERVICE_OPERATOR_IMAGE",
Expand Down
Loading

0 comments on commit 653095e

Please sign in to comment.