-
Notifications
You must be signed in to change notification settings - Fork 459
/
istio_config.go
104 lines (92 loc) · 4.19 KB
/
istio_config.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
// Copyright 2022 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 operation
import (
"strings"
"k8s.io/apimachinery/pkg/util/sets"
resourcesv1alpha1 "github.com/gardener/gardener/pkg/apis/resources/v1alpha1"
gardenletconfig "github.com/gardener/gardener/pkg/gardenlet/apis/config"
sharedcomponent "github.com/gardener/gardener/pkg/operation/botanist/component/shared"
"github.com/gardener/gardener/pkg/utils"
gardenerutils "github.com/gardener/gardener/pkg/utils/gardener"
)
// IstioServiceName is the currently used name of the istio ingress service, which is responsible for the shoot cluster.
func (o *Operation) IstioServiceName() string {
return *o.sniConfig().Ingress.ServiceName
}
// IstioNamespace is the currently used namespace of the istio ingress gateway, which is responsible for the shoot cluster.
func (o *Operation) IstioNamespace() string {
return o.addZonePinningIfRequired(*o.sniConfig().Ingress.Namespace)
}
// IstioLoadBalancerAnnotations contain the annotation to be used for the istio ingress service load balancer.
func (o *Operation) IstioLoadBalancerAnnotations() map[string]string {
zone := o.singleZoneIfPinned()
if exposureClassHandler := o.exposureClassHandler(); exposureClassHandler != nil {
if zone != nil {
return utils.MergeStringMaps(exposureClassHandler.LoadBalancerService.Annotations, o.Seed.GetZonalLoadBalancerServiceAnnotations(*zone))
}
return utils.MergeStringMaps(o.Seed.GetLoadBalancerServiceAnnotations(), exposureClassHandler.LoadBalancerService.Annotations)
}
if zone != nil {
return o.Seed.GetZonalLoadBalancerServiceAnnotations(*zone)
}
return o.Seed.GetLoadBalancerServiceAnnotations()
}
// IstioLabels contain the labels to be used for the istio ingress gateway entities.
func (o *Operation) IstioLabels() map[string]string {
zone := o.singleZoneIfPinned()
if exposureClassHandler := o.exposureClassHandler(); exposureClassHandler != nil {
return sharedcomponent.GetIstioZoneLabels(gardenerutils.GetMandatoryExposureClassHandlerSNILabels(exposureClassHandler.SNI.Ingress.Labels, exposureClassHandler.Name), zone)
}
return sharedcomponent.GetIstioZoneLabels(o.sniConfig().Ingress.Labels, zone)
}
func (o *Operation) exposureClassHandler() *gardenletconfig.ExposureClassHandler {
if exposureClassName := o.Shoot.GetInfo().Spec.ExposureClassName; exposureClassName != nil {
for _, handler := range o.Config.ExposureClassHandlers {
if *exposureClassName == handler.Name {
return &handler
}
}
}
return nil
}
func (o *Operation) sniConfig() *gardenletconfig.SNI {
if exposureClassHandler := o.exposureClassHandler(); exposureClassHandler != nil {
return exposureClassHandler.SNI
}
return o.Config.SNI
}
func (o *Operation) addZonePinningIfRequired(namespace string) string {
// Only clusters pinned to exactly one zone are exposed via zonal istio ingress gateway.
// All other clusters, i.e. true HA and legacy/accidental multi-zonal clusters, are exposed
// via the default multi-zonal istio ingress gateway.
zone := o.singleZoneIfPinned()
if zone != nil {
return sharedcomponent.GetIstioNamespaceForZone(namespace, *zone)
}
return namespace
}
func (o *Operation) singleZoneIfPinned() *string {
// Zone-specific istio ingress gateways are only deployed with more than one zone
if len(o.Seed.GetInfo().Spec.Provider.Zones) <= 1 {
return nil
}
if v, ok := o.SeedNamespaceObject.Annotations[resourcesv1alpha1.HighAvailabilityConfigZones]; ok {
zones := sets.List(sets.New(strings.Split(v, ",")...).Delete(""))
if len(zones) == 1 {
return &zones[0]
}
}
return nil
}