From c8704b96037e90a3e5b7d44050cf9d09eed1423d Mon Sep 17 00:00:00 2001 From: Timo Riski Date: Mon, 13 Jan 2025 17:42:56 +0200 Subject: [PATCH] feat: scaffold Valkey resources Changes generated with: ```shell ./bin/operator-sdk-v1.36.0 create api --version v1alpha1 --kind Valkey --force ./bin/operator-sdk-v1.36.0 create webhook --version v1alpha1 --kind Valkey \ --defaulting --programmatic-validation --conversion ``` --- CHANGELOG.md | 1 + PROJECT | 13 +++ api/v1alpha1/valkey_types.go | 50 +++++++++++ api/v1alpha1/valkey_webhook.go | 61 +++++++++++++ api/v1alpha1/zz_generated.deepcopy.go | 89 +++++++++++++++++++ .../templates/aiven.io_valkeys.yaml | 55 ++++++++++++ .../templates/cluster_role.yaml | 26 ++++++ .../mutating_webhook_configuration.yaml | 21 +++++ .../validating_webhook_configuration.yaml | 21 +++++ config/crd/bases/aiven.io_valkeys.yaml | 55 ++++++++++++ config/crd/kustomization.yaml | 3 + .../crd/patches/cainjection_in_valkeys.yaml | 7 ++ config/crd/patches/webhook_in_valkeys.yaml | 16 ++++ config/rbac/role.yaml | 26 ++++++ config/rbac/valkey_editor_role.yaml | 31 +++++++ config/rbac/valkey_viewer_role.yaml | 27 ++++++ config/samples/_v1alpha1_valkey.yaml | 12 +++ config/samples/kustomization.yaml | 1 + config/webhook/manifests.yaml | 40 +++++++++ controllers/valkey_controller.go | 48 ++++++++++ docs/docs/api-reference/valkey.md | 24 +++++ go.mod | 5 +- go.sum | 16 ++-- 23 files changed, 638 insertions(+), 10 deletions(-) create mode 100644 api/v1alpha1/valkey_types.go create mode 100644 api/v1alpha1/valkey_webhook.go create mode 100644 charts/aiven-operator-crds/templates/aiven.io_valkeys.yaml create mode 100644 config/crd/bases/aiven.io_valkeys.yaml create mode 100644 config/crd/patches/cainjection_in_valkeys.yaml create mode 100644 config/crd/patches/webhook_in_valkeys.yaml create mode 100644 config/rbac/valkey_editor_role.yaml create mode 100644 config/rbac/valkey_viewer_role.yaml create mode 100644 config/samples/_v1alpha1_valkey.yaml create mode 100644 controllers/valkey_controller.go create mode 100644 docs/docs/api-reference/valkey.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 58cac74b..e9550495 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ the cluster nodes - Add `OpenSearch` field `userConfig.opensearch.segrep`, type `object`: Segment Replication Backpressure Settings +- Add kind: `Valkey` ## v0.26.0 - 2024-11-21 diff --git a/PROJECT b/PROJECT index caf11ecb..6bd5a777 100644 --- a/PROJECT +++ b/PROJECT @@ -304,4 +304,17 @@ resources: defaulting: true validation: true webhookVersion: v1 +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: aiven.io + kind: Valkey + path: github.com/aiven/aiven-operator/api/v1alpha1 + version: v1alpha1 + webhooks: + conversion: true + defaulting: true + validation: true + webhookVersion: v1 version: "3" diff --git a/api/v1alpha1/valkey_types.go b/api/v1alpha1/valkey_types.go new file mode 100644 index 00000000..dc84697a --- /dev/null +++ b/api/v1alpha1/valkey_types.go @@ -0,0 +1,50 @@ +// Copyright (c) 2024 Aiven, Helsinki, Finland. https://aiven.io/ + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +// ValkeySpec defines the desired state of Valkey +type ValkeySpec struct { + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + // Important: Run "make" to regenerate code after modifying this file + + // Foo is an example field of Valkey. Edit valkey_types.go to remove/update + Foo string `json:"foo,omitempty"` +} + +// ValkeyStatus defines the observed state of Valkey +type ValkeyStatus struct { + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster + // Important: Run "make" to regenerate code after modifying this file +} + +//+kubebuilder:object:root=true +//+kubebuilder:subresource:status + +// Valkey is the Schema for the valkeys API +type Valkey struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec ValkeySpec `json:"spec,omitempty"` + Status ValkeyStatus `json:"status,omitempty"` +} + +//+kubebuilder:object:root=true + +// ValkeyList contains a list of Valkey +type ValkeyList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []Valkey `json:"items"` +} + +func init() { + SchemeBuilder.Register(&Valkey{}, &ValkeyList{}) +} diff --git a/api/v1alpha1/valkey_webhook.go b/api/v1alpha1/valkey_webhook.go new file mode 100644 index 00000000..1ab11e14 --- /dev/null +++ b/api/v1alpha1/valkey_webhook.go @@ -0,0 +1,61 @@ +// Copyright (c) 2024 Aiven, Helsinki, Finland. https://aiven.io/ + +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/runtime" + ctrl "sigs.k8s.io/controller-runtime" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/webhook" +) + +// log is for logging in this package. +var valkeylog = logf.Log.WithName("valkey-resource") + +func (r *Valkey) SetupWebhookWithManager(mgr ctrl.Manager) error { + return ctrl.NewWebhookManagedBy(mgr). + For(r). + Complete() +} + +// TODO(user): EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! + +//+kubebuilder:webhook:path=/mutate-aiven-io-v1alpha1-valkey,mutating=true,failurePolicy=fail,sideEffects=None,groups=aiven.io,resources=valkeys,verbs=create;update,versions=v1alpha1,name=mvalkey.kb.io,admissionReviewVersions=v1 + +var _ webhook.Defaulter = &Valkey{} + +// Default implements webhook.Defaulter so a webhook will be registered for the type +func (r *Valkey) Default() { + valkeylog.Info("default", "name", r.Name) + + // TODO(user): fill in your defaulting logic. +} + +// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation. +//+kubebuilder:webhook:path=/validate-aiven-io-v1alpha1-valkey,mutating=false,failurePolicy=fail,sideEffects=None,groups=aiven.io,resources=valkeys,verbs=create;update,versions=v1alpha1,name=vvalkey.kb.io,admissionReviewVersions=v1 + +var _ webhook.Validator = &Valkey{} + +// ValidateCreate implements webhook.Validator so a webhook will be registered for the type +func (r *Valkey) ValidateCreate() error { + valkeylog.Info("validate create", "name", r.Name) + + // TODO(user): fill in your validation logic upon object creation. + return nil +} + +// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type +func (r *Valkey) ValidateUpdate(old runtime.Object) error { + valkeylog.Info("validate update", "name", r.Name) + + // TODO(user): fill in your validation logic upon object update. + return nil +} + +// ValidateDelete implements webhook.Validator so a webhook will be registered for the type +func (r *Valkey) ValidateDelete() error { + valkeylog.Info("validate delete", "name", r.Name) + + // TODO(user): fill in your validation logic upon object deletion. + return nil +} diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index e4873e38..d1d4d42d 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -3142,3 +3142,92 @@ func (in *ServiceUserStatus) DeepCopy() *ServiceUserStatus { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Valkey) DeepCopyInto(out *Valkey) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Valkey. +func (in *Valkey) DeepCopy() *Valkey { + if in == nil { + return nil + } + out := new(Valkey) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Valkey) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ValkeyList) DeepCopyInto(out *ValkeyList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Valkey, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ValkeyList. +func (in *ValkeyList) DeepCopy() *ValkeyList { + if in == nil { + return nil + } + out := new(ValkeyList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ValkeyList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ValkeySpec) DeepCopyInto(out *ValkeySpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ValkeySpec. +func (in *ValkeySpec) DeepCopy() *ValkeySpec { + if in == nil { + return nil + } + out := new(ValkeySpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ValkeyStatus) DeepCopyInto(out *ValkeyStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ValkeyStatus. +func (in *ValkeyStatus) DeepCopy() *ValkeyStatus { + if in == nil { + return nil + } + out := new(ValkeyStatus) + in.DeepCopyInto(out) + return out +} diff --git a/charts/aiven-operator-crds/templates/aiven.io_valkeys.yaml b/charts/aiven-operator-crds/templates/aiven.io_valkeys.yaml new file mode 100644 index 00000000..67b2961c --- /dev/null +++ b/charts/aiven-operator-crds/templates/aiven.io_valkeys.yaml @@ -0,0 +1,55 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.15.0 + name: valkeys.aiven.io +spec: + group: aiven.io + names: + kind: Valkey + listKind: ValkeyList + plural: valkeys + singular: valkey + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: Valkey is the Schema for the valkeys API + 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: ValkeySpec defines the desired state of Valkey + properties: + foo: + description: + Foo is an example field of Valkey. Edit valkey_types.go + to remove/update + type: string + type: object + status: + description: ValkeyStatus defines the observed state of Valkey + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/charts/aiven-operator/templates/cluster_role.yaml b/charts/aiven-operator/templates/cluster_role.yaml index 5488d1f6..c716b5bf 100644 --- a/charts/aiven-operator/templates/cluster_role.yaml +++ b/charts/aiven-operator/templates/cluster_role.yaml @@ -753,6 +753,32 @@ rules: - get - patch - update + - apiGroups: + - aiven.io + resources: + - valkeys + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - aiven.io + resources: + - valkeys/finalizers + verbs: + - update + - apiGroups: + - aiven.io + resources: + - valkeys/status + verbs: + - get + - patch + - update - apiGroups: - coordination.k8s.io resources: diff --git a/charts/aiven-operator/templates/mutating_webhook_configuration.yaml b/charts/aiven-operator/templates/mutating_webhook_configuration.yaml index 8f476f85..b2772f2d 100644 --- a/charts/aiven-operator/templates/mutating_webhook_configuration.yaml +++ b/charts/aiven-operator/templates/mutating_webhook_configuration.yaml @@ -429,5 +429,26 @@ webhooks: - serviceusers sideEffects: None {{- include "aiven-operator.webhookNamespaceSelector" . | indent 4 }} + - admissionReviewVersions: + - v1 + clientConfig: + service: + name: {{ include "aiven-operator.fullname" . }}-webhook-service + namespace: {{ include "aiven-operator.namespace" . }} + path: /mutate-aiven-io-v1alpha1-valkey + failurePolicy: Fail + name: mvalkey.kb.io + rules: + - apiGroups: + - aiven.io + apiVersions: + - v1alpha1 + operations: + - CREATE + - UPDATE + resources: + - valkeys + sideEffects: None + {{- include "aiven-operator.webhookNamespaceSelector" . | indent 4 }} {{- end }} diff --git a/charts/aiven-operator/templates/validating_webhook_configuration.yaml b/charts/aiven-operator/templates/validating_webhook_configuration.yaml index db5832ef..ff9c7ff7 100644 --- a/charts/aiven-operator/templates/validating_webhook_configuration.yaml +++ b/charts/aiven-operator/templates/validating_webhook_configuration.yaml @@ -444,5 +444,26 @@ webhooks: - serviceusers sideEffects: None {{- include "aiven-operator.webhookNamespaceSelector" . | indent 4 }} + - admissionReviewVersions: + - v1 + clientConfig: + service: + name: {{ include "aiven-operator.fullname" . }}-webhook-service + namespace: {{ include "aiven-operator.namespace" . }} + path: /validate-aiven-io-v1alpha1-valkey + failurePolicy: Fail + name: vvalkey.kb.io + rules: + - apiGroups: + - aiven.io + apiVersions: + - v1alpha1 + operations: + - CREATE + - UPDATE + resources: + - valkeys + sideEffects: None + {{- include "aiven-operator.webhookNamespaceSelector" . | indent 4 }} {{- end }} diff --git a/config/crd/bases/aiven.io_valkeys.yaml b/config/crd/bases/aiven.io_valkeys.yaml new file mode 100644 index 00000000..67b2961c --- /dev/null +++ b/config/crd/bases/aiven.io_valkeys.yaml @@ -0,0 +1,55 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.15.0 + name: valkeys.aiven.io +spec: + group: aiven.io + names: + kind: Valkey + listKind: ValkeyList + plural: valkeys + singular: valkey + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: Valkey is the Schema for the valkeys API + 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: ValkeySpec defines the desired state of Valkey + properties: + foo: + description: + Foo is an example field of Valkey. Edit valkey_types.go + to remove/update + type: string + type: object + status: + description: ValkeyStatus defines the observed state of Valkey + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index 5c66e8c6..c31d62c9 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -28,6 +28,7 @@ resources: - bases/aiven.io_clickhousegrants.yaml - bases/aiven.io_serviceintegrationendpoints.yaml - bases/aiven.io_flinks.yaml + - bases/aiven.io_valkeys.yaml #+kubebuilder:scaffold:crdkustomizeresource patchesStrategicMerge: @@ -53,6 +54,7 @@ patchesStrategicMerge: - patches/webhook_in_grafanas.yaml - patches/webhook_in_serviceintegrationendpoints.yaml - patches/webhook_in_flinks.yaml + - patches/webhook_in_valkeys.yaml #+kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix. @@ -77,6 +79,7 @@ patchesStrategicMerge: - patches/cainjection_in_grafanas.yaml - patches/cainjection_in_serviceintegrationendpoints.yaml - patches/cainjection_in_flinks.yaml + - patches/cainjection_in_valkeys.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. diff --git a/config/crd/patches/cainjection_in_valkeys.yaml b/config/crd/patches/cainjection_in_valkeys.yaml new file mode 100644 index 00000000..da058859 --- /dev/null +++ b/config/crd/patches/cainjection_in_valkeys.yaml @@ -0,0 +1,7 @@ +# The following patch adds a directive for certmanager to inject CA into the CRD +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) + name: valkeys.aiven.io diff --git a/config/crd/patches/webhook_in_valkeys.yaml b/config/crd/patches/webhook_in_valkeys.yaml new file mode 100644 index 00000000..91db8198 --- /dev/null +++ b/config/crd/patches/webhook_in_valkeys.yaml @@ -0,0 +1,16 @@ +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: valkeys.aiven.io +spec: + conversion: + strategy: Webhook + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert + conversionReviewVersions: + - v1 diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index a187ebf6..e521602b 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -750,6 +750,32 @@ rules: - get - patch - update + - apiGroups: + - aiven.io + resources: + - valkeys + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - aiven.io + resources: + - valkeys/finalizers + verbs: + - update + - apiGroups: + - aiven.io + resources: + - valkeys/status + verbs: + - get + - patch + - update - apiGroups: - coordination.k8s.io resources: diff --git a/config/rbac/valkey_editor_role.yaml b/config/rbac/valkey_editor_role.yaml new file mode 100644 index 00000000..e2af3a74 --- /dev/null +++ b/config/rbac/valkey_editor_role.yaml @@ -0,0 +1,31 @@ +# permissions for end users to edit valkeys. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: clusterrole + app.kubernetes.io/instance: valkey-editor-role + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: aiven-operator + app.kubernetes.io/part-of: aiven-operator + app.kubernetes.io/managed-by: kustomize + name: valkey-editor-role +rules: + - apiGroups: + - aiven.io + resources: + - valkeys + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - aiven.io + resources: + - valkeys/status + verbs: + - get diff --git a/config/rbac/valkey_viewer_role.yaml b/config/rbac/valkey_viewer_role.yaml new file mode 100644 index 00000000..e2749a4f --- /dev/null +++ b/config/rbac/valkey_viewer_role.yaml @@ -0,0 +1,27 @@ +# permissions for end users to view valkeys. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/name: clusterrole + app.kubernetes.io/instance: valkey-viewer-role + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: aiven-operator + app.kubernetes.io/part-of: aiven-operator + app.kubernetes.io/managed-by: kustomize + name: valkey-viewer-role +rules: + - apiGroups: + - aiven.io + resources: + - valkeys + verbs: + - get + - list + - watch + - apiGroups: + - aiven.io + resources: + - valkeys/status + verbs: + - get diff --git a/config/samples/_v1alpha1_valkey.yaml b/config/samples/_v1alpha1_valkey.yaml new file mode 100644 index 00000000..6e1d48ee --- /dev/null +++ b/config/samples/_v1alpha1_valkey.yaml @@ -0,0 +1,12 @@ +apiVersion: aiven.io/v1alpha1 +kind: Valkey +metadata: + labels: + app.kubernetes.io/name: valkey + app.kubernetes.io/instance: valkey-sample + app.kubernetes.io/part-of: aiven-operator + app.kubernetes.io/managed-by: kustomize + app.kubernetes.io/created-by: aiven-operator + name: valkey-sample +spec: + # TODO(user): Add fields here diff --git a/config/samples/kustomization.yaml b/config/samples/kustomization.yaml index 5d4b02b8..bf88583e 100644 --- a/config/samples/kustomization.yaml +++ b/config/samples/kustomization.yaml @@ -25,4 +25,5 @@ resources: - _v1alpha1_clickhouserole.yaml - _v1alpha1_serviceintegrationendpoint.yaml - _v1alpha1_flink.yaml + - _v1alpha1_valkey.yaml #+kubebuilder:scaffold:manifestskustomizesamples diff --git a/config/webhook/manifests.yaml b/config/webhook/manifests.yaml index 90621fa8..712d6dc6 100644 --- a/config/webhook/manifests.yaml +++ b/config/webhook/manifests.yaml @@ -404,6 +404,26 @@ webhooks: resources: - serviceusers sideEffects: None + - admissionReviewVersions: + - v1 + clientConfig: + service: + name: webhook-service + namespace: system + path: /mutate-aiven-io-v1alpha1-valkey + failurePolicy: Fail + name: mvalkey.kb.io + rules: + - apiGroups: + - aiven.io + apiVersions: + - v1alpha1 + operations: + - CREATE + - UPDATE + resources: + - valkeys + sideEffects: None --- apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration @@ -825,3 +845,23 @@ webhooks: resources: - serviceusers sideEffects: None + - admissionReviewVersions: + - v1 + clientConfig: + service: + name: webhook-service + namespace: system + path: /validate-aiven-io-v1alpha1-valkey + failurePolicy: Fail + name: vvalkey.kb.io + rules: + - apiGroups: + - aiven.io + apiVersions: + - v1alpha1 + operations: + - CREATE + - UPDATE + resources: + - valkeys + sideEffects: None diff --git a/controllers/valkey_controller.go b/controllers/valkey_controller.go new file mode 100644 index 00000000..7c333bc8 --- /dev/null +++ b/controllers/valkey_controller.go @@ -0,0 +1,48 @@ +// Copyright (c) 2024 Aiven, Helsinki, Finland. https://aiven.io/ + +package controllers + +import ( + "context" + + "k8s.io/apimachinery/pkg/runtime" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" + + aiveniov1alpha1 "github.com/aiven/aiven-operator/api/v1alpha1" +) + +// ValkeyReconciler reconciles a Valkey object +type ValkeyReconciler struct { + client.Client + Scheme *runtime.Scheme +} + +//+kubebuilder:rbac:groups=aiven.io,resources=valkeys,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=aiven.io,resources=valkeys/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=aiven.io,resources=valkeys/finalizers,verbs=update + +// Reconcile is part of the main kubernetes reconciliation loop which aims to +// move the current state of the cluster closer to the desired state. +// TODO(user): Modify the Reconcile function to compare the state specified by +// the Valkey object against the actual cluster state, and then +// perform operations to make the cluster state reflect the state specified by +// the user. +// +// For more details, check Reconcile and its Result here: +// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.4/pkg/reconcile +func (r *ValkeyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + _ = log.FromContext(ctx) + + // TODO(user): your logic here + + return ctrl.Result{}, nil +} + +// SetupWithManager sets up the controller with the Manager. +func (r *ValkeyReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&aiveniov1alpha1.Valkey{}). + Complete(r) +} diff --git a/docs/docs/api-reference/valkey.md b/docs/docs/api-reference/valkey.md new file mode 100644 index 00000000..98164d4a --- /dev/null +++ b/docs/docs/api-reference/valkey.md @@ -0,0 +1,24 @@ +--- +title: "Valkey" +--- + +## Valkey {: #Valkey } + +Valkey is the Schema for the valkeys API. + +**Required** + +- [`apiVersion`](#apiVersion-property){: name='apiVersion-property'} (string). Value `aiven.io/v1alpha1`. +- [`kind`](#kind-property){: name='kind-property'} (string). Value `Valkey`. +- [`metadata`](#metadata-property){: name='metadata-property'} (object). Data that identifies the object, including a `name` string and optional `namespace`. +- [`spec`](#spec-property){: name='spec-property'} (object). ValkeySpec defines the desired state of Valkey. See below for [nested schema](#spec). + +## spec {: #spec } + +_Appears on [`Valkey`](#Valkey)._ + +ValkeySpec defines the desired state of Valkey. + +**Required** + +- [`foo`](#spec.foo-property){: name='spec.foo-property'} (string). Foo is an example field of Valkey. Edit valkey_types.go to remove/update. diff --git a/go.mod b/go.mod index 2bf14e5d..9e95570c 100644 --- a/go.mod +++ b/go.mod @@ -53,6 +53,7 @@ require ( github.com/golang/protobuf v1.5.4 // indirect github.com/google/gnostic v0.5.7-v3refs // indirect github.com/google/gofuzz v1.1.0 // indirect + github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 // indirect github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect @@ -69,7 +70,7 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/onsi/ginkgo/v2 v2.15.0 // indirect + github.com/onsi/ginkgo/v2 v2.20.1 // indirect github.com/paulmach/orb v0.11.1 // indirect github.com/pierrec/lz4/v4 v4.1.21 // indirect github.com/pkg/errors v0.9.1 // indirect @@ -97,7 +98,7 @@ require ( golang.org/x/time v0.3.0 // indirect gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/protobuf v1.33.0 // indirect + google.golang.org/protobuf v1.35.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect k8s.io/apiextensions-apiserver v0.26.10 // indirect diff --git a/go.sum b/go.sum index dca90320..688a2b53 100644 --- a/go.sum +++ b/go.sum @@ -123,8 +123,8 @@ github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh github.com/go-openapi/swag v0.19.14 h1:gm3vOOXfiuw5i9p5N9xJvfjvuofpyvLA9Wr6QfK5Fng= github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= -github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= +github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= +github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= @@ -189,8 +189,8 @@ github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 h1:5iH8iuqE5apketRbSFBy+X1V0o+l+8NF1avt4HWl7cA= +github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -277,8 +277,8 @@ github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY= -github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM= +github.com/onsi/ginkgo/v2 v2.20.1 h1:YlVIbqct+ZmnEph770q9Q7NVAz4wwIiVNahee6JyUzo= +github.com/onsi/ginkgo/v2 v2.20.1/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI= github.com/onsi/gomega v1.36.0 h1:Pb12RlruUtj4XUuPUqeEWc6j5DkVVVA49Uf6YLfC95Y= github.com/onsi/gomega v1.36.0/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog= github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= @@ -683,8 +683,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=