Skip to content

Commit

Permalink
Add liqoctl install custom output
Browse files Browse the repository at this point in the history
  • Loading branch information
palexster committed Sep 12, 2021
1 parent 35de7ca commit 3c50776
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 45 deletions.
13 changes: 7 additions & 6 deletions cmd/liqoctl/cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ func newAddCommand(ctx context.Context) *cobra.Command {
func newAddClusterCommand(ctx context.Context) *cobra.Command {
installArgs := &add.ClusterArgs{}
var addClusterCmd = &cobra.Command{
Use: add.ClusterResourceName,
Short: add.LiqoctlAddShortHelp,
Long: add.LiqoctlAddLongHelp,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Use: add.ClusterResourceName,
Short: add.LiqoctlAddShortHelp,
Long: add.LiqoctlAddLongHelp,
Args: cobra.MinimumNArgs(1),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
installArgs.ClusterName = args[0]
add.HandleAddCommand(ctx, installArgs)
return add.HandleAddCommand(ctx, installArgs)
},
}
addClusterCmd.Flags().StringVar(&installArgs.ClusterAuthURL, add.AuthURLFlagName, "",
Expand Down
4 changes: 2 additions & 2 deletions cmd/liqoctl/cmd/generate-add.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func newGenerateAddCommand(ctx context.Context) *cobra.Command {
Use: generate.LiqoctlGenerateAddCommand,
Short: generate.LiqoctlGenerateShortHelp,
Long: generate.LiqoctlGenerateLongHelp,
Run: func(cmd *cobra.Command, args []string) {
generate.HandleGenerateAddCommand(ctx, liqoNamespace, os.Args[0])
RunE: func(cmd *cobra.Command, args []string) error {
return generate.HandleGenerateAddCommand(ctx, liqoNamespace, os.Args[0])
},
}
addCmd.Flags().StringVar(&liqoNamespace, "namespace", add.ClusterLiqoNamespace,
Expand Down
1 change: 0 additions & 1 deletion cmd/liqoctl/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func newInstallCommand(ctx context.Context) *cobra.Command {
Short: installutils.LiqoctlInstallShortHelp,
Long: installutils.LiqoctlInstallLongHelp,
}

installCmd.PersistentFlags().IntP("timeout", "t", 600, "Configure the timeout for the installation process in seconds")
installCmd.PersistentFlags().StringP("version", "", "", "Select the Liqo version (default: latest stable release)")
installCmd.PersistentFlags().BoolP("devel", "", false,
Expand Down
11 changes: 6 additions & 5 deletions cmd/liqoctl/cmd/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ var providerInitFunc = map[string]func(*cobra.Command){

func getCommand(ctx context.Context, provider string) (*cobra.Command, error) {
cmd := &cobra.Command{
Use: provider,
Short: fmt.Sprintf(installShortHelp, provider),
Long: fmt.Sprintf(installLongHelp, provider),
Run: func(cmd *cobra.Command, args []string) {
install.HandleInstallCommand(ctx, cmd, os.Args[0], provider)
Use: provider,
Short: fmt.Sprintf(installShortHelp, provider),
Long: fmt.Sprintf(installLongHelp, provider),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
return install.HandleInstallCommand(ctx, cmd, os.Args[0], provider)
},
}

Expand Down
1 change: 0 additions & 1 deletion cmd/liqoctl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func NewRootCommand(ctx context.Context) *cobra.Command {
rootCmd.PersistentFlags().AddGoFlag(f)
}
})

rateFlagset := flag.NewFlagSet("rate-limiting", flag.PanicOnError)
restcfg.InitFlags(rateFlagset)
rootCmd.PersistentFlags().AddGoFlagSet(rateFlagset)
Expand Down
8 changes: 4 additions & 4 deletions pkg/liqoctl/add/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ $ liqoctl add cluster my-cluster --auth-url https://my-cluster --id e8e3cdec-b00
sameClusterError = "the ClusterID of the adding cluster is the same of the local cluster"
// SuccesfulMessage is printed when ad add cluster command has scucceded.
SuccesfulMessage = `
Hooray 🎉! You have correctly added the cluster %s and activated an outgoing peering towards it.
Hooray 🎉! You have correctly added the cluster %s and activated an outgoing peering towards it.
You can now:
* Check the status of the peering to see when it is completely established.
* Check the status of the peering to see when it is completely established 👓.
Every field of the foreigncluster (but IncomingPeering) should be in "Established":
kubectl get foreignclusters %s
* Check if the virtual node is correctly created (this should take less than ~30s):
* Check if the virtual node is correctly created (this should take less than ~30s) 📦:
kubectl get nodes liqo-%s
* Ready to go! Let's deploy a simple application by simply typing:
* Ready to go! Let's deploy a simple cross-cluster application using Liqo 🚜:
kubectl create ns liqo-demo # Let's create a demo namespace
kubectl label ns liqo-demo liqo.io/enabled=true # Enable Liqo offloading on this namespace (Check out https://doc.liqo.io/usage for more details).
Expand Down
13 changes: 8 additions & 5 deletions pkg/liqoctl/add/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,30 @@ type ClusterArgs struct {
}

// HandleAddCommand handles the add command, configuring all the resources required to configure an outgoing peering.
func HandleAddCommand(ctx context.Context, t *ClusterArgs) {
func HandleAddCommand(ctx context.Context, t *ClusterArgs) error {
restConfig := common.GetLiqoctlRestConfOrDie()

klog.Info("* Initializing 🔌... ")
clientSet, err := kubernetes.NewForConfig(restConfig)
if err != nil {
klog.Fatalf(err.Error())
return err
}

k8sClient, err := client.New(restConfig, client.Options{})
if err != nil {
klog.Fatalf(err.Error())
return err
}

klog.Info("* Processing Cluster Addition 🔧... ")
if err := processAddCluster(ctx, t, clientSet, k8sClient); err != nil {
klog.Fatalf(err.Error())
return err
}

err = printSuccesfulOutputMessage(ctx, t, k8sClient)
if err != nil {
klog.Fatalf(err.Error())
return err
}
return nil
}

func printSuccesfulOutputMessage(ctx context.Context, t *ClusterArgs, k8sClient client.Client) error {
Expand Down
9 changes: 5 additions & 4 deletions pkg/liqoctl/generate/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@ import (
)

// HandleGenerateAddCommand outputs the liqoctl add command to use to add the target cluster.
func HandleGenerateAddCommand(ctx context.Context, liqoNamespace, commandName string) {
func HandleGenerateAddCommand(ctx context.Context, liqoNamespace, commandName string) error {
restConfig := common.GetLiqoctlRestConfOrDie()

clientSet, err := client.New(restConfig, client.Options{})
if err != nil {
klog.Fatalf(err.Error())
return err
}

commandString := processGenerateCommand(ctx, clientSet, liqoNamespace, commandName)

fmt.Printf("\nUse this command to peer with this cluster:\n\n")
fmt.Printf("%s\n", commandString)
fmt.Printf("\nUse this command on a DIFFERENT cluster to enable an outgoing peering WITH THE CURRENT cluster 🛠:\n\n")
fmt.Printf("%s\n\n", commandString)
return nil
}

func processGenerateCommand(ctx context.Context, clientSet client.Client, liqoNamespace, commandName string) string {
Expand Down
40 changes: 23 additions & 17 deletions pkg/liqoctl/install/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package install
import (
"context"
"fmt"
"os"

"github.com/spf13/cobra"

Expand All @@ -29,47 +28,54 @@ import (

// HandleInstallCommand implements the "install" command. It detects which provider has to be used, generates the chart
// with provider-specific values. Finally, it performs the installation on the target cluster.
func HandleInstallCommand(ctx context.Context, cmd *cobra.Command, baseCommand, providerName string) {
func HandleInstallCommand(ctx context.Context, cmd *cobra.Command, baseCommand, providerName string) error {
config := common.GetLiqoctlRestConfOrDie()
providerInstance := getProviderInstance(providerName)

if providerInstance == nil {
fmt.Printf("Provider of type %s not found", providerName)
return
return fmt.Errorf("provider %s not found", providerName)
}

fmt.Printf("* Initializing installer... 🔌 \n")
commonArgs, err := installprovider.ValidateCommonArguments(cmd.Flags())
if err != nil {
fmt.Printf("Unable to initialize configuration: %v", err)
os.Exit(1)
return err
}

helmClient, err := initHelmClient(config, commonArgs)
if err != nil {
fmt.Printf("Unable to create a client for the target cluster: %s", err)
return
return err
}

fmt.Printf("* Retrieving cluster configuration from cluster provider... 📜 \n")
err = providerInstance.ValidateCommandArguments(cmd.Flags())
if err != nil {
fmt.Printf("Unable to initialize configuration: %v", err)
os.Exit(1)
return err
}

err = providerInstance.ExtractChartParameters(ctx, config, commonArgs)
if err != nil {
fmt.Printf("Unable to initialize configuration: %v", err)
os.Exit(1)
return err
}

if commonArgs.DumpValues {
fmt.Printf("* Generating values.yaml file with the Liqo chart parameters for your cluster... 💾 \n")
} else {
fmt.Printf("* Installing or Upgrading Liqo... (this may take few minutes) ⏳ \n")
}
err = installOrUpdate(ctx, helmClient, providerInstance, commonArgs)
if err != nil {
fmt.Printf("Unable to initialize configuration: %v", err)
os.Exit(1)
return err
}

if !commonArgs.DumpValues && !commonArgs.DryRun {
// If the installation succeeded, let's print the add command to peer the target cluster with another one.
generate.HandleGenerateAddCommand(ctx, installutils.LiqoNamespace, baseCommand)
switch {
case !commonArgs.DumpValues && !commonArgs.DryRun:
fmt.Printf("* All Set! You can use Liqo now! 🚀\n")
return generate.HandleGenerateAddCommand(ctx, installutils.LiqoNamespace, baseCommand)
case commonArgs.DumpValues:
fmt.Printf("* All Set! Chart values written in file %s 🚀\n", commonArgs.DumpValuesPath)
case commonArgs.DryRun:
fmt.Printf("* All Set! You can use Liqo now! (Dry-run) 🚀\n")
}
return nil
}

0 comments on commit 3c50776

Please sign in to comment.