Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cmdline args to enable group snapshot webhooks #922

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion deploy/kubernetes/webhook-example/webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ spec:
- name: snapshot-validation
image: registry.k8s.io/sig-storage/snapshot-validation-webhook:v6.2.1 # change the image if you wish to use your own custom validation server image
imagePullPolicy: IfNotPresent
args: ['--tls-cert-file=/etc/snapshot-validation-webhook/certs/tls.crt', '--tls-private-key-file=/etc/snapshot-validation-webhook/certs/tls.key']
args:
- '--tls-cert-file=/etc/snapshot-validation-webhook/certs/tls.crt'
- '--tls-private-key-file=/etc/snapshot-validation-webhook/certs/tls.key'
# uncomment the following line to enable webhook for VolumeGroupSnapshot, VolumeGroupSnapshotContent and VolumeGroupSnapshotClass.
# - '--enable-volume-group-snapshot-webhook'
ports:
- containerPort: 443 # change the port as needed
volumeMounts:
Expand Down
30 changes: 20 additions & 10 deletions pkg/validation-webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ import (
)

var (
certFile string
keyFile string
kubeconfigFile string
port int
preventVolumeModeConversion bool
certFile string
keyFile string
kubeconfigFile string
port int
preventVolumeModeConversion bool
enableVolumeGroupSnapshotWebhook bool
)

// CmdWebhook is used by Cobra.
Expand All @@ -71,6 +72,8 @@ func init() {
CmdWebhook.Flags().StringVar(&kubeconfigFile, "kubeconfig", "", "kubeconfig file to use for volumesnapshotclasses")
CmdWebhook.Flags().BoolVar(&preventVolumeModeConversion, "prevent-volume-mode-conversion",
false, "Prevents an unauthorised user from modifying the volume mode when creating a PVC from an existing VolumeSnapshot.")
CmdWebhook.Flags().BoolVar(&enableVolumeGroupSnapshotWebhook, "enable-volume-group-snapshot-webhook",
false, "Enables webhook for VolumeGroupSnapshot, VolumeGroupSnapshotContent and VolumeGroupSnapshotClass.")
}

// admitv1beta1Func handles a v1beta1 admission
Expand Down Expand Up @@ -217,14 +220,18 @@ func startServer(
snapshotWebhook := serveSnapshotWebhook{
lister: vscLister,
}
groupSnapshotWebhook := serveGroupSnapshotWebhook{
lister: vgscLister,
}

fmt.Println("Starting webhook server")
mux := http.NewServeMux()
mux.Handle("/volumesnapshot", snapshotWebhook)
mux.Handle("/volumegroupsnapshot", groupSnapshotWebhook)

if enableVolumeGroupSnapshotWebhook {
groupSnapshotWebhook := serveGroupSnapshotWebhook{
lister: vgscLister,
}
mux.Handle("/volumegroupsnapshot", groupSnapshotWebhook)
}

mux.HandleFunc("/readyz", func(w http.ResponseWriter, req *http.Request) { w.Write([]byte("ok")) })
srv := &http.Server{
Handler: mux,
Expand Down Expand Up @@ -267,7 +274,10 @@ func main(cmd *cobra.Command, args []string) {

factory := informers.NewSharedInformerFactory(snapClient, 0)
snapshotLister := factory.Snapshot().V1().VolumeSnapshotClasses().Lister()
groupSnapshotLister := factory.Groupsnapshot().V1alpha1().VolumeGroupSnapshotClasses().Lister()
var groupSnapshotLister groupsnapshotlisters.VolumeGroupSnapshotClassLister
if enableVolumeGroupSnapshotWebhook {
groupSnapshotLister = factory.Groupsnapshot().V1alpha1().VolumeGroupSnapshotClasses().Lister()
}

// Start the informers
factory.Start(ctx.Done())
Expand Down