func()

in pkg/webhook/packagebundlecontroller_webhook.go [77:146]


func (v *activeBundleValidator) handleInner(ctx context.Context, pbc *v1alpha1.PackageBundleController, bundles *v1alpha1.PackageBundleList) (
	*admission.Response, error,
) {
	if pbc.Spec.ActiveBundle == "" {
		resp := &admission.Response{
			AdmissionResponse: admissionv1.AdmissionResponse{
				Allowed: true,
			},
		}
		return resp, nil
	}

	var found bool
	var theBundle v1alpha1.PackageBundle
	for _, b := range bundles.Items {
		if b.Name == pbc.Spec.ActiveBundle {
			theBundle = b
			found = true
			break
		}
	}

	if !found {
		reason := fmt.Sprintf("activeBundle %q not present on cluster", pbc.Spec.ActiveBundle)
		resp := &admission.Response{
			AdmissionResponse: admissionv1.AdmissionResponse{
				Allowed: false,
				Result: &metav1.Status{
					Status:  metav1.StatusFailure,
					Code:    http.StatusBadRequest,
					Message: reason,
					Reason:  metav1.StatusReason(reason),
				},
			},
		}
		return resp, nil
	}
	info, err := v.tcc.GetServerVersion(ctx, pbc.Name)
	if err != nil {
		return nil, fmt.Errorf("getting server version for %s: %w", pbc.Name, err)
	}

	matches, err := theBundle.KubeVersionMatches(info)
	if err != nil {
		return nil, fmt.Errorf("listing package bundles: %w", err)
	}

	if !matches {
		reason := fmt.Sprintf("kuberneetes version v%s-%s does not match %s", info.Major, info.Minor, pbc.Spec.ActiveBundle)
		resp := &admission.Response{
			AdmissionResponse: admissionv1.AdmissionResponse{
				Allowed: false,
				Result: &metav1.Status{
					Status:  metav1.StatusFailure,
					Code:    http.StatusBadRequest,
					Message: reason,
					Reason:  metav1.StatusReason(reason),
				},
			},
		}
		return resp, nil
	}

	resp := &admission.Response{
		AdmissionResponse: admissionv1.AdmissionResponse{
			Allowed: true,
		},
	}
	return resp, nil
}