-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add policies.rabbitmq.com - support create, update and delete - correct minor issues with crds description
- Loading branch information
Showing
27 changed files
with
911 additions
and
33 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
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
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
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,66 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
// PolicySpec defines the desired state of Policy | ||
// https://www.rabbitmq.com/parameters.html#policies | ||
type PolicySpec struct { | ||
// +kubebuilder:validation:Required | ||
Name string `json:"name"` | ||
// Default to vhost '/' | ||
// +kubebuilder:default:=/ | ||
Vhost string `json:"vhost,omitempty"` | ||
// Regular expression pattern used to match queues and exchanges, e.g. "^amq.". | ||
// Required property. | ||
// +kubebuilder:validation:Required | ||
Pattern string `json:"pattern"` | ||
// What this policy applies to: 'queues', 'exchanges', or 'all'. | ||
// Default to 'all'. | ||
// +kubebuilder:validation:Enum=queues;exchanges;all | ||
// +kubebuilder:default:=all | ||
ApplyTo string `json:"applyTo,omitempty"` | ||
// Default to '0'. | ||
// In the event that more than one policy can match a given exchange or queue, the policy with the greatest priority applies. | ||
// +kubebuilder:default:=0 | ||
Priority int `json:"priority,omitempty"` | ||
// Policy definition. Required property. | ||
// +kubebuilder:validation:Type=object | ||
// +kubebuilder:pruning:PreserveUnknownFields | ||
// +kubebuilder:validation:Required | ||
Definition *runtime.RawExtension `json:"definition"` | ||
// Reference to the RabbitmqCluster that the exchange will be created in. | ||
// Required property. | ||
// +kubebuilder:validation:Required | ||
RabbitmqClusterReference RabbitmqClusterReference `json:"rabbitmqClusterReference"` | ||
} | ||
|
||
// PolicyStatus defines the observed state of Policy | ||
type PolicyStatus struct { | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// Policy is the Schema for the policies API | ||
type Policy struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec PolicySpec `json:"spec,omitempty"` | ||
Status PolicyStatus `json:"status,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// PolicyList contains a list of Policy | ||
type PolicyList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []Policy `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&Policy{}, &PolicyList{}) | ||
} |
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,121 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"context" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
var _ = Describe("Policy", func() { | ||
var ( | ||
namespace = "default" | ||
ctx = context.Background() | ||
) | ||
|
||
It("creates a policy with minimal configurations", func() { | ||
policy := Policy{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-policy", | ||
Namespace: namespace, | ||
}, | ||
Spec: PolicySpec{ | ||
Name: "test-policy", | ||
Pattern: "a-queue-name", | ||
Definition: &runtime.RawExtension{ | ||
Raw: []byte(`{"key":"value"}`), | ||
}, | ||
RabbitmqClusterReference: RabbitmqClusterReference{ | ||
Name: "some-cluster", | ||
Namespace: namespace, | ||
}, | ||
}, | ||
} | ||
Expect(k8sClient.Create(ctx, &policy)).To(Succeed()) | ||
fetched := &Policy{} | ||
Expect(k8sClient.Get(ctx, types.NamespacedName{ | ||
Name: policy.Name, | ||
Namespace: policy.Namespace, | ||
}, fetched)).To(Succeed()) | ||
Expect(fetched.Spec.RabbitmqClusterReference).To(Equal(RabbitmqClusterReference{ | ||
Name: "some-cluster", | ||
Namespace: namespace, | ||
})) | ||
Expect(fetched.Spec.Name).To(Equal("test-policy")) | ||
Expect(fetched.Spec.Vhost).To(Equal("/")) | ||
Expect(fetched.Spec.Pattern).To(Equal("a-queue-name")) | ||
Expect(fetched.Spec.ApplyTo).To(Equal("all")) | ||
Expect(fetched.Spec.Priority).To(Equal(0)) | ||
Expect(fetched.Spec.Definition.Raw).To(Equal([]byte(`{"key":"value"}`))) | ||
}) | ||
|
||
It("creates policy with configurations", func() { | ||
policy := Policy{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "random-policy", | ||
Namespace: namespace, | ||
}, | ||
Spec: PolicySpec{ | ||
Name: "test-policy", | ||
Vhost: "/hello", | ||
Pattern: "*.", | ||
ApplyTo: "exchanges", | ||
Priority: 100, | ||
Definition: &runtime.RawExtension{ | ||
Raw: []byte(`{"key":"value"}`), | ||
}, | ||
RabbitmqClusterReference: RabbitmqClusterReference{ | ||
Name: "random-cluster", | ||
Namespace: namespace, | ||
}, | ||
}, | ||
} | ||
Expect(k8sClient.Create(ctx, &policy)).To(Succeed()) | ||
fetched := &Policy{} | ||
Expect(k8sClient.Get(ctx, types.NamespacedName{ | ||
Name: policy.Name, | ||
Namespace: policy.Namespace, | ||
}, fetched)).To(Succeed()) | ||
|
||
Expect(fetched.Spec.Name).To(Equal("test-policy")) | ||
Expect(fetched.Spec.Vhost).To(Equal("/hello")) | ||
Expect(fetched.Spec.Pattern).To(Equal("*.")) | ||
Expect(fetched.Spec.ApplyTo).To(Equal("exchanges")) | ||
Expect(fetched.Spec.Priority).To(Equal(100)) | ||
Expect(fetched.Spec.RabbitmqClusterReference).To(Equal( | ||
RabbitmqClusterReference{ | ||
Name: "random-cluster", | ||
Namespace: namespace, | ||
})) | ||
Expect(fetched.Spec.Definition.Raw).To(Equal([]byte(`{"key":"value"}`))) | ||
}) | ||
|
||
When("creating a policy with an invalid 'ApplyTo' value", func() { | ||
It("fails with validation errors", func() { | ||
policy := Policy{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "invalid", | ||
Namespace: namespace, | ||
}, | ||
Spec: PolicySpec{ | ||
Name: "test-policy", | ||
Pattern: "a-queue-name", | ||
Definition: &runtime.RawExtension{ | ||
Raw: []byte(`{"key":"value"}`), | ||
}, | ||
ApplyTo: "yo-yo", | ||
RabbitmqClusterReference: RabbitmqClusterReference{ | ||
Name: "some-cluster", | ||
Namespace: namespace, | ||
}, | ||
}, | ||
} | ||
Expect(k8sClient.Create(ctx, &policy)).To(HaveOccurred()) | ||
Expect(k8sClient.Create(ctx, &policy)).To(MatchError(`Policy.rabbitmq.com "invalid" is invalid: spec.applyTo: Unsupported value: "yo-yo": supported values: "queues", "exchanges", "all"`)) | ||
}) | ||
}) | ||
|
||
}) |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Oops, something went wrong.