-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(clickhousedatabase): add a new kind
- Loading branch information
Showing
29 changed files
with
1,095 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) 2024 Aiven, Helsinki, Finland. https://aiven.io/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// ClickhouseDatabaseSpec defines the desired state of ClickhouseDatabase | ||
type ClickhouseDatabaseSpec struct { | ||
// +kubebuilder:validation:MaxLength=63 | ||
// +kubebuilder:validation:Format="^[a-zA-Z0-9_-]*$" | ||
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable" | ||
// Project to link the database to | ||
Project string `json:"project"` | ||
|
||
// +kubebuilder:validation:MaxLength=63 | ||
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable" | ||
// Clickhouse service to link the database to | ||
ServiceName string `json:"serviceName"` | ||
|
||
// It is a Kubernetes side deletion protections, which prevents the database | ||
// from being deleted by Kubernetes. It is recommended to enable this for any production | ||
// databases containing critical data. | ||
TerminationProtection *bool `json:"terminationProtection,omitempty"` | ||
|
||
// Authentication reference to Aiven token in a secret | ||
AuthSecretRef *AuthSecretReference `json:"authSecretRef,omitempty"` | ||
} | ||
|
||
// ClickhouseDatabaseStatus defines the observed state of ClickhouseDatabase | ||
type ClickhouseDatabaseStatus struct { | ||
// Conditions represent the latest available observations of an ClickhouseDatabase state | ||
Conditions []metav1.Condition `json:"conditions"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:subresource:status | ||
|
||
// ClickhouseDatabase is the Schema for the databases API | ||
// +kubebuilder:printcolumn:name="Service Name",type="string",JSONPath=".spec.serviceName" | ||
// +kubebuilder:printcolumn:name="Project",type="string",JSONPath=".spec.project" | ||
type ClickhouseDatabase struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec ClickhouseDatabaseSpec `json:"spec,omitempty"` | ||
Status ClickhouseDatabaseStatus `json:"status,omitempty"` | ||
} | ||
|
||
var _ AivenManagedObject = &ClickhouseDatabase{} | ||
|
||
func (*ClickhouseDatabase) NoSecret() bool { | ||
return false | ||
} | ||
|
||
func (in *ClickhouseDatabase) AuthSecretRef() *AuthSecretReference { | ||
return in.Spec.AuthSecretRef | ||
} | ||
|
||
func (in *ClickhouseDatabase) Conditions() *[]metav1.Condition { | ||
return &in.Status.Conditions | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// ClickhouseDatabaseList contains a list of ClickhouseDatabase | ||
type ClickhouseDatabaseList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []ClickhouseDatabase `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&ClickhouseDatabase{}, &ClickhouseDatabaseList{}) | ||
} |
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,58 @@ | ||
// Copyright (c) 2024 Aiven, Helsinki, Finland. https://aiven.io/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"errors" | ||
|
||
"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 clickhousedatabaselog = logf.Log.WithName("clickhousedatabase-resource") | ||
|
||
func (in *ClickhouseDatabase) SetupWebhookWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewWebhookManagedBy(mgr). | ||
For(in). | ||
Complete() | ||
} | ||
|
||
//+kubebuilder:webhook:path=/mutate-aiven-io-v1alpha1-clickhousedatabase,mutating=true,failurePolicy=fail,groups=aiven.io,resources=clickhousedatabases,verbs=create;update,versions=v1alpha1,name=mclickhousedatabase.kb.io,sideEffects=none,admissionReviewVersions=v1 | ||
|
||
var _ webhook.Defaulter = &ClickhouseDatabase{} | ||
|
||
// Default implements webhook.Defaulter so a webhook will be registered for the type | ||
func (in *ClickhouseDatabase) Default() { | ||
clickhousedatabaselog.Info("default", "name", in.Name) | ||
} | ||
|
||
//+kubebuilder:webhook:verbs=create;update;delete,path=/validate-aiven-io-v1alpha1-clickhousedatabase,mutating=false,failurePolicy=fail,groups=aiven.io,resources=clickhousedatabases,versions=v1alpha1,name=vclickhousedatabase.kb.io,sideEffects=none,admissionReviewVersions=v1 | ||
|
||
var _ webhook.Validator = &ClickhouseDatabase{} | ||
|
||
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type | ||
func (in *ClickhouseDatabase) ValidateCreate() error { | ||
clickhousedatabaselog.Info("validate create", "name", in.Name) | ||
|
||
return nil | ||
} | ||
|
||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type | ||
func (in *ClickhouseDatabase) ValidateUpdate(old runtime.Object) error { | ||
clickhousedatabaselog.Info("validate update", "name", in.Name) | ||
|
||
return nil | ||
} | ||
|
||
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type | ||
func (in *ClickhouseDatabase) ValidateDelete() error { | ||
clickhousedatabaselog.Info("validate delete", "name", in.Name) | ||
|
||
if in.Spec.TerminationProtection != nil && *in.Spec.TerminationProtection { | ||
return errors.New("cannot delete ClickhouseDatabase, termination protection is on") | ||
} | ||
return nil | ||
} |
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.
Oops, something went wrong.