Skip to content

Commit

Permalink
Merge pull request sl1pm4t#40 from sl1pm4t/network-policy-ports
Browse files Browse the repository at this point in the history
Fix: network policy ports not handled
  • Loading branch information
sl1pm4t authored Sep 19, 2019
2 parents 06b268d + 7910220 commit 5eaee4c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
7 changes: 6 additions & 1 deletion pkg/tfkschema/name_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ func NormalizeTerraformName(s string, toSingular bool, path string) string {
if strings.Contains(path, "limit_range.spec") {
return "limit"
}

case "ports":
if strings.Contains(path, "kubernetes_network_policy.spec") {
return "ports"
}
}

if toSingular {
Expand Down Expand Up @@ -153,4 +158,4 @@ func NormalizeTerraformMapKey(s string) string {
return fmt.Sprintf(`"%s"`, s)
}
return s
}
}
26 changes: 26 additions & 0 deletions test-fixtures/networkPolicy.tf.golden
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ resource "kubernetes_network_policy" "default_deny" {
}
spec {
pod_selector {
match_labels = { IngressInternal = "active" }
}
ingress {
ports {
protocol = "TCP"
port = "80"
}
ports {
protocol = "TCP"
port = "443"
}
from {
ip_block {
cidr = "10.0.0.0/8"
}
}
from {
ip_block {
cidr = "172.16.0.0/12"
}
}
from {
ip_block {
cidr = "192.168.0.0/16"
}
}
}
policy_types = ["Ingress", "Egress"]
}
Expand Down
19 changes: 17 additions & 2 deletions test-fixtures/networkPolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@ kind: NetworkPolicy
metadata:
name: default-deny
spec:
podSelector: {}
podSelector:
matchLabels:
IngressInternal: active
ingress:
- from:
- ipBlock:
cidr: 10.0.0.0/8
- ipBlock:
cidr: 172.16.0.0/12
- ipBlock:
cidr: 192.168.0.0/16
ports:
- port: 80
protocol: TCP
- port: 443
protocol: TCP
policyTypes:
- Ingress
- Egress
- Egress

0 comments on commit 5eaee4c

Please sign in to comment.