From c3e787ad3f4f298ad3e45f5b708f658da4ef87ea Mon Sep 17 00:00:00 2001 From: raihankhan Date: Wed, 17 Jan 2024 18:21:41 +0600 Subject: [PATCH] Add Rabbitmq API Signed-off-by: raihankhan --- apis/catalog/v1alpha1/openapi_generated.go | 45 +---- .../catalog/v1alpha1/rabbitmqversion_types.go | 18 +- apis/catalog/v1alpha1/register.go | 6 +- .../catalog/v1alpha1/zz_generated.deepcopy.go | 19 -- apis/kubedb/v1alpha2/openapi_generated.go | 8 +- apis/kubedb/v1alpha2/rabbitmq_types.go | 5 - apis/kubedb/v1alpha2/rabbitmq_webhook.go | 23 +-- apis/kubedb/v1alpha2/zz_generated.deepcopy.go | 5 - crds/catalog.kubedb.com_rabbitmqversions.yaml | 65 ------ crds/kubedb.com_rabbitmqs.yaml | 188 ------------------ 10 files changed, 17 insertions(+), 365 deletions(-) diff --git a/apis/catalog/v1alpha1/openapi_generated.go b/apis/catalog/v1alpha1/openapi_generated.go index ec74123abf..13a113e89b 100644 --- a/apis/catalog/v1alpha1/openapi_generated.go +++ b/apis/catalog/v1alpha1/openapi_generated.go @@ -570,7 +570,6 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "kubedb.dev/apimachinery/apis/catalog/v1alpha1.RabbitMQVersion": schema_apimachinery_apis_catalog_v1alpha1_RabbitMQVersion(ref), "kubedb.dev/apimachinery/apis/catalog/v1alpha1.RabbitMQVersionDatabase": schema_apimachinery_apis_catalog_v1alpha1_RabbitMQVersionDatabase(ref), "kubedb.dev/apimachinery/apis/catalog/v1alpha1.RabbitMQVersionList": schema_apimachinery_apis_catalog_v1alpha1_RabbitMQVersionList(ref), - "kubedb.dev/apimachinery/apis/catalog/v1alpha1.RabbitMQVersionPodSecurityPolicy": schema_apimachinery_apis_catalog_v1alpha1_RabbitMQVersionPodSecurityPolicy(ref), "kubedb.dev/apimachinery/apis/catalog/v1alpha1.RabbitMQVersionSpec": schema_apimachinery_apis_catalog_v1alpha1_RabbitMQVersionSpec(ref), "kubedb.dev/apimachinery/apis/catalog/v1alpha1.RedisVersion": schema_apimachinery_apis_catalog_v1alpha1_RedisVersion(ref), "kubedb.dev/apimachinery/apis/catalog/v1alpha1.RedisVersionCoordinator": schema_apimachinery_apis_catalog_v1alpha1_RedisVersionCoordinator(ref), @@ -26872,27 +26871,6 @@ func schema_apimachinery_apis_catalog_v1alpha1_RabbitMQVersionList(ref common.Re } } -func schema_apimachinery_apis_catalog_v1alpha1_RabbitMQVersionPodSecurityPolicy(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "RabbitMQVersionPodSecurityPolicy is the RabbitMQ pod security policies", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "databasePolicyName": { - SchemaProps: spec.SchemaProps{ - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - Required: []string{"databasePolicyName"}, - }, - }, - } -} - func schema_apimachinery_apis_catalog_v1alpha1_RabbitMQVersionSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -26929,27 +26907,6 @@ func schema_apimachinery_apis_catalog_v1alpha1_RabbitMQVersionSpec(ref common.Re Format: "", }, }, - "podSecurityPolicies": { - SchemaProps: spec.SchemaProps{ - Description: "PSP names", - Default: map[string]interface{}{}, - Ref: ref("kubedb.dev/apimachinery/apis/catalog/v1alpha1.RabbitMQVersionPodSecurityPolicy"), - }, - }, - "stash": { - SchemaProps: spec.SchemaProps{ - Description: "Stash defines backup and restore task definitions.", - Default: map[string]interface{}{}, - Ref: ref("kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1.StashAddonSpec"), - }, - }, - "updateConstraints": { - SchemaProps: spec.SchemaProps{ - Description: "update constraints", - Default: map[string]interface{}{}, - Ref: ref("kubedb.dev/apimachinery/apis/catalog/v1alpha1.UpdateConstraints"), - }, - }, "securityContext": { SchemaProps: spec.SchemaProps{ Description: "SecurityContext is for the additional config for the DB container", @@ -26962,7 +26919,7 @@ func schema_apimachinery_apis_catalog_v1alpha1_RabbitMQVersionSpec(ref common.Re }, }, Dependencies: []string{ - "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1.StashAddonSpec", "kubedb.dev/apimachinery/apis/catalog/v1alpha1.RabbitMQInitContainer", "kubedb.dev/apimachinery/apis/catalog/v1alpha1.RabbitMQVersionDatabase", "kubedb.dev/apimachinery/apis/catalog/v1alpha1.RabbitMQVersionPodSecurityPolicy", "kubedb.dev/apimachinery/apis/catalog/v1alpha1.SecurityContext", "kubedb.dev/apimachinery/apis/catalog/v1alpha1.UpdateConstraints"}, + "kubedb.dev/apimachinery/apis/catalog/v1alpha1.RabbitMQInitContainer", "kubedb.dev/apimachinery/apis/catalog/v1alpha1.RabbitMQVersionDatabase", "kubedb.dev/apimachinery/apis/catalog/v1alpha1.SecurityContext"}, } } diff --git a/apis/catalog/v1alpha1/rabbitmqversion_types.go b/apis/catalog/v1alpha1/rabbitmqversion_types.go index 2a4194780b..e4b9bae6ee 100644 --- a/apis/catalog/v1alpha1/rabbitmqversion_types.go +++ b/apis/catalog/v1alpha1/rabbitmqversion_types.go @@ -18,14 +18,13 @@ package v1alpha1 import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - appcat "kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1" ) const ( ResourceCodeRabbitMQVersion = "rmversion" ResourceKindRabbitMQVersion = "RabbitMQVersion" - ResourceSingularRabbitMQVersion = "Rabbitmqversion" - ResourcePluralRabbitMQVersion = "Rabbitmqversions" + ResourceSingularRabbitMQVersion = "rabbitmqversion" + ResourcePluralRabbitMQVersion = "rabbitmqversions" ) // RabbitMQVersion defines a RabbitMQ database version. @@ -59,14 +58,6 @@ type RabbitMQVersionSpec struct { // Deprecated versions usable but regarded as obsolete and best avoided, typically due to having been superseded. // +optional Deprecated bool `json:"deprecated,omitempty"` - // PSP names - // +optional - PodSecurityPolicies RabbitMQVersionPodSecurityPolicy `json:"podSecurityPolicies"` - // Stash defines backup and restore task definitions. - // +optional - Stash appcat.StashAddonSpec `json:"stash,omitempty"` - // update constraints - UpdateConstraints UpdateConstraints `json:"updateConstraints,omitempty"` // SecurityContext is for the additional config for the DB container // +optional SecurityContext SecurityContext `json:"securityContext"` @@ -82,11 +73,6 @@ type RabbitMQInitContainer struct { Image string `json:"image"` } -// RabbitMQVersionPodSecurityPolicy is the RabbitMQ pod security policies -type RabbitMQVersionPodSecurityPolicy struct { - DatabasePolicyName string `json:"databasePolicyName"` -} - // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // RabbitMQVersionList is a list of RabbitmqVersions diff --git a/apis/catalog/v1alpha1/register.go b/apis/catalog/v1alpha1/register.go index f1db2ef0e0..0820e14a2b 100644 --- a/apis/catalog/v1alpha1/register.go +++ b/apis/catalog/v1alpha1/register.go @@ -86,12 +86,10 @@ func addKnownTypes(scheme *runtime.Scheme) error { &RedisVersionList{}, &SinglestoreVersion{}, &SinglestoreVersionList{}, - &ZooKeeperVersion{}, - &ZooKeeperVersionList{}, - &KafkaConnectorVersion{}, - &KafkaConnectorVersionList{}, &SolrVersion{}, &SolrVersionList{}, + &ZooKeeperVersion{}, + &ZooKeeperVersionList{}, ) scheme.AddKnownTypes(SchemeGroupVersion, diff --git a/apis/catalog/v1alpha1/zz_generated.deepcopy.go b/apis/catalog/v1alpha1/zz_generated.deepcopy.go index 2be128e180..91a24f1a94 100644 --- a/apis/catalog/v1alpha1/zz_generated.deepcopy.go +++ b/apis/catalog/v1alpha1/zz_generated.deepcopy.go @@ -2454,30 +2454,11 @@ func (in *RabbitMQVersionList) DeepCopyObject() runtime.Object { return nil } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RabbitMQVersionPodSecurityPolicy) DeepCopyInto(out *RabbitMQVersionPodSecurityPolicy) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RabbitMQVersionPodSecurityPolicy. -func (in *RabbitMQVersionPodSecurityPolicy) DeepCopy() *RabbitMQVersionPodSecurityPolicy { - if in == nil { - return nil - } - out := new(RabbitMQVersionPodSecurityPolicy) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RabbitMQVersionSpec) DeepCopyInto(out *RabbitMQVersionSpec) { *out = *in out.DB = in.DB out.InitContainer = in.InitContainer - out.PodSecurityPolicies = in.PodSecurityPolicies - in.Stash.DeepCopyInto(&out.Stash) - in.UpdateConstraints.DeepCopyInto(&out.UpdateConstraints) in.SecurityContext.DeepCopyInto(&out.SecurityContext) return } diff --git a/apis/kubedb/v1alpha2/openapi_generated.go b/apis/kubedb/v1alpha2/openapi_generated.go index 59a911e278..8382723c3b 100644 --- a/apis/kubedb/v1alpha2/openapi_generated.go +++ b/apis/kubedb/v1alpha2/openapi_generated.go @@ -28719,18 +28719,12 @@ func schema_apimachinery_apis_kubedb_v1alpha2_RabbitMQSpec(ref common.ReferenceC Ref: ref("kmodules.xyz/client-go/api/v1.HealthCheckSpec"), }, }, - "monitor": { - SchemaProps: spec.SchemaProps{ - Description: "Monitor is used monitor database instance", - Ref: ref("kmodules.xyz/monitoring-agent-api/api/v1.AgentSpec"), - }, - }, }, Required: []string{"version"}, }, }, Dependencies: []string{ - "k8s.io/api/core/v1.LocalObjectReference", "k8s.io/api/core/v1.PersistentVolumeClaimSpec", "kmodules.xyz/client-go/api/v1.HealthCheckSpec", "kmodules.xyz/client-go/api/v1.TLSConfig", "kmodules.xyz/monitoring-agent-api/api/v1.AgentSpec", "kmodules.xyz/offshoot-api/api/v2.PodTemplateSpec", "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.NamedServiceTemplateSpec", "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.SecretReference"}, + "k8s.io/api/core/v1.LocalObjectReference", "k8s.io/api/core/v1.PersistentVolumeClaimSpec", "kmodules.xyz/client-go/api/v1.HealthCheckSpec", "kmodules.xyz/client-go/api/v1.TLSConfig", "kmodules.xyz/offshoot-api/api/v2.PodTemplateSpec", "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.NamedServiceTemplateSpec", "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.SecretReference"}, } } diff --git a/apis/kubedb/v1alpha2/rabbitmq_types.go b/apis/kubedb/v1alpha2/rabbitmq_types.go index 7b2d2b37f3..e781c11e60 100644 --- a/apis/kubedb/v1alpha2/rabbitmq_types.go +++ b/apis/kubedb/v1alpha2/rabbitmq_types.go @@ -20,7 +20,6 @@ import ( core "k8s.io/api/core/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" kmapi "kmodules.xyz/client-go/api/v1" - mona "kmodules.xyz/monitoring-agent-api/api/v1" ofst "kmodules.xyz/offshoot-api/api/v2" ) @@ -114,10 +113,6 @@ type RabbitMQSpec struct { // +optional // +kubebuilder:default={periodSeconds: 20, timeoutSeconds: 10, failureThreshold: 3} HealthChecker kmapi.HealthCheckSpec `json:"healthChecker"` - - // Monitor is used monitor database instance - // +optional - Monitor *mona.AgentSpec `json:"monitor,omitempty"` } // RabbitMQStatus defines the observed state of RabbitMQ diff --git a/apis/kubedb/v1alpha2/rabbitmq_webhook.go b/apis/kubedb/v1alpha2/rabbitmq_webhook.go index eaee934cf3..61a1842a40 100644 --- a/apis/kubedb/v1alpha2/rabbitmq_webhook.go +++ b/apis/kubedb/v1alpha2/rabbitmq_webhook.go @@ -17,11 +17,15 @@ limitations under the License. package v1alpha2 import ( + "context" "errors" + catalog "kubedb.dev/apimachinery/apis/catalog/v1alpha1" + apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/validation/field" ofst "kmodules.xyz/offshoot-api/api/v2" logf "sigs.k8s.io/controller-runtime/pkg/log" @@ -100,7 +104,7 @@ func (r *RabbitMQ) ValidateCreateOrUpdate() error { "number of replicas can not be 0 or less")) } - err := r.validateVersion(r) + err := r.ValidateVersion(r) if err != nil { allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("version"), r.Name, @@ -139,18 +143,13 @@ func (r *RabbitMQ) ValidateCreateOrUpdate() error { return apierrors.NewInvalid(schema.GroupKind{Group: "kafka.kubedb.com", Kind: "Kafka"}, r.Name, allErr) } -var rabbitmqAvailableVersions = []string{ - "3.12", -} - -func (r *RabbitMQ) validateVersion(db *RabbitMQ) error { - version := db.Spec.Version - for _, v := range rabbitmqAvailableVersions { - if v == version { - return nil - } +func (r *RabbitMQ) ValidateVersion(db *RabbitMQ) error { + rmVersion := catalog.RabbitMQVersion{} + err := DefaultClient.Get(context.TODO(), types.NamespacedName{Name: db.Spec.Version}, &rmVersion) + if err != nil { + return errors.New("version not supported") } - return errors.New("version not supported") + return nil } var rabbitmqReservedVolumes = []string{ diff --git a/apis/kubedb/v1alpha2/zz_generated.deepcopy.go b/apis/kubedb/v1alpha2/zz_generated.deepcopy.go index e6c44add14..a3cf381b69 100644 --- a/apis/kubedb/v1alpha2/zz_generated.deepcopy.go +++ b/apis/kubedb/v1alpha2/zz_generated.deepcopy.go @@ -3503,11 +3503,6 @@ func (in *RabbitMQSpec) DeepCopyInto(out *RabbitMQSpec) { } } in.HealthChecker.DeepCopyInto(&out.HealthChecker) - if in.Monitor != nil { - in, out := &in.Monitor, &out.Monitor - *out = new(monitoringagentapiapiv1.AgentSpec) - (*in).DeepCopyInto(*out) - } return } diff --git a/crds/catalog.kubedb.com_rabbitmqversions.yaml b/crds/catalog.kubedb.com_rabbitmqversions.yaml index a6385943c9..ed8a9e344d 100644 --- a/crds/catalog.kubedb.com_rabbitmqversions.yaml +++ b/crds/catalog.kubedb.com_rabbitmqversions.yaml @@ -61,77 +61,12 @@ spec: required: - image type: object - podSecurityPolicies: - properties: - databasePolicyName: - type: string - required: - - databasePolicyName - type: object securityContext: properties: runAsUser: format: int64 type: integer type: object - stash: - properties: - addon: - properties: - backupTask: - properties: - name: - type: string - params: - items: - properties: - name: - type: string - value: - type: string - required: - - name - - value - type: object - type: array - required: - - name - type: object - restoreTask: - properties: - name: - type: string - params: - items: - properties: - name: - type: string - value: - type: string - required: - - name - - value - type: object - type: array - required: - - name - type: object - required: - - backupTask - - restoreTask - type: object - type: object - updateConstraints: - properties: - allowlist: - items: - type: string - type: array - denylist: - items: - type: string - type: array - type: object version: type: string required: diff --git a/crds/kubedb.com_rabbitmqs.yaml b/crds/kubedb.com_rabbitmqs.yaml index 45da153f8d..fa880c8dd8 100644 --- a/crds/kubedb.com_rabbitmqs.yaml +++ b/crds/kubedb.com_rabbitmqs.yaml @@ -82,194 +82,6 @@ spec: format: int32 type: integer type: object - monitor: - properties: - agent: - enum: - - prometheus.io/operator - - prometheus.io - - prometheus.io/builtin - type: string - prometheus: - properties: - exporter: - properties: - args: - items: - type: string - type: array - env: - items: - properties: - name: - type: string - value: - type: string - valueFrom: - properties: - configMapKeyRef: - properties: - key: - type: string - name: - type: string - optional: - type: boolean - required: - - key - type: object - x-kubernetes-map-type: atomic - fieldRef: - properties: - apiVersion: - type: string - fieldPath: - type: string - required: - - fieldPath - type: object - x-kubernetes-map-type: atomic - resourceFieldRef: - properties: - containerName: - type: string - divisor: - anyOf: - - type: integer - - type: string - pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ - x-kubernetes-int-or-string: true - resource: - type: string - required: - - resource - type: object - x-kubernetes-map-type: atomic - secretKeyRef: - properties: - key: - type: string - name: - type: string - optional: - type: boolean - required: - - key - type: object - x-kubernetes-map-type: atomic - type: object - required: - - name - type: object - type: array - port: - default: 56790 - format: int32 - type: integer - resources: - properties: - claims: - items: - properties: - name: - type: string - required: - - name - type: object - type: array - x-kubernetes-list-map-keys: - - name - x-kubernetes-list-type: map - limits: - additionalProperties: - anyOf: - - type: integer - - type: string - pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ - x-kubernetes-int-or-string: true - type: object - requests: - additionalProperties: - anyOf: - - type: integer - - type: string - pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ - x-kubernetes-int-or-string: true - type: object - type: object - securityContext: - properties: - allowPrivilegeEscalation: - type: boolean - capabilities: - properties: - add: - items: - type: string - type: array - drop: - items: - type: string - type: array - type: object - privileged: - type: boolean - procMount: - type: string - readOnlyRootFilesystem: - type: boolean - runAsGroup: - format: int64 - type: integer - runAsNonRoot: - type: boolean - runAsUser: - format: int64 - type: integer - seLinuxOptions: - properties: - level: - type: string - role: - type: string - type: - type: string - user: - type: string - type: object - seccompProfile: - properties: - localhostProfile: - type: string - type: - type: string - required: - - type - type: object - windowsOptions: - properties: - gmsaCredentialSpec: - type: string - gmsaCredentialSpecName: - type: string - hostProcess: - type: boolean - runAsUserName: - type: string - type: object - type: object - type: object - serviceMonitor: - properties: - interval: - type: string - labels: - additionalProperties: - type: string - type: object - type: object - type: object - type: object podTemplate: properties: controller: