Skip to content

Commit

Permalink
Set Group Version Kind
Browse files Browse the repository at this point in the history
  • Loading branch information
nickschuch committed Nov 27, 2024
1 parent 2f03e7a commit 0a5d59c
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions internal/mutator/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,18 @@ func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) {
return
}

admissionReviewResponse := &admissionv1.AdmissionReview{
Response: &admissionv1.AdmissionResponse{
UID: admissionReviewRequest.Request.UID,
Allowed: true,
},
}

admissionReviewResponse.SetGroupVersionKind(admissionReviewRequest.GroupVersionKind())

if len(nodeSelector) == 0 {
logger.Info("skipping because no namespace node selectors found")

// No changes needed; return Allowed response without a patch
admissionReviewResponse := admissionv1.AdmissionReview{
Response: &admissionv1.AdmissionResponse{
UID: admissionReviewRequest.Request.UID,
Allowed: true,
},
}

w.Header().Set("Content-Type", "application/json")

if err := json.NewEncoder(w).Encode(admissionReviewResponse); err != nil {
Expand Down Expand Up @@ -104,14 +105,8 @@ func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) {
}

// Construct the AdmissionReview response
admissionReviewResponse := admissionv1.AdmissionReview{
Response: &admissionv1.AdmissionResponse{
UID: admissionReviewRequest.Request.UID,
Allowed: true,
Patch: patchBytes,
PatchType: func() *admissionv1.PatchType { pt := admissionv1.PatchTypeJSONPatch; return &pt }(),
},
}
admissionReviewResponse.Response.Patch = patchBytes
admissionReviewResponse.Response.PatchType = func() *admissionv1.PatchType { pt := admissionv1.PatchTypeJSONPatch; return &pt }()

w.Header().Set("Content-Type", "application/json")

Expand Down

0 comments on commit 0a5d59c

Please sign in to comment.