Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ws-manager-api/go/crd/v1/workspace_webhook.go
2501 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License-AGPL.txt in the project root for license information.
4
5
package v1
6
7
import (
8
"k8s.io/apimachinery/pkg/runtime"
9
ctrl "sigs.k8s.io/controller-runtime"
10
logf "sigs.k8s.io/controller-runtime/pkg/log"
11
"sigs.k8s.io/controller-runtime/pkg/webhook"
12
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
13
)
14
15
// log is for logging in this package.
16
var workspacelog = logf.Log.WithName("workspace-resource")
17
18
func (r *Workspace) SetupWebhookWithManager(mgr ctrl.Manager) error {
19
return ctrl.NewWebhookManagedBy(mgr).
20
For(r).
21
Complete()
22
}
23
24
// TODO(user): EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
25
26
//+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=v1
27
28
var _ webhook.Defaulter = &Workspace{}
29
30
// Default implements webhook.Defaulter so a webhook will be registered for the type
31
func (r *Workspace) Default() {
32
workspacelog.Info("default", "name", r.Name)
33
34
// TODO(user): fill in your defaulting logic.
35
}
36
37
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
38
//+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=v1
39
40
var _ webhook.Validator = &Workspace{}
41
42
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
43
func (r *Workspace) ValidateCreate() (admission.Warnings, error) {
44
workspacelog.Info("validate create", "name", r.Name)
45
46
return r.validateWorkspace()
47
}
48
49
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
50
func (r *Workspace) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
51
workspacelog.Info("validate update", "name", r.Name)
52
53
return r.validateWorkspace()
54
}
55
56
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
57
func (r *Workspace) ValidateDelete() (admission.Warnings, error) {
58
workspacelog.Info("validate delete", "name", r.Name)
59
60
// TODO(user): fill in your validation logic upon object deletion.
61
return nil, nil
62
}
63
64
func (r *Workspace) validateWorkspace() (admission.Warnings, error) {
65
return nil, nil
66
}
67
68