Skip to content

Commit

Permalink
Merge pull request #552 from tirthct/ocm-3801
Browse files Browse the repository at this point in the history
OCM-3801 | Feat | Added default values for CIDRs and host prefix
  • Loading branch information
gdbranco committed Sep 25, 2023
2 parents 1dbda42 + fbff80f commit 55cf5e9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
33 changes: 33 additions & 0 deletions cmd/ocm/create/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,34 @@ func getFlavourOptions(connection *sdk.Connection) ([]arguments.Option, error) {
return options, nil
}

func GetDefaultClusterFlavors(connection *sdk.Connection, flavour string) (dMachinecidr *net.IPNet, dPodcidr *net.IPNet,
dServicecidr *net.IPNet, dhostPrefix int) {
flavourGetResponse, err := connection.ClustersMgmt().V1().Flavours().Flavour(flavour).Get().Send()
if err != nil {
flavourGetResponse, _ = connection.ClustersMgmt().V1().Flavours().Flavour("osd-4").Get().Send()
}

network, ok := flavourGetResponse.Body().GetNetwork()
if !ok {
return nil, nil, nil, 0
}
_, dMachinecidr, err = net.ParseCIDR(network.MachineCIDR())
if err != nil {
dMachinecidr = nil
}
_, dPodcidr, err = net.ParseCIDR(network.PodCIDR())
if err != nil {
dPodcidr = nil
}
_, dServicecidr, err = net.ParseCIDR(network.ServiceCIDR())
if err != nil {
dServicecidr = nil
}
dhostPrefix, _ = network.GetHostPrefix()

return dMachinecidr, dPodcidr, dServicecidr, dhostPrefix
}

func getVersionOptions(connection *sdk.Connection) ([]arguments.Option, error) {
options, _, err := getVersionOptionsWithDefault(connection, "")
return options, err
Expand Down Expand Up @@ -595,6 +623,11 @@ func preRun(cmd *cobra.Command, argv []string) error {
return err
}

if args.interactive {
machineCIDR, podCIDR, serviceCIDR, hostPrefix := GetDefaultClusterFlavors(connection, args.flavour)
args.machineCIDR, args.podCIDR, args.serviceCIDR, args.hostPrefix = *machineCIDR, *podCIDR, *serviceCIDR, hostPrefix
}

err = promptNetwork(fs)
if err != nil {
return err
Expand Down
9 changes: 6 additions & 3 deletions pkg/arguments/interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,15 @@ func PromptIPNet(fs *pflag.FlagSet, flagName string) error {
if flag.Changed {
return nil
}

// We set the default value here (if nil) so that shown on the console when the user does not provide any input
// (awkward because https://github.com/golang/go/issues/39516).
if flag.DefValue == "<nil>" {
flag.DefValue = flag.Value.String()
}
prompt := &survey.Input{
Message: getQuestion(flag),
Help: flag.Usage,
// TODO respect flag default, if set
// (awkward because https://github.com/golang/go/issues/39516).
Default: flag.DefValue,
}
var response string
// Set() flag as side effect of validation => prompts again if invalid.
Expand Down

0 comments on commit 55cf5e9

Please sign in to comment.