Skip to content

Commit

Permalink
Merge pull request #56 from rabbitmq/statusconditions
Browse files Browse the repository at this point in the history
Add and set Status Conditions 'Ready' in all resources
  • Loading branch information
ChunyiLyu committed Mar 12, 2021
2 parents c7dc7d7 + faeb9b0 commit 92c8e73
Show file tree
Hide file tree
Showing 35 changed files with 550 additions and 20 deletions.
2 changes: 2 additions & 0 deletions api/v1alpha1/binding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ type BindingSpec struct {

// BindingStatus defines the observed state of Binding
type BindingStatus struct {
Conditions []Condition `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// Binding is the Schema for the bindings API
type Binding struct {
Expand Down
44 changes: 44 additions & 0 deletions api/v1alpha1/conditions.go
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,
}
}
32 changes: 32 additions & 0 deletions api/v1alpha1/conditions_test.go
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
})
})
})
4 changes: 2 additions & 2 deletions api/v1alpha1/exchange_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ type ExchangeSpec struct {

// ExchangeStatus defines the observed state of Exchange
type ExchangeStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Conditions []Condition `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// Exchange is the Schema for the exchanges API
type Exchange struct {
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha1/policy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ type PolicySpec struct {

// PolicyStatus defines the observed state of Policy
type PolicyStatus struct {
Conditions []Condition `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// Policy is the Schema for the policies API
type Policy struct {
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha1/queue_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ type RabbitmqClusterReference struct {

// QueueStatus defines the observed state of Queue
type QueueStatus struct {
Conditions []Condition `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// Queue is the Schema for the queues API
type Queue struct {
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha1/user_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type UserSpec struct {

// UserStatus defines the observed state of User.
type UserStatus struct {
Conditions []Condition `json:"conditions,omitempty"`
// Provides a reference to a Secret object containing the user credentials.
Credentials *corev1.LocalObjectReference `json:"credentials,omitempty"`
}
Expand All @@ -47,6 +48,7 @@ type UserStatus struct {
type UserTag string

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// User is the Schema for the users API.
// +kubebuilder:subresource:status
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha1/vhost_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ type VhostSpec struct {

// VhostStatus defines the observed state of Vhost
type VhostStatus struct {
Conditions []Condition `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// Vhost is the Schema for the vhosts API
type Vhost struct {
Expand Down
68 changes: 63 additions & 5 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions config/crd/bases/rabbitmq.com_bindings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,39 @@ spec:
type: object
status:
description: BindingStatus defines the observed state of Binding
properties:
conditions:
items:
properties:
lastTransitionTime:
description: The last time this Condition type changed.
format: date-time
type: string
message:
description: Full text reason for current status of the condition.
type: string
reason:
description: One word, camel-case reason for current status
of the condition.
type: string
status:
description: True, False, or Unknown
type: string
type:
description: Type indicates the scope of RabbitmqCluster status
addressed by the condition.
type: string
required:
- status
- type
type: object
type: array
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
Expand Down
29 changes: 29 additions & 0 deletions config/crd/bases/rabbitmq.com_exchanges.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,39 @@ spec:
type: object
status:
description: ExchangeStatus defines the observed state of Exchange
properties:
conditions:
items:
properties:
lastTransitionTime:
description: The last time this Condition type changed.
format: date-time
type: string
message:
description: Full text reason for current status of the condition.
type: string
reason:
description: One word, camel-case reason for current status
of the condition.
type: string
status:
description: True, False, or Unknown
type: string
type:
description: Type indicates the scope of RabbitmqCluster status
addressed by the condition.
type: string
required:
- status
- type
type: object
type: array
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
Expand Down

0 comments on commit 92c8e73

Please sign in to comment.