Skip to content

Commit 714a5bf

Browse files
authored
Merge pull request #71 from metal-stack/export-namespace
Export Namespace where CNWPs are expected
2 parents ad2e46a + 5b0842d commit 714a5bf

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

api/v1/clusterwidenetworkpolicy_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ type ClusterwideNetworkPolicyList struct {
4545
Items []ClusterwideNetworkPolicy `json:"items"`
4646
}
4747

48+
const (
49+
// ClusterwideNetworkPolicyNamespace defines the namespace CNWPs are expected.
50+
ClusterwideNetworkPolicyNamespace = "firewall"
51+
)
52+
4853
// PolicySpec defines the rules to create for ingress and egress
4954
type PolicySpec struct {
5055
// Description is a free form string, it can be used by the creator of

controllers/clusterwidenetworkpolicy_controller.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ type ClusterwideNetworkPolicyReconciler struct {
3737
recorder record.EventRecorder
3838
}
3939

40-
const clusterwideNPNamespace = "firewall"
41-
4240
// Reconcile ClusterwideNetworkPolicy and creates nftables rules accordingly
4341
// +kubebuilder:rbac:groups=metal-stack.io,resources=clusterwidenetworkpolicies,verbs=get;list;watch;create;update;patch;delete
4442
// +kubebuilder:rbac:groups=metal-stack.io,resources=clusterwidenetworkpolicies/status,verbs=get;update;patch
@@ -52,8 +50,8 @@ func (r *ClusterwideNetworkPolicyReconciler) Reconcile(req ctrl.Request) (ctrl.R
5250

5351
// if network policy does not belong to the namespace where clusterwide network policies are stored:
5452
// update status with error message
55-
if req.Namespace != clusterwideNPNamespace {
56-
r.recorder.Event(&clusterNP, "Warning", "Unapplicable", fmt.Sprintf("cluster wide network policies must be defined in namespace %s otherwise they won't take effect", clusterwideNPNamespace))
53+
if req.Namespace != firewallv1.ClusterwideNetworkPolicyNamespace {
54+
r.recorder.Event(&clusterNP, "Warning", "Unapplicable", fmt.Sprintf("cluster wide network policies must be defined in namespace %s otherwise they won't take effect", firewallv1.ClusterwideNetworkPolicyNamespace))
5755
return ctrl.Result{}, nil
5856
}
5957

0 commit comments

Comments
 (0)