Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 2012069: Refactoring Status controller #498

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
84 changes: 84 additions & 0 deletions pkg/controller/status/conditions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package status

import (
v1 "github.com/openshift/api/config/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
// OperatorDisabled defines the condition type when the operator's primary function has been disabled
OperatorDisabled v1.ClusterStatusConditionType = "Disabled"
// InsightsUploadDegraded defines the condition type (when set to True) when an archive can't be successfully uploaded
InsightsUploadDegraded v1.ClusterStatusConditionType = "UploadDegraded"
// InsightsDownloadDegraded defines the condition type (when set to True) when the Insights report can't be successfully downloaded
InsightsDownloadDegraded v1.ClusterStatusConditionType = "InsightsDownloadDegraded"
)

type conditionsMap map[v1.ClusterStatusConditionType]v1.ClusterOperatorStatusCondition

type conditions struct {
entryMap conditionsMap
}

func newConditions(cos *v1.ClusterOperatorStatus) *conditions {
entries := conditionsMap{}
for _, c := range cos.Conditions {
entries[c.Type] = c
}
return &conditions{
entryMap: entries,
}
}

func (c *conditions) setCondition(condition v1.ClusterStatusConditionType,
status v1.ConditionStatus, message, reason string, lastTime metav1.Time) {
entries := make(conditionsMap)
for k, v := range c.entryMap {
entries[k] = v
}

existing, ok := c.entryMap[condition]
if !ok || existing.Status != status || existing.Reason != reason {
if lastTime.IsZero() {
lastTime = metav1.Now()
}
entries[condition] = v1.ClusterOperatorStatusCondition{
Type: condition,
Status: status,
Reason: reason,
Message: message,
LastTransitionTime: lastTime,
}
}

c.entryMap = entries
}

func (c *conditions) removeCondition(condition v1.ClusterStatusConditionType) {
if !c.hasCondition(condition) {
return
}

entries := make(conditionsMap)
rluders marked this conversation as resolved.
Show resolved Hide resolved
for k, v := range c.entryMap {
if k == condition {
continue
}
entries[k] = v
}

c.entryMap = entries
}

func (c *conditions) hasCondition(condition v1.ClusterStatusConditionType) bool {
_, ok := c.entryMap[condition]
return ok
}

func (c *conditions) findCondition(condition v1.ClusterStatusConditionType) *v1.ClusterOperatorStatusCondition {
existing, ok := c.entryMap[condition]
if ok {
return &existing
}
return nil
}
Loading