-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
const ready ConditionType = "Ready" | ||
|
||
type ConditionType string | ||
|
||
type Condition struct { | ||
// Type indicates the scope of RabbitmqCluster status addressed by the condition. | ||
Type ConditionType `json:"type"` | ||
// True, False, or Unknown | ||
Status corev1.ConditionStatus `json:"status"` | ||
// The last time this Condition type changed. | ||
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` | ||
// One word, camel-case reason for current status of the condition. | ||
Reason string `json:"reason,omitempty"` | ||
// Full text reason for current status of the condition. | ||
Message string `json:"message,omitempty"` | ||
} | ||
|
||
// Ready indicates that the last Create/Update operator on the CR was successful. | ||
func Ready() Condition { | ||
return Condition{ | ||
Type: ready, | ||
Status: corev1.ConditionTrue, | ||
LastTransitionTime: metav1.Now(), | ||
Reason: "SuccessfulCreateOrUpdate", | ||
} | ||
} | ||
|
||
// NotReady indicates that the last Create/Update operator on the CR failed. | ||
func NotReady(msg string) Condition { | ||
return Condition{ | ||
Type: ready, | ||
Status: corev1.ConditionFalse, | ||
LastTransitionTime: metav1.Now(), | ||
Reason: "FailedCreateOrUpdate", | ||
Message: msg, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
var _ = Describe("Conditions", func() { | ||
Context("Ready", func() { | ||
It("returns 'Ready' condition set to true", func() { | ||
c := Ready() | ||
Expect(string(c.Type)).To(Equal("Ready")) | ||
Expect(c.Status).To(Equal(corev1.ConditionTrue)) | ||
Expect(c.Reason).To(Equal("SuccessfulCreateOrUpdate")) | ||
Expect(c.LastTransitionTime).NotTo(Equal(metav1.Time{})) // has been set; not empty | ||
}) | ||
|
||
}) | ||
|
||
Context("NotReady", func() { | ||
It("returns 'Ready' condition set to false", func() { | ||
c := NotReady("fail to declare queue") | ||
Expect(string(c.Type)).To(Equal("Ready")) | ||
Expect(c.Status).To(Equal(corev1.ConditionFalse)) | ||
Expect(c.Reason).To(Equal("FailedCreateOrUpdate")) | ||
Expect(c.Message).To(Equal("fail to declare queue")) | ||
Expect(c.LastTransitionTime).NotTo(Equal(metav1.Time{})) // has been set; not empty | ||
}) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.