func MyAdmissionController(attributes admission.Attributes, object runtime.Object) error { kind := attributes.GetKind().GroupKind().String() // do something with kind... return nil }
func MyValidationWebhook(w http.ResponseWriter, req *http.Request) { decoder := json.NewDecoder(req.Body) var admissionReview admissionv1.AdmissionReview err := decoder.Decode(&admissionReview) if err != nil { http.Error(w, "could not decode admission review", http.StatusBadRequest) return } kind := admissionReview.Request.Kind.Kind // do some validation based on kind... admissionReview.Response = &admissionv1.AdmissionResponse{ Allowed: true, } respBytes, err := json.Marshal(admissionReview) if err != nil { http.Error(w, "could not encode response", http.StatusInternalServerError) return } w.WriteHeader(http.StatusOK) w.Write(respBytes) }In this example, the GetKind method is used indirectly as part of a validation webhook implementation. The kind string is extracted from the AdmissionReview object and used to perform some validation logic. Finally, the webhook returns an AdmissionResponse indicating whether the request is allowed.