From 99a302cf50131dc4543b983ee560fd3bd65c712c Mon Sep 17 00:00:00 2001 From: Artyom Lukianov Date: Mon, 12 Aug 2019 16:11:41 +0300 Subject: [PATCH] Use conditions status from core package --- .../machineremediationoperator_types.go | 15 +-------------- pkg/operator/operator.go | 19 ++++++++++--------- pkg/operator/operator_test.go | 18 +++++++++--------- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/pkg/apis/machineremediation/v1alpha1/machineremediationoperator_types.go b/pkg/apis/machineremediation/v1alpha1/machineremediationoperator_types.go index 6ff9bfd2..c11cf8ea 100644 --- a/pkg/apis/machineremediation/v1alpha1/machineremediationoperator_types.go +++ b/pkg/apis/machineremediation/v1alpha1/machineremediationoperator_types.go @@ -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 @@ -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"` diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index 42d2dc82..3f07ac9a 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -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" @@ -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}, }, } @@ -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, @@ -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}, }, } diff --git a/pkg/operator/operator_test.go b/pkg/operator/operator_test.go index 5a0eb5a9..81b75476 100644 --- a/pkg/operator/operator_test.go +++ b/pkg/operator/operator_test.go @@ -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 { @@ -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 @@ -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