Skip to content

Commit

Permalink
[BUG FIX] Handles Issue 205 (#206)
Browse files Browse the repository at this point in the history
* initialize fix for #205

* reorder netpol
  • Loading branch information
nschhina authored Apr 15, 2019
1 parent b19f650 commit 9f7b46e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 11 deletions.
16 changes: 5 additions & 11 deletions cmd/autofix_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ var identifyingKey = map[string]string{
"options": "name", // PodDNSConfig.options : PodDNSConfigOption.name
// TopologySelectorTerm.matchLabelExpressions : TopologySelectorLabelRequirement.key
"matchLabelExpressions": "key",
"paths": "path", // HTTPIngressRuleValue.paths : HTTPIngressPath.path
"pending": "name", // Initializers.pending : Initializer.name
"readinessGates": "conditionType", // PodSpec.readinessGates : PodReadinessGate.conditionType
// PodAffinity.requiredDuringSchedulingIgnoredDuringExecution : PodAffinityTerm.labelSelector
Expand Down Expand Up @@ -559,17 +558,12 @@ func sequenceItemMatch(sequenceKey string, item1, item2 yaml.SequenceItem) bool
// IngressSpec.rules : IngressRule.http
// Role.rules : PolicyRule.resources
case "rules":
// ClusterRole.rules : PolicyRule.resources
// Role.rules : PolicyRule.resources
if mapPairMatch("resources", map1, map2) {
return true
}
// IngressSpec.rules : IngressRule.http
if mapPairMatch("http", map1, map2) {
return true
if val1, index1 := findItemInMapSlice("host", map1); index1 != -1 {
if val2, index2 := findItemInMapSlice("host", map2); index2 != -1 {
return val1.Value == val2.Value
}
return false
}
// IngressSpec.rules : IngressRule.host
return mapPairMatch("host", map1, map2)

// ProjectedVolumeSource.sources
case "sources":
Expand Down
32 changes: 32 additions & 0 deletions fixtures/autofix-all-resources-fixed_v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,38 @@ spec:
automountServiceAccountToken: false
selector: null
status: {}
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: web
annotations:
kubernetes.io/ingress.class: nginx
kubernetes.io/tls-acme: "false"
labels:
name: web
app: testApp
env: production
spec:
tls:
- hosts:
- testapp.shopifycloud.com
- testapp.shopifyapps.com
secretName: someSecret
rules:
- host: testapp.shopifycloud.com # comment 2
http: # comment 2
paths: # comment 2
- backend: # comment 2
serviceName: web # comment 2
servicePort: 80 # comment 2
- host: testapp.shopifyapps.com # comment
http: # comment
paths: # comment
- backend: # comment
serviceName: web # comment
servicePort: 80 # comment

---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
Expand Down
31 changes: 31 additions & 0 deletions fixtures/autofix-all-resources_v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,34 @@ spec:
name: fakeContainerImg
resources: {}
status: {}
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: web
annotations:
kubernetes.io/ingress.class: nginx
kubernetes.io/tls-acme: "false"
labels:
name: web
app: testApp
env: production
spec:
tls:
- hosts:
- testapp.shopifycloud.com
- testapp.shopifyapps.com
secretName: someSecret
rules:
- host: testapp.shopifycloud.com # comment 2
http: # comment 2
paths: # comment 2
- backend: # comment 2
serviceName: web # comment 2
servicePort: 80 # comment 2
- host: testapp.shopifyapps.com # comment
http: # comment
paths: # comment
- backend: # comment
serviceName: web # comment
servicePort: 80 # comment

0 comments on commit 9f7b46e

Please sign in to comment.