Skip to content
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

[installer] Add serviceAnnotations config to proxy #9773

Merged
merged 2 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions install/installer/pkg/components/proxy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ func service(ctx *common.RenderContext) ([]runtime.Object, error) {
return nil
})

var annotations map[string]string
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
if cfg.WebApp != nil && cfg.WebApp.ProxyConfig != nil {
annotations = cfg.WebApp.ProxyConfig.ServiceAnnotations
}
return nil
})

ports := map[string]common.ServicePort{
ContainerHTTPName: {
ContainerPort: ContainerHTTPPort,
Expand All @@ -47,7 +55,12 @@ func service(ctx *common.RenderContext) ([]runtime.Object, error) {
return common.GenerateService(Component, ports, func(service *corev1.Service) {
service.Spec.Type = corev1.ServiceTypeLoadBalancer
service.Spec.LoadBalancerIP = loadBalancerIP

service.Annotations["external-dns.alpha.kubernetes.io/hostname"] = fmt.Sprintf("%s,*.%s,*.ws.%s", ctx.Config.Domain, ctx.Config.Domain, ctx.Config.Domain)
service.Annotations["cloud.google.com/neg"] = `{"exposed_ports": {"80":{},"443": {}}}`

for k, v := range annotations {
service.Annotations[k] = v
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

}
})(ctx)
}
25 changes: 20 additions & 5 deletions install/installer/pkg/components/proxy/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func TestServiceLoadBalancerIP(t *testing.T) {
const loadBalancerIP = "123.456.789.0"
ctx := renderContextWithLoadBalancerIP(t, loadBalancerIP)
ctx := renderContextWithProxyConfig(t, &experimental.ProxyConfig{StaticIP: loadBalancerIP})

objects, err := service(ctx)
require.NoError(t, err)
Expand All @@ -27,13 +27,28 @@ func TestServiceLoadBalancerIP(t *testing.T) {
require.Equal(t, loadBalancerIP, svc.Spec.LoadBalancerIP)
}

func renderContextWithLoadBalancerIP(t *testing.T, loadBalancerIp string) *common.RenderContext {
func TestServiceAnnotations(t *testing.T) {
annotations := map[string]string{"hello": "world"}

ctx := renderContextWithProxyConfig(t, &experimental.ProxyConfig{ServiceAnnotations: annotations})

objects, err := service(ctx)
require.NoError(t, err)

require.Len(t, objects, 1, "must render only one object")

svc := objects[0].(*corev1.Service)
for k, v := range annotations {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be possible to use require.EqualValues(t, annotations, svc.Annotations)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we are checking here is slightly different; we need to check that the extra annotations are a subset of those on the rendered service. The installer hard-codes a couple of annotations too.

require.Equalf(t, annotations[k], svc.Annotations[k],
"expected to find annotation %q:%q on proxy service, but found %q:%q", k, v, k, svc.Annotations[k])
}
}

func renderContextWithProxyConfig(t *testing.T, proxyConfig *experimental.ProxyConfig) *common.RenderContext {
ctx, err := common.NewRenderContext(config.Config{
Experimental: &experimental.Config{
WebApp: &experimental.WebAppConfig{
ProxyConfig: &experimental.ProxyConfig{
StaticIP: loadBalancerIp,
},
ProxyConfig: proxyConfig,
},
},
}, versions.Manifest{
Expand Down
3 changes: 2 additions & 1 deletion install/installer/pkg/config/v1/experimental/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ type ServerConfig struct {
}

type ProxyConfig struct {
StaticIP string `json:"staticIP"`
StaticIP string `json:"staticIP"`
ServiceAnnotations map[string]string `json:"serviceAnnotations"`
}

type PublicAPIConfig struct {
Expand Down