Skip to content

Commit

Permalink
Merge pull request #38 from cynepco3hahue/change_condition_type
Browse files Browse the repository at this point in the history
Use conditions status from core package
  • Loading branch information
Artyom Lukianov authored Aug 12, 2019
2 parents 0089716 + 99a302c commit 4a7f171
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,6 @@ const (
OperatorDegraded OperatorConditionType = "Degraded"
)

// OperatorConditionStatus contains the status of the operator condition.
type OperatorConditionStatus string

// These are valid condition statuses. "ConditionTrue" means a resource is in the condition.
// "ConditionFalse" means a resource is not in the condition. "ConditionUnknown" means kubernetes
// can't decide if a resource is in the condition or not. In the future, we could add other
// intermediate conditions, e.g. ConditionDegraded.
const (
ConditionTrue OperatorConditionStatus = "True"
ConditionFalse OperatorConditionStatus = "False"
ConditionUnknown OperatorConditionStatus = "Unknown"
)

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down Expand Up @@ -86,7 +73,7 @@ type MachineRemediationOperatorStatusCondition struct {
Type OperatorConditionType `json:"type"`

// status of the condition, one either True or False.
Status OperatorConditionStatus `json:"status"`
Status corev1.ConditionStatus `json:"status"`

// lastTransitionTime is the time of the last update to the current status object.
LastTransitionTime metav1.Time `json:"lastTransitionTime"`
Expand Down
19 changes: 10 additions & 9 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/golang/glog"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -218,17 +219,17 @@ func (r *ReconcileMachineRemediationOperator) statusAvailable(mro *mrv1.MachineR
mro.Status.Conditions = []mrv1.MachineRemediationOperatorStatusCondition{
{
Type: mrv1.OperatorAvailable,
Status: mrv1.ConditionTrue,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.Time{Time: now},
},
{
Type: mrv1.OperatorProgressing,
Status: mrv1.ConditionFalse,
Status: corev1.ConditionFalse,
LastTransitionTime: metav1.Time{Time: now},
},
{
Type: mrv1.OperatorDegraded,
Status: mrv1.ConditionFalse,
Status: corev1.ConditionFalse,
LastTransitionTime: metav1.Time{Time: now},
},
}
Expand All @@ -240,17 +241,17 @@ func (r *ReconcileMachineRemediationOperator) statusDegraded(mro *mrv1.MachineRe
mro.Status.Conditions = []mrv1.MachineRemediationOperatorStatusCondition{
{
Type: mrv1.OperatorAvailable,
Status: mrv1.ConditionFalse,
Status: corev1.ConditionFalse,
LastTransitionTime: metav1.Time{Time: now},
},
{
Type: mrv1.OperatorProgressing,
Status: mrv1.ConditionFalse,
Status: corev1.ConditionFalse,
LastTransitionTime: metav1.Time{Time: now},
},
{
Type: mrv1.OperatorDegraded,
Status: mrv1.ConditionTrue,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.Time{Time: now},
Reason: reason,
Message: message,
Expand All @@ -264,19 +265,19 @@ func (r *ReconcileMachineRemediationOperator) statusProgressing(mro *mrv1.Machin
mro.Status.Conditions = []mrv1.MachineRemediationOperatorStatusCondition{
{
Type: mrv1.OperatorAvailable,
Status: mrv1.ConditionFalse,
Status: corev1.ConditionFalse,
LastTransitionTime: metav1.Time{Time: now},
},
{
Type: mrv1.OperatorProgressing,
Status: mrv1.ConditionTrue,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.Time{Time: now},
Reason: reason,
Message: message,
},
{
Type: mrv1.OperatorDegraded,
Status: mrv1.ConditionFalse,
Status: corev1.ConditionFalse,
LastTransitionTime: metav1.Time{Time: now},
},
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/operator/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func init() {

func verifyMachineRemediationOperatorConditions(
conditions []mrv1.MachineRemediationOperatorStatusCondition,
availabe mrv1.OperatorConditionStatus,
degraded mrv1.OperatorConditionStatus,
progressing mrv1.OperatorConditionStatus,
availabe corev1.ConditionStatus,
degraded corev1.ConditionStatus,
progressing corev1.ConditionStatus,
) bool {
for _, c := range conditions {
switch c.Type {
Expand Down Expand Up @@ -131,9 +131,9 @@ func TestReconcile(t *testing.T) {
assert.NoError(t, r.client.Get(context.TODO(), key, updatedMro))
assert.Equal(t, true, verifyMachineRemediationOperatorConditions(
updatedMro.Status.Conditions,
mrv1.ConditionFalse,
mrv1.ConditionFalse,
mrv1.ConditionTrue,
corev1.ConditionFalse,
corev1.ConditionFalse,
corev1.ConditionTrue,
))

// update all deployments status to have desired number of replicas
Expand All @@ -152,9 +152,9 @@ func TestReconcile(t *testing.T) {
assert.NoError(t, r.client.Get(context.TODO(), key, updatedMro))
assert.Equal(t, true, verifyMachineRemediationOperatorConditions(
updatedMro.Status.Conditions,
mrv1.ConditionTrue,
mrv1.ConditionFalse,
mrv1.ConditionFalse,
corev1.ConditionTrue,
corev1.ConditionFalse,
corev1.ConditionFalse,
))

// update mro object deletion timestamp
Expand Down

0 comments on commit 4a7f171

Please sign in to comment.