Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump survey to v2 #4915

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.14

require (
cloud.google.com/go v0.65.0
github.com/AlecAivazis/survey/v2 v2.2.12
github.com/Azure/azure-sdk-for-go v51.2.0+incompatible
github.com/Azure/go-autorest/autorest v0.11.17
github.com/Azure/go-autorest/autorest/adal v0.9.10
Expand Down Expand Up @@ -95,7 +96,6 @@ require (
google.golang.org/api v0.33.0
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a
google.golang.org/grpc v1.32.0
gopkg.in/AlecAivazis/survey.v1 v1.8.9-0.20200217094205-6773bdf39b7f
gopkg.in/ini.v1 v1.61.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.21.0-rc.0
Expand Down
36 changes: 2 additions & 34 deletions go.sum

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions pkg/asset/installconfig/aws/basedomain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"sort"
"strings"

survey "github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/core"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
survey "gopkg.in/AlecAivazis/survey.v1"
)

// IsForbidden returns true if and only if the input error is an HTTP
Expand Down Expand Up @@ -61,14 +62,14 @@ func GetBaseDomain() (string, error) {
Message: "Base Domain",
Help: "The base domain of the cluster. All DNS records will be sub-domains of this base and will also include the cluster name.\n\nIf you don't see you intended base-domain listed, create a new public Route53 hosted zone and rerun the installer.",
Options: publicZones,
}, &domain, func(ans interface{}) error {
choice := ans.(string)
}, &domain, survey.WithValidator(func(ans interface{}) error {
choice := ans.(core.OptionAnswer).Value
i := sort.SearchStrings(publicZones, choice)
if i == len(publicZones) || publicZones[i] != choice {
return errors.Errorf("invalid base domain %q", choice)
}
return nil
}); err != nil {
})); err != nil {
return "", errors.Wrap(err, "failed UserInput")
}

Expand Down
18 changes: 13 additions & 5 deletions pkg/asset/installconfig/aws/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"sort"
"strings"

survey "github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/core"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
survey "gopkg.in/AlecAivazis/survey.v1"

"github.com/openshift/installer/pkg/types/aws"
)
Expand All @@ -21,9 +22,16 @@ func Platform() (*aws.Platform, error) {
longRegions = append(longRegions, fmt.Sprintf("%s (%s)", id, location))
shortRegions = append(shortRegions, id)
}
regionTransform := survey.TransformString(func(s string) string {
return strings.SplitN(s, " ", 2)[0]
})

var regionTransform survey.Transformer = func(ans interface{}) interface{} {
switch v := ans.(type) {
case core.OptionAnswer:
return core.OptionAnswer{Value: strings.SplitN(v.Value, " ", 2)[0], Index: v.Index}
case string:
return strings.SplitN(v, " ", 2)[0]
}
return ""
}

defaultRegion := "us-east-1"
if !IsKnownRegion(defaultRegion) {
Expand Down Expand Up @@ -57,7 +65,7 @@ func Platform() (*aws.Platform, error) {
Options: longRegions,
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
choice := regionTransform(ans).(string)
choice := regionTransform(ans).(core.OptionAnswer).Value
i := sort.SearchStrings(shortRegions, choice)
if i == len(shortRegions) || shortRegions[i] != choice {
return errors.Errorf("invalid region %q", choice)
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/installconfig/aws/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"sync"

survey "github.com/AlecAivazis/survey/v2"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
Expand All @@ -15,7 +16,6 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
survey "gopkg.in/AlecAivazis/survey.v1"
ini "gopkg.in/ini.v1"

typesaws "github.com/openshift/installer/pkg/types/aws"
Expand Down
20 changes: 13 additions & 7 deletions pkg/asset/installconfig/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"sort"
"strings"

survey "github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/core"
"github.com/Azure/go-autorest/autorest/to"
"github.com/pkg/errors"

"github.com/openshift/installer/pkg/types/azure"

"github.com/pkg/errors"
survey "gopkg.in/AlecAivazis/survey.v1"
)

const (
Expand Down Expand Up @@ -51,9 +51,15 @@ func Platform() (*azure.Platform, error) {
}
}

regionTransform := survey.TransformString(func(s string) string {
return strings.SplitN(s, " ", 2)[0]
})
var regionTransform survey.Transformer = func(ans interface{}) interface{} {
switch v := ans.(type) {
case core.OptionAnswer:
return core.OptionAnswer{Value: strings.SplitN(v.Value, " ", 2)[0], Index: v.Index}
case string:
return strings.SplitN(v, " ", 2)[0]
}
return ""
}

_, ok := regions[defaultRegion]
if !ok {
Expand All @@ -73,7 +79,7 @@ func Platform() (*azure.Platform, error) {
Options: longRegions,
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
choice := regionTransform(ans).(string)
choice := regionTransform(ans).(core.OptionAnswer).Value
i := sort.SearchStrings(shortRegions, choice)
if i == len(shortRegions) || shortRegions[i] != choice {
return errors.Errorf("invalid region %q", choice)
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/installconfig/azure/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"
"time"

survey "github.com/AlecAivazis/survey/v2"
azdns "github.com/Azure/azure-sdk-for-go/profiles/latest/dns/mgmt/dns"
"github.com/Azure/go-autorest/autorest/to"
"github.com/pkg/errors"
survey "gopkg.in/AlecAivazis/survey.v1"
)

//DNSConfig exposes functions to choose the DNS settings
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/installconfig/azure/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"path/filepath"
"sync"

"github.com/AlecAivazis/survey/v2"
"github.com/Azure/go-autorest/autorest"
azureenv "github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/azure/auth"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"gopkg.in/AlecAivazis/survey.v1"

"github.com/openshift/installer/pkg/types/azure"
)
Expand Down
5 changes: 3 additions & 2 deletions pkg/asset/installconfig/baremetal/baremetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package baremetal

import (
"fmt"

"github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/terminal"
"github.com/pkg/errors"
"gopkg.in/AlecAivazis/survey.v1"
"gopkg.in/AlecAivazis/survey.v1/terminal"

"github.com/openshift/installer/pkg/ipnet"
"github.com/openshift/installer/pkg/types/baremetal"
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/installconfig/baremetal/host.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package baremetal

import (
"gopkg.in/AlecAivazis/survey.v1"
"github.com/AlecAivazis/survey/v2"

"github.com/openshift/installer/pkg/types/baremetal"
"github.com/openshift/installer/pkg/validate"
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/installconfig/basedomain.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package installconfig

import (
survey "github.com/AlecAivazis/survey/v2"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/pkg/errors"
survey "gopkg.in/AlecAivazis/survey.v1"

"github.com/openshift/installer/pkg/asset"
awsconfig "github.com/openshift/installer/pkg/asset/installconfig/aws"
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/installconfig/clustername.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package installconfig

import (
survey "github.com/AlecAivazis/survey/v2"
"github.com/pkg/errors"
survey "gopkg.in/AlecAivazis/survey.v1"

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/types"
Expand Down
9 changes: 5 additions & 4 deletions pkg/asset/installconfig/gcp/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"sort"
"time"

survey "github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/core"
"github.com/pkg/errors"
dns "google.golang.org/api/dns/v1"
"google.golang.org/api/googleapi"
survey "gopkg.in/AlecAivazis/survey.v1"
)

// GetPublicZone returns a DNS managed zone from the provided project which matches the baseDomain
Expand Down Expand Up @@ -51,14 +52,14 @@ func GetBaseDomain(project string) (string, error) {
Message: "Base Domain",
Help: "The base domain of the cluster. All DNS records will be sub-domains of this base and will also include the cluster name.\n\nIf you don't see you intended base-domain listed, create a new public hosted zone and rerun the installer.",
Options: publicZones,
}, &domain, func(ans interface{}) error {
choice := ans.(string)
}, &domain, survey.WithValidator(func(ans interface{}) error {
choice := ans.(core.OptionAnswer).Value
i := sort.SearchStrings(publicZones, choice)
if i == len(publicZones) || publicZones[i] != choice {
return errors.Errorf("invalid base domain %q", choice)
}
return nil
}); err != nil {
})); err != nil {
return "", errors.Wrap(err, "failed UserInput")
}

Expand Down
20 changes: 14 additions & 6 deletions pkg/asset/installconfig/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"strings"
"time"

"gopkg.in/AlecAivazis/survey.v1"
"github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/core"
"github.com/pkg/errors"

"github.com/openshift/installer/pkg/types/gcp"
"github.com/openshift/installer/pkg/types/gcp/validation"
"github.com/pkg/errors"
)

// Platform collects GCP-specific configuration.
Expand Down Expand Up @@ -88,9 +89,16 @@ func selectRegion(project string) (string, error) {
longRegions = append(longRegions, fmt.Sprintf("%s (%s)", id, location))
shortRegions = append(shortRegions, id)
}
regionTransform := survey.TransformString(func(s string) string {
return strings.SplitN(s, " ", 2)[0]
})

var regionTransform survey.Transformer = func(ans interface{}) interface{} {
switch v := ans.(type) {
case core.OptionAnswer:
return core.OptionAnswer{Value: strings.SplitN(v.Value, " ", 2)[0], Index: v.Index}
case string:
return strings.SplitN(v, " ", 2)[0]
}
return ""
}

sort.Strings(longRegions)
sort.Strings(shortRegions)
Expand All @@ -106,7 +114,7 @@ func selectRegion(project string) (string, error) {
Options: longRegions,
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
choice := regionTransform(ans).(string)
choice := regionTransform(ans).(core.OptionAnswer).Value
i := sort.SearchStrings(shortRegions, choice)
if i == len(shortRegions) || shortRegions[i] != choice {
return errors.Errorf("invalid region %q", choice)
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/installconfig/gcp/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"strings"
"sync"

"github.com/AlecAivazis/survey/v2"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
googleoauth "golang.org/x/oauth2/google"
compute "google.golang.org/api/compute/v1"
"gopkg.in/AlecAivazis/survey.v1"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/installconfig/kubevirt/kubevirt.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package kubevirt

import (
"gopkg.in/AlecAivazis/survey.v1"
"github.com/AlecAivazis/survey/v2"

"github.com/openshift/installer/pkg/types/kubevirt"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/installconfig/libvirt/libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
package libvirt

import (
survey "github.com/AlecAivazis/survey/v2"
"github.com/pkg/errors"
survey "gopkg.in/AlecAivazis/survey.v1"

"github.com/openshift/installer/pkg/types/libvirt"
libvirtdefaults "github.com/openshift/installer/pkg/types/libvirt/defaults"
Expand Down
2 changes: 1 addition & 1 deletion pkg/asset/installconfig/networking.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package installconfig

import (
survey "gopkg.in/AlecAivazis/survey.v1"
survey "github.com/AlecAivazis/survey/v2"

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/ipnet"
Expand Down
11 changes: 6 additions & 5 deletions pkg/asset/installconfig/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"sort"
"strings"

survey "github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/core"
"github.com/pkg/errors"
survey "gopkg.in/AlecAivazis/survey.v1"

"github.com/openshift/installer/pkg/types/openstack"
)
Expand All @@ -32,7 +33,7 @@ func Platform() (*openstack.Platform, error) {
Options: cloudNames,
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
value := ans.(string)
value := ans.(core.OptionAnswer).Value
i := sort.SearchStrings(cloudNames, value)
if i == len(cloudNames) || cloudNames[i] != value {
return errors.Errorf("invalid cloud name %q, should be one of %+v", value, strings.Join(cloudNames, ", "))
Expand Down Expand Up @@ -61,7 +62,7 @@ func Platform() (*openstack.Platform, error) {
Default: noExtNet,
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
value := ans.(string)
value := ans.(core.OptionAnswer).Value
i := sort.SearchStrings(networkNames, value)
if i == len(networkNames) || networkNames[i] != value {
return errors.Errorf("invalid network name %q, should be one of %+v", value, strings.Join(networkNames, ", "))
Expand Down Expand Up @@ -92,7 +93,7 @@ func Platform() (*openstack.Platform, error) {
Options: floatingIPNames,
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
value := ans.(string)
value := ans.(core.OptionAnswer).Value
i := sort.SearchStrings(floatingIPNames, value)
if i == len(floatingIPNames) || floatingIPNames[i] != value {
return errors.Errorf("invalid floating IP %q, should be one of %+v", value, strings.Join(floatingIPNames, ", "))
Expand Down Expand Up @@ -120,7 +121,7 @@ func Platform() (*openstack.Platform, error) {
Options: flavorNames,
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
value := ans.(string)
value := ans.(core.OptionAnswer).Value
i := sort.SearchStrings(flavorNames, value)
if i == len(flavorNames) || flavorNames[i] != value {
return errors.Errorf("invalid flavor name %q, should be one of %+v", value, strings.Join(flavorNames, ", "))
Expand Down