1717package v1alpha1
1818
1919import (
20+ "context"
2021 "strings"
2122 "sync"
2223 "time"
2324
25+ client "sigs.k8s.io/controller-runtime/pkg/client"
26+
2427 gset "github.com/deckarep/golang-set"
2528 corev1 "k8s.io/api/core/v1"
2629 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -149,6 +152,37 @@ type Condition struct {
149152 Message string `json:"message,omitempty"`
150153}
151154
155+ type ResourceStatus struct { //Status of CRs not created by ODLM
156+ ObjectName string `json:"objectName,omitempty"`
157+ APIVersion string `json:"apiVersion,omitempty"`
158+ Namespace string `json:"namespace,omitempty"`
159+ Kind string `json:"kind,omitempty"`
160+ // Type string `json:"type,omitempty"`
161+ Status string `json:"status,omitempty"`
162+ // LastTransitionTime string `json:"lastTransitionTime"` //might need to change the variable type
163+ // Message string `json:"message"`
164+ }
165+ type OperandStatus struct { //Top level CR status ie the CR created by ODLM
166+ ObjectName string `json:"objectName,omitempty"`
167+ APIVersion string `json:"apiVersion,omitempty"`
168+ Namespace string `json:"namespace,omitempty"`
169+ Kind string `json:"kind,omitempty"`
170+ // Type string `json:"type,omitempty"`
171+ Status string `json:"status,omitempty"`
172+ // LastTransitionTime string `json:"lastTransitionTime,omitempty"` //might need to change the variable type
173+ // Message string `json:"message,omitempty"`
174+ ManagedResources []ResourceStatus `json:"managedResources,omitempty"`
175+ }
176+
177+ type ServiceStatus struct { //Top level service status
178+ OperatorName string `json:"operatorName,omitempty"`
179+ Namespace string `json:"namespace,omitempty"`
180+ // Type string `json:"type,omitempty"`
181+ Status string `json:"status,omitempty"`
182+ // LastUpdateTime string `json:"lastTransitionTime,omitempty"`
183+ Resources []OperandStatus `json:"resources,omitempty"`
184+ }
185+
152186// OperandRequestStatus defines the observed state of OperandRequest.
153187type OperandRequestStatus struct {
154188 // Conditions represents the current state of the Request Service.
@@ -162,6 +196,8 @@ type OperandRequestStatus struct {
162196 // +operator-sdk:csv:customresourcedefinitions:type=status,displayName="Phase",xDescriptors="urn:alm:descriptor:io.kubernetes.phase"
163197 // +optional
164198 Phase ClusterPhase `json:"phase,omitempty"`
199+ //Services reflect the status of operands beyond whether they have been created
200+ Services []ServiceStatus `json:"services,omitempty"`
165201}
166202
167203// MemberPhase shows the phase of the operator and operator instance.
@@ -373,6 +409,54 @@ func (r *OperandRequest) RemoveMemberCRStatus(name, CRName, CRKind string, mu sy
373409 }
374410}
375411
412+ func (r * OperandRequest ) SetServiceStatus (ctx context.Context , service ServiceStatus , updater client.StatusClient , mu sync.Locker ) error {
413+ mu .Lock ()
414+ defer mu .Unlock ()
415+ pos , _ := getServiceStatus (& r .Status , service .OperatorName )
416+ if pos != - 1 {
417+ if len (r .Status .Services [pos ].Resources ) == 0 {
418+ r .Status .Services [pos ] = service
419+ updateerr := updater .Status ().Update (ctx , r )
420+ if updateerr != nil {
421+ return updateerr
422+ }
423+ } else {
424+ if r .Status .Services [pos ].Status != service .Status {
425+ r .Status .Services [pos ].Status = service .Status
426+ updateerr := updater .Status ().Update (ctx , r )
427+ if updateerr != nil {
428+ return updateerr
429+ }
430+ }
431+ for i := range service .Resources {
432+ if service .Resources [i ].ObjectName != "" {
433+ resourcePos , _ := getResourceStatus (r .Status .Services [pos ].Resources , service .Resources [i ].ObjectName )
434+ if resourcePos != - 1 {
435+ r .Status .Services [pos ].Resources [resourcePos ] = service .Resources [i ]
436+ updateerr := updater .Status ().Update (ctx , r )
437+ if updateerr != nil {
438+ return updateerr
439+ }
440+ } else {
441+ r .Status .Services [pos ].Resources = append (r .Status .Services [pos ].Resources , service .Resources [i ])
442+ updateerr := updater .Status ().Update (ctx , r )
443+ if updateerr != nil {
444+ return updateerr
445+ }
446+ }
447+ }
448+ }
449+ }
450+ } else {
451+ r .Status .Services = append (r .Status .Services , service )
452+ updateerr := updater .Status ().Update (ctx , r )
453+ if updateerr != nil {
454+ return updateerr
455+ }
456+ }
457+ return nil
458+ }
459+
376460func (r * OperandRequest ) setOperatorReadyCondition (operatorPhase OperatorPhase , name string ) {
377461 if operatorPhase == OperatorRunning {
378462 r .setReadyCondition (name , ResourceTypeOperator , corev1 .ConditionTrue )
@@ -420,6 +504,24 @@ func getMemberStatus(status *OperandRequestStatus, name string) (int, *MemberSta
420504 return - 1 , nil
421505}
422506
507+ func getServiceStatus (status * OperandRequestStatus , name string ) (int , * ServiceStatus ) {
508+ for i , s := range status .Services {
509+ if name == s .OperatorName {
510+ return i , & s
511+ }
512+ }
513+ return - 1 , nil
514+ }
515+
516+ func getResourceStatus (resources []OperandStatus , name string ) (int , * OperandStatus ) {
517+ for i , r := range resources {
518+ if name == resources [i ].ObjectName {
519+ return i , & r
520+ }
521+ }
522+ return - 1 , nil
523+ }
524+
423525func newMemberStatus (name string , operatorPhase OperatorPhase , operandPhase ServicePhase ) MemberStatus {
424526 return MemberStatus {
425527 Name : name ,
@@ -499,7 +601,7 @@ func (r *OperandRequest) GetRegistryKey(req Request) types.NamespacedName {
499601 return types.NamespacedName {Namespace : regNs , Name : regName }
500602}
501603
502- //InitRequestStatus OperandConfig status.
604+ // InitRequestStatus OperandConfig status.
503605func (r * OperandRequest ) InitRequestStatus () bool {
504606 isInitialized := true
505607 if r .Status .Phase == "" {
0 commit comments