Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit f613a8b

Browse files
authored
Merge pull request #226 from alexbrand/openstack-lb
discovery: don't make lb name part of the k8s name
2 parents 47d33b5 + dc6006a commit f613a8b

File tree

3 files changed

+40
-49
lines changed

3 files changed

+40
-49
lines changed

discovery/pkg/openstack/translate.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
package openstack
1515

1616
import (
17-
"fmt"
1817
"strconv"
1918
"strings"
2019

@@ -104,14 +103,10 @@ func loadbalancerLabels(lb loadbalancers.LoadBalancer) map[string]string {
104103
}
105104
}
106105

107-
// the service name in openstack is obtained from the LB's name and ID. If the
108-
// name is empty, the service name is the LB's ID.
106+
// use the load balancer ID as the service name
107+
// context: heptio/gimbal #216
109108
func serviceName(lb loadbalancers.LoadBalancer) string {
110-
lbName := lb.ID
111-
if lb.Name != "" {
112-
lbName = fmt.Sprintf("%s-%s", lb.Name, lb.ID)
113-
}
114-
return strings.ToLower(lbName)
109+
return strings.ToLower(lb.ID)
115110
}
116111

117112
// get the lb Name or ID if name is empty

discovery/pkg/openstack/translate_test.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ func TestKubeServices(t *testing.T) {
5959
loadbalancer("5a5c3d9e-e679-43ec-b9fc-9bc51132541e", "stocks"),
6060
},
6161
expected: []v1.Service{
62-
service("finance", "us-east-stocks-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
62+
service("finance", "us-east-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
6363
map[string]string{
6464
"gimbal.heptio.com/backend": "us-east",
65-
"gimbal.heptio.com/service": "stocks-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
65+
"gimbal.heptio.com/service": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
6666
"gimbal.heptio.com/load-balancer-id": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
6767
"gimbal.heptio.com/load-balancer-name": "stocks"},
6868
nil),
@@ -76,10 +76,10 @@ func TestKubeServices(t *testing.T) {
7676
loadbalancer("5a5c3d9e-e679-43ec-b9fc-9bc51132541e", "very-long-openstack-load-balancer-name-that-is-longer-than-the-limit"),
7777
},
7878
expected: []v1.Service{
79-
service("finance", "us-east-very-long-openstack-load-951f9d",
79+
service("finance", "us-east-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
8080
map[string]string{
8181
"gimbal.heptio.com/backend": "us-east",
82-
"gimbal.heptio.com/service": "very-long-openstack-load-balancer-name-that-is-longer-tha951f9d",
82+
"gimbal.heptio.com/service": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
8383
"gimbal.heptio.com/load-balancer-id": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
8484
"gimbal.heptio.com/load-balancer-name": "very-long-openstack-load-balancer-name-that-is-longer-tha80b28c"},
8585
nil),
@@ -93,10 +93,10 @@ func TestKubeServices(t *testing.T) {
9393
loadbalancer("5a5c3d9e-e679-43ec-b9fc-9bc51132541e", "1234-stocks"),
9494
},
9595
expected: []v1.Service{
96-
service("finance", "us-east-1234-stocks-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
96+
service("finance", "us-east-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
9797
map[string]string{
9898
"gimbal.heptio.com/backend": "us-east",
99-
"gimbal.heptio.com/service": "1234-stocks-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
99+
"gimbal.heptio.com/service": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
100100
"gimbal.heptio.com/load-balancer-id": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
101101
"gimbal.heptio.com/load-balancer-name": "1234-stocks"},
102102
nil),
@@ -110,10 +110,10 @@ func TestKubeServices(t *testing.T) {
110110
loadbalancer("5a5c3d9e-e679-43ec-b9fc-9bc51132541e", "1234-STOCKS"),
111111
},
112112
expected: []v1.Service{
113-
service("finance", "us-east-1234-stocks-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
113+
service("finance", "us-east-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
114114
map[string]string{
115115
"gimbal.heptio.com/backend": "us-east",
116-
"gimbal.heptio.com/service": "1234-stocks-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
116+
"gimbal.heptio.com/service": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
117117
"gimbal.heptio.com/load-balancer-id": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
118118
"gimbal.heptio.com/load-balancer-name": "1234-STOCKS"},
119119
nil),
@@ -127,10 +127,10 @@ func TestKubeServices(t *testing.T) {
127127
loadbalancer("5a5c3d9e-e679-43ec-b9fc-9bc51132541e", "nginx"),
128128
},
129129
expected: []v1.Service{
130-
service("finance", "cluster-name-that-is-defib224b3-nginx-5a5c3d9e-e679-43ec-e1c9a7",
130+
service("finance", "cluster-name-that-is-defib224b3-5a5c3d9e-e679-43ec-b9fc-9f5b1ae",
131131
map[string]string{
132132
"gimbal.heptio.com/backend": "cluster-name-that-is-definitely-too-long-to-be-useful",
133-
"gimbal.heptio.com/service": "nginx-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
133+
"gimbal.heptio.com/service": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
134134
"gimbal.heptio.com/load-balancer-id": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
135135
"gimbal.heptio.com/load-balancer-name": "nginx"},
136136
nil),
@@ -144,10 +144,10 @@ func TestKubeServices(t *testing.T) {
144144
loadbalancer("5a5c3d9e-e679-43ec-b9fc-9bc51132541e", "very-long-openstack-load-balancer-name-that-is-longer-than-the-limit"),
145145
},
146146
expected: []v1.Service{
147-
service("finance", "cluster-name-that-is-defib224b3-very-long-openstack-load-951f9d",
147+
service("finance", "cluster-name-that-is-defib224b3-5a5c3d9e-e679-43ec-b9fc-9f5b1ae",
148148
map[string]string{
149149
"gimbal.heptio.com/backend": "cluster-name-that-is-definitely-too-long-to-be-useful",
150-
"gimbal.heptio.com/service": "very-long-openstack-load-balancer-name-that-is-longer-tha951f9d",
150+
"gimbal.heptio.com/service": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
151151
"gimbal.heptio.com/load-balancer-id": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
152152
"gimbal.heptio.com/load-balancer-name": "very-long-openstack-load-balancer-name-that-is-longer-tha80b28c"},
153153
nil),
@@ -161,10 +161,10 @@ func TestKubeServices(t *testing.T) {
161161
loadbalancer("5a5c3d9e-e679-43ec-b9fc-9bc51132541e", "stocks", listener("ls-1", "http", "tcp", "pool-1", 80)),
162162
},
163163
expected: []v1.Service{
164-
service("finance", "us-east-stocks-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
164+
service("finance", "us-east-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
165165
map[string]string{
166166
"gimbal.heptio.com/backend": "us-east",
167-
"gimbal.heptio.com/service": "stocks-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
167+
"gimbal.heptio.com/service": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
168168
"gimbal.heptio.com/load-balancer-id": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
169169
"gimbal.heptio.com/load-balancer-name": "stocks"},
170170
[]v1.ServicePort{
@@ -185,10 +185,10 @@ func TestKubeServices(t *testing.T) {
185185
loadbalancer("5a5c3d9e-e679-43ec-b9fc-9bc51132541e", "stocks", listener("ls-1", "http", "tcp", "pool-1", 80)),
186186
},
187187
expected: []v1.Service{
188-
service("finance", "us-east-stocks-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
188+
service("finance", "us-east-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
189189
map[string]string{
190190
"gimbal.heptio.com/backend": "us-east",
191-
"gimbal.heptio.com/service": "stocks-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
191+
"gimbal.heptio.com/service": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
192192
"gimbal.heptio.com/load-balancer-id": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
193193
"gimbal.heptio.com/load-balancer-name": "stocks"},
194194
[]v1.ServicePort{
@@ -209,10 +209,10 @@ func TestKubeServices(t *testing.T) {
209209
loadbalancer("5a5c3d9e-e679-43ec-b9fc-9bc51132541e", "stocks", listener("ls-1", "http", "tcp", "pool-1", 80), listener("ls-1", "https", "tcp", "pool-1", 443)),
210210
},
211211
expected: []v1.Service{
212-
service("finance", "us-east-stocks-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
212+
service("finance", "us-east-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
213213
map[string]string{
214214
"gimbal.heptio.com/backend": "us-east",
215-
"gimbal.heptio.com/service": "stocks-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
215+
"gimbal.heptio.com/service": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
216216
"gimbal.heptio.com/load-balancer-id": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
217217
"gimbal.heptio.com/load-balancer-name": "stocks"},
218218
[]v1.ServicePort{
@@ -292,10 +292,10 @@ func TestKubeEndpoints(t *testing.T) {
292292
pool("pool-1", "HTTP", "5a5c3d9e-e679-43ec-b9fc-9bc51132541e", poolmember("10.0.0.1", 8080)),
293293
},
294294
expected: []v1.Endpoints{
295-
endpoints("finance", "us-east-stocks-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
295+
endpoints("finance", "us-east-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
296296
map[string]string{
297297
"gimbal.heptio.com/backend": "us-east",
298-
"gimbal.heptio.com/service": "stocks-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
298+
"gimbal.heptio.com/service": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
299299
"gimbal.heptio.com/load-balancer-id": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
300300
"gimbal.heptio.com/load-balancer-name": "stocks"},
301301
[]v1.EndpointSubset{
@@ -317,10 +317,10 @@ func TestKubeEndpoints(t *testing.T) {
317317
pool("pool-1", "HTTP", "5a5c3d9e-e679-43ec-b9fc-9bc51132541e", poolmember("10.0.0.1", 8080)),
318318
},
319319
expected: []v1.Endpoints{
320-
endpoints("finance", "cluster-name-that-is-defi7afb09-stocks-5a5c3d9e-e679-43ec549cd6",
320+
endpoints("finance", "cluster-name-that-is-defi7afb09-5a5c3d9e-e679-43ec-b9fc-9f5b1ae",
321321
map[string]string{
322322
"gimbal.heptio.com/backend": "cluster-name-that-is-definitely-too-long-to-be-useful-in-7afb09",
323-
"gimbal.heptio.com/service": "stocks-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
323+
"gimbal.heptio.com/service": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
324324
"gimbal.heptio.com/load-balancer-id": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
325325
"gimbal.heptio.com/load-balancer-name": "stocks"},
326326
[]v1.EndpointSubset{
@@ -342,10 +342,10 @@ func TestKubeEndpoints(t *testing.T) {
342342
pool("pool-1", "HTTP", "5a5c3d9e-e679-43ec-b9fc-9bc51132541e", poolmember("10.0.0.1", 8080)),
343343
},
344344
expected: []v1.Endpoints{
345-
endpoints("finance", "us-east-very-long-openstack-load-951f9d",
345+
endpoints("finance", "us-east-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
346346
map[string]string{
347347
"gimbal.heptio.com/backend": "us-east",
348-
"gimbal.heptio.com/service": "very-long-openstack-load-balancer-name-that-is-longer-tha951f9d",
348+
"gimbal.heptio.com/service": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
349349
"gimbal.heptio.com/load-balancer-id": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
350350
"gimbal.heptio.com/load-balancer-name": "very-long-openstack-load-balancer-name-that-is-longer-tha80b28c"},
351351
[]v1.EndpointSubset{
@@ -361,18 +361,18 @@ func TestKubeEndpoints(t *testing.T) {
361361
tenantName: "finance",
362362
backendName: "us-east",
363363
lbs: []loadbalancers.LoadBalancer{
364-
loadbalancer("loadbalancer-1", "stocks", listener("listener-1", "http", "tcp", "pool-1", 80), listener("listener-2", "https", "tcp", "pool-2", 443)),
364+
loadbalancer("5a5c3d9e-e679-43ec-b9fc-9bc51132541e", "stocks", listener("listener-1", "http", "tcp", "pool-1", 80), listener("listener-2", "https", "tcp", "pool-2", 443)),
365365
},
366366
pools: []pools.Pool{
367-
pool("pool-1", "HTTP", "loadbalancer-1", poolmember("10.0.0.1", 8080), poolmember("10.0.0.2", 80), poolmember("10.0.0.3", 80), poolmember("10.0.0.4", 8080)),
368-
pool("pool-2", "HTTP", "loadbalancer-1", poolmember("10.0.0.5", 443), poolmember("10.0.0.6", 443), poolmember("10.0.0.7", 8443)),
367+
pool("pool-1", "HTTP", "5a5c3d9e-e679-43ec-b9fc-9bc51132541e", poolmember("10.0.0.1", 8080), poolmember("10.0.0.2", 80), poolmember("10.0.0.3", 80), poolmember("10.0.0.4", 8080)),
368+
pool("pool-2", "HTTP", "5a5c3d9e-e679-43ec-b9fc-9bc51132541e", poolmember("10.0.0.5", 443), poolmember("10.0.0.6", 443), poolmember("10.0.0.7", 8443)),
369369
},
370370
expected: []v1.Endpoints{
371-
endpoints("finance", "us-east-stocks-loadbalancer-1",
371+
endpoints("finance", "us-east-5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
372372
map[string]string{
373373
"gimbal.heptio.com/backend": "us-east",
374-
"gimbal.heptio.com/service": "stocks-loadbalancer-1",
375-
"gimbal.heptio.com/load-balancer-id": "loadbalancer-1",
374+
"gimbal.heptio.com/service": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
375+
"gimbal.heptio.com/load-balancer-id": "5a5c3d9e-e679-43ec-b9fc-9bc51132541e",
376376
"gimbal.heptio.com/load-balancer-name": "stocks"},
377377
[]v1.EndpointSubset{
378378
{

docs/discovery-naming-conventions.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,15 @@ Service port names are copied verbatim from the backend service.
107107
108108
- `${backend-name}`: The value of the `--backend-name` flag provided to the
109109
discoverer. Must begin with a lowercase letter.
110-
- `${service-name}`: `${name}-${id}` of the LBaaS Load Balancer. Both are
111-
lowercased during the discovery process.
110+
- `${service-name}`: `${id}` of the LBaaS Load Balancer. Lowercased during the discovery process.
112111
113112
Service port names are set to `port-${port-number}`.
114113
115-
#### Why is the `${service-name}` a composite name?
114+
#### Why is the Load Balancer name not part of the service name?
116115
117-
The `${service-name}` produced by the OpenStack discoverer is composed of the
118-
name and ID of the LBaaS Load Balancer. This is required because names are not
119-
guaranteed to be unique in an OpenStack project. By appending the ID, we ensure
120-
that we are referncing a single Load Balancer in the OpenStack cluster.
116+
The load balancer's name is not part of the service name because resources in
117+
OpenStack can be renamed. This prevents users from unintentionally renaming
118+
discovered services in Kubernetes and breaking IngressRoute rules.
121119
122-
#### What happens to Load Balancers that do not have a name?
123-
124-
Names in OpenStack are optional. In this scenario, the `${service-name}` will
125-
be the ID of the LBaaS Load Balancer.
120+
Instead, the load balancer's name is available as a label
121+
(`gimbal.heptio.com/load-balancer-name`) on the service.

0 commit comments

Comments
 (0)