-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a rare bug where external network policies were not deleted due t…
…o a race condition when the enforcement was turned off (#496)
- Loading branch information
Showing
6 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/operator/controllers/external_traffic/network_policy_reconciler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package external_traffic | ||
|
||
import ( | ||
"context" | ||
"github.com/otterize/intents-operator/src/shared/errors" | ||
"github.com/otterize/intents-operator/src/shared/injectablerecorder" | ||
"github.com/samber/lo" | ||
"github.com/sirupsen/logrus" | ||
v1 "k8s.io/api/networking/v1" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/controller" | ||
) | ||
|
||
//+kubebuilder:rbac:groups="networking.k8s.io",resources=networkpolicies,verbs=get;update;patch;list;watch;delete;create | ||
|
||
type NetworkPolicyReconciler struct { | ||
client.Client | ||
extNetpolHandler *NetworkPolicyHandler | ||
injectablerecorder.InjectableRecorder | ||
} | ||
|
||
func NewNetworkPolicyReconciler( | ||
client client.Client, | ||
extNetpolHandler *NetworkPolicyHandler, | ||
) *NetworkPolicyReconciler { | ||
return &NetworkPolicyReconciler{ | ||
Client: client, | ||
extNetpolHandler: extNetpolHandler, | ||
} | ||
} | ||
|
||
func (r *NetworkPolicyReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
recorder := mgr.GetEventRecorderFor("intents-operator") | ||
r.InjectRecorder(recorder) | ||
|
||
return ctrl.NewControllerManagedBy(mgr). | ||
For(&v1.NetworkPolicy{}). | ||
WithOptions(controller.Options{RecoverPanic: lo.ToPtr(true)}). | ||
Complete(r) | ||
} | ||
|
||
// Reconcile handles network policy creation, update and delete. In all of these cases, it calls the NetworkPolicyHandler | ||
// to handle the pods in the namespace of the network policy. | ||
func (r *NetworkPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
logrus.Info("Handling external for NetworkPolicy for namespace: ", req.Namespace) | ||
err := r.extNetpolHandler.HandlePodsByNamespace(ctx, req.Namespace) | ||
if err != nil { | ||
return ctrl.Result{}, errors.Wrap(err) | ||
} | ||
|
||
return ctrl.Result{}, nil | ||
} |
14 changes: 14 additions & 0 deletions
14
src/operator/controllers/intents_reconcilers/mocks/mock_external_netpol_handler.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters