Skip to content

Commit

Permalink
attempt to fix the error when we update the network policy
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Labarussias <issif+github@gadz.org>
  • Loading branch information
Issif committed Feb 15, 2024
1 parent ec58581 commit ddfff20
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions actionners/calico/networkpolicy/networkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,11 @@ func Action(action *rules.Action, event *events.Event) (utils.LogLine, error) {
payload.Spec.Egress = []networkingv3.Rule{*denyRule}
payload.Spec.Egress = append(payload.Spec.Egress, *allowRule)
_, err = calicoClient.ProjectcalicoV3().NetworkPolicies(namespace).Create(context.Background(), &payload, metav1.CreateOptions{})
if errorsv1.IsAlreadyExists(err) {
netpol, err = calicoClient.ProjectcalicoV3().NetworkPolicies(namespace).Get(context.Background(), owner, metav1.GetOptions{}) //nolint:golint,staticcheck
}
output = fmt.Sprintf("the networkpolicy '%v' in the namespace '%v' has been created", owner, namespace)
}
if errorsv1.IsAlreadyExists(err) {
netpol, err = calicoClient.ProjectcalicoV3().NetworkPolicies(namespace).Get(context.Background(), owner, metav1.GetOptions{})
}
if err == nil {
} else if err == nil {
payload.ObjectMeta.ResourceVersion = netpol.ObjectMeta.ResourceVersion
var denyCIDR []string
for _, i := range netpol.Spec.Egress {
Expand Down

0 comments on commit ddfff20

Please sign in to comment.