forked from openshift/installer
/
dns.go
112 lines (95 loc) · 3.13 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
106
107
108
109
110
111
112
package manifests
import (
"fmt"
"path/filepath"
"strings"
"github.com/ghodss/yaml"
"github.com/pkg/errors"
configv1 "github.com/openshift/api/config/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/installconfig"
icaws "github.com/openshift/installer/pkg/asset/installconfig/aws"
awstypes "github.com/openshift/installer/pkg/types/aws"
libvirttypes "github.com/openshift/installer/pkg/types/libvirt"
nonetypes "github.com/openshift/installer/pkg/types/none"
openstacktypes "github.com/openshift/installer/pkg/types/openstack"
vspheretypes "github.com/openshift/installer/pkg/types/vsphere"
)
var (
dnsCfgFilename = filepath.Join(manifestDir, "cluster-dns-02-config.yml")
)
// DNS generates the cluster-dns-*.yml files.
type DNS struct {
FileList []*asset.File
}
var _ asset.WritableAsset = (*DNS)(nil)
// Name returns a human friendly name for the asset.
func (*DNS) Name() string {
return "DNS Config"
}
// Dependencies returns all of the dependencies directly needed to generate
// the asset.
func (*DNS) Dependencies() []asset.Asset {
return []asset.Asset{
&installconfig.InstallConfig{},
&installconfig.ClusterID{},
// PlatformCredsCheck just checks the creds (and asks, if needed)
// We do not actually use it in this asset directly, hence
// it is put in the dependencies but not fetched in Generate
&installconfig.PlatformCredsCheck{},
}
}
// Generate generates the DNS config and its CRD.
func (d *DNS) Generate(dependencies asset.Parents) error {
installConfig := &installconfig.InstallConfig{}
clusterID := &installconfig.ClusterID{}
dependencies.Get(installConfig, clusterID)
config := &configv1.DNS{
TypeMeta: metav1.TypeMeta{
APIVersion: configv1.SchemeGroupVersion.String(),
Kind: "DNS",
},
ObjectMeta: metav1.ObjectMeta{
Name: "cluster",
// not namespaced
},
Spec: configv1.DNSSpec{
BaseDomain: installConfig.Config.ClusterDomain(),
},
}
switch installConfig.Config.Platform.Name() {
case awstypes.Name:
zone, err := icaws.GetPublicZone(installConfig.Config.BaseDomain)
if err != nil {
return errors.Wrapf(err, "getting public zone for %q", installConfig.Config.BaseDomain)
}
config.Spec.PublicZone = &configv1.DNSZone{ID: strings.TrimPrefix(*zone.Id, "/hostedzone/")}
config.Spec.PrivateZone = &configv1.DNSZone{Tags: map[string]string{
fmt.Sprintf("kubernetes.io/cluster/%s", clusterID.InfraID): "owned",
"Name": fmt.Sprintf("%s-int", clusterID.InfraID),
}}
case libvirttypes.Name, openstacktypes.Name, nonetypes.Name, vspheretypes.Name:
default:
return errors.New("invalid Platform")
}
configData, err := yaml.Marshal(config)
if err != nil {
return errors.Wrapf(err, "failed to create %s manifests from InstallConfig", d.Name())
}
d.FileList = []*asset.File{
{
Filename: dnsCfgFilename,
Data: configData,
},
}
return nil
}
// Files returns the files generated by the asset.
func (d *DNS) Files() []*asset.File {
return d.FileList
}
// Load loads the already-rendered files back from disk.
func (d *DNS) Load(f asset.FileFetcher) (bool, error) {
return false, nil
}