Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enhances FeatureTracker with spec #17

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions apis/features/v1/features_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ type FeatureTracker struct {
Status FeatureTrackerStatus `json:"status,omitempty"`
}

type OwnerType string

const (
ConditionPhaseFeatureCreated = "FeatureCreated"
ConditionPhasePreConditions = "FeaturePreConditions"
ConditionPhaseResourceCreation = "ResourceCreation"
ConditionPhaseLoadTemplateData = "LoadTemplateData"
ConditionPhaseProcessTemplates = "ProcessTemplates"
ConditionPhaseApplyManifests = "ApplyManifests"
ConditionPhasePostConditions = "FeaturePostConditions"
ConditionPhaseFeatureCreated = "FeatureCreated"
ConditionPhasePreConditions = "FeaturePreConditions"
ConditionPhaseResourceCreation = "ResourceCreation"
ConditionPhaseLoadTemplateData = "LoadTemplateData"
ConditionPhaseProcessTemplates = "ProcessTemplates"
ConditionPhaseApplyManifests = "ApplyManifests"
ConditionPhasePostConditions = "FeaturePostConditions"
ComponentType OwnerType = "Component"
DSCIType OwnerType = "DSCI"
)

func (s *FeatureTracker) ToOwnerReference() metav1.OwnerReference {
Expand All @@ -40,8 +44,16 @@ func (s *FeatureTracker) ToOwnerReference() metav1.OwnerReference {
}
}

// Origin describes the type of object that created the related Feature to this FeatureTracker.
type Origin struct {
Type OwnerType `json:"type,omitempty"`
Name string `json:"name,omitempty"`
}

// FeatureTrackerSpec defines the desired state of FeatureTracker.
type FeatureTrackerSpec struct {
Origin Origin `json:"origin,omitempty"`
AppNamespace string `json:"appNamespace,omitempty"`
}

// FeatureTrackerStatus defines the observed state of FeatureTracker.
Expand Down
16 changes: 16 additions & 0 deletions apis/features/v1/zz_generated.deepcopy.go

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

15 changes: 13 additions & 2 deletions components/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
featurev1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/features/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/common"
Expand Down Expand Up @@ -158,7 +159,12 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context,
return err
}

if err := d.configureServiceMesh(cli, owner, dscispec); err != nil {
origin := featurev1.Origin{
Type: featurev1.ComponentType,
Name: d.GetComponentName(),
}

if err := d.configureServiceMesh(cli, owner, dscispec, origin); err != nil {
return err
}

Expand Down Expand Up @@ -216,7 +222,12 @@ func (d *Dashboard) Cleanup(cli client.Client, dscispec *dsciv1.DSCInitializatio
}

if shouldConfigureServiceMesh {
serviceMeshInitializer := feature.NewFeaturesInitializer(dscispec, d.defineServiceMeshFeatures(dscispec))
origin := featurev1.Origin{
Type: featurev1.ComponentType,
Name: d.GetComponentName(),
}

serviceMeshInitializer := feature.NewFeaturesInitializer(dscispec, d.defineServiceMeshFeatures(dscispec, origin))

if err := serviceMeshInitializer.Prepare(); err != nil {
return err
Expand Down
9 changes: 5 additions & 4 deletions components/dashboard/servicemesh_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

dsci "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
featurev1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/features/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/feature"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/feature/servicemesh"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/gvr"
)

func (d *Dashboard) configureServiceMesh(cli client.Client, owner metav1.Object, dscispec *dsci.DSCInitializationSpec) error {
func (d *Dashboard) configureServiceMesh(cli client.Client, owner metav1.Object, dscispec *dsci.DSCInitializationSpec, origin featurev1.Origin) error {
shouldConfigureServiceMesh, err := deploy.ShouldConfigureServiceMesh(cli, dscispec)
if err != nil {
return err
}

if shouldConfigureServiceMesh {
serviceMeshInitializer := feature.NewFeaturesInitializer(dscispec, d.defineServiceMeshFeatures(dscispec))
serviceMeshInitializer := feature.NewFeaturesInitializer(dscispec, d.defineServiceMeshFeatures(dscispec, origin))

if err := serviceMeshInitializer.Prepare(); err != nil {
return err
Expand All @@ -40,10 +41,10 @@ func (d *Dashboard) configureServiceMesh(cli client.Client, owner metav1.Object,
return nil
}

func (d *Dashboard) defineServiceMeshFeatures(dscispec *dsci.DSCInitializationSpec) feature.DefinedFeatures {
func (d *Dashboard) defineServiceMeshFeatures(dscispec *dsci.DSCInitializationSpec, origin featurev1.Origin) feature.DefinedFeatures {
return func(s *feature.FeaturesInitializer) error {
createMeshResources, err := feature.CreateFeature("dashboard-create-service-mesh-routing-resources").
For(dscispec).
For(dscispec, origin).
Manifests(
path.Join(feature.ControlPlaneDir, "components", d.GetComponentName()),
).
Expand Down
15 changes: 12 additions & 3 deletions components/kserve/kserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
featurev1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/features/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
Expand Down Expand Up @@ -184,9 +185,13 @@ func (k *Kserve) configureServerless(instance *dsciv1.DSCInitializationSpec) err
case operatorv1.Managed: // standard workflow to create CR
switch instance.ServiceMesh.ManagementState {
case operatorv1.Unmanaged, operatorv1.Removed:
return fmt.Errorf("ServiceMesh is need to set to 'Managaed' in DSCI CR, it is required by KServe serving field")
return fmt.Errorf("ServiceMesh is need to set to 'Managed' in DSCI CR, it is required by KServe serving field")
}
serverlessInitializer := feature.NewFeaturesInitializer(instance, k.configureServerlessFeatures)
origin := featurev1.Origin{
Type: featurev1.ComponentType,
Name: k.GetComponentName(),
}
serverlessInitializer := feature.NewFeaturesInitializer(instance, k.configureServerlessFeatures(instance, origin))

if err := serverlessInitializer.Prepare(); err != nil {
return err
Expand All @@ -200,7 +205,11 @@ func (k *Kserve) configureServerless(instance *dsciv1.DSCInitializationSpec) err
}

func (k *Kserve) removeServerlessFeatures(instance *dsciv1.DSCInitializationSpec) error {
serverlessInitializer := feature.NewFeaturesInitializer(instance, k.configureServerlessFeatures)
origin := featurev1.Origin{
Type: featurev1.ComponentType,
Name: k.GetComponentName(),
}
serverlessInitializer := feature.NewFeaturesInitializer(instance, k.configureServerlessFeatures(instance, origin))

if err := serverlessInitializer.Prepare(); err != nil {
return err
Expand Down
87 changes: 45 additions & 42 deletions components/kserve/serverless_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package kserve
import (
"path"

dsci "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
featurev1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/features/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/feature"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/feature/serverless"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/feature/servicemesh"
Expand All @@ -14,50 +16,51 @@ const (
templatesDir = "templates/serverless"
)

func (k *Kserve) configureServerlessFeatures(s *feature.FeaturesInitializer) error {
servingDeployment, err := feature.CreateFeature("serverless-serving-deployment").
For(s.DSCInitializationSpec).
Manifests(
path.Join(templatesDir, "serving-install"),
).
WithData(PopulateComponentSettings(k)).
PreConditions(
serverless.EnsureServerlessOperatorInstalled,
serverless.EnsureServerlessAbsent,
servicemesh.EnsureServiceMeshInstalled,
feature.CreateNamespaceIfNotExists(knativeServingNamespace),
).
PostConditions(
feature.WaitForPodsToBeReady(knativeServingNamespace),
).
Load()
if err != nil {
return err
}
s.Features = append(s.Features, servingDeployment)
func (k *Kserve) configureServerlessFeatures(dscispec *dsci.DSCInitializationSpec, origin featurev1.Origin) feature.DefinedFeatures {
return func(s *feature.FeaturesInitializer) error {
servingDeployment, err := feature.CreateFeature("serverless-serving-deployment").
For(dscispec, origin).
Manifests(
path.Join(templatesDir, "serving-install"),
).
WithData(PopulateComponentSettings(k)).
PreConditions(
serverless.EnsureServerlessOperatorInstalled,
serverless.EnsureServerlessAbsent,
servicemesh.EnsureServiceMeshInstalled,
feature.CreateNamespaceIfNotExists(knativeServingNamespace),
).
PostConditions(
feature.WaitForPodsToBeReady(knativeServingNamespace),
).
Load()
if err != nil {
return err
}
s.Features = append(s.Features, servingDeployment)

servingIstioGateways, err := feature.CreateFeature("serverless-serving-gateways").
For(s.DSCInitializationSpec).
PreConditions(
// Check serverless is installed
feature.WaitForResourceToBeCreated(knativeServingNamespace, gvr.KnativeServing),
).
WithData(
serverless.ServingDefaultValues,
serverless.ServingIngressDomain,
PopulateComponentSettings(k),
).
WithResources(serverless.ServingCertificateResource).
Manifests(
path.Join(templatesDir, "serving-istio-gateways"),
).
Load()
if err != nil {
return err
servingIstioGateways, err := feature.CreateFeature("serverless-serving-gateways").
For(dscispec, origin).
PreConditions(
// Check serverless is installed
feature.WaitForResourceToBeCreated(knativeServingNamespace, gvr.KnativeServing),
).
WithData(
serverless.ServingDefaultValues,
serverless.ServingIngressDomain,
PopulateComponentSettings(k),
).
WithResources(serverless.ServingCertificateResource).
Manifests(
path.Join(templatesDir, "serving-istio-gateways"),
).
Load()
if err != nil {
return err
}
s.Features = append(s.Features, servingIstioGateways)
return nil
}
s.Features = append(s.Features, servingIstioGateways)

return nil
}

func PopulateComponentSettings(k *Kserve) feature.Action {
Expand Down
12 changes: 12 additions & 0 deletions config/crd/bases/features.opendatahub.io_featuretrackers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ spec:
type: object
spec:
description: FeatureTrackerSpec defines the desired state of FeatureTracker.
properties:
appNamespace:
type: string
origin:
description: Origin describes the type of object that created the
related Feature to this FeatureTracker.
properties:
name:
type: string
type:
type: string
type: object
type: object
status:
description: FeatureTrackerStatus defines the observed state of FeatureTracker.
Expand Down
Loading
Loading