Skip to content

Commit

Permalink
Improve alpha module list command UX (#2268)
Browse files Browse the repository at this point in the history
  • Loading branch information
pPrecel authored Dec 2, 2024
1 parent 6cf083b commit 7fc7e0d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
7 changes: 4 additions & 3 deletions internal/cmd/alpha/modules/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (

func NewModulesCMD(kymaConfig *cmdcommon.KymaConfig) *cobra.Command {
cmd := &cobra.Command{
Use: "modules",
Short: "Manage kyma modules.",
Long: `Use this command to manage modules on a kyma cluster.`,
Use: "module",
Aliases: []string{"modules"},
Short: "Manage kyma modules.",
Long: `Use this command to manage modules on a kyma cluster.`,
}

cmd.AddCommand(NewListCMD(kymaConfig))
Expand Down
5 changes: 5 additions & 0 deletions internal/modules/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func List(ctx context.Context, client kyma.Interface) (ModulesList, error) {
modulesList := ModulesList{}
for _, moduleTemplate := range moduleTemplates.Items {
moduleName := moduleTemplate.Spec.ModuleName
if moduleName == "" {
// ignore incompatible/corrupted ModuleTemplates
continue
}

version := ModuleVersion{
Version: moduleTemplate.Spec.Version,
Repository: moduleTemplate.Spec.Info.Repository,
Expand Down
32 changes: 32 additions & 0 deletions internal/modules/modules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ var (
},
}

// corrupted one - without spec
testModuleTemplate5 = unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "operator.kyma-project.io/v1beta2",
"kind": "ModuleTemplate",
"metadata": map[string]interface{}{
"name": "keda-3",
"namespace": "kyma-system",
},
},
}

testReleaseMeta1 = unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "operator.kyma-project.io/v1beta2",
Expand Down Expand Up @@ -274,4 +286,24 @@ func TestList(t *testing.T) {
require.NoError(t, err)
require.Equal(t, ModulesList(testManagedModuleList), modules)
})

t.Run("ignore corrupted ModuleTemplate", func(t *testing.T) {
scheme := runtime.NewScheme()
scheme.AddKnownTypes(kyma.GVRModuleTemplate.GroupVersion())
scheme.AddKnownTypes(kyma.GVRModuleReleaseMeta.GroupVersion())
dynamicClient := dynamic_fake.NewSimpleDynamicClient(scheme,
&testModuleTemplate1,
&testModuleTemplate2,
&testModuleTemplate3,
&testModuleTemplate4,
&testModuleTemplate5, // corrupted ModuleTemplate
&testReleaseMeta1,
&testReleaseMeta2,
)

modules, err := List(context.Background(), kyma.NewClient(dynamicClient))

require.NoError(t, err)
require.Equal(t, ModulesList(testModuleList), modules)
})
}
2 changes: 1 addition & 1 deletion internal/modules/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type TableInfo struct {

var (
ModulesTableInfo = TableInfo{
Header: []string{"NAME", "VERSIONS", "INSTALLED", "MANAGED"},
Header: []string{"NAME", "AVAILABLE VERSIONS", "INSTALLED", "MANAGED"},
RowConverter: func(m Module) []string {
return []string{
m.Name,
Expand Down
4 changes: 2 additions & 2 deletions internal/modules/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
)

const (
testModulesTableView = "NAME \tVERSIONS \tINSTALLED\tMANAGED \nkeda \t0.1(regular), 0.2(fast)\t \t \t\nserverless\t0.0.1(fast), 0.0.2 \t \t \t\n"
testManagedModulesTableView = "NAME \tVERSIONS \tINSTALLED \tMANAGED \nkeda \t0.1(regular), 0.2(fast)\t0.2(fast) \ttrue \t\nserverless\t0.0.1(fast), 0.0.2 \t0.0.1(fast)\tfalse \t\n"
testModulesTableView = "NAME \tAVAILABLE VERSIONS \tINSTALLED\tMANAGED \nkeda \t0.1(regular), 0.2(fast)\t \t \t\nserverless\t0.0.1(fast), 0.0.2 \t \t \t\n"
testManagedModulesTableView = "NAME \tAVAILABLE VERSIONS \tINSTALLED \tMANAGED \nkeda \t0.1(regular), 0.2(fast)\t0.2(fast) \ttrue \t\nserverless\t0.0.1(fast), 0.0.2 \t0.0.1(fast)\tfalse \t\n"
)

func TestRender(t *testing.T) {
Expand Down

0 comments on commit 7fc7e0d

Please sign in to comment.