-
Notifications
You must be signed in to change notification settings - Fork 473
/
kubeapiserverexposure.go
132 lines (121 loc) · 4.79 KB
/
kubeapiserverexposure.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright 2021 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 botanist
import (
"context"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"
v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
"github.com/gardener/gardener/pkg/component"
"github.com/gardener/gardener/pkg/component/kubeapiserverexposure"
gardenerutils "github.com/gardener/gardener/pkg/utils/gardener"
)
// DefaultKubeAPIServerService returns a deployer for the kube-apiserver service.
func (b *Botanist) DefaultKubeAPIServerService() component.DeployWaiter {
return kubeapiserverexposure.NewService(
b.Logger,
b.SeedClientSet.Client(),
b.Shoot.SeedNamespace,
&kubeapiserverexposure.ServiceValues{
AnnotationsFunc: func() map[string]string { return b.IstioLoadBalancerAnnotations() },
TopologyAwareRoutingEnabled: b.Shoot.TopologyAwareRoutingEnabled,
RuntimeKubernetesVersion: b.Seed.KubernetesVersion,
},
func() client.ObjectKey {
return client.ObjectKey{Name: b.IstioServiceName(), Namespace: b.IstioNamespace()}
},
nil,
b.setAPIServerServiceClusterIP,
func(address string) {
b.APIServerAddress = address
b.newDNSComponentsTargetingAPIServerAddress()
},
"",
)
}
// ShootUsesDNS returns true if the shoot uses internal and external DNS.
func (b *Botanist) ShootUsesDNS() bool {
return b.NeedsInternalDNS() && b.NeedsExternalDNS()
}
// DefaultKubeAPIServerSNI returns a deployer for the kube-apiserver SNI.
func (b *Botanist) DefaultKubeAPIServerSNI() component.DeployWaiter {
return component.OpDestroyWithoutWait(kubeapiserverexposure.NewSNI(
b.SeedClientSet.Client(),
b.SeedClientSet.Applier(),
v1beta1constants.DeploymentNameKubeAPIServer,
b.Shoot.SeedNamespace,
func() *kubeapiserverexposure.SNIValues {
return &kubeapiserverexposure.SNIValues{
IstioIngressGateway: kubeapiserverexposure.IstioIngressGateway{
Namespace: b.IstioNamespace(),
Labels: b.IstioLabels(),
},
}
},
))
}
// DeployKubeAPIServerSNI deploys the kube-apiserver SNI resources.
func (b *Botanist) DeployKubeAPIServerSNI(ctx context.Context) error {
return b.Shoot.Components.ControlPlane.KubeAPIServerSNI.Deploy(ctx)
}
func (b *Botanist) setAPIServerServiceClusterIP(clusterIP string) {
if b.Shoot.Networks.Services.IP.To4() != nil {
b.APIServerClusterIP = clusterIP
} else {
// "64:ff9b:1::" is a well known prefix for address translation for use
// in local networks.
b.APIServerClusterIP = "64:ff9b:1::" + clusterIP
}
b.Shoot.Components.ControlPlane.KubeAPIServerSNI = kubeapiserverexposure.NewSNI(
b.SeedClientSet.Client(),
b.SeedClientSet.Applier(),
v1beta1constants.DeploymentNameKubeAPIServer,
b.Shoot.SeedNamespace,
func() *kubeapiserverexposure.SNIValues {
return &kubeapiserverexposure.SNIValues{
Hosts: []string{
gardenerutils.GetAPIServerDomain(*b.Shoot.ExternalClusterDomain),
gardenerutils.GetAPIServerDomain(b.Shoot.InternalClusterDomain),
},
APIServerProxy: &kubeapiserverexposure.APIServerProxy{
APIServerClusterIP: b.APIServerClusterIP,
NamespaceUID: b.SeedNamespaceObject.UID,
},
IstioIngressGateway: kubeapiserverexposure.IstioIngressGateway{
Namespace: b.IstioNamespace(),
Labels: b.IstioLabels(),
},
}
},
)
}
// DefaultKubeAPIServerIngress returns a deployer for the kube-apiserver ingress.
func (b *Botanist) DefaultKubeAPIServerIngress() component.Deployer {
return kubeapiserverexposure.NewIngress(
b.SeedClientSet.Client(),
b.Shoot.SeedNamespace,
kubeapiserverexposure.IngressValues{
ServiceName: v1beta1constants.DeploymentNameKubeAPIServer,
Host: b.ComputeKubeAPIServerHost(),
IngressClassName: pointer.String(v1beta1constants.SeedNginxIngressClass),
})
}
// DeployKubeAPIServerIngress deploys the ingress for the kube-apiserver.
func (b *Botanist) DeployKubeAPIServerIngress(ctx context.Context) error {
// Do not deploy ingress if there is no wildcard certificate
if b.ControlPlaneWildcardCert == nil {
return b.Shoot.Components.ControlPlane.KubeAPIServerIngress.Destroy(ctx)
}
return b.Shoot.Components.ControlPlane.KubeAPIServerIngress.Deploy(ctx)
}