Skip to content

Commit

Permalink
Gloo: Add support for listener.metadataStatic
Browse files Browse the repository at this point in the history
  • Loading branch information
megum1n committed Mar 14, 2023
1 parent dd61d0f commit 041ca37
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
31 changes: 29 additions & 2 deletions source/gloo_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
22 changes: 22 additions & 0 deletions source/gloo_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -75,6 +86,17 @@ var internalProxy = proxy{
},
},
},
MetadataStatic: proxyVirtualHostMetadataStatic{
Source: []proxyVirtualHostMetadataStaticSource{
{
ResourceKind: "*v1.VirtualService",
ResourceRef: proxyVirtualHostMetadataSourceResourceRef{
Name: "my-internal-svc",
Namespace: "internal",
},
},
},
},
},
},
},
Expand Down

0 comments on commit 041ca37

Please sign in to comment.