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

feat(kumactl) install gateway types #1950

Merged
merged 6 commits into from
May 7, 2021
Merged
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
2 changes: 1 addition & 1 deletion app/kumactl/cmd/completion/testdata/zsh.golden
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ function _kumactl_install_dns {
function _kumactl_install_gateway {
_arguments \
'--namespace[namespace to install gateway to]:' \
'--type[type of gateway to install. Available types: '\''kong'\'']:' \
'--type[type of gateway to install. Available types: "kong"]:' \
'--config-file[path to the configuration file to use]:' \
'--log-level[log level: one of off|info|debug]:' \
'(-m --mesh)'{-m,--mesh}'[mesh to use]:'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ type InstallGatewayArgs struct {
}

type InstallGatewayContext struct {
Args InstallGatewayArgs
Args InstallGatewayArgs
AvailableTypes map[string]struct{}
}

func DefaultInstallGatewayContext() InstallGatewayContext {
return InstallGatewayContext{
Args: InstallGatewayArgs{
Namespace: "kuma-gateway",
},
AvailableTypes: map[string]struct{}{"kong": {}},
}
}
24 changes: 19 additions & 5 deletions app/kumactl/cmd/install/install_gateway.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package install

import (
"fmt"
"strings"

"github.com/pkg/errors"
"github.com/spf13/cobra"

Expand All @@ -14,14 +17,24 @@ type gatewayTemplateArgs struct {
Namespace string
}

func availableTypesStr(types map[string]struct{}) string {
var typesArr []string
for typeStr := range types {
typesArr = append(typesArr, fmt.Sprintf("%q", typeStr))
}
parkanzky marked this conversation as resolved.
Show resolved Hide resolved
return strings.Join(typesArr, ", ")
}

func newInstallGatewayCmd(ctx *install_context.InstallGatewayContext) *cobra.Command {
args := ctx.Args
types := ctx.AvailableTypes
typesStr := availableTypesStr(types)
cmd := &cobra.Command{
Use: "gateway",
Short: "Install ingress gateway on Kubernetes",
Long: "Install ingress gateway on Kubernetes in a 'kuma-gateway' namespace.",
RunE: func(cmd *cobra.Command, _ []string) error {
if err := validateGWArgs(args); err != nil {
if err := validateGWArgs(args, types); err != nil {
return err
}

Expand Down Expand Up @@ -53,15 +66,16 @@ func newInstallGatewayCmd(ctx *install_context.InstallGatewayContext) *cobra.Com
return nil
},
}
cmd.Flags().StringVar(&args.Type, "type", args.Type, "type of gateway to install. Available types: 'kong'")
cmd.Flags().StringVar(&args.Type, "type", args.Type, "type of gateway to install. Available types: "+typesStr)
_ = cmd.MarkFlagRequired("type")
cmd.Flags().StringVar(&args.Namespace, "namespace", args.Namespace, "namespace to install gateway to")
return cmd
}

func validateGWArgs(args install_context.InstallGatewayArgs) error {
if args.Type != "kong" {
return errors.New("Only gateway type 'kong' currently supported")
func validateGWArgs(args install_context.InstallGatewayArgs, availableTypes map[string]struct{}) error {
if _, ok := availableTypes[args.Type]; !ok {
typesStr := availableTypesStr(availableTypes)
return errors.New("Unsupported type '" + args.Type + "'. Available types: " + typesStr)
}
return nil
}
2 changes: 1 addition & 1 deletion app/kumactl/cmd/install/install_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var _ = Describe("kumactl install gateway", func() {
extraArgs: []string{
"--type", "invalidtype",
},
expectedErr: "Only gateway type 'kong' currently supported",
expectedErr: "Unsupported type 'invalidtype'. Available types: \"kong\"",
}),
)

Expand Down