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

update: add status update on component CR's phase #1394

Closed
Closed
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
10 changes: 10 additions & 0 deletions controllers/components/dashboard/dashboard.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package dashboard

import (
"context"
"fmt"

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

"github.com/opendatahub-io/opendatahub-operator/v2/apis/components"
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"
Expand Down Expand Up @@ -63,3 +65,11 @@ func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Obj
},
})
}

func (s *componentHandler) GetStatus(ctx context.Context, cli client.Client) (components.Status, error) {
d := &componentsv1.Dashboard{}
if err := cli.Get(ctx, client.ObjectKey{Name: componentsv1.DashboardInstanceName}, d); err != nil {
return components.Status{}, fmt.Errorf("error get component CR %v %w ", componentsv1.DashboardInstanceName, err)
}
return *d.GetStatus(), nil
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package datasciencepipelines

import (
"context"
"fmt"

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

"github.com/opendatahub-io/opendatahub-operator/v2/apis/components"
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"
Expand Down Expand Up @@ -84,3 +86,11 @@ func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Obj
},
})
}

func (s *componentHandler) GetStatus(ctx context.Context, cli client.Client) (components.Status, error) {
d := &componentsv1.DataSciencePipelines{}
if err := cli.Get(ctx, client.ObjectKey{Name: componentsv1.DataSciencePipelinesInstanceName}, d); err != nil {
return components.Status{}, fmt.Errorf("error get component CR %v %w ", componentsv1.DataSciencePipelinesInstanceName, err)
}
return *d.GetStatus(), nil
}
10 changes: 10 additions & 0 deletions controllers/components/kueue/kueue.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package kueue

import (
"context"
"fmt"

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

"github.com/opendatahub-io/opendatahub-operator/v2/apis/components"
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"
Expand Down Expand Up @@ -72,3 +74,11 @@ func (s *componentHandler) Init(platform cluster.Platform) error {

return nil
}

func (s *componentHandler) GetStatus(ctx context.Context, cli client.Client) (components.Status, error) {
k := &componentsv1.Dashboard{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
k := &componentsv1.Dashboard{}
k := &componentsv1.Kueue{}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💤 i was not myself

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's still a draft PR and not yet ready for review, but I thought it might be useful to highlight these in case you didn't catch them before making it ready 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, thanks!
history proves this again: do not eat and work at the same time!

if err := cli.Get(ctx, client.ObjectKey{Name: componentsv1.KueueInstanceName}, k); err != nil {
return components.Status{}, fmt.Errorf("error get component CR %v %w ", componentsv1.KueueInstanceName, err)
}
return *k.GetStatus(), nil
}
9 changes: 9 additions & 0 deletions controllers/components/modelregistry/modelregistry.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package modelregistry

import (
"context"
"fmt"

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

"github.com/opendatahub-io/opendatahub-operator/v2/apis/components"
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"
Expand Down Expand Up @@ -72,3 +74,10 @@ func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) client.Obj
},
})
}
func (s *componentHandler) GetStatus(ctx context.Context, cli client.Client) (components.Status, error) {
m := &componentsv1.Dashboard{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
m := &componentsv1.Dashboard{}
m := &componentsv1.ModelRegistry{}

if err := cli.Get(ctx, client.ObjectKey{Name: componentsv1.ModelRegistryInstanceName}, m); err != nil {
return components.Status{}, fmt.Errorf("error get component CR %v %w ", componentsv1.ModelRegistryInstanceName, err)
}
return *m.GetStatus(), nil
}
9 changes: 9 additions & 0 deletions controllers/components/ray/ray.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package ray

import (
"context"
"fmt"

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

"github.com/opendatahub-io/opendatahub-operator/v2/apis/components"
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"
Expand Down Expand Up @@ -72,3 +74,10 @@ func (s *componentHandler) Init(platform cluster.Platform) error {

return nil
}
func (s *componentHandler) GetStatus(ctx context.Context, cli client.Client) (components.Status, error) {
r := &componentsv1.Dashboard{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
r := &componentsv1.Dashboard{}
r := &componentsv1.Ray{}

if err := cli.Get(ctx, client.ObjectKey{Name: componentsv1.RayInstanceName}, r); err != nil {
return components.Status{}, fmt.Errorf("error get component CR %v %w ", componentsv1.RayInstanceName, err)
}
return *r.GetStatus(), nil
}
15 changes: 12 additions & 3 deletions controllers/components/trainingoperator/trainingoperator.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package trainingoperator

import (
"context"
"fmt"

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

"github.com/opendatahub-io/opendatahub-operator/v2/apis/components"
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"
Expand Down Expand Up @@ -37,7 +39,7 @@ func (s *componentHandler) GetManagementState(dsc *dscv1.DataScienceCluster) ope
return dsc.Spec.Components.TrainingOperator.ManagementState
}

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

return k8sclient.Object(&componentsv1.TrainingOperator{
return client.Object(&componentsv1.TrainingOperator{
TypeMeta: metav1.TypeMeta{
Kind: componentsv1.TrainingOperatorKind,
APIVersion: componentsv1.GroupVersion.String(),
Expand All @@ -72,3 +74,10 @@ func (s *componentHandler) Init(platform cluster.Platform) error {

return nil
}
func (s *componentHandler) GetStatus(ctx context.Context, cli client.Client) (components.Status, error) {
t := &componentsv1.Dashboard{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t := &componentsv1.Dashboard{}
t := &componentsv1.TrainingOperator{}

if err := cli.Get(ctx, client.ObjectKey{Name: componentsv1.TrainingOperatorInstanceName}, t); err != nil {
return components.Status{}, fmt.Errorf("error get component CR %v %w ", componentsv1.TrainingOperatorInstanceName, err)
}
return *t.GetStatus(), nil
}
9 changes: 9 additions & 0 deletions controllers/components/trustyai/trustyai.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package trustyai

import (
"context"
"fmt"

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

"github.com/opendatahub-io/opendatahub-operator/v2/apis/components"
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"
Expand Down Expand Up @@ -79,3 +81,10 @@ func (s *componentHandler) Init(platform cluster.Platform) error {

return nil
}
func (s *componentHandler) GetStatus(ctx context.Context, cli client.Client) (components.Status, error) {
t := &componentsv1.Dashboard{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t := &componentsv1.Dashboard{}
t := &componentsv1.TrustyAI{}

if err := cli.Get(ctx, client.ObjectKey{Name: componentsv1.TrustyAIInstanceName}, t); err != nil {
return components.Status{}, fmt.Errorf("error get component CR %v %w ", componentsv1.TrustyAIInstanceName, err)
}
return *t.GetStatus(), nil
}
25 changes: 17 additions & 8 deletions controllers/datasciencecluster/datasciencecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import (
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
cr "github.com/opendatahub-io/opendatahub-operator/v2/pkg/componentsregistry"
odhClient "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/client"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/predicates/resources"
annotations "github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/annotations"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/upgrade"
Expand Down Expand Up @@ -309,13 +310,21 @@ func (r *DataScienceClusterReconciler) ReconcileComponent(
}

r.Log.Info("component reconciled successfully: " + componentName)
s, e := component.GetStatus(ctx, r.Client)
if e != nil {
return instance, e
}
instance, err = status.UpdateWithRetry(ctx, r.Client, instance, func(saved *dscv1.DataScienceCluster) {
if saved.Status.InstalledComponents == nil {
saved.Status.InstalledComponents = make(map[string]bool)
}
saved.Status.InstalledComponents[componentName] = enabled
if enabled {
status.SetComponentCondition(&saved.Status.Conditions, componentName, status.ReconcileCompleted, "Component reconciled successfully", corev1.ConditionTrue)
if s.Phase == "Ready" {
// should use status.PhaseReady but to keep backwards compatibility use status.ReconcileCompleted
status.SetComponentCondition(&saved.Status.Conditions, componentName, status.ReconcileCompleted, "Component reconciled successfully", corev1.ConditionTrue)
}
status.SetComponentCondition(&saved.Status.Conditions, componentName, status.PhaseNotReady, "Component reconciled in progress", corev1.ConditionTrue)
} else {
status.RemoveComponentCondition(&saved.Status.Conditions, componentName)
}
Expand Down Expand Up @@ -494,13 +503,13 @@ func (r *DataScienceClusterReconciler) SetupWithManager(ctx context.Context, mgr
builder.WithPredicates(modelMeshwebhookPredicates),
).
// components CRs
Owns(&componentsv1.Dashboard{}).
Owns(&componentsv1.Ray{}).
Owns(&componentsv1.ModelRegistry{}).
Owns(&componentsv1.TrustyAI{}).
Owns(&componentsv1.Kueue{}).
Owns(&componentsv1.TrainingOperator{}).
Owns(&componentsv1.DataSciencePipelines{}).
Owns(&componentsv1.Dashboard{}, builder.WithPredicates(resources.ComponentStatusPredicate())).
Owns(&componentsv1.Ray{}, builder.WithPredicates(resources.ComponentStatusPredicate())).
Owns(&componentsv1.ModelRegistry{}, builder.WithPredicates(resources.ComponentStatusPredicate())).
Owns(&componentsv1.TrustyAI{}, builder.WithPredicates(resources.ComponentStatusPredicate())).
Owns(&componentsv1.Kueue{}, builder.WithPredicates(resources.ComponentStatusPredicate())).
Owns(&componentsv1.TrainingOperator{}, builder.WithPredicates(resources.ComponentStatusPredicate())).
Owns(&componentsv1.DataSciencePipelines{}, builder.WithPredicates(resources.ComponentStatusPredicate())).
Owns(
&corev1.ServiceAccount{},
builder.WithPredicates(saPredicates),
Expand Down
2 changes: 2 additions & 0 deletions pkg/componentsregistry/componentsregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/opendatahub-io/opendatahub-operator/v2/apis/components"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
)
Expand All @@ -27,6 +28,7 @@ type ComponentHandler interface {
// It returns interface, but it simplifies DSC reconciler code a lot
NewCRObject(dsc *dscv1.DataScienceCluster) client.Object
NewComponentReconciler(ctx context.Context, mgr ctrl.Manager) error
GetStatus(ctx context.Context, cli client.Client) (components.Status, error)
}

var registry = []ComponentHandler{}
Expand Down
21 changes: 21 additions & 0 deletions pkg/controller/predicates/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/predicate"
)
Expand Down Expand Up @@ -53,3 +54,23 @@ func Deleted() predicate.Funcs {
},
}
}

func ComponentStatusPredicate() predicate.Funcs {
return predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
oldCR, okOld := e.ObjectOld.(*unstructured.Unstructured)
newCR, okNew := e.ObjectNew.(*unstructured.Unstructured)
if !okOld || !okNew {
return false
}

// Check if the `.status.phase` is different: "", "Ready", "NotReady"
oldPhase, _, errO := unstructured.NestedString(oldCR.Object, "status", "phase")
newPhase, _, errN := unstructured.NestedString(newCR.Object, "status", "phase")
if errO != nil || errN != nil {
return false
}
return oldPhase != newPhase
},
}
}