Skip to content

Commit

Permalink
initial version of sym test
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodeassassin committed Nov 28, 2022
1 parent 003f190 commit c3f4b0a
Show file tree
Hide file tree
Showing 22 changed files with 465 additions and 104 deletions.
4 changes: 2 additions & 2 deletions commands/apikeys/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"github.com/jedib0t/go-pretty/v6/text"
"github.com/spf13/cobra"
"github.com/symbiosis-cloud/cli/pkg/output"
"github.com/symbiosis-cloud/cli/pkg/symcommand"
"github.com/symbiosis-cloud/cli/pkg/util"
"github.com/symbiosis-cloud/symbiosis-go"
)

Expand Down Expand Up @@ -55,7 +55,7 @@ func (c *CreateApiKeyCommand) Command() *cobra.Command {

c.CommandOpts.Logger.Info().Msgf("%s** NOTE ** This token will not be shown again.%s", text.FgRed.EscapeSeq(), text.FgWhite.EscapeSeq())

err = util.NewOutput(util.TableOutput{
err = output.NewOutput(output.TableOutput{
Headers: []string{"ID", "Description", "Token", "Role"},
Data: [][]interface{}{{apiKey.ID, apiKey.Description, apiKey.Token, apiKey.Role}},
},
Expand Down
4 changes: 2 additions & 2 deletions commands/apikeys/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/symbiosis-cloud/cli/pkg/output"
"github.com/symbiosis-cloud/cli/pkg/symcommand"
"github.com/symbiosis-cloud/cli/pkg/util"
"github.com/symbiosis-cloud/symbiosis-go"
)

Expand All @@ -28,7 +28,7 @@ func (c *DeleteApiKeyCommand) Command() *cobra.Command {
return fmt.Errorf("Please provide an api-key ID (sym api-key delete <id>")
}

return util.Confirmation(fmt.Sprintf("Are you sure you want want to delete api-key %s", args[0]))
return output.Confirmation(fmt.Sprintf("Are you sure you want want to delete api-key %s", args[0]))
},
RunE: func(command *cobra.Command, args []string) error {
apiKeyId := args[0]
Expand Down
4 changes: 2 additions & 2 deletions commands/apikeys/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package apikeys

import (
"github.com/spf13/cobra"
"github.com/symbiosis-cloud/cli/pkg/output"
"github.com/symbiosis-cloud/cli/pkg/symcommand"
"github.com/symbiosis-cloud/cli/pkg/util"
"github.com/symbiosis-cloud/symbiosis-go"
)

Expand All @@ -29,7 +29,7 @@ func (c *ListApiKeysCommand) Execute(command *cobra.Command, args []string) erro
data = append(data, []interface{}{apiKey.ID, apiKey.Description, apiKey.Token, apiKey.Role})
}

err = util.NewOutput(util.TableOutput{
err = output.NewOutput(output.TableOutput{
Headers: []string{"ID", "Description", "Token", "Role"},
Data: data,
},
Expand Down
36 changes: 17 additions & 19 deletions commands/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,50 @@ type ApplyCommand struct {

func (c *ApplyCommand) Execute(command *cobra.Command, args []string) error {

deploymentFlags, err := symcommand.GetDeploymentFlags(command)

if err != nil {
return err
if len(args) == 0 {
return fmt.Errorf("Please provide a cluster name (sym apply <cluster>")
}

c.CommandOpts.Namespace = deploymentFlags.Namespace

projectConfig, err := project.NewProjectConfig(deploymentFlags.File, c.CommandOpts, c.Client)
clusterName := args[0]
_, err := c.Client.Cluster.Describe(clusterName)

if err != nil {
return err
return fmt.Errorf("Cluster %s does not exist", clusterName)
}

err = projectConfig.Parse()
deploymentFlags, err := symcommand.GetDeploymentFlags(command)

if err != nil {
return err
}

err = projectConfig.RunBuilders()
c.CommandOpts.Namespace = deploymentFlags.Namespace

identity, err := identity.NewClusterIdentity(c.Client, clusterName, deploymentFlags.IdentityOutputPath, merge)

if err != nil {
return err
}

if len(args) == 0 {
return fmt.Errorf("Please provide a cluster name (sym apply <cluster>")
}
c.CommandOpts.Logger.Info().Msgf("Written identity to %s", identity.KubeConfigPath)

clusterName := args[0]
_, err = c.Client.Cluster.Describe(clusterName)
projectConfig, err := project.NewProjectConfig(deploymentFlags.File, c.CommandOpts, c.Client, identity)

if err != nil {
return fmt.Errorf("Cluster %s does not exist", clusterName)
return err
}

identity, err := identity.NewClusterIdentity(c.Client, clusterName, deploymentFlags.IdentityOutputPath, merge)
err = projectConfig.Parse()

if err != nil {
return err
}

c.CommandOpts.Logger.Info().Msgf("Written identity to %s", identity.KubeConfigPath)
err = projectConfig.RunBuilders()

projectConfig.SetIdentity(identity)
if err != nil {
return err
}

err = projectConfig.RunDeploy()

Expand Down
5 changes: 3 additions & 2 deletions commands/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/spf13/cobra"
"github.com/symbiosis-cloud/cli/pkg/identity"
"github.com/symbiosis-cloud/cli/pkg/output"
"github.com/symbiosis-cloud/cli/pkg/symcommand"
"github.com/symbiosis-cloud/cli/pkg/util"
"github.com/symbiosis-cloud/symbiosis-go"
Expand Down Expand Up @@ -47,7 +48,7 @@ func (c *CreateClusterCommand) Command() *cobra.Command {
}

if merge {
return util.Confirmation("Are you sure you want to merge the new config with your existing .kube/config file")
return output.Confirmation("Are you sure you want to merge the new config with your existing .kube/config file")
}

return nil
Expand Down Expand Up @@ -116,7 +117,7 @@ func (c *CreateClusterCommand) Command() *cobra.Command {

}

err = util.NewOutput(util.TableOutput{
err = output.NewOutput(output.TableOutput{
Headers: []string{"ID", "Name", "Version", "Node type", "# Nodes"},
Data: [][]interface{}{{cluster.ID, cluster.Name, cluster.KubeVersion, nodeType, nodeCount}},
},
Expand Down
4 changes: 2 additions & 2 deletions commands/cluster/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/symbiosis-cloud/cli/pkg/output"
"github.com/symbiosis-cloud/cli/pkg/symcommand"
"github.com/symbiosis-cloud/cli/pkg/util"
"github.com/symbiosis-cloud/symbiosis-go"
)

Expand All @@ -28,7 +28,7 @@ func (c *DeleteClusterCommand) Command() *cobra.Command {
return fmt.Errorf("Please provide a cluster name (sym cluster delete <cluster>")
}

return util.Confirmation(fmt.Sprintf("Are you sure you want want to delete %s", args[0]))
return output.Confirmation(fmt.Sprintf("Are you sure you want want to delete %s", args[0]))
},
RunE: func(command *cobra.Command, args []string) error {
clusterName := args[0]
Expand Down
4 changes: 2 additions & 2 deletions commands/cluster/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/symbiosis-cloud/cli/pkg/output"
"github.com/symbiosis-cloud/cli/pkg/symcommand"
"github.com/symbiosis-cloud/cli/pkg/util"
"github.com/symbiosis-cloud/symbiosis-go"
)

Expand All @@ -25,7 +25,7 @@ func (c *DescribeClusterCommand) Execute(command *cobra.Command, args []string)
return err
}

err = util.NewOutput(util.TableOutput{
err = output.NewOutput(output.TableOutput{
Headers: []string{"ID", "Name", "Version", "Highly available"},
Data: [][]interface{}{{cluster.ID, cluster.Name, cluster.KubeVersion, cluster.IsHighlyAvailable}},
},
Expand Down
4 changes: 2 additions & 2 deletions commands/cluster/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"github.com/spf13/cobra"
"github.com/symbiosis-cloud/cli/pkg/identity"
"github.com/symbiosis-cloud/cli/pkg/output"
"github.com/symbiosis-cloud/cli/pkg/symcommand"
"github.com/symbiosis-cloud/cli/pkg/util"
"github.com/symbiosis-cloud/symbiosis-go"
)

Expand Down Expand Up @@ -52,7 +52,7 @@ func (c *ClusterIdentityCommand) Command() *cobra.Command {
}

if merge {
return util.Confirmation("Are you sure you want to merge the new config with your existing .kube/config file")
return output.Confirmation("Are you sure you want to merge the new config with your existing .kube/config file")
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions commands/cluster/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package cluster

import (
"github.com/spf13/cobra"
"github.com/symbiosis-cloud/cli/pkg/output"
"github.com/symbiosis-cloud/cli/pkg/symcommand"
"github.com/symbiosis-cloud/cli/pkg/util"
"github.com/symbiosis-cloud/symbiosis-go"
)

Expand All @@ -29,7 +29,7 @@ func (c *ListClusterCommand) Execute(command *cobra.Command, args []string) erro
data = append(data, []interface{}{cluster.ID, cluster.Name, cluster.KubeVersion})
}

err = util.NewOutput(util.TableOutput{
err = output.NewOutput(output.TableOutput{
Headers: []string{"ID", "Name", "Version"},
Data: data,
},
Expand Down
12 changes: 6 additions & 6 deletions commands/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"strings"

"github.com/spf13/cobra"
"github.com/symbiosis-cloud/cli/pkg/output"
"github.com/symbiosis-cloud/cli/pkg/symcommand"
"github.com/symbiosis-cloud/cli/pkg/util"
"github.com/symbiosis-cloud/symbiosis-go"
"k8s.io/utils/strings/slices"
)
Expand Down Expand Up @@ -77,7 +77,7 @@ func (c *InfoCommand) printNodeTypes() error {
data = append(data, []interface{}{nodeType.ID, nodeType.Name, nodeType.Vcpu, nodeType.MemoryMi})
}

err = util.NewOutput(util.TableOutput{
err = output.NewOutput(output.TableOutput{
Headers: []string{"ID", "Name", "vCPU", "Memory"},
Data: data,
},
Expand Down Expand Up @@ -105,8 +105,8 @@ func (c *InfoCommand) printRegions() error {
data = append(data, []interface{}{region.ID, region.Name})
}

err = util.NewOutput(
util.TableOutput{
err = output.NewOutput(
output.TableOutput{
Headers: []string{"ID", "Name"},
Data: data,
},
Expand All @@ -130,8 +130,8 @@ func (c *InfoCommand) printRoles() error {
data = append(data, []interface{}{role, valid})
}

err := util.NewOutput(
util.TableOutput{
err := output.NewOutput(
output.TableOutput{
Headers: []string{"Role", "Valid"},
Data: data,
},
Expand Down
3 changes: 2 additions & 1 deletion commands/nodepool/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/symbiosis-cloud/cli/pkg/output"
"github.com/symbiosis-cloud/cli/pkg/symcommand"
"github.com/symbiosis-cloud/cli/pkg/util"
"github.com/symbiosis-cloud/symbiosis-go"
Expand Down Expand Up @@ -93,7 +94,7 @@ func (c *CreateNodePoolCommand) Command() *cobra.Command {

c.CommandOpts.Logger.Info().Msgf("Node-pool %s created.", nodePool.Name)

err = util.NewOutput(util.TableOutput{
err = output.NewOutput(output.TableOutput{
Headers: []string{"ID", "Name", "Type", "Quantity"},
Data: [][]interface{}{{nodePool.ID, nodePool.Name, nodeType, nodeCount}},
},
Expand Down
4 changes: 2 additions & 2 deletions commands/nodepool/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/symbiosis-cloud/cli/pkg/output"
"github.com/symbiosis-cloud/cli/pkg/symcommand"
"github.com/symbiosis-cloud/cli/pkg/util"
"github.com/symbiosis-cloud/symbiosis-go"
)

Expand All @@ -28,7 +28,7 @@ func (c *DeleteNodePoolCommand) Command() *cobra.Command {
return fmt.Errorf("Please provide a cluster name (sym node-pool delete <nodePoolId>")
}

return util.Confirmation(fmt.Sprintf("Are you sure you want want to delete node-pool with ID %s", args[0]))
return output.Confirmation(fmt.Sprintf("Are you sure you want want to delete node-pool with ID %s", args[0]))
},
RunE: func(command *cobra.Command, args []string) error {
nodePoolId := args[0]
Expand Down
4 changes: 2 additions & 2 deletions commands/nodepool/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/symbiosis-cloud/cli/pkg/output"
"github.com/symbiosis-cloud/cli/pkg/symcommand"
"github.com/symbiosis-cloud/cli/pkg/util"
"github.com/symbiosis-cloud/symbiosis-go"
)

Expand Down Expand Up @@ -72,7 +72,7 @@ func nodePoolOutput(nodepools []*symbiosis.NodePool, isSingular bool) error {
dataOutput = nodepools[0]
}

err := util.NewOutput(util.TableOutput{
err := output.NewOutput(output.TableOutput{
Headers: []string{"ID", "Name", "Type", "# Nodes", "Autoscaling", "Min nodes", "Nax nodes"},
Data: data,
},
Expand Down
22 changes: 18 additions & 4 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/symbiosis-cloud/cli/pkg/output"
"github.com/symbiosis-cloud/cli/pkg/symcommand"
"github.com/symbiosis-cloud/cli/pkg/util"
"github.com/symbiosis-cloud/symbiosis-go"
)

var (
EnableBetaCommands bool
commands []symcommand.Command
cfgFile string
verbose bool
OutputFormat string
)

// RootCmd represents the base command when called without any subcommands
Expand All @@ -34,6 +36,8 @@ var RootCmd = &cobra.Command{
SilenceUsage: true,
PersistentPreRunE: func(command *cobra.Command, args []string) error {

// TODO: find a better way to initialise clients. Because of these commands cannot have pre-runs
// probably move it to OnInitialize
err := symcommand.Initialise(commands, command)

if err != nil {
Expand All @@ -57,14 +61,12 @@ func init() {
cobra.OnInitialize(initConfig)

RootCmd.PersistentFlags().String("config", "$HOME/.symbiosis/config.yaml", "config file (default is $HOME/.symbiosis/config.yaml)")
RootCmd.PersistentFlags().StringP("output", "o", "table", "Output format (table, json or yaml). Default: table")
RootCmd.PersistentFlags().StringP("project", "p", "", "Manually sets the project")
RootCmd.PersistentFlags().Bool("verbose", false, "Enable verbose logging")
RootCmd.PersistentFlags().Bool("yes", false, "Skip manual confirmation")
// RootCmd.PersistentFlags().Bool("beta", false, "Enable beta features (set to --beta=true to enable)")

viper.BindPFlag("output", RootCmd.PersistentFlags().Lookup("output"))
viper.SetDefault("output", string(util.OUTPUT_TABLE))
RootCmd.PersistentFlags().StringVarP(&OutputFormat, "output", "o", "table", "Output format (table, json or yaml). Default: table")

viper.BindPFlag("config", RootCmd.PersistentFlags().Lookup("config"))
viper.BindPFlag("yes", RootCmd.PersistentFlags().Lookup("yes"))
Expand All @@ -81,6 +83,7 @@ func init() {
&InfoCommand{},
&ApiKeysCommand{},
&VersionCommand{},
&TestCommand{},
}

// TODO: find a way to toggle beta commands via a flag
Expand All @@ -101,8 +104,19 @@ func init() {
func initConfig() {
viper.SetConfigType("yaml")

// set global output format
output.OutputFormat = OutputFormat

isDefault := false

symbiosisApiUrl := symbiosis.APIEndpoint

if url := os.Getenv("SYMBIOSIS_API_URL"); url != "" {
symbiosisApiUrl = url
}

viper.Set("api_url", symbiosisApiUrl)

home, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
Expand Down
Loading

0 comments on commit c3f4b0a

Please sign in to comment.