Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Demchuk <[email protected]>
  • Loading branch information
NikolayDemchuk committed Oct 17, 2024
1 parent 2dbb679 commit 883ab52
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions images/webhooks/src/handlers/nscValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package handlers

import (
"context"
"encoding/json"
cn "github.com/deckhouse/csi-nfs/api/v1alpha1"
"github.com/slok/kubewebhook/v2/pkg/model"
kwhvalidating "github.com/slok/kubewebhook/v2/pkg/webhook/validating"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
mc "webhooks/api"
)

Expand Down Expand Up @@ -66,24 +64,10 @@ func NSCValidate(ctx context.Context, arReview *model.AdmissionReview, obj metav
klog.Infof("NFSv3 support enabled: %t", v3enabled)

if v3presents && !v3enabled {
klog.Info("Enabling v3 support")
patchBytes, err := json.Marshal(map[string]interface{}{
"spec": map[string]interface{}{
"settings": map[string]interface{}{
"v3support": true,
},
},
})
if err != nil {
klog.Fatalf("Error marshalling patch: %s", err.Error())
}

err = cl.Patch(context.TODO(), nfsModuleConfig, client.RawPatch(types.MergePatchType, patchBytes))
if err != nil {
klog.Fatalf("Error patching object: %s", err.Error())
}
klog.Info("NFS v3 is present in module config, disable it first")
return &kwhvalidating.ValidatorResult{Valid: false}, nil
} else if !v3presents && v3enabled {
klog.Info("NFS v3 is not enabled, enable it first")
klog.Info("NFS v3 is not enabled in module config, enable it first")
return &kwhvalidating.ValidatorResult{Valid: false}, nil
}

Expand Down

0 comments on commit 883ab52

Please sign in to comment.