Skip to content

Commit

Permalink
Upgrade CAPVC
Browse files Browse the repository at this point in the history
  • Loading branch information
a-kad committed May 17, 2024
1 parent 30a5328 commit 3e7e1e4
Show file tree
Hide file tree
Showing 8 changed files with 379 additions and 918 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,6 @@ binaries: download-chart ## Download binaries
HELM=$(BIN_DIR)/helm-$(GOOS)-$(GOARCH)

.PHONY: download-chart
download-chart: ## Download vcluster chart
$(HELM) repo add loft https://charts.loft.sh
$(HELM) pull loft/vcluster --version $(VCLUSTER_CHART_VERSION) -d $(BIN_DIR)
download-chart: bin-dir ## Download vcluster chart
helm repo add loft https://charts.loft.sh
helm pull loft/vcluster --version $(VCLUSTER_CHART_VERSION) -d $(BIN_DIR)
15 changes: 8 additions & 7 deletions api/v1alpha1/vcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1alpha1

import (
"fmt"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -33,25 +34,25 @@ func (r *VCluster) Default() {
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *VCluster) ValidateCreate() error {
func (r *VCluster) ValidateCreate() (admission.Warnings, error) {
vclusterlog.Info("validate create", "name", r.Name)
return nil
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *VCluster) ValidateUpdate(old runtime.Object) error {
func (r *VCluster) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
vclusterlog.Info("validate update", "name", r.Name)
oldVcluster := old.(*VCluster)

if r.Name != oldVcluster.Name {
return apierrors.NewBadRequest(fmt.Sprintf("vcluster name change is not allowed, old=%s, new=%s", oldVcluster.Name, r.Name))
return nil, apierrors.NewBadRequest(fmt.Sprintf("vcluster name change is not allowed, old=%s, new=%s", oldVcluster.Name, r.Name))
}

return nil
return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *VCluster) ValidateDelete() error {
func (r *VCluster) ValidateDelete() (admission.Warnings, error) {
vclusterlog.Info("validate delete", "name", r.Name)
return nil
return nil, nil
}
7 changes: 2 additions & 5 deletions api/v1alpha1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)
Expand All @@ -36,9 +34,8 @@ var cancel context.CancelFunc
func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)

RunSpecsWithDefaultAndCustomReporters(t,
"Webhook Suite",
[]Reporter{printer.NewlineReporter{}})
RunSpecs(t,
"Webhook Suite")
}

var _ = BeforeSuite(func() {
Expand Down
Loading

0 comments on commit 3e7e1e4

Please sign in to comment.