Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
tamalsaha committed Feb 21, 2025
1 parent dfde555 commit 363b95e
Show file tree
Hide file tree
Showing 198 changed files with 9,213 additions and 4,183 deletions.
9 changes: 5 additions & 4 deletions apis/core/v1alpha1/backupbatch_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
"context"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand All @@ -38,26 +39,26 @@ func (r *BackupBatch) SetupWebhookWithManager(mgr ctrl.Manager) error {
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//+kubebuilder:webhook:path=/validate-core-kubestash-com-v1alpha1-backupbatch,mutating=false,failurePolicy=fail,sideEffects=None,groups=core.kubestash.com,resources=backupbatches,verbs=create;update,versions=v1alpha1,name=vbackupbatch.kb.io,admissionReviewVersions=v1

var _ webhook.Validator = &BackupBatch{}
var _ webhook.CustomValidator = &BackupBatch{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *BackupBatch) ValidateCreate() (admission.Warnings, error) {
func (r *BackupBatch) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
backupbatchlog.Info("validate create", "name", r.Name)

// TODO(user): fill in your validation logic upon object creation.
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *BackupBatch) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
func (r *BackupBatch) ValidateUpdate(ctx context.Context, old, newObj runtime.Object) (admission.Warnings, error) {
backupbatchlog.Info("validate update", "name", r.Name)

// TODO(user): fill in your validation logic upon object update.
return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *BackupBatch) ValidateDelete() (admission.Warnings, error) {
func (r *BackupBatch) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
backupbatchlog.Info("validate delete", "name", r.Name)

// TODO(user): fill in your validation logic upon object deletion.
Expand Down
13 changes: 7 additions & 6 deletions apis/core/v1alpha1/backupblueprint_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,25 @@ func (r *BackupBlueprint) SetupWebhookWithManager(mgr ctrl.Manager) error {

//+kubebuilder:webhook:path=/mutate-core-kubestash-com-v1alpha1-backupblueprint,mutating=true,failurePolicy=fail,sideEffects=None,groups=core.kubestash.com,resources=backupblueprints,verbs=create;update,versions=v1alpha1,name=mbackupblueprint.kb.io,admissionReviewVersions=v1

var _ webhook.Defaulter = &BackupBlueprint{}
var _ webhook.CustomDefaulter = &BackupBlueprint{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
func (r *BackupBlueprint) Default() {
func (r *BackupBlueprint) Default(ctx context.Context, obj runtime.Object) error {
backupblueprintlog.Info("default", "name", r.Name)

if r.Spec.UsagePolicy == nil {
r.setDefaultUsagePolicy()
}
return nil
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//+kubebuilder:webhook:path=/validate-core-kubestash-com-v1alpha1-backupblueprint,mutating=false,failurePolicy=fail,sideEffects=None,groups=core.kubestash.com,resources=backupblueprints,verbs=create;update,versions=v1alpha1,name=vbackupblueprint.kb.io,admissionReviewVersions=v1

var _ webhook.Validator = &BackupBlueprint{}
var _ webhook.CustomValidator = &BackupBlueprint{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *BackupBlueprint) ValidateCreate() (admission.Warnings, error) {
func (r *BackupBlueprint) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
backupblueprintlog.Info("validate create", "name", r.Name)

if err := r.validateUsagePolicy(); err != nil {
Expand All @@ -74,7 +75,7 @@ func (r *BackupBlueprint) ValidateCreate() (admission.Warnings, error) {
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *BackupBlueprint) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
func (r *BackupBlueprint) ValidateUpdate(ctx context.Context, old, newObj runtime.Object) (admission.Warnings, error) {
backupblueprintlog.Info("validate update", "name", r.Name)

if err := r.validateUsagePolicy(); err != nil {
Expand All @@ -85,7 +86,7 @@ func (r *BackupBlueprint) ValidateUpdate(old runtime.Object) (admission.Warnings
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *BackupBlueprint) ValidateDelete() (admission.Warnings, error) {
func (r *BackupBlueprint) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
backupblueprintlog.Info("validate delete", "name", r.Name)

// TODO(user): fill in your validation logic upon object deletion.
Expand Down
13 changes: 7 additions & 6 deletions apis/core/v1alpha1/backupconfiguration_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ func (b *BackupConfiguration) SetupWebhookWithManager(mgr ctrl.Manager) error {

//+kubebuilder:webhook:path=/mutate-core-kubestash-com-v1alpha1-backupconfiguration,mutating=true,failurePolicy=fail,sideEffects=None,groups=core.kubestash.com,resources=backupconfigurations,verbs=create;update,versions=v1alpha1,name=mbackupconfiguration.kb.io,admissionReviewVersions=v1

var _ webhook.Defaulter = &BackupConfiguration{}
var _ webhook.CustomDefaulter = &BackupConfiguration{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
func (b *BackupConfiguration) Default() {
func (b *BackupConfiguration) Default(ctx context.Context, obj runtime.Object) error {
backupconfigurationlog.Info("default", "name", b.Name)

c := apis.GetRuntimeClient()
Expand All @@ -59,6 +59,7 @@ func (b *BackupConfiguration) Default() {
}

b.setDefaultRetentionPolicy(context.Background(), c)
return nil
}

func (b *BackupConfiguration) setDefaultBackend(ctx context.Context, c client.Client) {
Expand Down Expand Up @@ -180,10 +181,10 @@ func (b *BackupConfiguration) getDefaultRetentionPolicy(ctx context.Context, c c
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//+kubebuilder:webhook:path=/validate-core-kubestash-com-v1alpha1-backupconfiguration,mutating=false,failurePolicy=fail,sideEffects=None,groups=core.kubestash.com,resources=backupconfigurations,verbs=create;update,versions=v1alpha1,name=vbackupconfiguration.kb.io,admissionReviewVersions=v1

var _ webhook.Validator = &BackupConfiguration{}
var _ webhook.CustomValidator = &BackupConfiguration{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (b *BackupConfiguration) ValidateCreate() (admission.Warnings, error) {
func (b *BackupConfiguration) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
backupconfigurationlog.Info("validate create", apis.KeyName, b.Name)

c := apis.GetRuntimeClient()
Expand Down Expand Up @@ -600,7 +601,7 @@ func (b *BackupConfiguration) getHookTemplatesFromHookInfo(hooks []HookInfo) []H
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (b *BackupConfiguration) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
func (b *BackupConfiguration) ValidateUpdate(ctx context.Context, old, newObj runtime.Object) (admission.Warnings, error) {
backupconfigurationlog.Info("validate update", apis.KeyName, b.Name)
c := apis.GetRuntimeClient()
if err := b.validateBackends(); err != nil {
Expand All @@ -619,7 +620,7 @@ func (b *BackupConfiguration) ValidateUpdate(old runtime.Object) (admission.Warn
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (b *BackupConfiguration) ValidateDelete() (admission.Warnings, error) {
func (b *BackupConfiguration) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
backupconfigurationlog.Info("validate delete", apis.KeyName, b.Name)

// TODO(user): fill in your validation logic upon object deletion.
Expand Down
9 changes: 5 additions & 4 deletions apis/core/v1alpha1/backupsession_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/runtime"
"reflect"
Expand All @@ -40,18 +41,18 @@ func (r *BackupSession) SetupWebhookWithManager(mgr ctrl.Manager) error {
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//+kubebuilder:webhook:path=/validate-core-kubestash-com-v1alpha1-backupsession,mutating=false,failurePolicy=fail,sideEffects=None,groups=core.kubestash.com,resources=backupsessions,verbs=create;update,versions=v1alpha1,name=vbackupsession.kb.io,admissionReviewVersions=v1

var _ webhook.Validator = &BackupSession{}
var _ webhook.CustomValidator = &BackupSession{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *BackupSession) ValidateCreate() (admission.Warnings, error) {
func (r *BackupSession) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
backupsessionlog.Info("validate create", "name", r.Name)

// TODO(user): fill in your validation logic upon object creation.
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *BackupSession) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
func (r *BackupSession) ValidateUpdate(ctx context.Context, old, newObj runtime.Object) (admission.Warnings, error) {
backupsessionlog.Info("validate update", "name", r.Name)

oldBS := old.(*BackupSession)
Expand All @@ -63,7 +64,7 @@ func (r *BackupSession) ValidateUpdate(old runtime.Object) (admission.Warnings,
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *BackupSession) ValidateDelete() (admission.Warnings, error) {
func (r *BackupSession) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
backupsessionlog.Info("validate delete", "name", r.Name)

// TODO(user): fill in your validation logic upon object deletion.
Expand Down
9 changes: 5 additions & 4 deletions apis/core/v1alpha1/backupverificationsession_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/runtime"
"reflect"
Expand All @@ -40,18 +41,18 @@ func (r *BackupVerificationSession) SetupWebhookWithManager(mgr ctrl.Manager) er
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//+kubebuilder:webhook:path=/validate-core-kubestash-com-v1alpha1-backupverificationsession,mutating=false,failurePolicy=fail,sideEffects=None,groups=core.kubestash.com,resources=backupverificationsessions,verbs=create;update,versions=v1alpha1,name=vbackupverificationsession.kb.io,admissionReviewVersions=v1

var _ webhook.Validator = &BackupVerificationSession{}
var _ webhook.CustomValidator = &BackupVerificationSession{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *BackupVerificationSession) ValidateCreate() (admission.Warnings, error) {
func (r *BackupVerificationSession) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
backupverificationsessionlog.Info("validate create", "name", r.Name)

// TODO(user): fill in your validation logic upon object creation.
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *BackupVerificationSession) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
func (r *BackupVerificationSession) ValidateUpdate(ctx context.Context, old, newObj runtime.Object) (admission.Warnings, error) {
backupverificationsessionlog.Info("validate update", "name", r.Name)

oldBVS := old.(*BackupVerificationSession)
Expand All @@ -63,7 +64,7 @@ func (r *BackupVerificationSession) ValidateUpdate(old runtime.Object) (admissio
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *BackupVerificationSession) ValidateDelete() (admission.Warnings, error) {
func (r *BackupVerificationSession) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
backupverificationsessionlog.Info("validate delete", "name", r.Name)

// TODO(user): fill in your validation logic upon object deletion.
Expand Down
9 changes: 5 additions & 4 deletions apis/core/v1alpha1/backupverifier_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -39,10 +40,10 @@ func (v *BackupVerifier) SetupWebhookWithManager(mgr ctrl.Manager) error {
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//+kubebuilder:webhook:path=/validate-core-kubestash-com-v1alpha1-backupverifier,mutating=false,failurePolicy=fail,sideEffects=None,groups=core.kubestash.com,resources=backupverifiers,verbs=create;update,versions=v1alpha1,name=vbackupverifier.kb.io,admissionReviewVersions=v1

var _ webhook.Validator = &BackupVerifier{}
var _ webhook.CustomValidator = &BackupVerifier{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (v *BackupVerifier) ValidateCreate() (admission.Warnings, error) {
func (v *BackupVerifier) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
backupverifierlog.Info("validate create", "name", v.Name)

if err := v.validateVerifier(); err != nil {
Expand All @@ -53,7 +54,7 @@ func (v *BackupVerifier) ValidateCreate() (admission.Warnings, error) {
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (v *BackupVerifier) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
func (v *BackupVerifier) ValidateUpdate(ctx context.Context, old, newObj runtime.Object) (admission.Warnings, error) {
backupverifierlog.Info("validate update", "name", v.Name)

if err := v.validateVerifier(); err != nil {
Expand All @@ -64,7 +65,7 @@ func (v *BackupVerifier) ValidateUpdate(old runtime.Object) (admission.Warnings,
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (v *BackupVerifier) ValidateDelete() (admission.Warnings, error) {
func (v *BackupVerifier) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
backupverifierlog.Info("validate delete", "name", v.Name)

// TODO(user): fill in your validation logic upon object deletion.
Expand Down
14 changes: 8 additions & 6 deletions apis/core/v1alpha1/hooktemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/runtime"
"kubestash.dev/apimachinery/apis"
Expand All @@ -40,24 +41,25 @@ func (r *HookTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {

//+kubebuilder:webhook:path=/mutate-core-kubestash-com-v1alpha1-hooktemplate,mutating=true,failurePolicy=fail,sideEffects=None,groups=core.kubestash.com,resources=hooktemplates,verbs=create;update,versions=v1alpha1,name=mhooktemplate.kb.io,admissionReviewVersions=v1

var _ webhook.Defaulter = &HookTemplate{}
var _ webhook.CustomDefaulter = &HookTemplate{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
func (r *HookTemplate) Default() {
func (r *HookTemplate) Default(ctx context.Context, obj runtime.Object) error {
hooktemplatelog.Info("default", "name", r.Name)

if r.Spec.UsagePolicy == nil {
r.setDefaultUsagePolicy()
}
return nil
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//+kubebuilder:webhook:path=/validate-core-kubestash-com-v1alpha1-hooktemplate,mutating=false,failurePolicy=fail,sideEffects=None,groups=core.kubestash.com,resources=hooktemplates,verbs=create;update,versions=v1alpha1,name=vhooktemplate.kb.io,admissionReviewVersions=v1

var _ webhook.Validator = &HookTemplate{}
var _ webhook.CustomValidator = &HookTemplate{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *HookTemplate) ValidateCreate() (admission.Warnings, error) {
func (r *HookTemplate) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
hooktemplatelog.Info("validate create", "name", r.Name)

if r.Spec.Executor == nil {
Expand All @@ -76,7 +78,7 @@ func (r *HookTemplate) ValidateCreate() (admission.Warnings, error) {
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *HookTemplate) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
func (r *HookTemplate) ValidateUpdate(ctx context.Context, old, newObj runtime.Object) (admission.Warnings, error) {
hooktemplatelog.Info("validate update", "name", r.Name)

if r.Spec.Executor == nil {
Expand All @@ -95,7 +97,7 @@ func (r *HookTemplate) ValidateUpdate(old runtime.Object) (admission.Warnings, e
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *HookTemplate) ValidateDelete() (admission.Warnings, error) {
func (r *HookTemplate) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
hooktemplatelog.Info("validate delete", "name", r.Name)

// TODO(user): fill in your validation logic upon object deletion.
Expand Down
8 changes: 4 additions & 4 deletions apis/core/v1alpha1/restoresession_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ func (r *RestoreSession) SetupWebhookWithManager(mgr ctrl.Manager) error {
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//+kubebuilder:webhook:path=/validate-core-kubestash-com-v1alpha1-restoresession,mutating=false,failurePolicy=fail,sideEffects=None,groups=core.kubestash.com,resources=restoresessions,verbs=create;update,versions=v1alpha1,name=vrestoresession.kb.io,admissionReviewVersions=v1

var _ webhook.Validator = &RestoreSession{}
var _ webhook.CustomValidator = &RestoreSession{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *RestoreSession) ValidateCreate() (admission.Warnings, error) {
func (r *RestoreSession) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
restoresessionlog.Info("validate create", "name", r.Name)

if err := r.ValidateDataSource(); err != nil {
Expand All @@ -59,7 +59,7 @@ func (r *RestoreSession) ValidateCreate() (admission.Warnings, error) {
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *RestoreSession) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
func (r *RestoreSession) ValidateUpdate(ctx context.Context, old, newObj runtime.Object) (admission.Warnings, error) {
restoresessionlog.Info("validate update", "name", r.Name)

if err := r.ValidateDataSource(); err != nil {
Expand All @@ -70,7 +70,7 @@ func (r *RestoreSession) ValidateUpdate(old runtime.Object) (admission.Warnings,
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *RestoreSession) ValidateDelete() (admission.Warnings, error) {
func (r *RestoreSession) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
restoresessionlog.Info("validate delete", "name", r.Name)

// TODO(user): fill in your validation logic upon object deletion.
Expand Down
Loading

0 comments on commit 363b95e

Please sign in to comment.