-
Notifications
You must be signed in to change notification settings - Fork 451
/
internal_name_service.go
54 lines (43 loc) · 1.75 KB
/
internal_name_service.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
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package apiserverexposure
import (
"context"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"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/controllerutils"
)
type internalNameService struct {
client client.Client
namespace string
}
// NewInternalNameService creates a new instance of Deployer for the service kubernetes.default.svc.cluster.local.
func NewInternalNameService(c client.Client, namespace string) component.Deployer {
return &internalNameService{
client: c,
namespace: namespace,
}
}
func (in *internalNameService) Deploy(ctx context.Context) error {
svc := in.emptyKubernetesDefaultService()
if _, err := controllerutils.GetAndCreateOrMergePatch(ctx, in.client, svc, func() error {
metav1.SetMetaDataAnnotation(&svc.ObjectMeta, "networking.istio.io/exportTo", "*")
return nil
}); err != nil {
return err
}
return client.IgnoreNotFound(in.client.Delete(ctx, in.emptyService()))
}
func (in *internalNameService) Destroy(ctx context.Context) error {
return client.IgnoreNotFound(in.client.Delete(ctx, in.emptyService()))
}
func (in *internalNameService) emptyService() *corev1.Service {
return &corev1.Service{ObjectMeta: metav1.ObjectMeta{Name: v1beta1constants.DeploymentNameKubeAPIServer, Namespace: in.namespace}}
}
func (in *internalNameService) emptyKubernetesDefaultService() *corev1.Service {
return &corev1.Service{ObjectMeta: metav1.ObjectMeta{Name: "kubernetes", Namespace: metav1.NamespaceDefault}}
}