Skip to content

Commit

Permalink
Merge pull request openshift#1233 from abhinavdahiya/dns_zones
Browse files Browse the repository at this point in the history
manifest: set the public and private zones for AWS
  • Loading branch information
openshift-merge-robot committed Feb 14, 2019
2 parents 7cdfd61 + b65b613 commit 1886b7d
Show file tree
Hide file tree
Showing 15 changed files with 904 additions and 38 deletions.
8 changes: 4 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions pkg/asset/installconfig/aws/basedomain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sort"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/pkg/errors"
Expand Down Expand Up @@ -78,3 +79,30 @@ func GetBaseDomain() (string, error) {

return domain, nil
}

// GetPublicZone returns a public route53 zone that matches the name.
func GetPublicZone(name string) (*route53.HostedZone, error) {
var res *route53.HostedZone
f := func(resp *route53.ListHostedZonesOutput, lastPage bool) (shouldContinue bool) {
for idx, zone := range resp.HostedZones {
if zone.Config != nil && !aws.BoolValue(zone.Config.PrivateZone) && strings.TrimSuffix(aws.StringValue(zone.Name), ".") == strings.TrimSuffix(name, ".") {
res = resp.HostedZones[idx]
return false
}
}
return !lastPage
}

session, err := GetSession()
if err != nil {
return nil, errors.Wrap(err, "getting AWS session")
}
client := route53.New(session)
if err := client.ListHostedZonesPages(&route53.ListHostedZonesInput{}, f); err != nil {
return nil, errors.Wrap(err, "listing hosted zones")
}
if res == nil {
return nil, errors.Errorf("No public route53 zone found matching name %q", name)
}
return res, nil
}
38 changes: 34 additions & 4 deletions pkg/asset/manifests/dns.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
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"
"github.com/openshift/installer/pkg/asset/templates/content"

configv1 "github.com/openshift/api/config/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
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"
)

var (
Expand All @@ -36,13 +43,19 @@ func (*DNS) Name() string {
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{}
dependencies.Get(installConfig)
clusterID := &installconfig.ClusterID{}
dependencies.Get(installConfig, clusterID)

config := &configv1.DNS{
TypeMeta: metav1.TypeMeta{
Expand All @@ -58,6 +71,23 @@ func (d *DNS) Generate(dependencies asset.Parents) error {
},
}

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{
"openshiftClusterID": clusterID.ClusterID,
fmt.Sprintf("kubernetes.io/cluster/%s", installConfig.Config.ObjectMeta.Name): "owned",
"Name": fmt.Sprintf("%s_int", installConfig.Config.ObjectMeta.Name),
}}
case libvirttypes.Name, openstacktypes.Name, nonetypes.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())
Expand Down
4 changes: 4 additions & 0 deletions vendor/github.com/openshift/api/config/v1/register.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions vendor/github.com/openshift/api/config/v1/type_features.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions vendor/github.com/openshift/api/config/v1/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions vendor/github.com/openshift/api/config/v1/types_build.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions vendor/github.com/openshift/api/config/v1/types_dns.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions vendor/github.com/openshift/api/config/v1/types_registries.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1886b7d

Please sign in to comment.