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

[v2][non-kube] site create command and CLI adaptation #1563

Merged
merged 38 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
27577a4
add factory method for kube and non-kube site commands
nluaces Jul 31, 2024
6de179a
refactor site commands to include podman CLI implementation
nluaces Aug 12, 2024
815974f
defer stop from the spinner and fix message
nluaces Aug 12, 2024
37355ca
refactor link commands and fix site unit tests
nluaces Aug 13, 2024
a973105
adapt token commands for podman implementation
nluaces Aug 14, 2024
6ccbfef
adapt connector commands to podman CLI
nluaces Aug 14, 2024
07f063e
adapt listener commands to podman CLI
nluaces Aug 16, 2024
cd167fd
removal of AddFlags method in the skupper command interface
nluaces Aug 16, 2024
fc187ee
refactor common and utils packages
nluaces Aug 16, 2024
44dfeca
refactor common and utils packages
nluaces Aug 16, 2024
f056aa3
added path provider
nluaces Aug 16, 2024
0cd7136
add tests to check not applicable flags in running commands
nluaces Aug 19, 2024
e46ba8a
fix write resources in a specific path for non-kube commands
nluaces Aug 19, 2024
32ba805
fix creating a non-kube site while providing a namespace
nluaces Aug 19, 2024
0bfcafa
add custom resources abstraction for nonkube CLI
nluaces Aug 19, 2024
16b1a0a
move nonkube components to the correct directory
nluaces Aug 21, 2024
982033a
replace PostRunE by PostRun function in the cobra command definition …
nluaces Aug 21, 2024
c42121a
fix tests
nluaces Aug 21, 2024
9424e0d
fixed descriptions and spacing based on comments
nluaces Aug 22, 2024
db02c3b
fix format
nluaces Aug 27, 2024
97f9d13
fix tests
nluaces Aug 27, 2024
78f2277
fix description
nluaces Aug 30, 2024
5551539
rename non_kube packages to nonkube
nluaces Sep 2, 2024
bc38e4b
fix package name
nluaces Sep 3, 2024
a8457a4
fix default values in link status
nluaces Sep 9, 2024
8958a42
update description
nluaces Sep 9, 2024
a05a6b2
fix tests
nluaces Sep 9, 2024
c97bcfd
modify paths for nonkube cli commands
nluaces Sep 12, 2024
c2f0139
fixed import aliases
nluaces Sep 12, 2024
033af21
fix import aliases and replace host flag for bind-host flag when crea…
nluaces Sep 12, 2024
4e8742c
rename attributes to bindHost
nluaces Sep 12, 2024
bc4653c
add subject alternative names flag for non kube sites
nluaces Sep 12, 2024
7f9af84
fix descriptions
nluaces Sep 12, 2024
56ab3d4
mark flags as hidden based on the env. variable SKUPPER_PLATFORM
nluaces Sep 12, 2024
d840814
hide kubernetes flags for non kube configured environments in the hel…
nluaces Sep 13, 2024
e6f1f8c
replace validation errors for warnings in cases of flags not applicab…
nluaces Sep 13, 2024
47ab653
fix path provider paths for nonkube platforms
nluaces Sep 13, 2024
774a6a4
add validation for the user to choose from one of the target types
nluaces Sep 13, 2024
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 cmd/skupper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Copyright © 2024 Skupper Team <[email protected]>
package main

import (
"github.com/skupperproject/skupper/internal/cmd/skupper/common/utils"
"github.com/skupperproject/skupper/internal/cmd/skupper/root"
"github.com/skupperproject/skupper/internal/cmd/skupper/utils"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/generate-doc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package main

import (
"fmt"
"github.com/skupperproject/skupper/internal/cmd/skupper/common/utils"
"os"

"github.com/skupperproject/skupper/internal/cmd/skupper/root"
"github.com/skupperproject/skupper/internal/cmd/skupper/utils"
"github.com/spf13/cobra/doc"
)

Expand Down
64 changes: 64 additions & 0 deletions internal/cmd/skupper/common/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package common

import (
"fmt"
"github.com/skupperproject/skupper/api/types"
"github.com/skupperproject/skupper/internal/cmd/skupper/common/utils"
"github.com/spf13/cobra"
)

type SkupperCommand interface {
NewClient(cobraCommand *cobra.Command, args []string)
ValidateInput(args []string) []error
InputToOptions()
Run() error
WaitUntil() error
}

type SkupperCmdDescription struct {
Use string
Short string
Long string
Example string
}

func ConfigureCobraCommand(configuredPlatform types.Platform, description SkupperCmdDescription, kubeImpl SkupperCommand, nonKubeImpl SkupperCommand) *cobra.Command {
var skupperCommand SkupperCommand
var platform string

cmd := cobra.Command{
Use: description.Use,
Short: description.Short,
Long: description.Long,
Example: description.Example,
PreRunE: func(cmd *cobra.Command, args []string) error {

platform = string(configuredPlatform)
if cmd.Flag("platform") != nil && cmd.Flag("platform").Value.String() != "" {
platform = cmd.Flag("platform").Value.String()
}

switch platform {
case "kubernetes":
skupperCommand = kubeImpl
case "podman", "docker", "systemd":
skupperCommand = nonKubeImpl
default:
return fmt.Errorf("platform %q not supported", platform)
}

skupperCommand.NewClient(cmd, args)
return nil
},
Run: func(cmd *cobra.Command, args []string) {
utils.HandleErrorList(skupperCommand.ValidateInput(args))
skupperCommand.InputToOptions()
utils.HandleError(skupperCommand.Run())
},
PostRun: func(cmd *cobra.Command, args []string) {
utils.HandleError(skupperCommand.WaitUntil())
},
}

return &cmd
}
137 changes: 137 additions & 0 deletions internal/cmd/skupper/common/command_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package common

import (
"github.com/skupperproject/skupper/api/types"
"github.com/spf13/cobra"
"gotest.tools/assert"
"testing"
)

type MockSkupperCommand struct {
CalledNewClient bool
CalledValidateInput bool
CalledInputToOptions bool
CalledRun bool
CalledWaitUntil bool
}

func (m *MockSkupperCommand) NewClient(cmd *cobra.Command, args []string) {
m.CalledNewClient = true
}

func (m *MockSkupperCommand) ValidateInput(args []string) []error {
m.CalledValidateInput = true
return nil
}

func (m *MockSkupperCommand) InputToOptions() {
m.CalledInputToOptions = true
}

func (m *MockSkupperCommand) Run() error {
m.CalledRun = true
return nil
}

func (m *MockSkupperCommand) WaitUntil() error {
m.CalledWaitUntil = true
return nil
}

func TestConfigureCobraCommand(t *testing.T) {
t.Run("Test with kubernetes platform", func(t *testing.T) {
kubeCmd := &MockSkupperCommand{}
nonKubeCmd := &MockSkupperCommand{}
desc := SkupperCmdDescription{
Use: "testuse",
Short: "testshort",
Long: "testlong",
Example: "testexample",
}

result := ConfigureCobraCommand(types.PlatformKubernetes, desc, kubeCmd, nonKubeCmd)

// After executing the returned cobra.Command,
// the corresponding methods on the correct SkupperCommand should have been called
err := result.Execute()
assert.Check(t, err)

assert.Check(t, kubeCmd.CalledNewClient)
assert.Check(t, kubeCmd.CalledValidateInput)
assert.Check(t, kubeCmd.CalledInputToOptions)
assert.Check(t, kubeCmd.CalledRun)
assert.Check(t, kubeCmd.CalledWaitUntil)

// Ensure nonKubeCmd wasn't called
assert.Check(t, !nonKubeCmd.CalledNewClient)
assert.Check(t, !nonKubeCmd.CalledValidateInput)
assert.Check(t, !nonKubeCmd.CalledInputToOptions)
assert.Check(t, !nonKubeCmd.CalledRun)
assert.Check(t, !nonKubeCmd.CalledWaitUntil)
})

t.Run("Test with non kubernetes platform", func(t *testing.T) {
kubeCmd := &MockSkupperCommand{}
nonKubeCmd := &MockSkupperCommand{}
desc := SkupperCmdDescription{
Use: "testuse",
Short: "testshort",
Long: "testlong",
Example: "testexample",
}

var selectedPlatform string
result := ConfigureCobraCommand(types.PlatformKubernetes, desc, kubeCmd, nonKubeCmd)
result.Flags().StringVarP(&selectedPlatform, FlagNamePlatform, "p", "docker", FlagDescPlatform)

// After executing the returned cobra.Command,
// the corresponding methods on the correct SkupperCommand should have been called
err := result.Execute()
assert.Check(t, err)

// Ensure KubeCmd wasn't called
assert.Check(t, !kubeCmd.CalledNewClient)
assert.Check(t, !kubeCmd.CalledValidateInput)
assert.Check(t, !kubeCmd.CalledInputToOptions)
assert.Check(t, !kubeCmd.CalledRun)
assert.Check(t, !kubeCmd.CalledWaitUntil)

assert.Check(t, nonKubeCmd.CalledNewClient)
assert.Check(t, nonKubeCmd.CalledValidateInput)
assert.Check(t, nonKubeCmd.CalledInputToOptions)
assert.Check(t, nonKubeCmd.CalledRun)
assert.Check(t, nonKubeCmd.CalledWaitUntil)
})

t.Run("Test with unsupported platform", func(t *testing.T) {
kubeCmd := &MockSkupperCommand{}
nonKubeCmd := &MockSkupperCommand{}
desc := SkupperCmdDescription{
Use: "testuse",
Short: "testshort",
Long: "testlong",
Example: "testexample",
}

var selectedPlatform string
result := ConfigureCobraCommand(types.PlatformKubernetes, desc, kubeCmd, nonKubeCmd)
result.Flags().StringVarP(&selectedPlatform, FlagNamePlatform, "p", "unsupported", FlagDescPlatform)

// After executing the returned cobra.Command,
// the corresponding methods on the correct SkupperCommand should have been called
err := result.Execute()
assert.Check(t, err.Error() == "platform \"unsupported\" not supported")

assert.Check(t, !kubeCmd.CalledNewClient)
assert.Check(t, !kubeCmd.CalledValidateInput)
assert.Check(t, !kubeCmd.CalledInputToOptions)
assert.Check(t, !kubeCmd.CalledRun)
assert.Check(t, !kubeCmd.CalledWaitUntil)

assert.Check(t, !nonKubeCmd.CalledNewClient)
assert.Check(t, !nonKubeCmd.CalledValidateInput)
assert.Check(t, !nonKubeCmd.CalledInputToOptions)
assert.Check(t, !nonKubeCmd.CalledRun)
assert.Check(t, !nonKubeCmd.CalledWaitUntil)
})
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package utils
package common

var (
LinkAccessTypes = []string{"route", "loadbalancer", "default"}
OutputTypes = []string{"json", "yaml"}
ListenerTypes = []string{"tcp"}
ConnectorTypes = []string{"tcp"}
)
Loading