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

added cni select from the addons list #46

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"os"

"github.com/ksctl/cli/v2/pkg/cli"
"github.com/ksctl/cli/v2/pkg/config"
cLogger "github.com/ksctl/cli/v2/pkg/logger"
"github.com/ksctl/ksctl/v2/pkg/consts"
Expand All @@ -34,7 +35,8 @@ type KsctlCommand struct {
ksctlStorage storage.Storage
root *cobra.Command
verbose int
dryRun bool
debugMode bool
menuDriven cli.MenuDriven
KsctlConfig *config.Config
inMemInstanceTypesInReg map[string]provider.InstanceRegionOutput
}
Expand Down
29 changes: 14 additions & 15 deletions cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ func (k *KsctlCommand) ConfigureCloud() *cobra.Command {
}

func (k *KsctlCommand) handleStorageConfig() bool {
if v, err := cli.DropDown(
if v, err := k.menuDriven.DropDown(
"What should be your default storageDriver?",
map[string]string{
"MongoDb": string(consts.StoreExtMongo),
"Local": string(consts.StoreLocal),
},
"Local",
cli.WithDefaultValue("Local"),
); err != nil {
k.l.Error("Failed to get the storageDriver", "Reason", err)
return false
Expand All @@ -103,13 +103,12 @@ func (k *KsctlCommand) handleStorageConfig() bool {
}

func (k *KsctlCommand) handleCloudConfig() bool {
if v, err := cli.DropDown(
if v, err := k.menuDriven.DropDown(
"Credentials",
map[string]string{
"Amazon Web Services": string(consts.CloudAws),
"Azure": string(consts.CloudAzure),
},
"",
); err != nil {
k.l.Error("Failed to get the credentials", "Reason", err)
return false
Expand All @@ -133,11 +132,11 @@ func (k *KsctlCommand) handleCloudConfig() bool {

func (k *KsctlCommand) storeAwsCredentials() (err error) {
c := new(statefile.CredentialsAws)
c.AccessKeyId, err = cli.TextInputPassword("Enter your AWS Access Key ID")
c.AccessKeyId, err = k.menuDriven.TextInputPassword("Enter your AWS Access Key ID")
if err != nil {
return err
}
c.SecretAccessKey, err = cli.TextInputPassword("Enter your AWS Secret Access Key")
c.SecretAccessKey, err = k.menuDriven.TextInputPassword("Enter your AWS Secret Access Key")
if err != nil {
return err
}
Expand All @@ -160,21 +159,21 @@ func (k *KsctlCommand) loadAwsCredentials() error {

func (k *KsctlCommand) storeAzureCredentials() (err error) {
c := new(statefile.CredentialsAzure)
c.SubscriptionID, err = cli.TextInputPassword("Enter your Azure Subscription ID")
c.SubscriptionID, err = k.menuDriven.TextInputPassword("Enter your Azure Subscription ID")
if err != nil {
return err
}

c.TenantID, err = cli.TextInputPassword("Enter your Azure Tenant ID")
c.TenantID, err = k.menuDriven.TextInputPassword("Enter your Azure Tenant ID")
if err != nil {
return err
}

c.ClientID, err = cli.TextInputPassword("Enter your Azure Client ID")
c.ClientID, err = k.menuDriven.TextInputPassword("Enter your Azure Client ID")
if err != nil {
return err
}
c.ClientSecret, err = cli.TextInputPassword("Enter your Azure Client Secret")
c.ClientSecret, err = k.menuDriven.TextInputPassword("Enter your Azure Client Secret")
if err != nil {
return err
}
Expand All @@ -197,26 +196,26 @@ func (k *KsctlCommand) loadAzureCredentials() error {

func (k *KsctlCommand) storeMongoCredentials() (err error) {
c := new(statefile.CredentialsMongodb)
srv, err := cli.Confirmation("Enter whether MongoDB has SRV record or not", "no")
srv, err := k.menuDriven.Confirmation("Enter whether MongoDB has SRV record or not", cli.WithDefaultValue("no"))
if err != nil {
return err
}
c.SRV = srv

c.Domain, err = cli.TextInput("Enter your MongoDB URI", "")
c.Domain, err = k.menuDriven.TextInput("Enter your MongoDB URI")
if err != nil {
return err
}
c.Username, err = cli.TextInputPassword("Enter your MongoDB Username")
c.Username, err = k.menuDriven.TextInputPassword("Enter your MongoDB Username")
if err != nil {
return err
}
c.Password, err = cli.TextInputPassword("Enter your MongoDB Password")
c.Password, err = k.menuDriven.TextInputPassword("Enter your MongoDB Password")
if err != nil {
return err
}
port := ""
if port, err = cli.TextInput("Enter your MongoDB Port", ""); err != nil {
if port, err = k.menuDriven.TextInput("Enter your MongoDB Port"); err != nil {
return err
}
if len(port) != 0 {
Expand Down
7 changes: 3 additions & 4 deletions cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"github.com/creack/pty"
"github.com/fatih/color"
"github.com/ksctl/cli/v2/pkg/cli"
"github.com/ksctl/ksctl/v2/pkg/handler/cluster/common"

Check failure on line 31 in cmd/connect.go

View workflow job for this annotation

GitHub Actions / linux

github.com/ksctl/ksctl/[email protected]: replacement directory ../ksctl does not exist

Check failure on line 31 in cmd/connect.go

View workflow job for this annotation

GitHub Actions / macos

github.com/ksctl/ksctl/[email protected]: replacement directory ../ksctl does not exist
"github.com/ksctl/ksctl/v2/pkg/handler/cluster/controller"

Check failure on line 32 in cmd/connect.go

View workflow job for this annotation

GitHub Actions / linux

github.com/ksctl/ksctl/[email protected]: replacement directory ../ksctl does not exist

Check failure on line 32 in cmd/connect.go

View workflow job for this annotation

GitHub Actions / macos

github.com/ksctl/ksctl/[email protected]: replacement directory ../ksctl does not exist
"github.com/ksctl/ksctl/v2/pkg/logger"
"github.com/spf13/cobra"
"golang.org/x/term"
Expand Down Expand Up @@ -74,10 +74,9 @@
}
}

selectedCluster, err := cli.DropDown(
selectedCluster, err := k.menuDriven.DropDown(
"Select the cluster to delete",
selectDisplay,
"",
)
if err != nil {
k.l.Error("Failed to get userinput", "Reason", err)
Expand Down Expand Up @@ -108,14 +107,14 @@

k.writeKubeconfig([]byte(*kubeconfig))

accessMode, err := cli.DropDown(
accessMode, err := k.menuDriven.DropDown(
"Select the access mode",
map[string]string{
"k9s": "k9s",
"bash": "shell",
"none": "none",
},
"none",
cli.WithDefaultValue("none"),
)
if err != nil {
k.l.Error("Failed to get userinput", "Reason", err)
Expand Down
47 changes: 34 additions & 13 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import (
"os"

"github.com/ksctl/ksctl/v2/pkg/addons"
"github.com/ksctl/ksctl/v2/pkg/consts"

"github.com/ksctl/cli/v2/pkg/cli"
"github.com/ksctl/ksctl/v2/pkg/handler/cluster/controller"

controllerManaged "github.com/ksctl/ksctl/v2/pkg/handler/cluster/managed"

Check failure on line 25 in cmd/create.go

View workflow job for this annotation

GitHub Actions / linux

github.com/ksctl/ksctl/[email protected]: replacement directory ../ksctl does not exist

Check failure on line 25 in cmd/create.go

View workflow job for this annotation

GitHub Actions / macos

github.com/ksctl/ksctl/[email protected]: replacement directory ../ksctl does not exist
controllerMeta "github.com/ksctl/ksctl/v2/pkg/handler/cluster/metadata"

Check failure on line 26 in cmd/create.go

View workflow job for this annotation

GitHub Actions / linux

github.com/ksctl/ksctl/[email protected]: replacement directory ../ksctl does not exist

Check failure on line 26 in cmd/create.go

View workflow job for this annotation

GitHub Actions / macos

github.com/ksctl/ksctl/[email protected]: replacement directory ../ksctl does not exist
controllerSelfManaged "github.com/ksctl/ksctl/v2/pkg/handler/cluster/selfmanaged"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -116,7 +115,7 @@
k.l.Error("Failed to get the list of bootstrap versions", "Reason", err)
os.Exit(1)
}
if v, err := cli.DropDownList("Select the bootstrap version", bootstrapVers, bootstrapVers[0]); err != nil {
if v, err := k.menuDriven.DropDownList("Select the bootstrap version", bootstrapVers, cli.WithDefaultValue(bootstrapVers[0])); err != nil {
k.l.Error("Failed to get the bootstrap version", "Reason", err)
os.Exit(1)
} else {
Expand All @@ -129,7 +128,7 @@
k.l.Error("Failed to get the list of etcd versions", "Reason", err)
os.Exit(1)
}
if v, err := cli.DropDownList("Select the etcd version", etcdVers, etcdVers[0]); err != nil {
if v, err := k.menuDriven.DropDownList("Select the etcd version", etcdVers, cli.WithDefaultValue(etcdVers[0])); err != nil {
k.l.Error("Failed to get the etcd version", "Reason", err)
os.Exit(1)
} else {
Expand All @@ -153,9 +152,23 @@
os.Exit(1)
}

managedCNI, defaultCNI, ksctlCNI, defaultKsctl, err := metaClient.ListBootstrapCNIs()
if err != nil {
k.l.Error("Failed to get the list of self managed CNIs", "Reason", err)
os.Exit(1)
}

v, err := k.handleCNI(managedCNI, defaultCNI, ksctlCNI, defaultKsctl)
if err != nil {
k.l.Error("Failed to get the CNI", "Reason", err)
os.Exit(1)
}

meta.Addons = v

k.metadataSummary(*meta)

if ok, _ := cli.Confirmation("Do you want to proceed with the cluster creation", "no"); !ok {
if ok, _ := k.menuDriven.Confirmation("Do you want to proceed with the cluster creation", cli.WithDefaultValue("no")); !ok {
os.Exit(1)
}

Expand Down Expand Up @@ -208,16 +221,15 @@
vm := k.handleInstanceTypeSelection(metaClient, meta, "Select instance_type for Managed Nodes")
meta.ManagedNodeType = vm.Sku

ss := cli.GetSpinner()
ss.Start("Fetching the managed cluster offerings")
k.menuDriven.GetProgressAnimation().Start("Fetching the managed cluster offerings")

listOfOfferings, err := metaClient.ListAllManagedClusterManagementOfferings(meta.Region, nil)
if err != nil {
ss.Stop()
k.menuDriven.GetProgressAnimation().Stop()
k.l.Error("Failed to sync the metadata", "Reason", err)
os.Exit(1)
}
ss.Stop()
k.menuDriven.GetProgressAnimation().Stop()

offeringSelected := ""

Expand All @@ -240,11 +252,24 @@
}
}

managedCNI, defaultCNI, ksctlCNI, defaultKsctl, err := metaClient.ListManagedCNIs()
if err != nil {
k.l.Error("Failed to get the list of managed CNIs", "Reason", err)
os.Exit(1)
}

if v, err := k.handleCNI(managedCNI, defaultCNI, ksctlCNI, defaultKsctl); err != nil {
k.l.Error("Failed to get the CNI", "Reason", err)
os.Exit(1)
} else {
meta.Addons = v
}

k.handleManagedK8sVersion(metaClient, meta)

k.metadataSummary(*meta)

if ok, _ := cli.Confirmation("Do you want to proceed with the cluster creation", "no"); !ok {
if ok, _ := k.menuDriven.Confirmation("Do you want to proceed with the cluster creation", cli.WithDefaultValue("no")); !ok {
os.Exit(1)
}

Expand All @@ -267,7 +292,3 @@

return
}

func (k *KsctlCommand) processAddons() (_ addons.ClusterAddons, _ error) {
return nil, nil
}
5 changes: 2 additions & 3 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ ksctl delete --help
}
}

selectedCluster, err := cli.DropDown(
selectedCluster, err := k.menuDriven.DropDown(
"Select the cluster to delete",
selectDisplay,
"",
)
if err != nil {
k.l.Error("Failed to get userinput", "Reason", err)
Expand All @@ -78,7 +77,7 @@ ksctl delete --help

m := valueMaping[selectedCluster]

if ok, _ := cli.Confirmation("Do you want to proceed with the cluster deletion", "no"); !ok {
if ok, _ := k.menuDriven.Confirmation("Do you want to proceed with the cluster deletion", cli.WithDefaultValue("no")); !ok {
os.Exit(1)
}

Expand Down
4 changes: 1 addition & 3 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"strconv"
"strings"

"github.com/ksctl/cli/v2/pkg/cli"
"github.com/ksctl/ksctl/v2/pkg/consts"
"github.com/ksctl/ksctl/v2/pkg/logger"
"github.com/ksctl/ksctl/v2/pkg/provider"
Expand Down Expand Up @@ -56,10 +55,9 @@ ksctl get --help
valueMaping[strconv.Itoa(idx)] = cluster
}

selectedCluster, err := cli.DropDown(
selectedCluster, err := k.menuDriven.DropDown(
"Select the cluster to delete",
selectDisplay,
"",
)
if err != nil {
k.l.Error("Failed to get userinput", "Reason", err)
Expand Down
55 changes: 52 additions & 3 deletions cmd/handle_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

import (
"encoding/json"
"fmt"
"os"
"strconv"

"github.com/ksctl/cli/v2/pkg/cli"
"github.com/ksctl/ksctl/v2/pkg/addons"

Check failure on line 24 in cmd/handle_meta.go

View workflow job for this annotation

GitHub Actions / linux

github.com/ksctl/ksctl/[email protected]: replacement directory ../ksctl does not exist

Check failure on line 24 in cmd/handle_meta.go

View workflow job for this annotation

GitHub Actions / macos

github.com/ksctl/ksctl/[email protected]: replacement directory ../ksctl does not exist
"github.com/ksctl/ksctl/v2/pkg/consts"
"github.com/ksctl/ksctl/v2/pkg/errors"
"github.com/ksctl/ksctl/v2/pkg/handler/cluster/controller"
controllerMeta "github.com/ksctl/ksctl/v2/pkg/handler/cluster/metadata"
"github.com/ksctl/ksctl/v2/pkg/provider"
Expand Down Expand Up @@ -61,7 +64,7 @@
}

func (k *KsctlCommand) handleRegionSelection(meta *controllerMeta.Controller, m *controller.Metadata) {
ss := cli.GetSpinner()
ss := k.menuDriven.GetProgressAnimation()
ss.Start("Fetching the region list")

listOfRegions, err := meta.ListAllRegions()
Expand All @@ -81,7 +84,7 @@

func (k *KsctlCommand) handleInstanceTypeSelection(meta *controllerMeta.Controller, m *controller.Metadata, prompt string) provider.InstanceRegionOutput {
if len(k.inMemInstanceTypesInReg) == 0 {
ss := cli.GetSpinner()
ss := k.menuDriven.GetProgressAnimation()
ss.Start("Fetching the instance type list")

listOfVMs, err := meta.ListAllInstances(m.Region)
Expand All @@ -103,7 +106,7 @@
}

func (k *KsctlCommand) handleManagedK8sVersion(meta *controllerMeta.Controller, m *controller.Metadata) {
ss := cli.GetSpinner()
ss := k.menuDriven.GetProgressAnimation()
ss.Start("Fetching the managed cluster k8s versions")

listOfK8sVersions, err := meta.ListAllManagedClusterK8sVersions(m.Region)
Expand Down Expand Up @@ -202,5 +205,51 @@
println()
}
}
}

func (k *KsctlCommand) handleCNI(managedCNI addons.ClusterAddons, defaultOptionManaged string, ksctlCNI addons.ClusterAddons, defaultOptionKsctl string) (addons.ClusterAddons, error) {
var v addons.ClusterAddons

handleInput := func(vc addons.ClusterAddons, prompt string, defaultOpt string, errorPrompt string) (addons.ClusterAddon, error) {
cc := map[string]string{}
cm := map[string]addons.ClusterAddon{}
for _, c := range vc {
cc[fmt.Sprintf("%s <%s>", c.Name, c.Label)] = c.Name
cm[c.Name] = c
}

selected, err := k.menuDriven.DropDown(
prompt,
cc,
cli.WithDefaultValue(defaultOpt),
)
if err != nil {
return addons.ClusterAddon{}, errors.WrapError(
errors.ErrInvalidUserInput,
k.l.NewError(k.Ctx, errorPrompt, "Reason", err),
)
}

return cm[selected], nil
}

_v0, err := handleInput(managedCNI, "Select the CNI addon provided by offering", defaultOptionManaged, "Failed to get the CNI addon provided by managed offering")
if err != nil {
return nil, err
}

v = append(v, _v0)

if _v0.Name != string(consts.CNINone) {
return v, nil
}

_v1, err := handleInput(ksctlCNI, "Select the CNI addon provided by ksctl", defaultOptionKsctl, "Failed to get the CNI addon provided by ksctl")
if err != nil {
return nil, err
}

v = append(v, _v1)

return v, nil
}
Loading
Loading