Skip to content

Commit

Permalink
Merge pull request #531 from caseydavenport/fix-defaulting
Browse files Browse the repository at this point in the history
k8s conversion code handles 1.7 clusters
  • Loading branch information
caseydavenport authored Sep 24, 2017
2 parents fb0f930 + 4e68ec2 commit 5cabf71
Show file tree
Hide file tree
Showing 2 changed files with 425 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/backend/k8s/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,23 @@ func (c Converter) NetworkPolicyToPolicy(np *extensions.NetworkPolicy) (*model.K
types := []string{}
if ingress {
types = append(types, "ingress")
} else if len(inboundRules) > 0 {
log.Warn("K8s PolicyTypes don't include 'ingress', but NetworkPolicy has ingress rules.")
}
if egress {
types = append(types, "egress")
} else if len(outboundRules) > 0 {
// Egress was introduced at the same time as policyTypes. It shouldn't be possible to
// receive a NetworkPolicy with an egress rule but without "egress" specified in its types,
// but we'll warn about it anyway.
log.Warn("K8s PolicyTypes don't include 'egress', but NetworkPolicy has egress rules.")
}

// If no types were specified in the policy, then we're running on a cluster that doesn't
// include support for that field in the API. In that case, the correct behavior is for the policy
// to apply to only ingress traffic.
if len(types) == 0 {
types = append(types, "ingress")
}

// Build and return the KVPair.
return &model.KVPair{
Key: model.PolicyKey{
Expand Down
Loading

0 comments on commit 5cabf71

Please sign in to comment.