Skip to content

Commit 5cabf71

Browse files
Merge pull request #531 from caseydavenport/fix-defaulting
k8s conversion code handles 1.7 clusters
2 parents fb0f930 + 4e68ec2 commit 5cabf71

File tree

2 files changed

+425
-2
lines changed

2 files changed

+425
-2
lines changed

lib/backend/k8s/conversion.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,23 @@ func (c Converter) NetworkPolicyToPolicy(np *extensions.NetworkPolicy) (*model.K
223223
types := []string{}
224224
if ingress {
225225
types = append(types, "ingress")
226-
} else if len(inboundRules) > 0 {
227-
log.Warn("K8s PolicyTypes don't include 'ingress', but NetworkPolicy has ingress rules.")
228226
}
229227
if egress {
230228
types = append(types, "egress")
231229
} else if len(outboundRules) > 0 {
230+
// Egress was introduced at the same time as policyTypes. It shouldn't be possible to
231+
// receive a NetworkPolicy with an egress rule but without "egress" specified in its types,
232+
// but we'll warn about it anyway.
232233
log.Warn("K8s PolicyTypes don't include 'egress', but NetworkPolicy has egress rules.")
233234
}
234235

236+
// If no types were specified in the policy, then we're running on a cluster that doesn't
237+
// include support for that field in the API. In that case, the correct behavior is for the policy
238+
// to apply to only ingress traffic.
239+
if len(types) == 0 {
240+
types = append(types, "ingress")
241+
}
242+
235243
// Build and return the KVPair.
236244
return &model.KVPair{
237245
Key: model.PolicyKey{

0 commit comments

Comments
 (0)