Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Namespace where CNWPs are expected #71

Merged
merged 1 commit into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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