Skip to content

Commit 82071e8

Browse files
committed
switching to v1 admission review
Signed-off-by: Min Jin <[email protected]>
1 parent 2a1a113 commit 82071e8

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

pkg/handler/handler.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import (
3030

3131
"github.com/aws/amazon-eks-pod-identity-webhook/pkg"
3232
"github.com/aws/amazon-eks-pod-identity-webhook/pkg/cache"
33-
"k8s.io/api/admission/v1beta1"
33+
"k8s.io/api/admission/v1"
34+
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
3435
admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1"
3536
corev1 "k8s.io/api/core/v1"
3637
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -41,6 +42,7 @@ import (
4142

4243
func init() {
4344
_ = corev1.AddToScheme(runtimeScheme)
45+
_ = admissionregistrationv1.AddToScheme(runtimeScheme)
4446
_ = admissionregistrationv1beta1.AddToScheme(runtimeScheme)
4547
}
4648

@@ -480,8 +482,8 @@ func (m *Modifier) buildPodPatchConfig(pod *corev1.Pod) *podPatchConfig {
480482
}
481483

482484
// MutatePod takes a AdmissionReview, mutates the pod, and returns an AdmissionResponse
483-
func (m *Modifier) MutatePod(ar *v1beta1.AdmissionReview) *v1beta1.AdmissionResponse {
484-
badRequest := &v1beta1.AdmissionResponse{
485+
func (m *Modifier) MutatePod(ar *v1.AdmissionReview) *v1.AdmissionResponse {
486+
badRequest := &v1.AdmissionResponse{
485487
Result: &metav1.Status{
486488
Message: "bad content",
487489
},
@@ -498,7 +500,7 @@ func (m *Modifier) MutatePod(ar *v1beta1.AdmissionReview) *v1beta1.AdmissionResp
498500
if err := json.Unmarshal(req.Object.Raw, &pod); err != nil {
499501
klog.Errorf("Could not unmarshal raw object: %v", err)
500502
klog.Errorf("Object: %v", string(req.Object.Raw))
501-
return &v1beta1.AdmissionResponse{
503+
return &v1.AdmissionResponse{
502504
Result: &metav1.Status{
503505
Message: err.Error(),
504506
},
@@ -511,7 +513,7 @@ func (m *Modifier) MutatePod(ar *v1beta1.AdmissionReview) *v1beta1.AdmissionResp
511513
if patchConfig == nil {
512514
klog.V(4).Infof("Pod was not mutated. Reason: "+
513515
"Service account did not have the right annotations or was not found in the cache. %s", logContext(pod.Name, pod.GenerateName, pod.Spec.ServiceAccountName, pod.Namespace))
514-
return &v1beta1.AdmissionResponse{
516+
return &v1.AdmissionResponse{
515517
Allowed: true,
516518
}
517519
}
@@ -520,7 +522,7 @@ func (m *Modifier) MutatePod(ar *v1beta1.AdmissionReview) *v1beta1.AdmissionResp
520522
patchBytes, err := json.Marshal(patch)
521523
if err != nil {
522524
klog.Errorf("Error marshaling pod update: %v", err.Error())
523-
return &v1beta1.AdmissionResponse{
525+
return &v1.AdmissionResponse{
524526
Result: &metav1.Status{
525527
Message: err.Error(),
526528
},
@@ -535,11 +537,11 @@ func (m *Modifier) MutatePod(ar *v1beta1.AdmissionReview) *v1beta1.AdmissionResp
535537
"Required volume mounts and env variables were already present. %s", logContext(pod.Name, pod.GenerateName, pod.Spec.ServiceAccountName, pod.Namespace))
536538
}
537539

538-
return &v1beta1.AdmissionResponse{
540+
return &v1.AdmissionResponse{
539541
Allowed: true,
540542
Patch: patchBytes,
541-
PatchType: func() *v1beta1.PatchType {
542-
pt := v1beta1.PatchTypeJSONPatch
543+
PatchType: func() *v1.PatchType {
544+
pt := v1.PatchTypeJSONPatch
543545
return &pt
544546
}(),
545547
}
@@ -562,11 +564,11 @@ func (m *Modifier) Handle(w http.ResponseWriter, r *http.Request) {
562564
return
563565
}
564566

565-
var admissionResponse *v1beta1.AdmissionResponse
566-
ar := v1beta1.AdmissionReview{}
567+
var admissionResponse *v1.AdmissionResponse
568+
ar := v1.AdmissionReview{}
567569
if _, _, err := deserializer.Decode(body, nil, &ar); err != nil {
568570
klog.Errorf("Can't decode body: %v", err)
569-
admissionResponse = &v1beta1.AdmissionResponse{
571+
admissionResponse = &v1.AdmissionResponse{
570572
Result: &metav1.Status{
571573
Message: err.Error(),
572574
},
@@ -575,7 +577,7 @@ func (m *Modifier) Handle(w http.ResponseWriter, r *http.Request) {
575577
admissionResponse = m.MutatePod(&ar)
576578
}
577579

578-
admissionReview := v1beta1.AdmissionReview{}
580+
admissionReview := v1.AdmissionReview{}
579581
if admissionResponse != nil {
580582
admissionReview.Response = admissionResponse
581583
if ar.Request != nil {

0 commit comments

Comments
 (0)