Skip to content

Commit

Permalink
adding constructor for vapbinding name
Browse files Browse the repository at this point in the history
Signed-off-by: Jaydip Gabani <[email protected]>
  • Loading branch information
JaydipGabani committed Nov 22, 2024
1 parent 32f4591 commit a1481e8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/controller/constraint/constraint_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func (r *ReconcileConstraint) Reconcile(ctx context.Context, request reconcile.R
if err != nil {
return reconcile.Result{}, err
}
vapBindingName := fmt.Sprintf("gatekeeper-%s", instance.GetName())
vapBindingName := getVAPBindingName(instance.GetName())
currentVapBinding.SetName(vapBindingName)
if err := r.writer.Delete(ctx, currentVapBinding); err != nil {
if !apierrors.IsNotFound(err) {
Expand Down Expand Up @@ -567,7 +567,7 @@ func (r *ReconcileConstraint) manageVAPB(ctx context.Context, enforcementAction
if err != nil {
return noDelay, r.reportErrorOnConstraintStatus(ctx, status, err, "could not get ValidatingAdmissionPolicyBinding API version")
}
vapBindingName := fmt.Sprintf("gatekeeper-%s", instance.GetName())
vapBindingName := getVAPBindingName(instance.GetName())
log.Info("check if vapbinding exists", "vapBindingName", vapBindingName)
if err := r.reader.Get(ctx, types.NamespacedName{Name: vapBindingName}, currentVapBinding); err != nil {
if !apierrors.IsNotFound(err) {
Expand Down Expand Up @@ -609,7 +609,7 @@ func (r *ReconcileConstraint) manageVAPB(ctx context.Context, enforcementAction
if err != nil {
return noDelay, r.reportErrorOnConstraintStatus(ctx, status, err, "could not get ValidatingAdmissionPolicyBinding API version")
}
vapBindingName := fmt.Sprintf("gatekeeper-%s", instance.GetName())
vapBindingName := getVAPBindingName(instance.GetName())
log.Info("check if vapbinding exists", "vapBindingName", vapBindingName)
if err := r.reader.Get(ctx, types.NamespacedName{Name: vapBindingName}, currentVapBinding); err != nil {
if !apierrors.IsNotFound(err) && !errors.As(err, &discoveryErr) && !meta.IsNoMatchError(err) {
Expand Down Expand Up @@ -767,3 +767,7 @@ func cleanEnforcementPointStatus(status *constraintstatusv1beta1.ConstraintPodSt
}
}
}

func getVAPBindingName(constraintName string) string {
return fmt.Sprintf("gatekeeper-%s", constraintName)
}

0 comments on commit a1481e8

Please sign in to comment.