Skip to content

Commit

Permalink
Move docker infrastructure experimental API v1beta1 webhooks to separ…
Browse files Browse the repository at this point in the history
…ate package
  • Loading branch information
Ankitasw committed Sep 19, 2023
1 parent 1ab45a6 commit 85c2d25
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 3 deletions.
17 changes: 17 additions & 0 deletions test/infrastructure/docker/exp/internal/webhooks/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package webhooks implements docker infrastructure exp webhooks.
package webhooks
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1
package webhooks

import (
ctrl "sigs.k8s.io/controller-runtime"

infraexpv1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/exp/api/v1beta1"
)

// DockerMachinePool implements a validating and defaulting webhook for DockerMachinePool.
type DockerMachinePool struct{}

func (c *DockerMachinePool) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(c).
For(&infraexpv1.DockerMachinePool{}).
Complete()
}
15 changes: 15 additions & 0 deletions test/infrastructure/docker/exp/webhooks/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package webhooks

import (
ctrl "sigs.k8s.io/controller-runtime"

"sigs.k8s.io/cluster-api/test/infrastructure/docker/exp/internal/webhooks"
)

// DockerMachinePool implements a validating and defaulting webhook for DockerMachinePool.
type DockerMachinePool struct{}

// SetupWebhookWithManager sets up DockerMachinePool webhooks.
func (webhook *DockerMachinePool) SetupWebhookWithManager(mgr ctrl.Manager) error {
return (&webhooks.DockerMachinePool{}).SetupWebhookWithManager(mgr)
}
17 changes: 17 additions & 0 deletions test/infrastructure/docker/exp/webhooks/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package webhooks contains docker infrastructure experimental webhook implementations for some of our API types.
package webhooks
5 changes: 4 additions & 1 deletion test/infrastructure/docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
goruntime "runtime"
"time"

"sigs.k8s.io/cluster-api/test/infrastructure/docker/exp/webhooks"

"github.com/spf13/pflag"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -55,6 +57,7 @@ import (
infraexpv1alpha4 "sigs.k8s.io/cluster-api/test/infrastructure/docker/exp/api/v1alpha4"
infraexpv1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/exp/api/v1beta1"
expcontrollers "sigs.k8s.io/cluster-api/test/infrastructure/docker/exp/controllers"
"sigs.k8s.io/cluster-api/test/infrastructure/docker/exp/webhooks"
"sigs.k8s.io/cluster-api/util/flags"
"sigs.k8s.io/cluster-api/version"
)
Expand Down Expand Up @@ -377,7 +380,7 @@ func setupWebhooks(mgr ctrl.Manager) {
}

if feature.Gates.Enabled(feature.MachinePool) {
if err := (&infraexpv1.DockerMachinePool{}).SetupWebhookWithManager(mgr); err != nil {
if err := (&webhooks.DockerMachinePool{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "DockerMachinePool")
os.Exit(1)
}
Expand Down

0 comments on commit 85c2d25

Please sign in to comment.