From ddd3b7e79ea319e8202164e2c1452db7a11c90c4 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Mon, 11 Sep 2023 16:17:05 +0200 Subject: [PATCH] [wip] --- modules/common/service/service.go | 14 ++- modules/common/service/service_test.go | 118 +++++++++--------- modules/common/service/types.go | 18 ++- .../common/service/zz_generated.deepcopy.go | 26 +++- 4 files changed, 96 insertions(+), 80 deletions(-) diff --git a/modules/common/service/service.go b/modules/common/service/service.go index 5a3116ba..5305d87b 100644 --- a/modules/common/service/service.go +++ b/modules/common/service/service.go @@ -147,11 +147,11 @@ func (s *Service) AddAnnotation(anno map[string]string) { } // GetAPIEndpoint - returns the API endpoint URL for the service to register in keystone. -func (s *Service) GetAPIEndpoint(svcOverride *OverrideSpec, protocol *Protocol, path string) (string, error) { +func (s *Service) GetAPIEndpoint(endpointURL *string, protocol *Protocol, path string) (string, error) { var apiEndpoint *url.URL var err error - if svcOverride != nil && svcOverride.EndpointURL != nil { - apiEndpoint, err = url.Parse(*svcOverride.EndpointURL) + if endpointURL != nil { + apiEndpoint, err = url.Parse(*endpointURL) if err != nil { return "", err } @@ -426,3 +426,11 @@ func EndptProtocol(proto *Protocol) string { return string(*proto) + "://" } + +// GetOverrideSpec - +func (r *RoutedOverrideSpec) GetOverrideSpec() *OverrideSpec { + return &OverrideSpec{ + EmbeddedLabelsAnnotations: r.EmbeddedLabelsAnnotations, + Spec: r.Spec, + } +} diff --git a/modules/common/service/service_test.go b/modules/common/service/service_test.go index 78b9dca3..b02441cd 100644 --- a/modules/common/service/service_test.go +++ b/modules/common/service/service_test.go @@ -302,81 +302,77 @@ func TestNewService(t *testing.T) { func TestGetAPIEndpoint(t *testing.T) { tests := []struct { - name string - service *corev1.Service - override OverrideSpec - proto Protocol - port string - path string - want string + name string + service *corev1.Service + endpointURL *string + proto Protocol + port string + path string + want string }{ { - name: "HTTP ClusterIP service default port 80, no override", - service: getServiceWithPort(svcClusterIP, portHTTP), - override: OverrideSpec{}, - proto: ProtocolHTTP, - path: "", - want: "http://foo.namespace.svc", + name: "HTTP ClusterIP service default port 80, no override", + service: getServiceWithPort(svcClusterIP, portHTTP), + endpointURL: nil, + proto: ProtocolHTTP, + path: "", + want: "http://foo.namespace.svc", }, { - name: "HTTP ClusterIP service non default 8080 port, no override", - service: getServiceWithPort(svcClusterIP, portCustom), - override: OverrideSpec{}, - proto: ProtocolHTTP, - path: "/path", - want: "http://foo.namespace.svc:8080/path", + name: "HTTP ClusterIP service non default 8080 port, no override", + service: getServiceWithPort(svcClusterIP, portCustom), + endpointURL: nil, + proto: ProtocolHTTP, + path: "/path", + want: "http://foo.namespace.svc:8080/path", }, { - name: "HTTPS ClusterIP service default 443 port, no override", - service: getServiceWithPort(svcClusterIP, portHTTPS), - override: OverrideSpec{}, - proto: ProtocolHTTPS, - path: "/path", - want: "https://foo.namespace.svc/path", + name: "HTTPS ClusterIP service default 443 port, no override", + service: getServiceWithPort(svcClusterIP, portHTTPS), + endpointURL: nil, + proto: ProtocolHTTPS, + path: "/path", + want: "https://foo.namespace.svc/path", }, { - name: "HTTPS ClusterIP service non default 8080 port, no override", - service: getServiceWithPort(svcClusterIP, portCustom), - override: OverrideSpec{}, - proto: ProtocolHTTPS, - path: "/path", - want: "https://foo.namespace.svc:8080/path", + name: "HTTPS ClusterIP service non default 8080 port, no override", + service: getServiceWithPort(svcClusterIP, portCustom), + endpointURL: nil, + proto: ProtocolHTTPS, + path: "/path", + want: "https://foo.namespace.svc:8080/path", }, { - name: "None ClusterIP service port 80 no override", - service: getServiceWithPort(svcClusterIP, portHTTP), - override: OverrideSpec{}, - proto: ProtocolNone, - path: "/path", - want: "foo.namespace.svc:80/path", + name: "None ClusterIP service port 80 no override", + service: getServiceWithPort(svcClusterIP, portHTTP), + endpointURL: nil, + proto: ProtocolNone, + path: "/path", + want: "foo.namespace.svc:80/path", }, { - name: "None ClusterIP service port 8080 override", - service: getServiceWithPort(svcClusterIP, portCustom), - override: OverrideSpec{}, - proto: ProtocolNone, - path: "/path", - want: "foo.namespace.svc:8080/path", + name: "None ClusterIP service port 8080 override", + service: getServiceWithPort(svcClusterIP, portCustom), + endpointURL: nil, + proto: ProtocolNone, + path: "/path", + want: "foo.namespace.svc:8080/path", }, { - name: "Override EndpointURL with path", - service: getServiceWithPort(svcClusterIP, portCustom), - override: OverrideSpec{ - EndpointURL: ptr.To("http://override.me"), - }, - proto: ProtocolNone, - path: "/path", - want: "http://override.me/path", + name: "Override EndpointURL with path", + service: getServiceWithPort(svcClusterIP, portCustom), + endpointURL: ptr.To("http://this.url"), + proto: ProtocolNone, + path: "/path", + want: "http://this.url/path", }, { - name: "Override EndpointURL no path", - service: getServiceWithPort(svcClusterIP, portCustom), - override: OverrideSpec{ - EndpointURL: ptr.To("http://override.me"), - }, - proto: ProtocolNone, - path: "", - want: "http://override.me", + name: "Override EndpointURL no path", + service: getServiceWithPort(svcClusterIP, portCustom), + endpointURL: ptr.To("http://this.url"), + proto: ProtocolNone, + path: "", + want: "http://this.url", }, } @@ -384,9 +380,9 @@ func TestGetAPIEndpoint(t *testing.T) { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) - service, err := NewService(tt.service, timeout, &tt.override) + service, err := NewService(tt.service, timeout, &OverrideSpec{}) g.Expect(err).ToNot(HaveOccurred()) - url, err := service.GetAPIEndpoint(&tt.override, ptr.To(tt.proto), tt.path) + url, err := service.GetAPIEndpoint(tt.endpointURL, ptr.To(tt.proto), tt.path) g.Expect(err).ToNot(HaveOccurred()) g.Expect(url).To(Equal(tt.want)) }) diff --git a/modules/common/service/types.go b/modules/common/service/types.go index badbe732..b7b6aeb0 100644 --- a/modules/common/service/types.go +++ b/modules/common/service/types.go @@ -42,8 +42,6 @@ const ( EndpointPublic Endpoint = "public" // AnnotationIngressCreateKey - AnnotationIngressCreateKey = "core.openstack.org/ingress_create" - // AnnotationIngressNameKey - - AnnotationIngressNameKey = "core.openstack.org/ingress_name" // AnnotationEndpointKey - AnnotationEndpointKey = "endpoint" // AnnotationHostnameKey - @@ -114,17 +112,15 @@ const ( // OverrideSpec - service override configuration for the Service created to serve traffic to the cluster. // Allows for the manifest of the created Service to be overwritten with custom configuration. type OverrideSpec struct { - // EndpointURL to be used to register the service in keystone. - // +optional - EndpointURL *string `json:"endpointURL,omitempty"` - - // +optional *EmbeddedLabelsAnnotations `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + Spec *OverrideServiceSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` +} - // Spec defines the behavior of a Service. - // https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status - // +optional - Spec *OverrideServiceSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` +// RoutedOverrideSpec - a routed service override configuration for the Service created to serve traffic +// to the cluster. Allows for the manifest of the created Service to be overwritten with custom configuration. +type RoutedOverrideSpec struct { + OverrideSpec `json:",inline"` + EndpointURL *string `json:"endpointURL,omitempty"` } // EmbeddedLabelsAnnotations is an embedded subset of the fields included in k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta. diff --git a/modules/common/service/zz_generated.deepcopy.go b/modules/common/service/zz_generated.deepcopy.go index 8ad2d6f0..a0e4de0c 100644 --- a/modules/common/service/zz_generated.deepcopy.go +++ b/modules/common/service/zz_generated.deepcopy.go @@ -97,11 +97,6 @@ func (in *OverrideServiceSpec) DeepCopy() *OverrideServiceSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *OverrideSpec) DeepCopyInto(out *OverrideSpec) { *out = *in - if in.EndpointURL != nil { - in, out := &in.EndpointURL, &out.EndpointURL - *out = new(string) - **out = **in - } if in.EmbeddedLabelsAnnotations != nil { in, out := &in.EmbeddedLabelsAnnotations, &out.EmbeddedLabelsAnnotations *out = new(EmbeddedLabelsAnnotations) @@ -123,3 +118,24 @@ func (in *OverrideSpec) DeepCopy() *OverrideSpec { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RoutedOverrideSpec) DeepCopyInto(out *RoutedOverrideSpec) { + *out = *in + in.OverrideSpec.DeepCopyInto(&out.OverrideSpec) + if in.EndpointURL != nil { + in, out := &in.EndpointURL, &out.EndpointURL + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RoutedOverrideSpec. +func (in *RoutedOverrideSpec) DeepCopy() *RoutedOverrideSpec { + if in == nil { + return nil + } + out := new(RoutedOverrideSpec) + in.DeepCopyInto(out) + return out +}