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 all 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
14 changes: 2 additions & 12 deletions pkg/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ func (s *Operator) Run(ctx context.Context, controller *controllercmd.Controller
}

// the metrics client will connect to prometheus and scrape a small set of metrics
// TODO: the oauth-proxy and delegating authorizer do not support Impersonate-User,
// so we do not impersonate gather
metricsGatherKubeConfig := rest.CopyConfig(controller.KubeConfig)
metricsGatherKubeConfig.CAFile = metricCAFile
metricsGatherKubeConfig.NegotiatedSerializer = scheme.Codecs
Expand All @@ -86,7 +84,7 @@ func (s *Operator) Run(ctx context.Context, controller *controllercmd.Controller

// If we fail, it's likely due to the service CA not existing yet. Warn and continue,
// and when the service-ca is loaded we will be restarted.
gatherKubeClient, err := kubernetes.NewForConfig(gatherProtoKubeConfig)
_, err = kubernetes.NewForConfig(gatherProtoKubeConfig)
if err != nil {
return err
}
Expand All @@ -103,7 +101,7 @@ func (s *Operator) Run(ctx context.Context, controller *controllercmd.Controller

// the status controller initializes the cluster operator object and retrieves
// the last sync time, if any was set
statusReporter := status.NewController(configClient, gatherKubeClient.CoreV1(), configObserver, os.Getenv("POD_NAMESPACE"))
statusReporter := status.NewController(configClient, configObserver, os.Getenv("POD_NAMESPACE"))

var anonymizer *anonymization.Anonymizer
if anonymization.IsObfuscationEnabled(configObserver) {
Expand Down Expand Up @@ -148,14 +146,6 @@ func (s *Operator) Run(ctx context.Context, controller *controllercmd.Controller
uploader := insightsuploader.New(recdriver, insightsClient, configObserver, statusReporter, initialDelay)
statusReporter.AddSources(uploader)

// TODO: future ideas
//
// * poll periodically for new insights commands to run, then delegate
// * periodically dump crashlooping pod logs / save their messages
// * watch cluster version for an upgrade, go into extra capture mode
// * gather heap dumps from core components when master memory is above
// a threshold

// start reporting status now that all controller loops are added as sources
if err = statusReporter.Start(ctx); err != nil {
return fmt.Errorf("unable to set initial cluster status: %v", err)
Expand Down
101 changes: 101 additions & 0 deletions pkg/controller/status/conditions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package status

import (
configv1 "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 configv1.ClusterStatusConditionType = "Disabled"
// InsightsUploadDegraded defines the condition type (when set to True) when an archive can't be successfully uploaded
InsightsUploadDegraded configv1.ClusterStatusConditionType = "UploadDegraded"
// InsightsDownloadDegraded defines the condition type (when set to True) when the Insights report can't be successfully downloaded
InsightsDownloadDegraded configv1.ClusterStatusConditionType = "InsightsDownloadDegraded"
)

type conditionsMap map[configv1.ClusterStatusConditionType]configv1.ClusterOperatorStatusCondition

type conditions struct {
entryMap conditionsMap
}

func newConditions(cos *configv1.ClusterOperatorStatus, time metav1.Time) *conditions {
entries := map[configv1.ClusterStatusConditionType]configv1.ClusterOperatorStatusCondition{
configv1.OperatorAvailable: {
Type: configv1.OperatorAvailable,
Status: configv1.ConditionUnknown,
LastTransitionTime: time,
Reason: "",
},
configv1.OperatorProgressing: {
Type: configv1.OperatorProgressing,
Status: configv1.ConditionUnknown,
LastTransitionTime: time,
Reason: "",
},
configv1.OperatorDegraded: {
Type: configv1.OperatorDegraded,
Status: configv1.ConditionUnknown,
LastTransitionTime: time,
Reason: "",
},
}

for _, c := range cos.Conditions {
entries[c.Type] = c
}

return &conditions{
entryMap: entries,
}
}

func (c *conditions) setCondition(condition configv1.ClusterStatusConditionType,
status configv1.ConditionStatus, reason, message 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] = configv1.ClusterOperatorStatusCondition{
Type: condition,
Status: status,
Reason: reason,
Message: message,
LastTransitionTime: lastTime,
}
}

c.entryMap = entries
}

func (c *conditions) removeCondition(condition configv1.ClusterStatusConditionType) {
delete(c.entryMap, condition)
}

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

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

func (c *conditions) entries() []configv1.ClusterOperatorStatusCondition {
var res []configv1.ClusterOperatorStatusCondition
for _, v := range c.entryMap {
res = append(res, v)
}
return res
}
Loading