Skip to content

Commit

Permalink
Adding private DNS domains to survey for PowerVS
Browse files Browse the repository at this point in the history
Signed-off-by: Hiro Miyamoto <miyamotoh@us.ibm.com>
  • Loading branch information
miyamotoh committed Apr 23, 2024
1 parent 8353ac4 commit 1db371c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
3 changes: 3 additions & 0 deletions pkg/asset/installconfig/basedomain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
gcpconfig "github.com/openshift/installer/pkg/asset/installconfig/gcp"
ibmcloudconfig "github.com/openshift/installer/pkg/asset/installconfig/ibmcloud"
powervsconfig "github.com/openshift/installer/pkg/asset/installconfig/powervs"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/aws"
"github.com/openshift/installer/pkg/types/azure"
"github.com/openshift/installer/pkg/types/gcp"
Expand All @@ -21,6 +22,7 @@ import (

type baseDomain struct {
BaseDomain string
Publish types.PublishingStrategy
}

var _ asset.Asset = (*baseDomain)(nil)
Expand Down Expand Up @@ -78,6 +80,7 @@ func (a *baseDomain) Generate(parents asset.Parents) error {
return err
}
a.BaseDomain = zone.Name
a.Publish = zone.Publish
return nil
default:
//Do nothing
Expand Down
1 change: 1 addition & 0 deletions pkg/asset/installconfig/installconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (a *InstallConfig) Generate(parents asset.Parents) error {
},
SSHKey: sshPublicKey.Key,
BaseDomain: baseDomain.BaseDomain,
Publish: baseDomain.Publish,
PullSecret: pullSecret.PullSecret,
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/installconfig/installconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

func TestInstallConfigGenerate_FillsInDefaults(t *testing.T) {
sshPublicKey := &sshPublicKey{}
baseDomain := &baseDomain{"test-domain"}
baseDomain := &baseDomain{"test-domain", types.ExternalPublishingStrategy}
clusterName := &clusterName{"test-cluster"}
pullSecret := &pullSecret{`{"auths":{"example.com":{"auth":"authorization value"}}}`}
platform := &platform{
Expand Down
41 changes: 24 additions & 17 deletions pkg/asset/installconfig/powervs/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (
// Zone represents a DNS Zone
type Zone struct {
Name string
CISInstanceCRN string
InstanceCRN string
ResourceGroupID string
Publish types.PublishingStrategy
}

// GetDNSZone returns a DNS Zone chosen by survey.
Expand All @@ -28,23 +29,29 @@ func GetDNSZone() (*Zone, error) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()

// Default to offering only external DNS entries, as IBM Cloud does in their provider
// TODO(mjturek): Offer private zones (IBM DNS) when deploying a private cluster
publicZones, err := client.GetDNSZones(ctx, types.ExternalPublishingStrategy)
if err != nil {
return nil, fmt.Errorf("could not retrieve base domains: %w", err)
}

var options []string
var optionToZoneMap = make(map[string]*Zone, len(publicZones))
for _, zone := range publicZones {
option := fmt.Sprintf("%s (%s)", zone.Name, zone.InstanceName)
optionToZoneMap[option] = &Zone{
Name: zone.Name,
CISInstanceCRN: zone.InstanceCRN,
ResourceGroupID: zone.ResourceGroupID,
var optionToZoneMap = make(map[string]*Zone, 10)
isInternal := ""
strategies := []types.PublishingStrategy{types.ExternalPublishingStrategy, types.InternalPublishingStrategy}
for _, s := range strategies {
zones, err := client.GetDNSZones(ctx, s)
if err != nil {
return nil, fmt.Errorf("could not retrieve base domains: %w", err)
}

for _, zone := range zones {
if s == types.InternalPublishingStrategy {
isInternal = " (Internal)"
}
option := fmt.Sprintf("%s%s", zone.Name, isInternal)
optionToZoneMap[option] = &Zone{
Name: zone.Name,
InstanceCRN: zone.InstanceCRN,
ResourceGroupID: zone.ResourceGroupID,
Publish: s,
}
options = append(options, option)
}
options = append(options, option)
}
sort.Strings(options)

Expand All @@ -58,7 +65,7 @@ func GetDNSZone() (*Zone, error) {
survey.WithValidator(func(ans interface{}) error {
choice := ans.(core.OptionAnswer).Value
i := sort.SearchStrings(options, choice)
if i == len(publicZones) || options[i] != choice {
if i == len(options) || options[i] != choice {
return fmt.Errorf("invalid base domain %q", choice)
}
return nil
Expand Down

0 comments on commit 1db371c

Please sign in to comment.