Path: blob/main/components/ws-manager-api/go/crd/v1/workspace_webhook.go
2501 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License-AGPL.txt in the project root for license information.34package v156import (7"k8s.io/apimachinery/pkg/runtime"8ctrl "sigs.k8s.io/controller-runtime"9logf "sigs.k8s.io/controller-runtime/pkg/log"10"sigs.k8s.io/controller-runtime/pkg/webhook"11"sigs.k8s.io/controller-runtime/pkg/webhook/admission"12)1314// log is for logging in this package.15var workspacelog = logf.Log.WithName("workspace-resource")1617func (r *Workspace) SetupWebhookWithManager(mgr ctrl.Manager) error {18return ctrl.NewWebhookManagedBy(mgr).19For(r).20Complete()21}2223// TODO(user): EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!2425//+kubebuilder:webhook:path=/mutate-workspace-gitpod-io-v1-workspace,mutating=true,failurePolicy=fail,sideEffects=None,groups=workspace.gitpod.io,resources=workspaces,verbs=create;update,versions=v1,name=mworkspace.kb.io,admissionReviewVersions=v12627var _ webhook.Defaulter = &Workspace{}2829// Default implements webhook.Defaulter so a webhook will be registered for the type30func (r *Workspace) Default() {31workspacelog.Info("default", "name", r.Name)3233// TODO(user): fill in your defaulting logic.34}3536// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.37//+kubebuilder:webhook:path=/validate-workspace-gitpod-io-v1-workspace,mutating=false,failurePolicy=fail,sideEffects=None,groups=workspace.gitpod.io,resources=workspaces,verbs=create;update,versions=v1,name=vworkspace.kb.io,admissionReviewVersions=v13839var _ webhook.Validator = &Workspace{}4041// ValidateCreate implements webhook.Validator so a webhook will be registered for the type42func (r *Workspace) ValidateCreate() (admission.Warnings, error) {43workspacelog.Info("validate create", "name", r.Name)4445return r.validateWorkspace()46}4748// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type49func (r *Workspace) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {50workspacelog.Info("validate update", "name", r.Name)5152return r.validateWorkspace()53}5455// ValidateDelete implements webhook.Validator so a webhook will be registered for the type56func (r *Workspace) ValidateDelete() (admission.Warnings, error) {57workspacelog.Info("validate delete", "name", r.Name)5859// TODO(user): fill in your validation logic upon object deletion.60return nil, nil61}6263func (r *Workspace) validateWorkspace() (admission.Warnings, error) {64return nil, nil65}666768