Skip to content

Commit

Permalink
chore: cleanup duplicated functions packages and add more for godoc (o…
Browse files Browse the repository at this point in the history
…pendatahub-io#981)

* chore: cleanup duplicated functions/package and add godoc

- move GetPlatform() from deploy package to cluster package
- move const ManagedRhods SelfManagedRhods OpenDataHub from deploy to cluster package
- move WaitForDeploymentAvailable() monitoring package to cluster package
- remove monitoring package
- move UpdatePodSecurityRolebinding() from common package to cluster package
- deprecate GetDomain from common package, to only use GetDomain from cluster package.
- remove gvk package, move its GVK to cluster package
- move DeleteExistingSubscription() from deploy package to upgrade package
- do not export getSubscription()

Signed-off-by: Wen Zhou <[email protected]>

* update: remove gvk into one file but under cluster package

Signed-off-by: Wen Zhou <[email protected]>

* update: rename variable, removing GVK from it

Signed-off-by: Wen Zhou <[email protected]>

* update: move gvk into a sub package under cluster

Signed-off-by: Wen Zhou <[email protected]>

---------

Signed-off-by: Wen Zhou <[email protected]>
  • Loading branch information
zdtsw committed May 9, 2024
1 parent 8f4ea15 commit 8267869
Show file tree
Hide file tree
Showing 32 changed files with 305 additions and 286 deletions.
2 changes: 1 addition & 1 deletion apis/features/v1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
// +kubebuilder:object:generate=true
// +groupName=features.opendatahub.io

// Package v1 contains API Schema definitions for the datasciencecluster v1 API group
// Package v1 contains API Schema definitions for the feature v1 API group
package v1

import (
Expand Down
10 changes: 5 additions & 5 deletions components/codeflare/codeflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/monitoring"
)

var (
Expand Down Expand Up @@ -67,7 +67,7 @@ func (c *CodeFlare) ReconcileComponent(ctx context.Context, cli client.Client, l

enabled := c.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
platform, err := deploy.GetPlatform(cli)
platform, err := cluster.GetPlatform(cli)
if err != nil {
return err
}
Expand All @@ -81,7 +81,7 @@ func (c *CodeFlare) ReconcileComponent(ctx context.Context, cli client.Client, l
// check if the CodeFlare operator is installed: it should not be installed
dependentOperator := CodeflareOperator
// overwrite dependent operator if downstream not match upstream
if platform == deploy.SelfManagedRhods || platform == deploy.ManagedRhods {
if platform == cluster.SelfManagedRhods || platform == cluster.ManagedRhods {
dependentOperator = RHCodeflareOperator
}

Expand Down Expand Up @@ -109,10 +109,10 @@ func (c *CodeFlare) ReconcileComponent(ctx context.Context, cli client.Client, l
}
l.Info("apply manifests done")
// CloudServiceMonitoring handling
if platform == deploy.ManagedRhods {
if platform == cluster.ManagedRhods {
if enabled {
// first check if the service is up, so prometheus won't fire alerts when it is just startup
if err := monitoring.WaitForDeploymentAvailable(ctx, cli, ComponentName, dscispec.ApplicationsNamespace, 20, 2); err != nil {
if err := cluster.WaitForDeploymentAvailable(ctx, cli, ComponentName, dscispec.ApplicationsNamespace, 20, 2); err != nil {
return fmt.Errorf("deployment for %s is not ready to server: %w", ComponentName, err)
}
l.Info("deployment is done, updating monitoring rules")
Expand Down
37 changes: 18 additions & 19 deletions components/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/monitoring"
)

var (
Expand Down Expand Up @@ -62,7 +61,7 @@ func (d *Dashboard) OverrideManifests(platform string) error {
return err
}
// If overlay is defined, update paths
if platform == string(deploy.ManagedRhods) || platform == string(deploy.SelfManagedRhods) {
if platform == string(cluster.ManagedRhods) || platform == string(cluster.SelfManagedRhods) {
defaultKustomizePath := "overlays/rhoai"
if manifestConfig.SourcePath != "" {
defaultKustomizePath = manifestConfig.SourcePath
Expand Down Expand Up @@ -93,11 +92,11 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context,
currentComponentExist bool,
) error {
var l logr.Logger
platform, err := deploy.GetPlatform(cli)
platform, err := cluster.GetPlatform(cli)
if err != nil {
return err
}
if platform == deploy.SelfManagedRhods || platform == deploy.ManagedRhods {
if platform == cluster.SelfManagedRhods || platform == cluster.ManagedRhods {
l = d.ConfigComponentLogger(logger, ComponentNameSupported, dscispec)
} else {
l = d.ConfigComponentLogger(logger, ComponentName, dscispec)
Expand Down Expand Up @@ -128,14 +127,14 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context,
}

// 2. platform specific RBAC
if platform == deploy.OpenDataHub || platform == "" {
if platform == cluster.OpenDataHub || platform == "" {
err := cluster.UpdatePodSecurityRolebinding(cli, dscispec.ApplicationsNamespace, "odh-dashboard")
if err != nil {
return err
}
}

if platform == deploy.SelfManagedRhods || platform == deploy.ManagedRhods {
if platform == cluster.SelfManagedRhods || platform == cluster.ManagedRhods {
err := cluster.UpdatePodSecurityRolebinding(cli, dscispec.ApplicationsNamespace, "rhods-dashboard")
if err != nil {
return err
Expand All @@ -153,7 +152,7 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context,
// common: Deploy odh-dashboard manifests
// TODO: check if we can have the same component name odh-dashboard for both, or still keep rhods-dashboard for RHOAI
switch platform {
case deploy.SelfManagedRhods, deploy.ManagedRhods:
case cluster.SelfManagedRhods, cluster.ManagedRhods:
// anaconda
if err := cluster.CreateSecret(cli, "anaconda-ce-access", dscispec.ApplicationsNamespace); err != nil {
return fmt.Errorf("failed to create access-secret for anaconda: %w", err)
Expand All @@ -178,10 +177,10 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context,
l.Info("apply manifests done")

// CloudService Monitoring handling
if platform == deploy.ManagedRhods {
if platform == cluster.ManagedRhods {
if enabled {
// first check if the service is up, so prometheus won't fire alerts when it is just startup
if err := monitoring.WaitForDeploymentAvailable(ctx, cli, ComponentNameSupported, dscispec.ApplicationsNamespace, 20, 3); err != nil {
if err := cluster.WaitForDeploymentAvailable(ctx, cli, ComponentNameSupported, dscispec.ApplicationsNamespace, 20, 3); err != nil {
return fmt.Errorf("deployment for %s is not ready to server: %w", ComponentName, err)
}
l.Info("deployment is done, updating monitoring rules")
Expand Down Expand Up @@ -221,23 +220,23 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context,
}
}

func (d *Dashboard) deployCRDsForPlatform(cli client.Client, owner metav1.Object, namespace string, platform deploy.Platform) error {
func (d *Dashboard) deployCRDsForPlatform(cli client.Client, owner metav1.Object, namespace string, platform cluster.Platform) error {
componentName := ComponentName
if platform == deploy.SelfManagedRhods || platform == deploy.ManagedRhods {
if platform == cluster.SelfManagedRhods || platform == cluster.ManagedRhods {
componentName = ComponentNameSupported
}
// we only deploy CRD, we do not remove CRD
return deploy.DeployManifestsFromPath(cli, owner, PathCRDs, namespace, componentName, true)
}

func (d *Dashboard) applyRHOAISpecificConfigs(cli client.Client, owner metav1.Object, namespace string, platform deploy.Platform) error {
func (d *Dashboard) applyRHOAISpecificConfigs(cli client.Client, owner metav1.Object, namespace string, platform cluster.Platform) error {
enabled := d.ManagementState == operatorv1.Managed

// set proper group name
dashboardConfig := filepath.Join(PathODHDashboardConfig, "odhdashboardconfig.yaml")
adminGroups := map[deploy.Platform]string{
deploy.SelfManagedRhods: "rhods-admins",
deploy.ManagedRhods: "dedicated-admins",
adminGroups := map[cluster.Platform]string{
cluster.SelfManagedRhods: "rhods-admins",
cluster.ManagedRhods: "dedicated-admins",
}[platform]

if err := common.ReplaceStringsInFile(dashboardConfig, map[string]string{"<admin_groups>": adminGroups}); err != nil {
Expand All @@ -248,7 +247,7 @@ func (d *Dashboard) applyRHOAISpecificConfigs(cli client.Client, owner metav1.Ob
}
// ISV
path := PathISVSM
if platform == deploy.ManagedRhods {
if platform == cluster.ManagedRhods {
path = PathISVAddOn
}
if err := deploy.DeployManifestsFromPath(cli, owner, path, namespace, ComponentNameSupported, enabled); err != nil {
Expand All @@ -257,14 +256,14 @@ func (d *Dashboard) applyRHOAISpecificConfigs(cli client.Client, owner metav1.Ob
return nil
}

func (d *Dashboard) deployConsoleLink(cli client.Client, owner metav1.Object, platform deploy.Platform, namespace, componentName string) error {
func (d *Dashboard) deployConsoleLink(cli client.Client, owner metav1.Object, platform cluster.Platform, namespace, componentName string) error {
var manifestsPath, sectionTitle, routeName string
switch platform {
case deploy.SelfManagedRhods:
case cluster.SelfManagedRhods:
sectionTitle = "OpenShift Self Managed Services"
manifestsPath = PathConsoleLinkSupported
routeName = componentName
case deploy.ManagedRhods:
case cluster.ManagedRhods:
sectionTitle = "OpenShift Managed Services"
manifestsPath = PathConsoleLinkSupported
routeName = componentName
Expand Down
12 changes: 6 additions & 6 deletions components/datasciencepipelines/datasciencepipelines.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package datasciencepipelines provides utility functions to config Data Science Pipelines:
// Pipeline solution for end to end MLOps workflows that support the Kubeflow Pipelines SDK and Tekton
// Pipeline solution for end to end MLOps workflows that support the Kubeflow Pipelines SDK, Tekton and Argo Workflows.
// +groupName=datasciencecluster.opendatahub.io
package datasciencepipelines

Expand All @@ -17,9 +17,9 @@ import (

dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/monitoring"
)

var (
Expand Down Expand Up @@ -90,7 +90,7 @@ func (d *DataSciencePipelines) ReconcileComponent(ctx context.Context,
enabled := d.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed

platform, err := deploy.GetPlatform(cli)
platform, err := cluster.GetPlatform(cli)
if err != nil {
return err
}
Expand All @@ -116,7 +116,7 @@ func (d *DataSciencePipelines) ReconcileComponent(ctx context.Context,

// new overlay
manifestsPath := filepath.Join(OverlayPath, "rhoai")
if platform == deploy.OpenDataHub || platform == "" {
if platform == cluster.OpenDataHub || platform == "" {
manifestsPath = filepath.Join(OverlayPath, "odh")
}
if err = deploy.DeployManifestsFromPath(cli, owner, manifestsPath, dscispec.ApplicationsNamespace, ComponentName, enabled); err != nil {
Expand All @@ -125,11 +125,11 @@ func (d *DataSciencePipelines) ReconcileComponent(ctx context.Context,
l.Info("apply manifests done")

// CloudService Monitoring handling
if platform == deploy.ManagedRhods {
if platform == cluster.ManagedRhods {
if enabled {
// first check if the service is up, so prometheus won't fire alerts when it is just startup
// only 1 replica should be very quick
if err := monitoring.WaitForDeploymentAvailable(ctx, cli, ComponentName, dscispec.ApplicationsNamespace, 10, 1); err != nil {
if err := cluster.WaitForDeploymentAvailable(ctx, cli, ComponentName, dscispec.ApplicationsNamespace, 10, 1); err != nil {
return fmt.Errorf("deployment for %s is not ready to server: %w", ComponentName, err)
}
l.Info("deployment is done, updating monitoring rules")
Expand Down
7 changes: 3 additions & 4 deletions components/kserve/kserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/monitoring"
)

var (
Expand Down Expand Up @@ -107,7 +106,7 @@ func (k *Kserve) ReconcileComponent(ctx context.Context, cli client.Client,

enabled := k.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
platform, err := deploy.GetPlatform(cli)
platform, err := cluster.GetPlatform(cli)
if err != nil {
return err
}
Expand Down Expand Up @@ -167,10 +166,10 @@ func (k *Kserve) ReconcileComponent(ctx context.Context, cli client.Client,
}
l.WithValues("Path", Path).Info("apply manifests done for odh-model-controller")
// CloudService Monitoring handling
if platform == deploy.ManagedRhods {
if platform == cluster.ManagedRhods {
if enabled {
// first check if the service is up, so prometheus won't fire alerts when it is just startup
if err := monitoring.WaitForDeploymentAvailable(ctx, cli, ComponentName, dscispec.ApplicationsNamespace, 20, 2); err != nil {
if err := cluster.WaitForDeploymentAvailable(ctx, cli, ComponentName, dscispec.ApplicationsNamespace, 20, 2); err != nil {
return fmt.Errorf("deployment for %s is not ready to server: %w", ComponentName, err)
}
l.Info("deployment is done, updating monitoing rules")
Expand Down
8 changes: 4 additions & 4 deletions components/kueue/kueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/monitoring"
)

var (
Expand Down Expand Up @@ -62,7 +62,7 @@ func (k *Kueue) ReconcileComponent(ctx context.Context, cli client.Client, logge

enabled := k.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
platform, err := deploy.GetPlatform(cli)
platform, err := cluster.GetPlatform(cli)
if err != nil {
return err
}
Expand All @@ -86,10 +86,10 @@ func (k *Kueue) ReconcileComponent(ctx context.Context, cli client.Client, logge
}
l.Info("apply manifests done")
// CloudService Monitoring handling
if platform == deploy.ManagedRhods {
if platform == cluster.ManagedRhods {
if enabled {
// first check if the service is up, so prometheus won't fire alerts when it is just startup
if err := monitoring.WaitForDeploymentAvailable(ctx, cli, ComponentName, dscispec.ApplicationsNamespace, 20, 2); err != nil {
if err := cluster.WaitForDeploymentAvailable(ctx, cli, ComponentName, dscispec.ApplicationsNamespace, 20, 2); err != nil {
return fmt.Errorf("deployment for %s is not ready to server: %w", ComponentName, err)
}
l.Info("deployment is done, updating monitoring rules")
Expand Down
7 changes: 3 additions & 4 deletions components/modelmeshserving/modelmeshserving.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/monitoring"
)

var (
Expand Down Expand Up @@ -95,7 +94,7 @@ func (m *ModelMeshServing) ReconcileComponent(ctx context.Context,

enabled := m.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
platform, err := deploy.GetPlatform(cli)
platform, err := cluster.GetPlatform(cli)
if err != nil {
return err
}
Expand Down Expand Up @@ -150,10 +149,10 @@ func (m *ModelMeshServing) ReconcileComponent(ctx context.Context,

l.WithValues("Path", DependentPath).Info("apply manifests done for odh-model-controller")
// CloudService Monitoring handling
if platform == deploy.ManagedRhods {
if platform == cluster.ManagedRhods {
if enabled {
// first check if service is up, so prometheus won't fire alerts when it is just startup
if err := monitoring.WaitForDeploymentAvailable(ctx, cli, ComponentName, dscispec.ApplicationsNamespace, 20, 2); err != nil {
if err := cluster.WaitForDeploymentAvailable(ctx, cli, ComponentName, dscispec.ApplicationsNamespace, 20, 2); err != nil {
return fmt.Errorf("deployment for %s is not ready to server: %w", ComponentName, err)
}
l.Info("deployment is done, updating monitoring rules")
Expand Down
8 changes: 4 additions & 4 deletions components/ray/ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/monitoring"
)

var (
Expand Down Expand Up @@ -65,7 +65,7 @@ func (r *Ray) ReconcileComponent(ctx context.Context, cli client.Client, logger

enabled := r.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
platform, err := deploy.GetPlatform(cli)
platform, err := cluster.GetPlatform(cli)
if err != nil {
return err
}
Expand All @@ -89,10 +89,10 @@ func (r *Ray) ReconcileComponent(ctx context.Context, cli client.Client, logger
}
l.Info("apply manifests done")
// CloudService Monitoring handling
if platform == deploy.ManagedRhods {
if platform == cluster.ManagedRhods {
if enabled {
// first check if the service is up, so prometheus won't fire alerts when it is just startup
if err := monitoring.WaitForDeploymentAvailable(ctx, cli, ComponentName, dscispec.ApplicationsNamespace, 20, 2); err != nil {
if err := cluster.WaitForDeploymentAvailable(ctx, cli, ComponentName, dscispec.ApplicationsNamespace, 20, 2); err != nil {
return fmt.Errorf("deployment for %s is not ready to server: %w", ComponentName, err)
}
l.Info("deployment is done, updating monitoring rules")
Expand Down
10 changes: 5 additions & 5 deletions components/trustyai/trustyai.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/monitoring"
)

var (
Expand Down Expand Up @@ -67,13 +67,13 @@ func (t *TrustyAI) ReconcileComponent(ctx context.Context, cli client.Client, lo
enabled := t.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed

platform, err := deploy.GetPlatform(cli)
platform, err := cluster.GetPlatform(cli)
if err != nil {
return err
}

// Return when platform is RHOAI
if platform == deploy.SelfManagedRhods || platform == deploy.ManagedRhods {
if platform == cluster.SelfManagedRhods || platform == cluster.ManagedRhods {
enabled = false
}

Expand All @@ -97,9 +97,9 @@ func (t *TrustyAI) ReconcileComponent(ctx context.Context, cli client.Client, lo
l.Info("apply manifests done")

// CloudService Monitoring handling
if platform == deploy.ManagedRhods {
if platform == cluster.ManagedRhods {
if enabled {
if err := monitoring.WaitForDeploymentAvailable(ctx, cli, ComponentName, dscispec.ApplicationsNamespace, 10, 1); err != nil {
if err := cluster.WaitForDeploymentAvailable(ctx, cli, ComponentName, dscispec.ApplicationsNamespace, 10, 1); err != nil {
return fmt.Errorf("deployment for %s is not ready to server: %w", ComponentName, err)
}
l.Info("deployment is done, updating monitoring rules")
Expand Down
Loading

0 comments on commit 8267869

Please sign in to comment.