Skip to content

Commit

Permalink
Adding csm-status to driver and modules (merge to main) (#455)
Browse files Browse the repository at this point in the history
* Adding csm-status to driver and modules

* calculating node status

* fix lint errors

---------

Co-authored-by: panigs7 <[email protected]>
  • Loading branch information
abhi16394 and panigs7 authored Feb 13, 2024
1 parent 0aec78d commit a0a79d6
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ spec:
labels:
app.kubernetes.io/name: karavi-metrics-powerflex
app.kubernetes.io/instance: karavi
csm: <NAME>
spec:
serviceAccount: karavi-metrics-powerflex-controller
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ spec:
labels:
app.kubernetes.io/name: karavi-metrics-powermax
app.kubernetes.io/instance: karavi
csm: <NAME>
spec:
serviceAccountName: karavi-metrics-powermax-controller
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ spec:
labels:
app.kubernetes.io/name: karavi-metrics-powerscale
app.kubernetes.io/instance: karavi
csm: <NAME>
spec:
serviceAccount: karavi-metrics-powerscale-controller
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ spec:
labels:
app.kubernetes.io/name: otel-collector
app.kubernetes.io/instance: karavi-observability
csm: <NAME>
spec:
volumes:
- name: tls-secret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ spec:
labels:
app.kubernetes.io/name: karavi-topology
app.kubernetes.io/instance: karavi-observability
csm: <NAME>
spec:
volumes:
- name: karavi-topology-secret-volume
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ spec:
labels:
app.kubernetes.io/name: karavi-metrics-powerflex
app.kubernetes.io/instance: karavi
csm: <NAME>
spec:
serviceAccount: karavi-metrics-powerflex-controller
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ spec:
labels:
app.kubernetes.io/name: karavi-metrics-powermax
app.kubernetes.io/instance: karavi
csm: <NAME>
spec:
serviceAccountName: karavi-metrics-powermax-controller
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ spec:
labels:
app.kubernetes.io/name: karavi-metrics-powerscale
app.kubernetes.io/instance: karavi
csm: <NAME>
spec:
serviceAccount: karavi-metrics-powerscale-controller
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ spec:
labels:
app.kubernetes.io/name: otel-collector
app.kubernetes.io/instance: karavi-observability
csm: <NAME>
spec:
volumes:
- name: tls-secret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ spec:
labels:
app.kubernetes.io/name: karavi-topology
app.kubernetes.io/instance: karavi-observability
csm: <NAME>
spec:
volumes:
- name: karavi-topology-secret-volume
Expand Down
72 changes: 40 additions & 32 deletions pkg/utils/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,7 @@ func getDaemonSetStatus(ctx context.Context, instance *csmv1.ContainerStorageMod

func calculateState(ctx context.Context, instance *csmv1.ContainerStorageModule, r ReconcileCSM, newStatus *csmv1.ContainerStorageModuleStatus) (bool, error) {
log := logger.GetLogger(ctx)
running := false
// appEnabled := false
// var appRunning bool
// obsEnabled := false
// var obsRunning bool
// modrunning := false
running := true
var err error
// TODO: Currently commented this block of code as the API used to get the latest deployment status is not working as expected
// TODO: Can be uncommented once this issues gets sorted out
Expand All @@ -338,36 +333,33 @@ func calculateState(ctx context.Context, instance *csmv1.ContainerStorageModule,
controllerReplicas := newStatus.ControllerStatus.Desired
controllerStatus := newStatus.ControllerStatus

newStatus.State = constants.Failed
newStatus.State = constants.Succeeded
log.Infof("deployment controllerReplicas [%s]", controllerReplicas)
log.Infof("deployment controllerStatus.Available [%s]", controllerStatus.Available)

log.Infof("daemonset expected [%d]", expected)
log.Infof("daemonset nodeStatus.Available [%s]", nodeStatus.Available)

for _, module := range instance.Spec.Modules {
moduleStatus, exists := checkModuleStatus[module.Name]
if exists && module.Enabled {
moduleRunning, err := moduleStatus(ctx, instance, r, newStatus)
if err != nil {
log.Infof("status for Application-Mobility err msg [%s]", err.Error())
}
if (controllerReplicas == controllerStatus.Available) && (fmt.Sprintf("%d", expected) == nodeStatus.Available) {
for _, module := range instance.Spec.Modules {
moduleStatus, exists := checkModuleStatus[module.Name]
if exists && module.Enabled {
moduleRunning, err := moduleStatus(ctx, instance, r, newStatus)
if err != nil {
log.Infof("status for module err msg [%s]", err.Error())
}

if moduleRunning {
if (controllerReplicas == controllerStatus.Available) && (fmt.Sprintf("%d", expected) == nodeStatus.Available) {
running = true
newStatus.State = constants.Succeeded
} else {
if !moduleRunning {
running = false
newStatus.State = constants.Failed
log.Infof("%s module not running", module)
break
}
} else {
running = false
newStatus.State = constants.Failed
log.Infof("%s module not running", module)
break

}
}
} else {
running = false
newStatus.State = constants.Failed
}

log.Infof("calculate overall state [%s]", newStatus.State)
Expand Down Expand Up @@ -655,8 +647,8 @@ func appMobStatusCheck(ctx context.Context, instance *csmv1.ContainerStorageModu
appMobRunning := false
veleroRunning := false
var daemonRunning bool
readyPods := 0
expected := 2
var readyPods int
var notreadyPods int
for _, m := range instance.Spec.Modules {
if m.Name == csmv1.ApplicationMobility {
for _, c := range m.Components {
Expand Down Expand Up @@ -732,10 +724,14 @@ func appMobStatusCheck(ctx context.Context, instance *csmv1.ContainerStorageModu
for _, pod := range podList.Items {
if pod.Status.Phase == corev1.PodRunning {
readyPods++
} else {
notreadyPods++
}
}

if readyPods == expected {
if notreadyPods > 0 {
daemonRunning = false
} else {
daemonRunning = true
}

Expand All @@ -760,10 +756,6 @@ func appMobStatusCheck(ctx context.Context, instance *csmv1.ContainerStorageModu

// observabilityStatusCheck - calculate success state for observability module
func observabilityStatusCheck(ctx context.Context, instance *csmv1.ContainerStorageModule, r ReconcileCSM, _ *csmv1.ContainerStorageModuleStatus) (bool, error) {
// log := logger.GetLogger(ctx)
// Observability launches three pods in the karavi namespace
// expectedObservabilityPods := 3
// readyPods := 0
topologyEnabled := false
otelEnabled := false
certEnabled := false
Expand Down Expand Up @@ -871,5 +863,21 @@ func observabilityStatusCheck(ctx context.Context, instance *csmv1.ContainerStor
return otelRunning && metricsRunning && topologyRunning, nil
}

if certEnabled && otelEnabled && metricsEnabled && !topologyEnabled {
return certManagerRunning && certManagerCainInjectorRunning && certManagerWebhookRunning && otelRunning && metricsRunning, nil
}

if !certEnabled && otelEnabled && metricsEnabled && !topologyEnabled {
return otelRunning && metricsRunning, nil
}

if certEnabled && metricsEnabled && !topologyEnabled && !otelEnabled {
return certManagerRunning && certManagerCainInjectorRunning && certManagerWebhookRunning && metricsRunning, nil
}

if !certEnabled && metricsEnabled && !topologyEnabled && !otelEnabled {
return metricsRunning, nil
}

return false, nil
}

0 comments on commit a0a79d6

Please sign in to comment.