Skip to content

Commit

Permalink
Update webhook version for template validator to v1
Browse files Browse the repository at this point in the history
The ValidatingWebhookConfiguration uses v1 admission review version.

Adds missing fields to AdmissionReview response. Without them, k8s
will reject the response.

Signed-off-by: Andrej Krejcir <[email protected]>
  • Loading branch information
akrejcir authored and kubevirt-bot committed Jun 1, 2021
1 parent 174b78d commit 486de05
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 3 additions & 9 deletions internal/operands/template-validator/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import (
"kubevirt.io/ssp-operator/internal/common"
)

// Resources from kubevirt-template-validator version v0.7.0
// TODO - move this code to the kubevirt-template-validator
// repository, and import it as a go module

const (
ContainerPort = 8443
KubevirtIo = "kubevirt.io"
Expand Down Expand Up @@ -217,11 +213,9 @@ func newValidatingWebhook(namespace string) *admission.ValidatingWebhookConfigur
Resources: []string{"virtualmachines"},
},
}},
FailurePolicy: &fail,
SideEffects: &sideEffectsNone,
// TODO - add "v1" to the list once the template-validator
// is updated to new API
AdmissionReviewVersions: []string{"v1beta1"},
FailurePolicy: &fail,
SideEffects: &sideEffectsNone,
AdmissionReviewVersions: []string{"v1"},
}},
}
}
9 changes: 8 additions & 1 deletion internal/template-validator/webhooks/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/davecgh/go-spew/spew"
admissionv1 "k8s.io/api/admission/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"kubevirt.io/client-go/log"
)
Expand Down Expand Up @@ -66,7 +67,6 @@ func admitVMTemplate(ar *admissionv1.AdmissionReview) *admissionv1.AdmissionResp
}

func serve(resp http.ResponseWriter, req *http.Request, admit admitFunc) {
response := admissionv1.AdmissionReview{}
review, err := GetAdmissionReview(req)

log.Log.V(8).Infof("evaluating admission")
Expand All @@ -83,6 +83,13 @@ func serve(resp http.ResponseWriter, req *http.Request, admit admitFunc) {

log.Log.V(8).Infof("admission review response:\n%s", spew.Sdump(reviewResponse))

response := admissionv1.AdmissionReview{
TypeMeta: metav1.TypeMeta{
APIVersion: admissionv1.SchemeGroupVersion.String(),
Kind: "AdmissionReview",
},
}

if reviewResponse != nil {
response.Response = reviewResponse
response.Response.UID = review.Request.UID
Expand Down

0 comments on commit 486de05

Please sign in to comment.