Skip to content

Commit 36ab76e

Browse files
authored
ODLM updated status projection (#894)
* initial commit * clean up debugging, add managedby logic Signed-off-by: Ben Luzarraga <[email protected]> * add subresourcewriter, solve reconciliation problem Signed-off-by: Ben Luzarraga <[email protected]> * add services to operandrequest crd Signed-off-by: Ben Luzarraga <[email protected]> * linter changes Signed-off-by: Ben Luzarraga <[email protected]> * linter changes Signed-off-by: Ben Luzarraga <[email protected]> * linter changes Signed-off-by: Ben Luzarraga <[email protected]> * linter changes Signed-off-by: Ben Luzarraga <[email protected]> * linter changes Signed-off-by: Ben Luzarraga <[email protected]> * add x-kubernetes-preserve-unknown-fields to crd --------- Signed-off-by: Ben Luzarraga <[email protected]> Co-authored-by: Ben Luzarraga <[email protected]>
1 parent 9714a1f commit 36ab76e

File tree

9 files changed

+278
-10
lines changed

9 files changed

+278
-10
lines changed

api/v1alpha1/operandconfig_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (r *OperandConfig) GetService(operandName string) *ConfigService {
142142
return nil
143143
}
144144

145-
//InitConfigServiceStatus initializes service status in the OperandConfig instance.
145+
// InitConfigServiceStatus initializes service status in the OperandConfig instance.
146146
func (r *OperandConfig) InitConfigServiceStatus() {
147147
r.Status.ServiceStatus = make(map[string]CrStatus)
148148

api/v1alpha1/operandrequest_types.go

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
package v1alpha1
1818

1919
import (
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.
153187
type 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+
376460
func (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+
423525
func 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.
503605
func (r *OperandRequest) InitRequestStatus() bool {
504606
isInitialized := true
505607
if r.Status.Phase == "" {

bundle/manifests/operator.ibm.com_operandrequests.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,52 @@ spec:
217217
phase:
218218
description: Phase is the cluster running phase.
219219
type: string
220+
services:
221+
description: Status for each of the services and their dependent resources specified in this request
222+
type: array
223+
items:
224+
type: object
225+
properties:
226+
namespace:
227+
type: string
228+
operatorName:
229+
type: string
230+
resources:
231+
description: Status of CRs created by ODLM that belong to a given service. This info comes from CRs like IM's Authentication and is populated by ODLM.
232+
type: array
233+
items:
234+
type: object
235+
properties:
236+
apiVersion:
237+
type: string
238+
kind:
239+
type: string
240+
managedResources:
241+
description: Status of resources that fall under the umbrella of the CR in the level above.
242+
type: array
243+
items:
244+
type: object
245+
properties:
246+
apiVersion:
247+
type: string
248+
kind:
249+
type: string
250+
namespace:
251+
type: string
252+
objectName:
253+
type: string
254+
status:
255+
type: string
256+
namespace:
257+
type: string
258+
objectName:
259+
type: string
260+
status:
261+
type: string
262+
status:
263+
type: string
220264
type: object
265+
x-kubernetes-preserve-unknown-fields: true
221266
type: object
222267
served: true
223268
storage: true

controllers/k8sutil/cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func NewODLMCache(isolatedModeEnable bool, namespaces []string, gvkLabelMap map[
8787
}
8888
}
8989

90-
//buildInformerMap generates informerMap of the specified resource
90+
// buildInformerMap generates informerMap of the specified resource
9191
func buildInformerMap(config *rest.Config, opts cache.Options, resync time.Duration, clusterGVKList []schema.GroupVersionKind) (map[schema.GroupVersionKind]toolscache.SharedIndexInformer, error) {
9292
// Initialize informerMap
9393
informerMap := make(map[schema.GroupVersionKind]toolscache.SharedIndexInformer)

0 commit comments

Comments
 (0)