-
Notifications
You must be signed in to change notification settings - Fork 455
/
dns.go
105 lines (92 loc) · 4.35 KB
/
dns.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
// 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 gardener
import (
"fmt"
)
const (
// DNSProvider is the key for an annotation on a Kubernetes Secret object whose value must point to a valid
// DNS provider.
DNSProvider = "dns.gardener.cloud/provider"
// DNSDomain is the key for an annotation on a Kubernetes Secret object whose value must point to a valid
// domain name.
DNSDomain = "dns.gardener.cloud/domain"
// DNSDefaultDomainPriority is the priority of the default domain. In case of multiple default domains
// the default domain with the highest priority is selected per default for new shoots.
DNSDefaultDomainPriority = "dns.gardener.cloud/domain-default-priority"
// DNSZone is the key for an annotation on a Kubernetes Secret object whose value must point to a valid
// DNS hosted zone id.
DNSZone = "dns.gardener.cloud/zone"
// APIServerFQDNPrefix is the part of a FQDN which will be used to construct the domain name for the kube-apiserver of
// a Shoot cluster. For example, when a Shoot specifies domain 'cluster.example.com', the apiserver domain would be
// 'api.cluster.example.com'.
APIServerFQDNPrefix = "api"
// OwnerFQDNPrefix is the part of a FQDN which will be used to construct the domain name for the owner of
// a Shoot cluster. For example, when a Shoot specifies domain 'cluster.example.com', the owner domain would be
// 'owner.cluster.example.com'.
OwnerFQDNPrefix = "owner"
// IngressPrefix is the part of a FQDN which will be used to construct the domain name for an ingress controller of
// a Shoot cluster. For example, when a Shoot specifies domain 'cluster.example.com', the ingress domain would be
// '*.<IngressPrefix>.cluster.example.com'.
IngressPrefix = "ingress"
// InternalDomainKey is a key which must be present in an internal domain constructed for a Shoot cluster. If the
// configured internal domain already contains it, it won't be added twice. If it does not contain it, it will be
// appended.
InternalDomainKey = "internal"
)
// GetDomainInfoFromAnnotations returns the provider, domain, and zones that are specified in the given annotations.
func GetDomainInfoFromAnnotations(annotations map[string]string) (provider string, domain string, zone string, err error) {
if annotations == nil {
return "", "", "", fmt.Errorf("domain secret has no annotations")
}
if providerAnnotation, ok := annotations[DNSProvider]; ok {
provider = providerAnnotation
}
if domainAnnotation, ok := annotations[DNSDomain]; ok {
domain = domainAnnotation
}
if zoneAnnotation, ok := annotations[DNSZone]; ok {
zone = zoneAnnotation
}
if len(domain) == 0 {
return "", "", "", fmt.Errorf("missing dns domain annotation on domain secret")
}
if len(provider) == 0 {
return "", "", "", fmt.Errorf("missing dns provider annotation on domain secret")
}
return
}
// GetAPIServerDomain returns the fully qualified domain name for the api-server of the Shoot cluster. The
// end result is 'api.<domain>'.
func GetAPIServerDomain(domain string) string {
return fmt.Sprintf("%s.%s", APIServerFQDNPrefix, domain)
}
// GetOwnerDomain returns the fully qualified domain name for the owner of the Shoot cluster. The
// end result is 'owner.<domain>'.
func GetOwnerDomain(domain string) string {
return fmt.Sprintf("%s.%s", OwnerFQDNPrefix, domain)
}
// GenerateDNSProviderName creates a name for the dns provider out of the passed `secretName` and `providerType`.
func GenerateDNSProviderName(secretName, providerType string) string {
switch {
case secretName != "" && providerType != "":
return fmt.Sprintf("%s-%s", providerType, secretName)
case secretName != "":
return secretName
case providerType != "":
return providerType
default:
return ""
}
}