Skip to content

Commit

Permalink
chore: move Release strcuts from pkg/cluster to apis/common (opendata…
Browse files Browse the repository at this point in the history
…hub-io#1580)

Structs that are part of the public APIs should be in the apis packages
for consistency and to avoid cyclic import issues
  • Loading branch information
lburgazzoli authored Jan 29, 2025
1 parent 90a78ea commit 1760dee
Show file tree
Hide file tree
Showing 37 changed files with 126 additions and 145 deletions.
10 changes: 10 additions & 0 deletions apis/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
operatorv1 "github.com/openshift/api/operator/v1"
"github.com/operator-framework/api/pkg/lib/version"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -82,3 +83,12 @@ type PlatformObject interface {
client.Object
WithStatus
}

type Platform string

// Release includes information on operator version and platform
// +kubebuilder:object:generate=true
type Release struct {
Name Platform `json:"name,omitempty"`
Version version.OperatorVersion `json:"version,omitempty"`
}
16 changes: 16 additions & 0 deletions apis/common/zz_generated.deepcopy.go

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

4 changes: 2 additions & 2 deletions apis/datasciencecluster/v1/datasciencecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ limitations under the License.
package v1

import (
"github.com/opendatahub-io/opendatahub-operator/v2/apis/common"
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
)

// DataScienceClusterSpec defines the desired state of the cluster.
Expand Down Expand Up @@ -134,7 +134,7 @@ type DataScienceClusterStatus struct {
Components ComponentsStatus `json:"components"`

// Version and release type
Release cluster.Release `json:"release,omitempty"`
Release common.Release `json:"release,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
4 changes: 2 additions & 2 deletions apis/dscinitialization/v1/dscinitialization_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ limitations under the License.
package v1

import (
"github.com/opendatahub-io/opendatahub-operator/v2/apis/common"
serviceApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/services/v1alpha1"
operatorv1 "github.com/openshift/api/operator/v1"
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
)

// +operator-sdk:csv:customresourcedefinitions:order=1
Expand Down Expand Up @@ -109,7 +109,7 @@ type DSCInitializationStatus struct {
ErrorMessage string `json:"errorMessage,omitempty"`

// Version and release type
Release cluster.Release `json:"release,omitempty"`
Release common.Release `json:"release,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
3 changes: 1 addition & 2 deletions controllers/components/codeflare/codeflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"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 Down Expand Up @@ -56,7 +55,7 @@ func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) common.Pla
}
}

func (s *componentHandler) Init(_ cluster.Platform) error {
func (s *componentHandler) Init(_ common.Platform) error {
if err := odhdeploy.ApplyParams(paramsPath, imageParamMap); err != nil {
return fmt.Errorf("failed to update images on path %s: %w", paramsPath, err)
}
Expand Down
3 changes: 1 addition & 2 deletions controllers/components/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"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 @@ -38,7 +37,7 @@ func (s *componentHandler) GetManagementState(dsc *dscv1.DataScienceCluster) ope
return operatorv1.Removed
}

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

if err := odhdeploy.ApplyParams(mi.String(), imagesMap); err != nil {
Expand Down
13 changes: 7 additions & 6 deletions controllers/components/dashboard/dashboard_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/opendatahub-io/opendatahub-operator/v2/apis/common"
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
Expand All @@ -29,28 +30,28 @@ const (
)

var (
adminGroups = map[cluster.Platform]string{
adminGroups = map[common.Platform]string{
cluster.SelfManagedRhoai: "rhods-admins",
cluster.ManagedRhoai: "dedicated-admins",
cluster.OpenDataHub: "odh-admins",
cluster.Unknown: "odh-admins",
}

sectionTitle = map[cluster.Platform]string{
sectionTitle = map[common.Platform]string{
cluster.SelfManagedRhoai: "OpenShift Self Managed Services",
cluster.ManagedRhoai: "OpenShift Managed Services",
cluster.OpenDataHub: "OpenShift Open Data Hub",
cluster.Unknown: "OpenShift Open Data Hub",
}

baseConsoleURL = map[cluster.Platform]string{
baseConsoleURL = map[common.Platform]string{
cluster.SelfManagedRhoai: "https://rhods-dashboard-",
cluster.ManagedRhoai: "https://rhods-dashboard-",
cluster.OpenDataHub: "https://odh-dashboard-",
cluster.Unknown: "https://odh-dashboard-",
}

overlaysSourcePaths = map[cluster.Platform]string{
overlaysSourcePaths = map[common.Platform]string{
cluster.SelfManagedRhoai: "/rhoai/onprem",
cluster.ManagedRhoai: "/rhoai/addon",
cluster.OpenDataHub: "/odh",
Expand All @@ -62,15 +63,15 @@ var (
}
)

func defaultManifestInfo(p cluster.Platform) odhtypes.ManifestInfo {
func defaultManifestInfo(p common.Platform) odhtypes.ManifestInfo {
return odhtypes.ManifestInfo{
Path: odhdeploy.DefaultManifestPath,
ContextDir: ComponentName,
SourcePath: overlaysSourcePaths[p],
}
}

func computeKustomizeVariable(ctx context.Context, cli client.Client, platform cluster.Platform, dscispec *dsciv1.DSCInitializationSpec) (map[string]string, error) {
func computeKustomizeVariable(ctx context.Context, cli client.Client, platform common.Platform, dscispec *dsciv1.DSCInitializationSpec) (map[string]string, error) {
consoleLinkDomain, err := cluster.GetDomain(ctx, cli)
if err != nil {
return nil, fmt.Errorf("error getting console route URL %s : %w", consoleLinkDomain, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
cr "github.com/opendatahub-io/opendatahub-operator/v2/pkg/componentsregistry"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/annotations"
Expand All @@ -38,7 +37,7 @@ func (s *componentHandler) GetManagementState(dsc *dscv1.DataScienceCluster) ope
return operatorv1.Removed
}

func (s *componentHandler) Init(_ cluster.Platform) error {
func (s *componentHandler) Init(_ common.Platform) error {
if err := deploy.ApplyParams(paramsPath().String(), imageParamMap); err != nil {
return fmt.Errorf("failed to update images on path %s: %w", paramsPath(), err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package datasciencepipelines
import (
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"

"github.com/opendatahub-io/opendatahub-operator/v2/apis/common"
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
Expand Down Expand Up @@ -35,7 +36,7 @@ var (
"IMAGES_MLMDGRPC": "RELATED_IMAGE_ODH_MLMD_GRPC_SERVER_IMAGE",
}

overlaysSourcePaths = map[cluster.Platform]string{
overlaysSourcePaths = map[common.Platform]string{
cluster.SelfManagedRhoai: "overlays/rhoai",
cluster.ManagedRhoai: "overlays/rhoai",
cluster.OpenDataHub: "overlays/odh",
Expand All @@ -51,7 +52,7 @@ func paramsPath() types.ManifestInfo {
}
}

func manifestPath(p cluster.Platform) types.ManifestInfo {
func manifestPath(p common.Platform) types.ManifestInfo {
return types.ManifestInfo{
Path: odhdeploy.DefaultManifestPath,
ContextDir: ComponentName,
Expand Down
3 changes: 1 addition & 2 deletions controllers/components/kserve/kserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
cr "github.com/opendatahub-io/opendatahub-operator/v2/pkg/componentsregistry"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/annotations"
)
Expand All @@ -42,7 +41,7 @@ func init() { //nolint:gochecknoinits
}

// Init for set images.
func (s *componentHandler) Init(platform cluster.Platform) error {
func (s *componentHandler) Init(platform common.Platform) error {
return nil
}

Expand Down
3 changes: 1 addition & 2 deletions controllers/components/kueue/kueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"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 Down Expand Up @@ -56,7 +55,7 @@ func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) common.Pla
}
}

func (s *componentHandler) Init(platform cluster.Platform) error {
func (s *componentHandler) Init(platform common.Platform) error {
if err := odhdeploy.ApplyParams(manifestsPath().String(), imageParamMap); err != nil {
return fmt.Errorf("failed to update images on path %s: %w", manifestsPath(), err)
}
Expand Down
3 changes: 1 addition & 2 deletions controllers/components/modelcontroller/modelcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"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 Down Expand Up @@ -76,7 +75,7 @@ func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) common.Pla
}

// Init for set images.
func (s *componentHandler) Init(_ cluster.Platform) error {
func (s *componentHandler) Init(_ common.Platform) error {
// Update image parameters
if err := odhdeploy.ApplyParams(manifestsPath().String(), imageParamMap); err != nil {
return fmt.Errorf("failed to update images on path %s: %w", manifestsPath(), err)
Expand Down
3 changes: 1 addition & 2 deletions controllers/components/modelmeshserving/modelmeshserving.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"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 @@ -38,7 +37,7 @@ func (s *componentHandler) GetManagementState(dsc *dscv1.DataScienceCluster) ope
return operatorv1.Removed
}

func (s *componentHandler) Init(_ cluster.Platform) error {
func (s *componentHandler) Init(_ common.Platform) error {
// Update image parameters
if err := odhdeploy.ApplyParams(manifestsPath().String(), imageParamMap); err != nil {
return fmt.Errorf("failed to update images on path %s: %w", manifestsPath(), err)
Expand Down
3 changes: 1 addition & 2 deletions controllers/components/modelregistry/modelregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"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 @@ -38,7 +37,7 @@ func (s *componentHandler) GetManagementState(dsc *dscv1.DataScienceCluster) ope
return operatorv1.Removed
}

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

if err := odhdeploy.ApplyParams(mi.String(), imagesMap, extraParamsMap); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions controllers/components/ray/ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"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 Down Expand Up @@ -56,7 +55,7 @@ func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) common.Pla
}
}

func (s *componentHandler) Init(_ cluster.Platform) error {
func (s *componentHandler) Init(_ common.Platform) error {
if err := odhdeploy.ApplyParams(manifestPath().String(), imageParamMap); err != nil {
return fmt.Errorf("failed to update images on path %s: %w", manifestPath(), err)
}
Expand Down
3 changes: 1 addition & 2 deletions controllers/components/trainingoperator/trainingoperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"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 Down Expand Up @@ -55,7 +54,7 @@ func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) common.Pla
}
}

func (s *componentHandler) Init(platform cluster.Platform) error {
func (s *componentHandler) Init(platform common.Platform) error {
if err := odhdeploy.ApplyParams(manifestPath().String(), imageParamMap); err != nil {
return fmt.Errorf("failed to update images on path %s: %w", manifestPath(), err)
}
Expand Down
3 changes: 1 addition & 2 deletions controllers/components/trustyai/trustyai.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"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 Down Expand Up @@ -56,7 +55,7 @@ func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) common.Pla
}
}

func (s *componentHandler) Init(platform cluster.Platform) error {
func (s *componentHandler) Init(platform common.Platform) error {
mp := manifestsPath(platform)

if err := odhdeploy.ApplyParams(mp.String(), imageParamMap); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions controllers/components/trustyai/trustyai_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package trustyai
import (
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"

"github.com/opendatahub-io/opendatahub-operator/v2/apis/common"
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
Expand All @@ -27,15 +28,15 @@ var (
"trustyaiOperatorImage": "RELATED_IMAGE_ODH_TRUSTYAI_SERVICE_OPERATOR_IMAGE",
}

overlaysSourcePaths = map[cluster.Platform]string{
overlaysSourcePaths = map[common.Platform]string{
cluster.SelfManagedRhoai: "/overlays/rhoai",
cluster.ManagedRhoai: "/overlays/rhoai",
cluster.OpenDataHub: "/overlays/odh",
cluster.Unknown: "/overlays/odh",
}
)

func manifestsPath(p cluster.Platform) types.ManifestInfo {
func manifestsPath(p common.Platform) types.ManifestInfo {
return types.ManifestInfo{
Path: odhdeploy.DefaultManifestPath,
ContextDir: ComponentName,
Expand Down
Loading

0 comments on commit 1760dee

Please sign in to comment.