Skip to content

Commit

Permalink
feat(kumactl) install gateway types (#1950)
Browse files Browse the repository at this point in the history
* feat(kumactl) More flexible valid gateway types

Signed-off-by: Paul Parkanzky <paul.parkanzky@konghq.com>

* fix(kumactl) make check updates

Signed-off-by: Paul Parkanzky <paul.parkanzky@konghq.com>

* fix(kumactl) Address PR comment

Signed-off-by: Paul Parkanzky <paul.parkanzky@konghq.com>

* fix(kumactl) Update protobufs with make check

Signed-off-by: Paul Parkanzky <paul.parkanzky@konghq.com>

* fix(kumactl) Update tests

Signed-off-by: Paul Parkanzky <paul.parkanzky@konghq.com>
  • Loading branch information
parkanzky authored May 7, 2021
1 parent 4826e86 commit 56443c1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
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
4 changes: 3 additions & 1 deletion app/kumactl/cmd/install/context/install_gateway_context.go
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))
}
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

0 comments on commit 56443c1

Please sign in to comment.