Skip to content

Commit

Permalink
feat: scaffold Valkey resources
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
rriski committed Jan 13, 2025
1 parent b42f143 commit c8704b9
Show file tree
Hide file tree
Showing 23 changed files with 638 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -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"
50 changes: 50 additions & 0 deletions api/v1alpha1/valkey_types.go
Original file line number Diff line number Diff line change
@@ -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{})
}
61 changes: 61 additions & 0 deletions api/v1alpha1/valkey_webhook.go
Original file line number Diff line number Diff line change
@@ -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
}
89 changes: 89 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

55 changes: 55 additions & 0 deletions charts/aiven-operator-crds/templates/aiven.io_valkeys.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
26 changes: 26 additions & 0 deletions charts/aiven-operator/templates/cluster_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Loading

0 comments on commit c8704b9

Please sign in to comment.