Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add default protocol to subset of ports if it is empty #347

Merged
merged 1 commit into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/diff/diff.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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