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
13 changes: 0 additions & 13 deletions pkg/apis/noobaa/v1alpha1/backingstore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,6 @@ type BackingStoreMode struct {
TimeStamp string `json:"timeStamp,omitempty"`
}

// BackingStorePhaseInfo defines the phase and the updated Mode of BackingStore
type BackingStorePhaseInfo struct {
// Phase specifies the phase of backingstore
// +optional
Phase BackingStorePhase `json:"phase,omitempty"`
// Reason specifies the reason of backingstore phase
// +optional
Reason string `json:"reason,omitempty"`
// Message specifies the message of backingstore phase
// +optional
Message string `json:"message,omitempty"`
}

// StoreType is the backing store type enum
type StoreType string

Expand Down
16 changes: 0 additions & 16 deletions pkg/apis/noobaa/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 33 additions & 24 deletions pkg/backingstore/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,36 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

var bsModeToPhaseMap map[string]nbv1.BackingStorePhaseInfo
// ModeInfo holds local information for a backing store mode.
type ModeInfo struct {
Phase nbv1.BackingStorePhase
Severity string
}

var bsModeInfoMap map[string]ModeInfo

func init() {
bsModeToPhaseMap = modeToPhaseMap()
bsModeInfoMap = modeInfoMap()
}

func modeToPhaseMap() map[string]nbv1.BackingStorePhaseInfo {
return map[string]nbv1.BackingStorePhaseInfo{
"INITIALIZING": {nbv1.BackingStorePhaseReady, "BackingStorePhaseReady", "Backing store mode: INITALIZING"},
"DELETING": {nbv1.BackingStorePhaseReady, "BackingStorePhaseReady", "Backing store mode: DELETING"},
"SCALING": {nbv1.BackingStorePhaseReady, "BackingStorePhaseReady", "Backing store mode: SCALING"},
"MOST_NODES_ISSUES": {nbv1.BackingStorePhaseReady, "BackingStorePhaseReady", "Backing store mode: MOST_NODES_ISSUES"},
"MANY_NODES_ISSUES": {nbv1.BackingStorePhaseReady, "BackingStorePhaseReady", "Backing store mode: MANY_NODES_ISSUES"},
"MOST_STORAGE_ISSUES": {nbv1.BackingStorePhaseReady, "BackingStorePhaseReady", "Backing store mode: MOST_STORAGE_ISSUES"},
"MANY_STORAGE_ISSUES": {nbv1.BackingStorePhaseReady, "BackingStorePhaseReady", "Backing store mode: MANY_STORAGE_ISSUES"},
"MANY_NODES_OFFLINE": {nbv1.BackingStorePhaseReady, "BackingStorePhaseReady", "Backing store mode: MANY_NODES_OFFLINE"},
"LOW_CAPACITY": {nbv1.BackingStorePhaseReady, "BackingStorePhaseReady", "Backing store mode: LOW_CAPACITY"},
"OPTIMAL": {nbv1.BackingStorePhaseReady, "BackingStorePhaseReady", "Backing store mode: OPTIMAL"},
"HAS_NO_NODES": {nbv1.BackingStorePhaseRejected, "BackingStorePhaseRejected", "Backing store mode: HAS_NO_NODES"},
"ALL_NODES_OFFLINE": {nbv1.BackingStorePhaseRejected, "BackingStorePhaseRejected", "Backing store mode: ALL_NODES_OFFLINE"},
"NO_CAPACITY": {nbv1.BackingStorePhaseRejected, "BackingStorePhaseRejected", "Backing store mode: NO_CAPACITY"},
"IO_ERRORS": {nbv1.BackingStorePhaseRejected, "BackingStorePhaseRejected", "Backing store mode: IO_ERRORS"},
"STORAGE_NOT_EXIST": {nbv1.BackingStorePhaseRejected, "BackingStorePhaseRejected", "Backing store mode: STORAGE_NOT_EXIST"},
"AUTH_FAILED": {nbv1.BackingStorePhaseRejected, "BackingStorePhaseRejected", "Backing store mode: AUTH_FAILED"},
func modeInfoMap() map[string]ModeInfo {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nb-ohad Why do you use an init() function to call another function just to return a map when you can create the map directly on the global var - am I missing something?

var bsModeInfoMap = map[string]ModeInfo{
	"INITIALIZING":        {nbv1.BackingStorePhaseReady, corev1.EventTypeNormal},
	"DELETING":            {nbv1.BackingStorePhaseReady, corev1.EventTypeNormal},
	"SCALING":             {nbv1.BackingStorePhaseReady, corev1.EventTypeNormal},
	...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guymguym this was in the original code. I didn't change it. But you are perfectly right.

return map[string]ModeInfo{
"INITIALIZING": {nbv1.BackingStorePhaseReady, corev1.EventTypeNormal},
"DELETING": {nbv1.BackingStorePhaseReady, corev1.EventTypeNormal},
"SCALING": {nbv1.BackingStorePhaseReady, corev1.EventTypeNormal},
"MOST_NODES_ISSUES": {nbv1.BackingStorePhaseReady, corev1.EventTypeWarning},
"MANY_NODES_ISSUES": {nbv1.BackingStorePhaseReady, corev1.EventTypeWarning},
"MOST_STORAGE_ISSUES": {nbv1.BackingStorePhaseReady, corev1.EventTypeWarning},
"MANY_STORAGE_ISSUES": {nbv1.BackingStorePhaseReady, corev1.EventTypeWarning},
"MANY_NODES_OFFLINE": {nbv1.BackingStorePhaseReady, corev1.EventTypeWarning},
"LOW_CAPACITY": {nbv1.BackingStorePhaseReady, corev1.EventTypeWarning},
"OPTIMAL": {nbv1.BackingStorePhaseReady, corev1.EventTypeNormal},
"HAS_NO_NODES": {nbv1.BackingStorePhaseRejected, corev1.EventTypeWarning},
"ALL_NODES_OFFLINE": {nbv1.BackingStorePhaseRejected, corev1.EventTypeWarning},
"NO_CAPACITY": {nbv1.BackingStorePhaseRejected, corev1.EventTypeWarning},
"IO_ERRORS": {nbv1.BackingStorePhaseRejected, corev1.EventTypeWarning},
"STORAGE_NOT_EXIST": {nbv1.BackingStorePhaseRejected, corev1.EventTypeWarning},
"AUTH_FAILED": {nbv1.BackingStorePhaseRejected, corev1.EventTypeWarning},
}
}

Expand Down Expand Up @@ -179,12 +185,15 @@ func (r *Reconciler) Reconcile() (reconcile.Result, error) {
log.Warnf("⏳ Temporary Error: %s", err)
}
} else {
bsPhase, exist := bsModeToPhaseMap[r.BackingStore.Status.Mode.ModeCode]
mode := r.BackingStore.Status.Mode.ModeCode
phaseInfo, exist := bsModeInfoMap[mode]

if exist && bsPhase.Phase != r.BackingStore.Status.Phase {
r.SetPhase(bsPhase.Phase, bsPhase.Message, bsPhase.Reason)
if exist && phaseInfo.Phase != r.BackingStore.Status.Phase {
phaseName := fmt.Sprintf("BackingStorePhase%s", phaseInfo.Phase)
desc := fmt.Sprintf("Backing store mode: %s", mode)
r.SetPhase(phaseInfo.Phase, desc, phaseName)
if r.Recorder != nil {
r.Recorder.Eventf(r.BackingStore, corev1.EventTypeWarning, bsPhase.Reason, bsPhase.Message)
r.Recorder.Eventf(r.BackingStore, phaseInfo.Severity, phaseName, desc)
}
} else {
r.SetPhase(
Expand Down