-
Notifications
You must be signed in to change notification settings - Fork 40
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
Allow customize service via service.Override and handle endpoint protocol #332
Changes from all commits
e89336d
0453ee8
4c3c5e5
5479d07
c76eb7b
0058795
559d36b
fb36ba6
37d5500
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ package endpoint | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/url" | ||
"strings" | ||
"time" | ||
|
@@ -50,13 +51,21 @@ type Data struct { | |
Port int32 | ||
// An optional path suffix to append to route hostname when forming Keystone endpoint URLs | ||
Path string | ||
// protocol of the endpoint (http/https/none) | ||
Protocol *service.Protocol | ||
// details for metallb service generation | ||
// NOTE: (mschuppert) deprecated, can be removed when external endpoint creation moved to openstack-operator | ||
// and ExposeEndpoints() can be removed | ||
MetalLB *MetalLBData | ||
// possible overrides for Route | ||
// NOTE: (mschuppert) deprecated, can be removed when external endpoint creation moved to openstack-operator | ||
// and ExposeEndpoints() can be removed | ||
RouteOverride *route.OverrideSpec | ||
} | ||
|
||
// MetalLBData - information specific to creating the MetalLB service | ||
// NOTE: (mschuppert) deprecated, can be removed when external endpoint creation moved to openstack-operator | ||
// and ExposeEndpoints() can be removed | ||
type MetalLBData struct { | ||
// Name of the metallb IpAddressPool | ||
IPAddressPool string | ||
|
@@ -73,12 +82,14 @@ type MetalLBData struct { | |
} | ||
|
||
// ExposeEndpoints - creates services, routes and returns a map of created openstack endpoint | ||
// NOTE: (mschuppert) deprecated, can be removed when external endpoint creation moved to openstack-operator | ||
// and ExposeEndpoints() can be removed | ||
func ExposeEndpoints( | ||
ctx context.Context, | ||
h *helper.Helper, | ||
serviceName string, | ||
endpointSelector map[string]string, | ||
endpoints map[Endpoint]Data, | ||
endpoints map[service.Endpoint]Data, | ||
timeout time.Duration, | ||
) (map[string]string, ctrl.Result, error) { | ||
endpointMap := make(map[string]string) | ||
|
@@ -95,6 +106,7 @@ func ExposeEndpoints( | |
|
||
// Create metallb service if specified, otherwise create a route | ||
var hostname string | ||
var port string | ||
if data.MetalLB != nil { | ||
var protocol corev1.Protocol | ||
if data.MetalLB.Protocol != nil { | ||
|
@@ -105,7 +117,7 @@ func ExposeEndpoints( | |
} | ||
|
||
// Create the service | ||
svc := service.NewService( | ||
svc, err := service.NewService( | ||
service.MetalLBService(&service.MetalLBServiceDetails{ | ||
Name: endpointName, | ||
Namespace: h.GetBeforeObject().GetNamespace(), | ||
|
@@ -117,12 +129,15 @@ func ExposeEndpoints( | |
Protocol: protocol, | ||
}, | ||
}), | ||
exportLabels, | ||
timeout, | ||
&service.OverrideSpec{}, | ||
) | ||
if err != nil { | ||
return endpointMap, ctrl.Result{}, err | ||
} | ||
annotations := map[string]string{ | ||
service.MetalLBAddressPoolAnnotation: data.MetalLB.IPAddressPool, | ||
AnnotationHostnameKey: svc.GetServiceHostname(), // add annotation to register service name in dnsmasq | ||
service.AnnotationHostnameKey: svc.GetServiceHostname(), // add annotation to register service name in dnsmasq | ||
} | ||
if len(data.MetalLB.LoadBalancerIPs) > 0 { | ||
annotations[service.MetalLBLoadBalancerIPs] = strings.Join(data.MetalLB.LoadBalancerIPs, ",") | ||
|
@@ -144,11 +159,11 @@ func ExposeEndpoints( | |
} | ||
// create service - end | ||
|
||
hostname = svc.GetServiceHostnamePort() | ||
hostname, port = svc.GetServiceHostnamePort() | ||
} else { | ||
|
||
// Create the service | ||
svc := service.NewService( | ||
svc, err := service.NewService( | ||
service.GenericService(&service.GenericServiceDetails{ | ||
Name: endpointName, | ||
Namespace: h.GetBeforeObject().GetNamespace(), | ||
|
@@ -159,9 +174,13 @@ func ExposeEndpoints( | |
Port: data.Port, | ||
Protocol: corev1.ProtocolTCP, | ||
}}), | ||
exportLabels, | ||
5, | ||
&service.OverrideSpec{}, | ||
) | ||
if err != nil { | ||
return endpointMap, ctrl.Result{}, err | ||
} | ||
|
||
ctrlResult, err := svc.CreateOrPatch(ctx, h) | ||
if err != nil { | ||
return endpointMap, ctrlResult, err | ||
|
@@ -170,10 +189,10 @@ func ExposeEndpoints( | |
} | ||
// create service - end | ||
|
||
hostname = svc.GetServiceHostnamePort() | ||
hostname, port = svc.GetServiceHostnamePort() | ||
|
||
// Create the route if it is public endpoint | ||
if endpointType == EndpointPublic { | ||
if endpointType == service.EndpointPublic { | ||
// Create the route | ||
// TODO TLS | ||
route, err := route.NewRoute( | ||
|
@@ -184,7 +203,6 @@ func ExposeEndpoints( | |
ServiceName: endpointName, | ||
TargetPortName: endpointName, | ||
}), | ||
exportLabels, | ||
timeout, | ||
data.RouteOverride, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stuggi quick question here: when a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, for TLS-E we terminate at the route and re-encrypt to the service pods. Before you start working on this, we already do initial work for TLS-E in a generic way for all services. So don't start before checking with us because its probably duplicate work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I'll wait to see the first patch series landed, and when doing tls we can sync up and discuss about the Glance use case. We might need to have an additional sidecar container w/ httpd or make it default like it is today in Manila/Cinder. |
||
) | ||
|
@@ -216,7 +234,8 @@ func ExposeEndpoints( | |
|
||
// Do not include data.Path in parsing check because %(project_id)s | ||
// is invalid without being encoded, but they should not be encoded in the actual endpoint | ||
apiEndpoint, err := url.Parse(protocol + hostname) | ||
endptURL := fmt.Sprintf("%s://%s:%s", protocol, hostname, port) | ||
apiEndpoint, err := url.Parse(endptURL) | ||
if err != nil { | ||
return endpointMap, ctrl.Result{}, err | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack, we still have this here but after the whole chain is merged we can do some cleanup.