Skip to content

Commit

Permalink
use vap binding in constraint controller
Browse files Browse the repository at this point in the history
Signed-off-by: Avinash Patnala <[email protected]>
  • Loading branch information
Avinash Patnala committed Oct 23, 2024
1 parent fcde683 commit 78f720f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/constraint/constraint_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (r *ReconcileConstraint) Reconcile(ctx context.Context, request reconcile.R
r.log.Info("constraint controller", "generateVAPB", generateVAPB)
// generate vapbinding resources
if generateVAPB && groupVersion != nil {
currentVapBinding, err := transform.VapForVersion(groupVersion)
currentVapBinding, err := transform.VapBindingForVersion(*groupVersion)
if err != nil {
return reconcile.Result{}, r.reportErrorOnConstraintStatus(ctx, status, err, "could not get ValidatingAdmissionPolicyBinding API version")
}
Expand Down Expand Up @@ -388,7 +388,7 @@ func (r *ReconcileConstraint) Reconcile(ctx context.Context, request reconcile.R
// do not generate vapbinding resources
// remove if exists
if !generateVAPB && groupVersion != nil {
currentVapBinding, err := transform.VapForVersion(groupVersion)
currentVapBinding, err := transform.VapBindingForVersion(*groupVersion)
if err != nil {
return reconcile.Result{}, r.reportErrorOnConstraintStatus(ctx, status, err, "could not get ValidatingAdmissionPolicyBinding API version")
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/drivers/k8scel/transform/vap_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,14 @@ func VapForVersion(gvk *schema.GroupVersion) (client.Object, error) {
return nil, errors.New("unrecognized version")
}
}

func VapBindingForVersion(gvk schema.GroupVersion) (client.Object, error) {
switch gvk.Version {
case "v1":
return &admissionregistrationv1.ValidatingAdmissionPolicyBinding{}, nil
case "v1beta1":
return &admissionregistrationv1beta1.ValidatingAdmissionPolicyBinding{}, nil
default:
return nil, errors.New("unrecognized version")
}
}

0 comments on commit 78f720f

Please sign in to comment.