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 <wenzhou@redhat.com>

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

Signed-off-by: Wen Zhou <wenzhou@redhat.com>

* update: rename variable, removing GVK from it

Signed-off-by: Wen Zhou <wenzhou@redhat.com>

* update: move gvk into a sub package under cluster

Signed-off-by: Wen Zhou <wenzhou@redhat.com>

---------

Signed-off-by: Wen Zhou <wenzhou@redhat.com>
  • Loading branch information
zdtsw authored Apr 23, 2024
1 parent c2b44c3 commit 96c85f2
Show file tree
Hide file tree
Showing 34 changed files with 302 additions and 327 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 @@ -108,7 +107,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 @@ -168,10 +167,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
2 changes: 1 addition & 1 deletion components/modelregistry/modelregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (m *ModelRegistry) ReconcileComponent(_ context.Context, cli client.Client,
}
enabled := m.GetManagementState() == operatorv1.Managed

platform, err := deploy.GetPlatform(cli)
platform, err := cluster.GetPlatform(cli)
if err != nil {
return err
}
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 @@ -66,7 +66,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 @@ -90,10 +90,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
9 changes: 5 additions & 4 deletions components/trainingoperator/trainingoperator.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Package trainingoperator provides utility functions to config trainingoperator as part of the stack
// which makes managing distributed compute infrastructure in the cloud easy and intuitive for Data Scientists
// +groupName=datasciencecluster.opendatahub.io
package trainingoperator

import (
Expand All @@ -14,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 +66,7 @@ func (r *TrainingOperator) ReconcileComponent(ctx context.Context, cli client.Cl

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 +90,10 @@ func (r *TrainingOperator) ReconcileComponent(ctx context.Context, cli client.Cl
}
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 wont 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)
}
fmt.Printf("deployment for %s is done, updating monitoring rules\n", ComponentName)
Expand Down
Loading

0 comments on commit 96c85f2

Please sign in to comment.