Skip to content

Commit

Permalink
Add schemareplications.rabbitmq.com
Browse files Browse the repository at this point in the history
- sets global parameter 'schema_definition_sync_upstream'
with value 'username' 'password' and 'endpoints'
  • Loading branch information
ChunyiLyu committed Apr 15, 2021
1 parent 00b1004 commit a7fd85a
Show file tree
Hide file tree
Showing 23 changed files with 1,276 additions and 7 deletions.
3 changes: 3 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ resources:
- group: rabbitmq.com
kind: Permission
version: v1alpha2
- group: rabbitmq.com
kind: SchemaReplication
version: v1alpha2
version: "2"
61 changes: 61 additions & 0 deletions api/v1alpha2/schemareplication_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
RabbitMQ Messaging Topology Kubernetes Operator
Copyright 2021 VMware, Inc.
This product is licensed to you under the Mozilla Public License 2.0 license (the "License"). You may not use this product except in compliance with the Mozilla 2.0 License.
This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
*/

package v1alpha2

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// SchemaReplicationSpec defines the desired state of SchemaReplication
type SchemaReplicationSpec struct {
// Reference to the RabbitmqCluster that schema replication would be set for. Must be an existing cluster.
// +kubebuilder:validation:Required
RabbitmqClusterReference RabbitmqClusterReference `json:"rabbitmqClusterReference"`
// Defines a Secret which contains credentials to be used for schema replication.
// The Secret must contain the keys `endpoints`, `username` and `password` in its Data field, or the controller errors.
// +kubebuilder:validation:Required
UpstreamSecret *corev1.LocalObjectReference `json:"upstreamSecret,omitempty"`
}

// SchemaReplicationStatus defines the observed state of SchemaReplication
type SchemaReplicationStatus struct {
// observedGeneration is the most recent successful generation observed for this Queue. It corresponds to the
// Queue's generation, which is updated on mutation by the API Server.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Conditions []Condition `json:"conditions,omitempty"`
}

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

// SchemaReplication is the Schema for the schemareplications API
// This feature requires Tanzu RabbitMQ with schema replication plugin.
// For more information, see: https://tanzu.vmware.com/rabbitmq and https://www.rabbitmq.com/definitions-standby.html.
type SchemaReplication struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec SchemaReplicationSpec `json:"spec,omitempty"`
Status SchemaReplicationStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// SchemaReplicationList contains a list of SchemaReplication
type SchemaReplicationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []SchemaReplication `json:"items"`
}

func init() {
SchemeBuilder.Register(&SchemaReplication{}, &SchemaReplicationList{})
}
39 changes: 39 additions & 0 deletions api/v1alpha2/schemareplication_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package v1alpha2

import (
"context"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

var _ = Describe("schemaReplication spec", func() {
It("creates a schemaReplication", func() {
replication := SchemaReplication{
ObjectMeta: metav1.ObjectMeta{
Name: "replication",
Namespace: "default",
},
Spec: SchemaReplicationSpec{
RabbitmqClusterReference: RabbitmqClusterReference{
Name: "some-cluster",
},
UpstreamSecret: &corev1.LocalObjectReference{
Name: "a-secret",
},
}}
Expect(k8sClient.Create(context.Background(), &replication)).To(Succeed())

fetched := &SchemaReplication{}
Expect(k8sClient.Get(context.Background(), types.NamespacedName{
Name: replication.Name,
Namespace: replication.Namespace,
}, fetched)).To(Succeed())
Expect(fetched.Spec.RabbitmqClusterReference).To(Equal(RabbitmqClusterReference{
Name: "some-cluster",
}))
Expect(fetched.Spec.UpstreamSecret.Name).To(Equal("a-secret"))
})
})
102 changes: 102 additions & 0 deletions api/v1alpha2/zz_generated.deepcopy.go

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

109 changes: 109 additions & 0 deletions config/crd/bases/rabbitmq.com_schemareplications.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.5.0
creationTimestamp: null
name: schemareplications.rabbitmq.com
spec:
group: rabbitmq.com
names:
kind: SchemaReplication
listKind: SchemaReplicationList
plural: schemareplications
singular: schemareplication
scope: Namespaced
versions:
- name: v1alpha2
schema:
openAPIV3Schema:
description: 'SchemaReplication is the Schema for the schemareplications API
This feature requires Tanzu RabbitMQ with schema replication plugin. For
more information, see: https://tanzu.vmware.com/rabbitmq and https://www.rabbitmq.com/definitions-standby.html.'
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: SchemaReplicationSpec defines the desired state of SchemaReplication
properties:
rabbitmqClusterReference:
description: Reference to the RabbitmqCluster that schema replication
would be set for. Must be an existing cluster.
properties:
name:
type: string
required:
- name
type: object
upstreamSecret:
description: Defines a Secret which contains credentials to be used
for schema replication. The Secret must contain the keys `endpoints`,
`username` and `password` in its Data field, or the controller errors.
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
type: object
required:
- rabbitmqClusterReference
type: object
status:
description: SchemaReplicationStatus defines the observed state of SchemaReplication
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
observedGeneration:
description: observedGeneration is the most recent successful generation
observed for this Queue. It corresponds to the Queue's generation,
which is updated on mutation by the API Server.
format: int64
type: integer
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ resources:
- bases/rabbitmq.com_vhosts.yaml
- bases/rabbitmq.com_policies.yaml
- bases/rabbitmq.com_permissions.yaml
- bases/rabbitmq.com_schemareplications.yaml
# +kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand All @@ -19,6 +20,7 @@ patchesStrategicMerge:
- patches/webhook_in_policies.yaml
- patches/webhook_in_users.yaml
- patches/webhook_in_permissions.yaml
#- patches/webhook_in_schemareplications.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch

- patches/cainjection_in_bindings.yaml
Expand All @@ -28,6 +30,7 @@ patchesStrategicMerge:
- patches/cainjection_in_policies.yaml
- patches/cainjection_in_users.yaml
- patches/cainjection_in_permissions.yaml
#- patches/cainjection_in_schemareplications.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch

configurations:
Expand Down
8 changes: 8 additions & 0 deletions config/crd/patches/cainjection_in_schemareplications.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
# CRD conversion requires k8s 1.13 or later.
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: schemareplications.rabbitmq.com
17 changes: 17 additions & 0 deletions config/crd/patches/webhook_in_schemareplications.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The following patch enables conversion webhook for CRD
# CRD conversion requires k8s 1.13 or later.
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: schemareplications.rabbitmq.com
spec:
conversion:
strategy: Webhook
webhook:
conversionReviewVersions: ["v1", "v1beta1"]
clientConfig:
caBundle: Cg==
service:
namespace: system
name: webhook-service
path: /convert
Loading

0 comments on commit a7fd85a

Please sign in to comment.