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

Improve conditions reporting #1605

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
34 changes: 23 additions & 11 deletions apis/datasciencecluster/v1/datasciencecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ 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"

Expand Down Expand Up @@ -115,16 +114,7 @@ type ComponentsStatus struct {

// DataScienceClusterStatus defines the observed state of DataScienceCluster.
type DataScienceClusterStatus struct {
// Phase describes the Phase of DataScienceCluster reconciliation state
// This is used by OLM UI to provide status information to the user
Phase string `json:"phase,omitempty"`

// Conditions describes the state of the DataScienceCluster resource.
// +optional
Conditions []conditionsv1.Condition `json:"conditions,omitempty"`

// The generation observed by the deployment controller.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
common.Status `json:",inline"`

// RelatedObjects is a list of objects created and maintained by this operator.
// Object references will be added to this list after they have been created AND found in the cluster.
Expand All @@ -143,10 +133,20 @@ type DataScienceClusterStatus struct {
Release common.Release `json:"release,omitempty"`
}

func (s *DataScienceClusterStatus) GetConditions() []common.Condition {
return s.Conditions
}

func (s *DataScienceClusterStatus) SetConditions(conditions []common.Condition) {
s.Conditions = append(conditions[:0:0], conditions...)
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,shortName=dsc
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`,description="Ready"
// +kubebuilder:printcolumn:name="Reason",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].reason`,description="Reason"

// DataScienceCluster is the Schema for the datascienceclusters API.
type DataScienceCluster struct {
Expand All @@ -166,6 +166,18 @@ type DataScienceClusterList struct {
Items []DataScienceCluster `json:"items"`
}

func (c *DataScienceCluster) GetConditions() []common.Condition {
return c.Status.GetConditions()
}

func (c *DataScienceCluster) GetStatus() *common.Status {
return &c.Status.Status
}

func (c *DataScienceCluster) SetConditions(conditions []common.Condition) {
c.Status.SetConditions(conditions)
}

func init() {
SchemeBuilder.Register(&DataScienceCluster{}, &DataScienceClusterList{})
}
9 changes: 1 addition & 8 deletions apis/datasciencecluster/v1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ spec:
singular: datasciencecluster
scope: Cluster
versions:
- name: v1
- additionalPrinterColumns:
- description: Ready
jsonPath: .status.conditions[?(@.type=="Ready")].status
name: Ready
type: string
- description: Reason
jsonPath: .status.conditions[?(@.type=="Ready")].reason
name: Reason
type: string
name: v1
schema:
openAPIV3Schema:
description: DataScienceCluster is the Schema for the datascienceclusters
Expand Down Expand Up @@ -1133,34 +1142,61 @@ spec:
type: object
type: object
conditions:
description: Conditions describes the state of the DataScienceCluster
resource.
items:
description: |-
Condition represents the state of the operator's
reconciliation functionality.
properties:
lastHeartbeatTime:
description: |-
The last time we got an update on a given condition, this should not be set and is
present only for backward compatibility reasons
format: date-time
type: string
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed.
If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: message is a human-readable message indicating
details about the transition.
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration
is 9, the condition is out of date with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
The value should be a CamelCase string.
type: string
severity:
description: |-
Severity with which to treat failures of this type of condition.
When this is not specified, it defaults to Error.
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: ConditionType is the state of the operator's reconciliation
functionality.
description: type of condition in CamelCase or in foo.example.com/CamelCase.
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- status
- type
type: object
type: array
x-kubernetes-list-type: atomic
errorMessage:
type: string
installedComponents:
Expand All @@ -1169,13 +1205,10 @@ spec:
description: List of components with status if installed or not
type: object
observedGeneration:
description: The generation observed by the deployment controller.
description: The generation observed by the resource controller.
format: int64
type: integer
phase:
description: |-
Phase describes the Phase of DataScienceCluster reconciliation state
This is used by OLM UI to provide status information to the user
type: string
relatedObjects:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ spec:
singular: datasciencecluster
scope: Cluster
versions:
- name: v1
- additionalPrinterColumns:
- description: Ready
jsonPath: .status.conditions[?(@.type=="Ready")].status
name: Ready
type: string
- description: Reason
jsonPath: .status.conditions[?(@.type=="Ready")].reason
name: Reason
type: string
name: v1
schema:
openAPIV3Schema:
description: DataScienceCluster is the Schema for the datascienceclusters
Expand Down Expand Up @@ -1133,34 +1142,61 @@ spec:
type: object
type: object
conditions:
description: Conditions describes the state of the DataScienceCluster
resource.
items:
description: |-
Condition represents the state of the operator's
reconciliation functionality.
properties:
lastHeartbeatTime:
description: |-
The last time we got an update on a given condition, this should not be set and is
present only for backward compatibility reasons
format: date-time
type: string
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed.
If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: message is a human-readable message indicating
details about the transition.
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration
is 9, the condition is out of date with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
The value should be a CamelCase string.
type: string
severity:
description: |-
Severity with which to treat failures of this type of condition.
When this is not specified, it defaults to Error.
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: ConditionType is the state of the operator's reconciliation
functionality.
description: type of condition in CamelCase or in foo.example.com/CamelCase.
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- status
- type
type: object
type: array
x-kubernetes-list-type: atomic
errorMessage:
type: string
installedComponents:
Expand All @@ -1169,13 +1205,10 @@ spec:
description: List of components with status if installed or not
type: object
observedGeneration:
description: The generation observed by the deployment controller.
description: The generation observed by the resource controller.
format: int64
type: integer
phase:
description: |-
Phase describes the Phase of DataScienceCluster reconciliation state
This is used by OLM UI to provide status information to the user
type: string
relatedObjects:
description: |-
Expand Down
51 changes: 29 additions & 22 deletions controllers/components/codeflare/codeflare.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package codeflare

import (
"context"
"errors"
"fmt"

operatorv1 "github.com/openshift/api/operator/v1"
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
corev1 "k8s.io/api/core/v1"
k8serr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -16,6 +16,7 @@
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
cr "github.com/opendatahub-io/opendatahub-operator/v2/pkg/componentsregistry"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/conditions"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/types"
odhdeploy "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/annotations"
)
Expand Down Expand Up @@ -63,44 +64,50 @@
return nil
}

func (s *componentHandler) UpdateDSCStatus(dsc *dscv1.DataScienceCluster, obj client.Object) error {
c, ok := obj.(*componentApi.CodeFlare)
func (s *componentHandler) UpdateDSCStatus(ctx context.Context, rr *types.ReconciliationRequest) (metav1.ConditionStatus, error) {
cs := metav1.ConditionUnknown

c := componentApi.CodeFlare{}
c.Name = componentApi.CodeFlareInstanceName

if err := rr.Client.Get(ctx, client.ObjectKeyFromObject(&c), &c); err != nil && !k8serr.IsNotFound(err) {
return cs, err
}

Check warning on line 75 in controllers/components/codeflare/codeflare.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/codeflare/codeflare.go#L67-L75

Added lines #L67 - L75 were not covered by tests

dsc, ok := rr.Instance.(*dscv1.DataScienceCluster)

Check warning on line 77 in controllers/components/codeflare/codeflare.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/codeflare/codeflare.go#L77

Added line #L77 was not covered by tests
if !ok {
return errors.New("failed to convert to CodeFlare")
return cs, errors.New("failed to convert to DataScienceCluster")

Check warning on line 79 in controllers/components/codeflare/codeflare.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/codeflare/codeflare.go#L79

Added line #L79 was not covered by tests
}

dsc.Status.InstalledComponents[LegacyComponentName] = false
dsc.Status.Components.CodeFlare.ManagementSpec.ManagementState = s.GetManagementState(dsc)
dsc.Status.Components.CodeFlare.CodeFlareCommonStatus = nil

nc := conditionsv1.Condition{
Type: ReadyConditionType,
Status: corev1.ConditionFalse,
Reason: "Unknown",
Message: "Not Available",
}
rr.Conditions.MarkFalse(ReadyConditionType)

Check warning on line 86 in controllers/components/codeflare/codeflare.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/codeflare/codeflare.go#L86

Added line #L86 was not covered by tests

switch s.GetManagementState(dsc) {
case operatorv1.Managed:
dsc.Status.InstalledComponents[LegacyComponentName] = true
dsc.Status.Components.CodeFlare.CodeFlareCommonStatus = c.Status.CodeFlareCommonStatus.DeepCopy()

if rc := conditions.FindStatusCondition(c, status.ConditionTypeReady); rc != nil {
nc.Status = corev1.ConditionStatus(rc.Status)
nc.Reason = rc.Reason
nc.Message = rc.Message
if rc := conditions.FindStatusCondition(c.GetStatus(), status.ConditionTypeReady); rc != nil {
rr.Conditions.MarkFrom(ReadyConditionType, *rc)
cs = rc.Status
} else {
cs = metav1.ConditionFalse

Check warning on line 97 in controllers/components/codeflare/codeflare.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/codeflare/codeflare.go#L93-L97

Added lines #L93 - L97 were not covered by tests
}

case operatorv1.Removed:
nc.Status = corev1.ConditionFalse
nc.Reason = string(operatorv1.Removed)
nc.Message = "Component ManagementState is set to " + string(operatorv1.Removed)
rr.Conditions.MarkFalse(
ReadyConditionType,
conditions.WithReason(string(operatorv1.Removed)),
conditions.WithMessage("Component ManagementState is set to %s", operatorv1.Removed),
conditions.WithSeverity(common.ConditionSeverityInfo),
)

Check warning on line 106 in controllers/components/codeflare/codeflare.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/codeflare/codeflare.go#L101-L106

Added lines #L101 - L106 were not covered by tests

default:
return fmt.Errorf("unknown state %s ", s.GetManagementState(dsc))
return cs, fmt.Errorf("unknown state %s ", s.GetManagementState(dsc))

Check warning on line 109 in controllers/components/codeflare/codeflare.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/codeflare/codeflare.go#L109

Added line #L109 was not covered by tests
}

conditionsv1.SetStatusCondition(&dsc.Status.Conditions, nc)

return nil
return cs, nil

Check warning on line 112 in controllers/components/codeflare/codeflare.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/codeflare/codeflare.go#L112

Added line #L112 was not covered by tests
}
Loading