Skip to content

Commit

Permalink
Add ManagementStateController
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminapetersen committed Jul 29, 2019
1 parent 3b2ab78 commit caad7e8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 94 deletions.
1 change: 1 addition & 0 deletions pkg/api/api.go
Expand Up @@ -7,6 +7,7 @@ const (

// consts to maintain existing names of various sub-resources
const (
ClusterOperatorName = "console"
OpenShiftConsoleName = "console"
OpenShiftConsoleNamespace = TargetNamespace
OpenShiftConsoleOperatorNamespace = "openshift-console-operator"
Expand Down
93 changes: 0 additions & 93 deletions pkg/console/operator/status.go
Expand Up @@ -51,9 +51,6 @@ import (
const (
reasonAsExpected = "AsExpected"
reasonWorkloadFailing = "WorkloadFailing"
reasonUnmanaged = "ManagementStateUnmanaged"
reasonRemoved = "ManagementStateRemoved"
reasonInvalid = "ManagementStateInvalid"
reasonSyncLoopProgressing = "SyncLoopProgressing"
reasonSyncError = "SynchronizationError"
reasonNoPodsAvailable = "NoPodsAvailable"
Expand Down Expand Up @@ -235,96 +232,6 @@ func (c *consoleOperator) ConditionResourceSyncDegraded(operatorConfig *operator
return operatorConfig
}

func (c *consoleOperator) ConditionsManagementStateUnmanaged(operatorConfig *operatorsv1.Console) *operatorsv1.Console {
v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{
Type: operatorsv1.OperatorStatusTypeAvailable,
// See https://github.com/openshift/api/pull/206
// While the ConditionUnknown state seems to be the correct fit, the current understanding is that
// If the operator is fulfilling the user's desired state, set Available:true
// Status: operatorsv1.ConditionUnknown,
Status: operatorsv1.ConditionTrue,
Reason: reasonUnmanaged,
Message: "The operator is in an unmanaged state, therefore its availability is unknown.",
LastTransitionTime: metav1.Now(),
})
v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{
Type: operatorsv1.OperatorStatusTypeProgressing,
Status: operatorsv1.ConditionFalse,
Reason: reasonUnmanaged,
Message: "The operator is in an unmanaged state, therefore no changes are being applied.",
LastTransitionTime: metav1.Now(),
})
v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{
Type: operatorsv1.OperatorStatusTypeDegraded,
Status: operatorsv1.ConditionFalse,
Reason: reasonUnmanaged,
Message: "The operator is in an unmanaged state, therefore no operator actions are degraded.",
LastTransitionTime: metav1.Now(),
})

return operatorConfig
}

func (c *consoleOperator) ConditionsManagementStateRemoved(operatorConfig *operatorsv1.Console) *operatorsv1.Console {
v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{
Type: operatorsv1.OperatorStatusTypeAvailable,
// See https://github.com/openshift/api/pull/206
// At present, Available is the gate for upgrades. The removal of an operand should NOT cause
// an upgrade to fail. Therefore, ManagementState:Removed should delete the operand (console),
// BUT should still report Available:True. Hopefully this will change.
Status: operatorsv1.ConditionTrue,
Reason: reasonRemoved,
Message: "The operator is in a removed state, the console has been removed.",
LastTransitionTime: metav1.Now(),
})
v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{
Type: operatorsv1.OperatorStatusTypeProgressing,
Status: operatorsv1.ConditionFalse,
Reason: reasonRemoved,
Message: "The operator is in a removed state, therefore no changes are being applied.",
LastTransitionTime: metav1.Now(),
})
v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{
Type: operatorsv1.OperatorStatusTypeDegraded,
Status: operatorsv1.ConditionFalse,
Reason: reasonRemoved,
Message: "The operator is in a removed state, therefore no operator actions are degraded.",
LastTransitionTime: metav1.Now(),
})

return operatorConfig
}

// If ManagementState is invalid,
// We don't know if the operand is available bc we exit the sync loop w/o assessing resources
// We aren't progressing because we exit the sync loop
// We don't know if we are degraded because we exit the sync loop
func (c *consoleOperator) ConditionsManagementStateInvalid(operatorConfig *operatorsv1.Console) *operatorsv1.Console {
v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{
Type: operatorsv1.OperatorStatusTypeAvailable,
Status: operatorsv1.ConditionUnknown,
Reason: reasonInvalid,
Message: "The operator management state is invalid",
LastTransitionTime: metav1.Now(),
})
v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{
Type: operatorsv1.OperatorStatusTypeProgressing,
Status: operatorsv1.ConditionFalse,
Reason: reasonInvalid,
Message: "The operator management state is invalid",
LastTransitionTime: metav1.Now(),
})
v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{
Type: operatorsv1.OperatorStatusTypeDegraded,
Status: operatorsv1.ConditionUnknown,
Reason: reasonInvalid,
Message: "The operator management state is invalid",
LastTransitionTime: metav1.Now(),
})

return operatorConfig
}

func (c *consoleOperator) ConditionsDefault(operatorConfig *operatorsv1.Console) *operatorsv1.Console {
v1helpers.SetOperatorCondition(&operatorConfig.Status.Conditions, operatorsv1.OperatorCondition{
Type: operatorsv1.OperatorStatusTypeAvailable,
Expand Down
6 changes: 5 additions & 1 deletion pkg/console/starter/starter.go
Expand Up @@ -5,6 +5,8 @@ import (
"os"
"time"

"github.com/openshift/library-go/pkg/operator/management"

// kube
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -154,7 +156,7 @@ func RunOperator(ctx *controllercmd.ControllerContext) error {
versionRecorder.SetVersion("operator", os.Getenv("RELEASE_VERSION"))

clusterOperatorStatus := status.NewClusterOperatorStatusController(
"console",
api.ClusterOperatorName,
[]configv1.ObjectReference{
{Group: operatorv1.GroupName, Resource: "consoles", Name: api.ConfigResourceName},
{Group: configv1.GroupName, Resource: "consoles", Name: api.ConfigResourceName},
Expand All @@ -175,6 +177,7 @@ func RunOperator(ctx *controllercmd.ControllerContext) error {
)

configUpgradeableController := unsupportedconfigoverridescontroller.NewUnsupportedConfigOverridesController(operatorClient, ctx.EventRecorder)
managementStateController := management.NewOperatorManagementStateController(api.ClusterOperatorName, operatorClient, ctx.EventRecorder)

for _, informer := range []interface {
Start(stopCh <-chan struct{})
Expand All @@ -194,6 +197,7 @@ func RunOperator(ctx *controllercmd.ControllerContext) error {
go resourceSyncer.Run(1, ctx.Done())
go clusterOperatorStatus.Run(1, ctx.Done())
go configUpgradeableController.Run(1, ctx.Done())
go managementStateController.Run(1, ctx.Done())

<-ctx.Done()
return fmt.Errorf("stopped")
Expand Down

0 comments on commit caad7e8

Please sign in to comment.