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

k8s: Invalidate Policies that Support "EndPort" #28704

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions pkg/k8s/network_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,26 @@ func ParseNetworkPolicy(np *slim_networkingv1.NetworkPolicy) (api.Rules, error)
return api.Rules{rule}, nil
}

// NetworkPolicyHasEndPort returns true if the network policy has an
// EndPort.
func NetworkPolicyHasEndPort(np *slim_networkingv1.NetworkPolicy) bool {
for _, iRule := range np.Spec.Ingress {
for _, port := range iRule.Ports {
if port.EndPort != nil && *port.EndPort > 0 {
return true
}
}
}
for _, eRule := range np.Spec.Egress {
for _, port := range eRule.Ports {
if port.EndPort != nil && *port.EndPort > 0 {
return true
}
}
}
return false
}

func parsePodSelector(podSelectorIn *slim_metav1.LabelSelector, namespace string) *slim_metav1.LabelSelector {
podSelector := &slim_metav1.LabelSelector{
MatchLabels: make(map[string]slim_metav1.MatchLabelsValue, len(podSelectorIn.MatchLabels)),
Expand Down
4 changes: 4 additions & 0 deletions pkg/k8s/watchers/network_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func (k *K8sWatcher) addK8sNetworkPolicyV1(k8sNP *slim_networkingv1.NetworkPolic
}
scopedLog = scopedLog.WithField(logfields.K8sNetworkPolicyName, k8sNP.ObjectMeta.Name)

if k8s.NetworkPolicyHasEndPort(k8sNP) {
scopedLog.Warning("EndPort in kubernetes NetworkPolicy is not supported")
}

opts := policy.AddOptions{
Replace: true,
Source: source.Kubernetes,
Expand Down