Skip to content

Commit

Permalink
Merge pull request #71 from metal-stack/export-namespace
Browse files Browse the repository at this point in the history
Export Namespace where CNWPs are expected
  • Loading branch information
mwindower committed Feb 9, 2021
2 parents ad2e46a + 5b0842d commit 714a5bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 5 additions & 0 deletions api/v1/clusterwidenetworkpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ type ClusterwideNetworkPolicyList struct {
Items []ClusterwideNetworkPolicy `json:"items"`
}

const (
// ClusterwideNetworkPolicyNamespace defines the namespace CNWPs are expected.
ClusterwideNetworkPolicyNamespace = "firewall"
)

// PolicySpec defines the rules to create for ingress and egress
type PolicySpec struct {
// Description is a free form string, it can be used by the creator of
Expand Down
6 changes: 2 additions & 4 deletions controllers/clusterwidenetworkpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ type ClusterwideNetworkPolicyReconciler struct {
recorder record.EventRecorder
}

const clusterwideNPNamespace = "firewall"

// Reconcile ClusterwideNetworkPolicy and creates nftables rules accordingly
// +kubebuilder:rbac:groups=metal-stack.io,resources=clusterwidenetworkpolicies,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=metal-stack.io,resources=clusterwidenetworkpolicies/status,verbs=get;update;patch
Expand All @@ -52,8 +50,8 @@ func (r *ClusterwideNetworkPolicyReconciler) Reconcile(req ctrl.Request) (ctrl.R

// if network policy does not belong to the namespace where clusterwide network policies are stored:
// update status with error message
if req.Namespace != clusterwideNPNamespace {
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))
if req.Namespace != firewallv1.ClusterwideNetworkPolicyNamespace {
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))
return ctrl.Result{}, nil
}

Expand Down

0 comments on commit 714a5bf

Please sign in to comment.