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 10 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
100 changes: 93 additions & 7 deletions apis/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,96 @@ type ManifestsConfig struct {
SourcePath string `json:"sourcePath,omitempty"`
}

// ConditionSeverity expresses the severity of a Condition Type failing.
type ConditionSeverity string

const (
ConditionSeverityError ConditionSeverity = ""
ConditionSeverityWarning ConditionSeverity = "Warning"
ConditionSeverityInfo ConditionSeverity = "Info"

ConditionReasonError = "Error"
)

// +kubebuilder:object:generate=true
type Condition struct {

// type of condition in CamelCase or in foo.example.com/CamelCase.
//
// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation: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])$`
// +kubebuilder:validation:MaxLength=316
Type string `json:"type"`

// status of the condition, one of True, False, Unknown.
// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum=True;False;Unknown
Status metav1.ConditionStatus `json:"status"`

// 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.
//
// +optional
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=0
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// 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.
//
// +optional
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=date-time
LastTransitionTime metav1.Time `json:"lastTransitionTime"`

// reason contains a programmatic identifier indicating the reason for the condition's last transition.
// The value should be a CamelCase string.
//
// +optional
// +kubebuilder:validation:Optional
Reason string `json:"reason,omitempty"`

// message is a human-readable message indicating details about the transition.
// +optional
// +kubebuilder:validation:Optional
Message string `json:"message,omitempty"`

// Severity with which to treat failures of this type of condition.
// When this is not specified, it defaults to Error.
// +optional
// +kubebuilder:validation:Optional
Severity ConditionSeverity `json:"severity,omitempty"`

// The last time we got an update on a given condition, this should not be set and is
// present only for backward compatibility reasons
//
// +optional
// +kubebuilder:validation:Optional
LastHeartbeatTime *metav1.Time `json:"lastHeartbeatTime,omitempty"`
}

// +kubebuilder:object:generate=true
type Status struct {
Phase string `json:"phase,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Phase string `json:"phase,omitempty"`

// +patchMergeKey=type
// +patchStrategy=merge
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions,omitempty"`
// The generation observed by the resource controller.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// +listType=atomic
Conditions []Condition `json:"conditions,omitempty"`
}

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

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

// ComponentRelease represents the detailed status of a component release.
Expand Down Expand Up @@ -99,6 +179,11 @@ type WithDevFlags interface {
GetDevFlags() *DevFlags
}

type ConditionsAccessor interface {
GetConditions() []Condition
SetConditions([]Condition)
}

type WithReleases interface {
GetReleaseStatus() *[]ComponentRelease
SetReleaseStatus(status []ComponentRelease)
Expand All @@ -107,6 +192,7 @@ type WithReleases interface {
type PlatformObject interface {
client.Object
WithStatus
ConditionsAccessor
}

type Platform string
Expand Down
26 changes: 22 additions & 4 deletions apis/common/zz_generated.deepcopy.go

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

11 changes: 11 additions & 0 deletions apis/components/v1alpha1/codeflare_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const (
CodeFlareKind = "CodeFlare"
)

// Check that the component implements common.PlatformObject.
var _ common.PlatformObject = (*CodeFlare)(nil)

// CodeFlareCommonStatus defines the shared observed state of CodeFlare
type CodeFlareCommonStatus struct {
common.ComponentReleaseStatus `json:",inline"`
Expand Down Expand Up @@ -71,6 +74,14 @@ func (c *CodeFlare) GetStatus() *common.Status {
return &c.Status.Status
}

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

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

func (c *CodeFlare) GetReleaseStatus() *[]common.ComponentRelease { return &c.Status.Releases }

func (c *CodeFlare) SetReleaseStatus(releases []common.ComponentRelease) {
Expand Down
11 changes: 11 additions & 0 deletions apis/components/v1alpha1/dashboard_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const (
DashboardKind = "Dashboard"
)

// Check that the component implements common.PlatformObject.
var _ common.PlatformObject = (*Dashboard)(nil)

// DashboardCommonSpec spec defines the shared desired state of Dashboard
type DashboardCommonSpec struct {
// dashboard spec exposed to DSC api
Expand Down Expand Up @@ -79,6 +82,14 @@ func (c *Dashboard) GetStatus() *common.Status {
return &c.Status.Status
}

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

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

// +kubebuilder:object:root=true

// DashboardList contains a list of Dashboard
Expand Down
11 changes: 11 additions & 0 deletions apis/components/v1alpha1/datasciencepipelines_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const (
DataSciencePipelinesKind = "DataSciencePipelines"
)

// Check that the component implements common.PlatformObject.
var _ common.PlatformObject = (*DataSciencePipelines)(nil)

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
Expand Down Expand Up @@ -74,6 +77,14 @@ func (c *DataSciencePipelines) GetStatus() *common.Status {
return &c.Status.Status
}

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

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

func (c *DataSciencePipelines) GetReleaseStatus() *[]common.ComponentRelease {
return &c.Status.Releases
}
Expand Down
8 changes: 8 additions & 0 deletions apis/components/v1alpha1/feastoperator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ func (c *FeastOperator) GetStatus() *common.Status {
return &c.Status.Status
}

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

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

// +kubebuilder:object:root=true

// FeastOperatorList contains a list of FeastOperator objects
Expand Down
11 changes: 11 additions & 0 deletions apis/components/v1alpha1/kserve_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const (
RawDeployment DefaultDeploymentMode = "RawDeployment"
)

// Check that the component implements common.PlatformObject.
var _ common.PlatformObject = (*Kserve)(nil)

// KserveCommonSpec spec defines the shared desired state of Kserve
type KserveCommonSpec struct {
common.DevFlagsSpec `json:",inline"`
Expand Down Expand Up @@ -111,6 +114,14 @@ func (c *Kserve) GetStatus() *common.Status {
return &c.Status.Status
}

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

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

func (c *Kserve) GetReleaseStatus() *[]common.ComponentRelease {
return &c.Status.Releases
}
Expand Down
11 changes: 11 additions & 0 deletions apis/components/v1alpha1/kueue_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const (
KueueKind = "Kueue"
)

// Check that the component implements common.PlatformObject.
var _ common.PlatformObject = (*Kueue)(nil)

// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// +kubebuilder:object:root=true
Expand Down Expand Up @@ -86,6 +89,14 @@ func (c *Kueue) GetStatus() *common.Status {
return &c.Status.Status
}

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

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

func (c *Kueue) GetReleaseStatus() *[]common.ComponentRelease { return &c.Status.Releases }

func (c *Kueue) SetReleaseStatus(releases []common.ComponentRelease) {
Expand Down
11 changes: 11 additions & 0 deletions apis/components/v1alpha1/modelcontroller_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const (
ModelControllerKind = "ModelController"
)

// Check that the component implements common.PlatformObject.
var _ common.PlatformObject = (*ModelController)(nil)

// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// +kubebuilder:object:root=true
Expand Down Expand Up @@ -99,3 +102,11 @@ func (c *ModelController) GetDevFlags() *common.DevFlags { return nil }
func (c *ModelController) GetStatus() *common.Status {
return &c.Status.Status
}

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

func (c *ModelController) SetConditions(conditions []common.Condition) {
c.Status.SetConditions(conditions)
}
11 changes: 11 additions & 0 deletions apis/components/v1alpha1/modelmeshserving_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const (
ModelMeshServingKind = "ModelMeshServing"
)

// Check that the component implements common.PlatformObject.
var _ common.PlatformObject = (*ModelMeshServing)(nil)

// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// +kubebuilder:object:root=true
Expand Down Expand Up @@ -86,6 +89,14 @@ func (c *ModelMeshServing) GetStatus() *common.Status {
return &c.Status.Status
}

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

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

func (c *ModelMeshServing) GetReleaseStatus() *[]common.ComponentRelease {
return &c.Status.Releases
}
Expand Down
11 changes: 11 additions & 0 deletions apis/components/v1alpha1/modelregistry_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const (
ModelRegistryKind = "ModelRegistry"
)

// Check that the component implements common.PlatformObject.
var _ common.PlatformObject = (*ModelRegistry)(nil)

// ModelRegistryCommonSpec spec defines the shared desired state of ModelRegistry
type ModelRegistryCommonSpec struct {
// model registry spec exposed to DSC api
Expand Down Expand Up @@ -84,6 +87,14 @@ func (c *ModelRegistry) GetStatus() *common.Status {
return &c.Status.Status
}

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

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

func (c *ModelRegistry) GetReleaseStatus() *[]common.ComponentRelease {
return &c.Status.Releases
}
Expand Down
Loading
Loading