Skip to content

Commit

Permalink
move check for nil podAdmission plugin up
Browse files Browse the repository at this point in the history
increases readability and we can assume that podAdmission is not nil if
the check is higher
  • Loading branch information
JacobTanenbaum committed May 13, 2024
1 parent 044a7d4 commit c348849
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions go-controller/pkg/ovnwebhook/podadmission.go
Expand Up @@ -89,19 +89,17 @@ func (p PodAdmission) ValidateUpdate(ctx context.Context, oldObj, newObj runtime
changes := mapDiff(oldPod.Annotations, newPod.Annotations)
changedKeys := maps.Keys(changes)

// user is in additional acceptance condition list
if podAdmission != nil {
// additional acceptance condition check
if !podAdmission.AllowedPodAnnotationKeys.HasAll(changedKeys...) {
return fmt.Errorf("%s node: %q is not allowed to set the following annotations on pod: %q: %v", podAdmission.CommonNamePrefix, nodeName, newPod.Name, sets.New[string](changedKeys...).Difference(podAdmission.AllowedPodAnnotationKeys).UnsortedList())
}
}

// if there is no matched acceptanceCondition as well as ovnkube-node, then skip following check
if podAdmission == nil {
return nil
}

// user is in additional acceptance condition list
// additional acceptance condition check
if !podAdmission.AllowedPodAnnotationKeys.HasAll(changedKeys...) {
return fmt.Errorf("%s node: %q is not allowed to set the following annotations on pod: %q: %v", podAdmission.CommonNamePrefix, nodeName, newPod.Name, sets.New[string](changedKeys...).Difference(podAdmission.AllowedPodAnnotationKeys).UnsortedList())
}

prefixName := podAdmission.CommonNamePrefix

if oldPod.Spec.NodeName != nodeName {
Expand Down

0 comments on commit c348849

Please sign in to comment.