Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrading to 0.30 api, creating v1 or v1beta1 VAP/VAPB #3472

Merged
merged 22 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4d3f669
upgrading to 0.30 api, creating v1 or v1beta1 VAP/VAPB
JaydipGabani Aug 2, 2024
9298580
adding config to enable beta api in kind cluster for 1.28, 1.29. fixi…
JaydipGabani Aug 2, 2024
f43b6bf
fixing lint
JaydipGabani Aug 3, 2024
9f58850
adding tests
JaydipGabani Aug 5, 2024
ef94027
upgrading to 0.30 api, creating v1 or v1beta1 VAP/VAPB
JaydipGabani Aug 2, 2024
f6b9ebe
adding config to enable beta api in kind cluster for 1.28, 1.29. fixi…
JaydipGabani Aug 2, 2024
c5793ea
fixing lint
JaydipGabani Aug 3, 2024
3a0eede
adding tests
JaydipGabani Aug 5, 2024
bb19964
using runtime.Object for VAP/VAPB versions
JaydipGabani Aug 5, 2024
f8791e6
merging with master
JaydipGabani Aug 5, 2024
1dff1e5
converting v1beta1 to v1 without unstructured
JaydipGabani Aug 5, 2024
de48c99
removing toolchain from go.mod
JaydipGabani Aug 5, 2024
1e26786
removing lib file
JaydipGabani Aug 5, 2024
ed5c510
checking for VAP API availability only when generation is on
JaydipGabani Aug 6, 2024
fe4998e
addressing nits
JaydipGabani Aug 6, 2024
3a77ea3
adding read lock while checking for vap api availability
JaydipGabani Aug 6, 2024
a63f998
Merge branch 'master' into k130
JaydipGabani Aug 6, 2024
6cb62fa
adding label-selector in mutation for backward comp check
JaydipGabani Aug 6, 2024
7e39997
Merge branch 'k130' of github.com:JaydipGabani/gatekeeper into k130
JaydipGabani Aug 6, 2024
f3a4977
using interim variables for read lock
JaydipGabani Aug 6, 2024
2f0b758
adding todo to use r.scheme.convert
JaydipGabani Aug 7, 2024
5b3ffa0
addressing nits
JaydipGabani Aug 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pkg/controller/constraint/constraint_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func (r *ReconcileConstraint) Reconcile(ctx context.Context, request reconcile.R
return reconcile.Result{}, err
}

newVapBinding, err := r.getRunTimeVAPBinding(groupVersion, transformedVapBinding, currentVapBinding)
newVapBinding, err := getRunTimeVAPBinding(groupVersion, transformedVapBinding, currentVapBinding)
if err != nil {
status.Status.Errors = append(status.Status.Errors, constraintstatusv1beta1.Error{Message: err.Error()})
if err2 := r.writer.Update(ctx, status); err2 != nil {
Expand Down Expand Up @@ -629,6 +629,13 @@ func (c *ConstraintsCache) reportTotalConstraints(ctx context.Context, reporter
}

func IsVapAPIEnabled() (bool, *schema.GroupVersion) {
vapMux.RLock()
if VapAPIEnabled != nil {
vapMux.RUnlock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For strict correctness, you should only access the variable while it's under a read lock. Suggest using intermediate variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added local variables for strict correctness.

return *VapAPIEnabled, GroupVersion
}

vapMux.RUnlock()
vapMux.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to have an RWMutex here to enable parallelism in the future.

This is especially true because this function is being called by two different reconcilers (constraint/constraint template).

General pattern:

  • acquire read lock
  • check if VapAPIEnabled has been assigned a value, if so, return it
  • Otherwise, drop read lock and acquire a write lock
  • check if VapAPIEnabled has been assigned a value, if so, return it (this is necessary b/c a write could have happened in the time the lock was released)
  • continue as written

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added read lock

defer vapMux.Unlock()

Expand Down Expand Up @@ -692,7 +699,7 @@ func vapBindingForVersion(gvk schema.GroupVersion) (client.Object, error) {
}
}

func (r *ReconcileConstraint) getRunTimeVAPBinding(gvk *schema.GroupVersion, transformedVapBinding *admissionregistrationv1beta1.ValidatingAdmissionPolicyBinding, currentVapBinding client.Object) (client.Object, error) {
func getRunTimeVAPBinding(gvk *schema.GroupVersion, transformedVapBinding *admissionregistrationv1beta1.ValidatingAdmissionPolicyBinding, currentVapBinding client.Object) (client.Object, error) {
if currentVapBinding == nil {
if gvk.Version == "v1" {
return v1beta1ToV1(transformedVapBinding)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func (r *ReconcileConstraintTemplate) handleUpdate(
return reconcile.Result{}, err
}

newVap, err := r.getRunTimeVAP(groupVersion, transformedVap, currentVap)
newVap, err := getRunTimeVAP(groupVersion, transformedVap, currentVap)
if err != nil {
logger.Error(err, "getRunTimeVAP error", "vapName", vapName)
createErr := &v1beta1.CreateCRDError{Code: ErrCreateCode, Message: err.Error()}
Expand Down Expand Up @@ -785,7 +785,7 @@ func vapForVersion(gvk *schema.GroupVersion) (client.Object, error) {
}
}

func (r *ReconcileConstraintTemplate) getRunTimeVAP(gvk *schema.GroupVersion, transformedVap *admissionregistrationv1beta1.ValidatingAdmissionPolicy, currentVap client.Object) (client.Object, error) {
func getRunTimeVAP(gvk *schema.GroupVersion, transformedVap *admissionregistrationv1beta1.ValidatingAdmissionPolicy, currentVap client.Object) (client.Object, error) {
if currentVap == nil {
if gvk.Version == "v1" {
return v1beta1ToV1(transformedVap)
Expand Down
Loading