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
36 changes: 13 additions & 23 deletions internal/controller/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package controller

import (
"context"
"encoding/json"
"fmt"
"math/rand"
"strconv"
Expand Down Expand Up @@ -110,7 +109,14 @@ func RemoveOLSConfig(
return false, err
}

return true, nil
_, err = GetOLSConfig(ctx, helper)
if err != nil && k8s_errors.IsNotFound(err) {
return true, nil
} else if err != nil {
return false, err
}

return false, nil
}

// GetOLSConfig returns OLSConfig if there is one present in the cluster.
Expand Down Expand Up @@ -267,36 +273,20 @@ func PatchOLSConfig(
return nil
}

// IsOLSConfigReady returns true if required conditions are true for OLSConfig
// IsOLSConfigReady returns true if OLSConfig's overallStatus is Ready
func IsOLSConfigReady(ctx context.Context, helper *common_helper.Helper) (bool, error) {
olsConfig, err := GetOLSConfig(ctx, helper)
if err != nil {
return false, err
}

olsConfigStatusList, found, err := uns.NestedSlice(olsConfig.Object, "status", "conditions")
if !found {
return false, err
}

jsonData, err := json.Marshal(olsConfigStatusList)
if err != nil {
return false, fmt.Errorf("failed to marshal OLSConfig status: %w", err)
}

var OLSConfigConditions []metav1.Condition
err = json.Unmarshal(jsonData, &OLSConfigConditions)
overallStatus, found, err := uns.NestedString(olsConfig.Object, "status", "overallStatus")
if err != nil {
return false, fmt.Errorf("failed to unmarshal JSON containing condition.Conditions: %w", err)
return false, err
}

requiredConditionTypes := []string{"ConsolePluginReady", "CacheReady", "ApiReady", "Reconciled"}
for _, OLSConfigCondition := range OLSConfigConditions {
for _, requiredConditionType := range requiredConditionTypes {
if OLSConfigCondition.Type == requiredConditionType && OLSConfigCondition.Status != metav1.ConditionTrue {
return false, OLSConfigPing(ctx, helper)
}
}
if !found || overallStatus != "Ready" {
return false, OLSConfigPing(ctx, helper)
}

return true, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ status:
- type: ApiReady
status: "True"
reason: Available
- type: Reconciled
status: "True"
reason: Available
overallStatus: Ready
---
apiVersion: lightspeed.openstack.org/v1beta1
kind: OpenStackLightspeed
Expand Down
Loading