Skip to content

Commit

Permalink
fix: add default protocol to subset of ports if it is empty (#347)
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Rudenko <3kmnazapad@gmail.com>
  • Loading branch information
ahalay committed Jan 26, 2022
1 parent 36e7746 commit b0c5e00
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
11 changes: 11 additions & 0 deletions pkg/diff/diff.go
Expand Up @@ -517,6 +517,17 @@ func normalizeEndpoint(un *unstructured.Unstructured, o options) {
return
}

// add default protocol to subsets ports if it is empty
for s := range ep.Subsets {
subset := &ep.Subsets[s]
for p := range subset.Ports {
port := &subset.Ports[p]
if port.Protocol == "" {
port.Protocol = corev1.ProtocolTCP
}
}
}

endpoints.SortSubsets(ep.Subsets)

newObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&ep)
Expand Down
13 changes: 13 additions & 0 deletions pkg/diff/testdata/endpoints-config.json
Expand Up @@ -35,6 +35,19 @@
{
"name": "solr-http",
"port": 8080
},
{
"name": "solr-https",
"port": 8443
},
{
"name": "solr-node",
"port": 8983,
"protocol": "UDP"
},
{
"name": "solr-zookeeper",
"port": 9983
}
]
}
Expand Down
34 changes: 24 additions & 10 deletions pkg/diff/testdata/endpoints-live.json
Expand Up @@ -4,7 +4,7 @@
"metadata": {
"annotations": {
"description": "A workaround to support a set of backend IPs for solr",
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Endpoints\",\"metadata\":{\"annotations\":{\"description\":\"A workaround to support a set of backend IPs for solr\",\"linkerd.io/inject\":\"disabled\"},\"labels\":{\"app.kubernetes.io/instance\":\"guestbook\"},\"name\":\"solrcloud\",\"namespace\":\"default\"},\"subsets\":[{\"addresses\":[{\"ip\":\"172.20.10.97\"},{\"ip\":\"172.20.10.98\"},{\"ip\":\"172.20.10.99\"},{\"ip\":\"172.20.10.100\"},{\"ip\":\"172.20.10.101\"}],\"ports\":[{\"name\":\"solr-http\",\"port\":8080}]}]}\n",
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Endpoints\",\"metadata\":{\"annotations\":{\"description\":\"A workaround to support a set of backend IPs for solr\",\"linkerd.io/inject\":\"disabled\"},\"labels\":{\"app.kubernetes.io/instance\":\"guestbook\"},\"name\":\"solrcloud\",\"namespace\":\"default\"},\"subsets\":[{\"addresses\":[{\"ip\":\"172.20.10.97\"},{\"ip\":\"172.20.10.98\"},{\"ip\":\"172.20.10.99\"},{\"ip\":\"172.20.10.100\"},{\"ip\":\"172.20.10.101\"}],\"ports\":[{\"name\":\"solr-http\",\"port\":8080},{\"name\":\"solr-https\",\"port\":8443},{\"name\":\"solr-node\",\"port\":8983,\"protocol\":\"UDP\"},{\"name\":\"solr-zookeeper\",\"port\":9983}]}]}\n",
"linkerd.io/inject": "disabled"
},
"creationTimestamp": null,
Expand Down Expand Up @@ -32,39 +32,53 @@
},
"manager": "main",
"operation": "Update",
"time": "2020-10-09T17:26:49Z"
"time": null
}
],
"name": "solrcloud",
"namespace": "default",
"resourceVersion": "139834",
"selfLink": "/api/v1/namespaces/default/endpoints/solrcloud",
"uid": "f11285f4-987b-4194-bda8-6372b3f3f08f"
"resourceVersion": "2336",
"uid": "439a86ee-cbf9-4717-9ce3-d44079333a27"
},
"subsets": [
{
"addresses": [
{
"ip": "172.20.10.100"
"ip": "172.20.10.97"
},
{
"ip": "172.20.10.101"
"ip": "172.20.10.98"
},
{
"ip": "172.20.10.97"
"ip": "172.20.10.99"
},
{
"ip": "172.20.10.98"
"ip": "172.20.10.100"
},
{
"ip": "172.20.10.99"
"ip": "172.20.10.101"
}
],
"ports": [
{
"name": "solr-http",
"port": 8080,
"protocol": "TCP"
},
{
"name": "solr-https",
"port": 8443,
"protocol": "TCP"
},
{
"name": "solr-node",
"port": 8983,
"protocol": "UDP"
},
{
"name": "solr-zookeeper",
"port": 9983,
"protocol": "TCP"
}
]
}
Expand Down

0 comments on commit b0c5e00

Please sign in to comment.