Skip to content
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
86 changes: 85 additions & 1 deletion api/v3/commonservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
package v3

import (
"sync"
"time"

olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

Expand Down Expand Up @@ -216,8 +220,48 @@ type CommonServiceStatus struct {
// OverallStatus describes whether the Installation for the foundational services has succeeded or not
OverallStatus string `json:"overallStatus,omitempty"`
ConfigStatus ConfigStatus `json:"configStatus,omitempty"`
// Conditions represents the current state of CommonService
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=status,displayName="Conditions",xDescriptors="urn:alm:descriptor:io.kubernetes.conditions"
Conditions []CommonServiceCondition `json:"conditions,omitempty"`
}

// CommonServiceCondition defines the observed condition of CommonService
type CommonServiceCondition struct {
// Type of condition.
// +optional
Type ConditionType `json:"type"`
// Status of the condition, one of True, False, Unknown.
// +optional
Status corev1.ConditionStatus `json:"status"`
// The last time this condition was updated.
// +optional
LastUpdateTime string `json:"lastUpdateTime,omitempty"`
// Last time the condition transitioned from one status to another.
// +optional
LastTransitionTime string `json:"lastTransitionTime,omitempty"`
// The reason for the condition's last transition.
// +optional
Reason string `json:"reason,omitempty"`
// A human readable message indicating details about the transition.
// +optional
Message string `json:"message,omitempty"`
}

// ConditionType is the condition of a service.
type ConditionType string

// ResourceType is the type of condition use.
type ResourceType string

const (
ConditionTypeBlocked ConditionType = "Blocked"
ConditionTypeReady ConditionType = "Ready"
ConditionTypeWarning ConditionType = "Warning"
ConditionTypeError ConditionType = "Error"
ConditionTypePending ConditionType = "Pending"
)

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +operator-sdk:gen-csv:customresourcedefinitions.displayName="CommonService"
Expand All @@ -240,7 +284,6 @@ type CommonService struct {
}

// +kubebuilder:object:root=true

// CommonServiceList contains a list of CommonService
type CommonServiceList struct {
metav1.TypeMeta `json:",inline"`
Expand Down Expand Up @@ -293,6 +336,47 @@ func (r *CommonService) UpdateNonMasterConfigStatus(CSData *CSData) {
r.UpdateTopologyCR(CSData)
}

// NewCondition Returns a new condition with the given values for CommonService
func newCondition(condType ConditionType, status corev1.ConditionStatus, reason, message string) *CommonServiceCondition {
now := time.Now().Format(time.RFC3339)
return &CommonServiceCondition{
Type: condType,
Status: status,
LastUpdateTime: now,
LastTransitionTime: now,
Reason: reason,
Message: message,
}
}

// GetCondition returns the condition status by given condition type and message
func getCondition(conds *[]CommonServiceCondition, condtype ConditionType, msg string) (int, *CommonServiceCondition) {
for i, condition := range *conds {
if condtype == condition.Type && msg == condition.Message {
return i, &condition
}
}
return -1, nil
}

// SetCondition append a new condition status
func (r *CommonService) setCondition(condition CommonServiceCondition) {
pos, cp := getCondition(&r.Status.Conditions, condition.Type, condition.Message)
if cp != nil {
r.Status.Conditions[pos] = condition
} else {
r.Status.Conditions = append(r.Status.Conditions, condition)
}
}

// SetCreatingCondition creates a new condition status
func (r *CommonService) SetCreatingCondition(name string, condstatus corev1.ConditionStatus, mu sync.Locker) {
mu.Lock()
defer mu.Unlock()
c := newCondition(ConditionTypePending, condstatus, "Creating", "Waiting for CommonService is ready.")
r.setCondition(*c)
}

func (r *CommonService) UpdateTopologyCR(CSData *CSData) {
var masterCRSlice []ConfigurableCR
var csCR ConfigurableCR
Expand Down
20 changes: 20 additions & 0 deletions api/v3/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 @@ -22,7 +22,7 @@ metadata:
]
capabilities: Seamless Upgrades
containerImage: icr.io/cpopen/common-service-operator:latest
createdAt: "2024-03-29T04:11:18Z"
createdAt: "2024-04-02T03:07:28Z"
description: The IBM Cloud Pak foundational services operator is used to deploy IBM foundational services.
nss.operator.ibm.com/managed-operators: ibm-common-service-operator
nss.operator.ibm.com/managed-webhooks: ""
Expand Down
28 changes: 28 additions & 0 deletions bundle/manifests/operator.ibm.com_commonservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,34 @@ spec:
type: string
type: object
type: array
conditions:
description: Conditions represents the current state of CommonService
items:
description: CommonServiceCondition defines the observed condition
of CommonService
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another.
type: string
lastUpdateTime:
description: The last time this condition was updated.
type: string
message:
description: A human readable message indicating details about
the transition.
type: string
reason:
description: The reason for the condition's last transition.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of condition.
type: string
type: object
type: array
configStatus:
description: ConfigStatus describes various configuration currently
applied onto the foundational services installer.
Expand Down
28 changes: 28 additions & 0 deletions config/crd/bases/operator.ibm.com_commonservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,34 @@ spec:
type: string
type: object
type: array
conditions:
description: Conditions represents the current state of CommonService
items:
description: CommonServiceCondition defines the observed condition
of CommonService
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another.
type: string
lastUpdateTime:
description: The last time this condition was updated.
type: string
message:
description: A human readable message indicating details about
the transition.
type: string
reason:
description: The reason for the condition's last transition.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of condition.
type: string
type: object
type: array
configStatus:
description: ConfigStatus describes various configuration currently
applied onto the foundational services installer.
Expand Down