From 041ca372c889737f848a8ac1ee868cd13f0c22f1 Mon Sep 17 00:00:00 2001 From: Megum1n Date: Tue, 14 Mar 2023 17:16:25 +0100 Subject: [PATCH] Gloo: Add support for listener.metadataStatic --- source/gloo_proxy.go | 31 +++++++++++++++++++++++++++++-- source/gloo_proxy_test.go | 22 ++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/source/gloo_proxy.go b/source/gloo_proxy.go index 845ccdee05..09e96ead05 100644 --- a/source/gloo_proxy.go +++ b/source/gloo_proxy.go @@ -64,20 +64,35 @@ type proxySpecHTTPListener struct { } type proxyVirtualHost struct { - Domains []string `json:"domains,omitempty"` - Metadata proxyVirtualHostMetadata `json:"metadata,omitempty"` + Domains []string `json:"domains,omitempty"` + Metadata proxyVirtualHostMetadata `json:"metadata,omitempty"` + MetadataStatic proxyVirtualHostMetadataStatic `json:"metadataStatic,omitempty"` } type proxyVirtualHostMetadata struct { Source []proxyVirtualHostMetadataSource `json:"sources,omitempty"` } +type proxyVirtualHostMetadataStatic struct { + Source []proxyVirtualHostMetadataStaticSource `json:"sources,omitempty"` +} + type proxyVirtualHostMetadataSource struct { Kind string `json:"kind,omitempty"` Name string `json:"name,omitempty"` Namespace string `json:"namespace,omitempty"` } +type proxyVirtualHostMetadataStaticSource struct { + ResourceKind string `json:"resourceKind,omitempty"` + ResourceRef proxyVirtualHostMetadataSourceResourceRef `json:"resourceRef,omitempty"` +} + +type proxyVirtualHostMetadataSourceResourceRef struct { + Name string `json:"name,omitempty"` + Namespace string `json:"namespace,omitempty"` +} + type glooSource struct { dynamicKubeClient dynamic.Interface kubeClient kubernetes.Interface @@ -165,6 +180,18 @@ func (gs *glooSource) annotationsFromProxySource(ctx context.Context, virtualHos } } } + for _, src := range virtualHost.MetadataStatic.Source { + kind := sourceKind(src.ResourceKind) + if kind != nil { + source, err := gs.dynamicKubeClient.Resource(*kind).Namespace(src.ResourceRef.Namespace).Get(ctx, src.ResourceRef.Name, metav1.GetOptions{}) + if err != nil { + return nil, err + } + for key, value := range source.GetAnnotations() { + annotations[key] = value + } + } + } return annotations, nil } diff --git a/source/gloo_proxy_test.go b/source/gloo_proxy_test.go index c1005fec2b..2df0246666 100644 --- a/source/gloo_proxy_test.go +++ b/source/gloo_proxy_test.go @@ -63,6 +63,17 @@ var internalProxy = proxy{ }, }, }, + MetadataStatic: proxyVirtualHostMetadataStatic{ + Source: []proxyVirtualHostMetadataStaticSource{ + { + ResourceKind: "*v1.Unknown", + ResourceRef: proxyVirtualHostMetadataSourceResourceRef{ + Name: "my-unknown-svc", + Namespace: "unknown", + }, + }, + }, + }, }, { Domains: []string{"c.test"}, @@ -75,6 +86,17 @@ var internalProxy = proxy{ }, }, }, + MetadataStatic: proxyVirtualHostMetadataStatic{ + Source: []proxyVirtualHostMetadataStaticSource{ + { + ResourceKind: "*v1.VirtualService", + ResourceRef: proxyVirtualHostMetadataSourceResourceRef{ + Name: "my-internal-svc", + Namespace: "internal", + }, + }, + }, + }, }, }, },