-
Notifications
You must be signed in to change notification settings - Fork 464
/
ingress_gateway.go
111 lines (96 loc) · 4.34 KB
/
ingress_gateway.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2020 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package istio
import (
"embed"
"path/filepath"
"strings"
corev1 "k8s.io/api/core/v1"
v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
"github.com/gardener/gardener/pkg/chartrenderer"
)
var (
//go:embed charts/istio/istio-ingress
chartIngress embed.FS
chartPathIngress = filepath.Join("charts", "istio", "istio-ingress")
)
// IngressGatewayValues holds values for the istio-ingress chart.
// The only opened port is 15021.
type IngressGatewayValues struct {
Annotations map[string]string
Labels map[string]string
NetworkPolicyLabels map[string]string
ExternalTrafficPolicy *corev1.ServiceExternalTrafficPolicyType
Image string
IstiodNamespace string
LoadBalancerIP *string
MaxReplicas *int
MinReplicas *int
Namespace string
PriorityClassName string
TrustDomain string
ProxyProtocolEnabled bool
VPNEnabled bool
Zones []string
// Ports is a list of all Ports the istio-ingress gateways is listening on.
// Port 15021 and 15000 cannot be used.
Ports []corev1.ServicePort
}
func (i *istiod) generateIstioIngressGatewayChart() (*chartrenderer.RenderedChart, error) {
renderedChart := &chartrenderer.RenderedChart{}
for _, istioIngressGateway := range i.values.IngressGateway {
values := map[string]interface{}{
"trustDomain": istioIngressGateway.TrustDomain,
"labels": istioIngressGateway.Labels,
"networkPolicyLabels": istioIngressGateway.NetworkPolicyLabels,
"annotations": istioIngressGateway.Annotations,
"externalTrafficPolicy": istioIngressGateway.ExternalTrafficPolicy,
"deployNamespace": false,
"priorityClassName": istioIngressGateway.PriorityClassName,
"ports": istioIngressGateway.Ports,
"image": istioIngressGateway.Image,
"istiodNamespace": istioIngressGateway.IstiodNamespace,
"loadBalancerIP": istioIngressGateway.LoadBalancerIP,
"serviceName": v1beta1constants.DefaultSNIIngressServiceName,
"proxyProtocolEnabled": istioIngressGateway.ProxyProtocolEnabled,
"vpn": map[string]interface{}{
"enabled": istioIngressGateway.VPNEnabled,
},
}
if istioIngressGateway.MinReplicas != nil {
// Apply minReplicas here to deploy the Ingress-Gateway with the intended number of replicas from the beginning (creation).
// Otherwise, we would need to wait until HPA scales up the deployment which then again can trigger unnecessary rolling updates
// when additional configuration is added by registered webhooks, e.g. high-availability-config webhook.
values["replicas"] = *istioIngressGateway.MinReplicas
values["minReplicas"] = *istioIngressGateway.MinReplicas
}
if istioIngressGateway.MaxReplicas != nil {
values["maxReplicas"] = *istioIngressGateway.MaxReplicas
}
renderedIngressChart, err := i.chartRenderer.RenderEmbeddedFS(chartIngress, chartPathIngress, releaseName, istioIngressGateway.Namespace, values)
if err != nil {
return nil, err
}
addSuffixToManifestsName(renderedIngressChart, istioIngressGateway.Namespace)
renderedChart.ChartName = renderedIngressChart.ChartName
renderedChart.Manifests = append(renderedChart.Manifests, renderedIngressChart.Manifests...)
}
return renderedChart, nil
}
func addSuffixToManifestsName(charts *chartrenderer.RenderedChart, suffix string) {
for i := 0; i < len(charts.Manifests); i++ {
charts.Manifests[i].Name = strings.TrimSuffix(charts.Manifests[i].Name, ".yaml")
charts.Manifests[i].Name = charts.Manifests[i].Name + "/" + suffix + ".yaml"
}
}