// HandleAdmission populates the admission Response
// with Allowed=false if the Object is an ingress that would prevent nginx to reload the configuration
// with Allowed=true otherwise
HandleAdmission populates the admission Response
with Allowed=false if the Object is an ingress that would prevent nginx to reload the configuration
with Allowed=true otherwise
// HandleAdmission populates the admission Response // with Allowed = false if the Object is an ingress that would prevent nginx to reload the configuration // with Allowed = true otherwise
func (ia *IngressAdmission) HandleAdmission(obj runtime.Object) (runtime.Object, error) {
	outputVersion := admissionv1.SchemeGroupVersion
	review, isV1 := obj.(*admissionv1.AdmissionReview)
	if !isV1 {
		outputVersion = admissionv1beta1.SchemeGroupVersion
		reviewv1beta1, isv1beta1 := obj.(*admissionv1beta1.AdmissionReview)
		if !isv1beta1 {
			return nil, fmt.Errorf("request is not of type AdmissionReview v1 or v1beta1")
		}
		review = &admissionv1.AdmissionReview{}
		convertV1beta1AdmissionReviewToAdmissionAdmissionReview(reviewv1beta1, review)
	}
	if !apiequality.Semantic.DeepEqual(review.Request.Kind, ingressResource) {
		return nil, fmt.Errorf("rejecting admission review because the request does not contain an Ingress resource but %s with name %s in namespace %s",
			review.Request.Kind.String(), review.Request.Name, review.Request.Namespace)
	}
	status := &admissionv1.AdmissionResponse{}
	status.UID = review.Request.UID
	ingress := networking.Ingress{}
	codec := json.NewSerializerWithOptions(json.DefaultMetaFactory, scheme, scheme, json.SerializerOptions{
		Pretty: true,
	})
	codec.Decode(review.Request.Object.Raw, nil, nil)
	_, _, err := codec.Decode(review.Request.Object.Raw, nil, &ingress)
	if err != nil {
		klog.ErrorS(err, "failed to decode ingress")
		status.Allowed = false
		status.Result = &metav1.Status{
			Status: metav1.StatusFailure, Code: http.StatusBadRequest, Reason: metav1.StatusReasonBadRequest,
			Message: err.Error(),
		}
		review.Response = status
		return convertResponse(review, outputVersion), nil
	}
	if err := ia.Checker.CheckIngress(&ingress); err != nil {
		klog.ErrorS(err, "invalid ingress configuration", "ingress", fmt.Sprintf("%v/%v", review.Request.Name, review.Request.Namespace))
		status.Allowed = false
		status.Result = &metav1.Status{
			Status: metav1.StatusFailure, Code: http.StatusBadRequest, Reason: metav1.StatusReasonBadRequest,
			Message: err.Error(),
		}
		review.Response = status
		return convertResponse(review, outputVersion), nil
	}
	klog.InfoS("successfully validated configuration, accepting", "ingress", fmt.Sprintf("%v/%v", review.Request.Name, review.Request.Namespace))
	status.Allowed = true
	review.Response = status
	return convertResponse(review, outputVersion), nil
}
func ( ia * IngressAdmission ) HandleAdmission ( obj runtime . Object ) ( runtime . Object , error ) { outputVersion := admissionv1 . SchemeGroupVersion review , isV1 := obj . ( * admissionv1 . AdmissionReview ) if ! isV1 { outputVersion = admissionv1beta1 . SchemeGroupVersion reviewv1beta1 , isv1beta1 := obj . ( * admissionv1beta1 . AdmissionReview ) if ! isv1beta1 { return nil , fmt . Errorf ( " " ) } review = & admissionv1 . AdmissionReview { } convertV1beta1AdmissionReviewToAdmissionAdmissionReview ( reviewv1beta1 , review ) } if ! apiequality . Semantic . DeepEqual ( review . Request . Kind , ingressResource ) { return nil , fmt . Errorf ( " " , review . Request . Kind . String ( ) , review . Request . Name , review . Request . Namespace ) } status := & admissionv1 . AdmissionResponse { } status . UID = review . Request . UID ingress := networking . Ingress { } codec := json . NewSerializerWithOptions ( json . DefaultMetaFactory , scheme , scheme , json . SerializerOptions { Pretty : true , } ) codec . Decode ( review . Request . Object . Raw , nil , nil ) _ , _ , err := codec . Decode ( review . Request . Object . Raw , nil , & ingress ) if err != nil { klog . ErrorS ( err , " " ) status . Allowed = false status . Result = & metav1 . Status { Status : metav1 . StatusFailure , Code : http . StatusBadRequest , Reason : metav1 . StatusReasonBadRequest , Message : err . Error ( ) , } review . Response = status return convertResponse ( review , outputVersion ) , nil } if err := ia . Checker . CheckIngress ( & ingress ) ; err != nil { klog . ErrorS ( err , " " , " " , fmt . Sprintf ( " " , review . Request . Name , review . Request . Namespace ) ) status . Allowed = false status . Result = & metav1 . Status { Status : metav1 . StatusFailure , Code : http . StatusBadRequest , Reason : metav1 . StatusReasonBadRequest , Message : err . Error ( ) , } review . Response = status return convertResponse ( review , outputVersion ) , nil } klog . InfoS ( " " , " " , fmt . Sprintf ( " " , review . Request . Name , review . Request . Namespace ) ) status . Allowed = true review . Response = status return convertResponse ( review , outputVersion ) , nil }
HandleAdmission populates the admission Response
with Allowed=false if the Object is an ingress that would prevent nginx to reload the configuration
with Allowed=true otherwise
HandleAdmission populates the admission Response with Allowed = false if the Object is an ingress that would prevent nginx to reload the configuration with Allowed = true otherwise