Skip to content

Commit e8ed944

Browse files
authored
🍒 Fixed channels display for module catalog command (#2814) (#2825)
1 parent 40a73f3 commit e8ed944

7 files changed

Lines changed: 42 additions & 33 deletions

File tree

internal/modules/compability.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ func listOldModulesCatalog(moduleTemplates *kyma.ModuleTemplateList) ModulesList
1717
version := ModuleVersion{
1818
Version: componentInfo.Version,
1919
Repository: moduleTemplate.Spec.Info.Repository,
20-
Channel: moduleTemplate.Spec.Channel,
20+
Channels: []string{moduleTemplate.Spec.Channel},
2121
}
2222

23-
if version.Version == "" || version.Channel == "" {
23+
if version.Version == "" || version.Channels[0] == "" {
2424
// ignore corrupted ModuleTemplates (without version or channel)
2525
continue
2626
}

internal/modules/enable.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package modules
33
import (
44
"context"
55
"fmt"
6+
"slices"
67
"time"
78

89
"github.com/kyma-project/cli.v3/internal/clierror"
@@ -98,7 +99,7 @@ func validateModuleAvailability(ctx context.Context, client kube.Client, repo re
9899
}
99100

100101
for _, v := range availableCoreVersions {
101-
if v.Channel == channel || channel == "" {
102+
if slices.Contains(v.Channels, channel) {
102103
return nil
103104
}
104105
}

internal/modules/list.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type ModuleInstallDetails struct {
5050
type ModuleVersion struct {
5151
Repository string
5252
Version string
53-
Channel string
53+
Channels []string
5454
}
5555

5656
type ModulesList []Module
@@ -285,7 +285,7 @@ func listCoreModulesCatalog(ctx context.Context, client kube.Client) (ModulesLis
285285
version := ModuleVersion{
286286
Version: moduleTemplate.Spec.Version,
287287
Repository: moduleTemplate.Spec.Info.Repository,
288-
Channel: getAssignedChannel(
288+
Channels: getAssignedChannels(
289289
*moduleReleaseMetas,
290290
moduleName,
291291
moduleTemplate.Spec.Version,
@@ -875,23 +875,25 @@ func getStateFromConditions(conditions []interface{}) string {
875875
}
876876

877877
// look for channel assigned to version with specified moduleName
878-
func getAssignedChannel(releaseMetas kyma.ModuleReleaseMetaList, moduleName, version string) string {
878+
func getAssignedChannels(releaseMetas kyma.ModuleReleaseMetaList, moduleName, version string) []string {
879879
for _, releaseMeta := range releaseMetas.Items {
880880
if releaseMeta.Spec.ModuleName == moduleName {
881-
return getChannelFromAssignments(releaseMeta.Spec.Channels, version)
881+
return getChannelsFromAssignments(releaseMeta.Spec.Channels, version)
882882
}
883883
}
884-
return ""
884+
return []string{}
885885
}
886886

887-
func getChannelFromAssignments(assignments []kyma.ChannelVersionAssignment, version string) string {
887+
func getChannelsFromAssignments(assignments []kyma.ChannelVersionAssignment, version string) []string {
888+
channels := []string{}
889+
888890
for _, assignment := range assignments {
889891
if assignment.Version == version {
890-
return assignment.Channel
892+
channels = append(channels, assignment.Channel)
891893
}
892894
}
893895

894-
return ""
896+
return channels
895897
}
896898

897899
// return index of module with given name. if not exists return -1

internal/modules/list_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,11 @@ var (
268268
{
269269
Repository: "url-3",
270270
Version: "0.1",
271-
Channel: "regular",
271+
Channels: []string{"regular"},
272272
},
273273
{
274-
Version: "0.2",
275-
Channel: "fast",
274+
Version: "0.2",
275+
Channels: []string{"fast"},
276276
},
277277
},
278278
CommunityModule: false,
@@ -284,11 +284,12 @@ var (
284284
{
285285
Repository: "url-1",
286286
Version: "0.0.1",
287-
Channel: "fast",
287+
Channels: []string{"fast"},
288288
},
289289
{
290290
Repository: "url-2",
291291
Version: "0.0.2",
292+
Channels: []string{},
292293
},
293294
},
294295
CommunityModule: false,

internal/modules/manage.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"slices"
78

89
"github.com/kyma-project/cli.v3/internal/kube"
910
"github.com/kyma-project/cli.v3/internal/kube/kyma"
@@ -52,18 +53,18 @@ func ManageModuleMissingInKyma(ctx context.Context, client kube.Client, repo rep
5253
return fmt.Errorf("failed to get module release metas: %v", err)
5354
}
5455

55-
channelAssignedToModuleVersion := getAssignedChannel(*moduleReleaseMetas, moduleName, installedModuleTemplate.Spec.Version)
56+
channelsAssignedToModuleVersion := getAssignedChannels(*moduleReleaseMetas, moduleName, installedModuleTemplate.Spec.Version)
5657
kymaCR, err := client.Kyma().GetDefaultKyma(ctx)
5758
if err != nil {
5859
return fmt.Errorf("failed to get kyma cr")
5960
}
6061
expectedChannel := kymaCR.Spec.Channel
6162

62-
if channelAssignedToModuleVersion != expectedChannel {
63+
if !slices.Contains(channelsAssignedToModuleVersion, expectedChannel) {
6364
return ErrModuleInstalledVersionNotInKymaChannel
6465
}
6566

66-
clierr := Enable(ctx, client, repo, moduleName, channelAssignedToModuleVersion, enableDefaultCr(policy), []unstructured.Unstructured{}...)
67+
clierr := Enable(ctx, client, repo, moduleName, expectedChannel, enableDefaultCr(policy), []unstructured.Unstructured{}...)
6768
if clierr != nil {
6869
return fmt.Errorf("failed to manage module: %v", clierr)
6970
}
@@ -132,10 +133,10 @@ func GetAvailableChannelsAndVersions(ctx context.Context, client kube.Client, re
132133
continue
133134
}
134135

135-
assignedChannel := getAssignedChannel(*moduleReleaseMetas, moduleName, coreModuleTemplate.Spec.Version)
136+
assignedChannels := getAssignedChannels(*moduleReleaseMetas, moduleName, coreModuleTemplate.Spec.Version)
136137

137-
if assignedChannel != "" {
138-
channelsAndVersions[assignedChannel] = coreModuleTemplate.Spec.Version
138+
for _, channel := range assignedChannels {
139+
channelsAndVersions[channel] = coreModuleTemplate.Spec.Version
139140
}
140141
}
141142

internal/modules/render.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,18 @@ func convertInstall(details ModuleInstallDetails) string {
145145
// convert versions to string containing values separated with '\n'
146146
// and in format 'VERSION (CHANNEL)' or 'VERSION' if channel is empty
147147
func convertVersions(versions []ModuleVersion) string {
148-
values := make([]string, len(versions))
149-
for i, version := range versions {
150-
value := version.Version
151-
if version.Channel != "" {
152-
value += fmt.Sprintf("(%s)", version.Channel)
153-
}
148+
values := make([]string, 0, len(versions))
149+
for _, version := range versions {
150+
if len(version.Channels) == 0 {
151+
values = append(values, version.Version)
152+
} else {
153+
versionsWithChannels := []string{}
154+
for _, channel := range version.Channels {
155+
versionsWithChannels = append(versionsWithChannels, fmt.Sprintf("%s(%s)", version.Version, channel))
156+
}
154157

155-
values[i] = value
158+
values = append(values, strings.Join(versionsWithChannels, ", "))
159+
}
156160
}
157161

158162
return strings.Join(values, ", ")

internal/modules/render_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ var testModules = []Module{
1616
{
1717
Repository: "url-3",
1818
Version: "0.1",
19-
Channel: "regular",
19+
Channels: []string{"regular"},
2020
},
2121
{
22-
Version: "0.2",
23-
Channel: "fast",
22+
Version: "0.2",
23+
Channels: []string{"fast"},
2424
},
2525
},
2626
CommunityModule: false,
@@ -32,7 +32,7 @@ var testModules = []Module{
3232
{
3333
Repository: "url-1",
3434
Version: "0.0.1",
35-
Channel: "fast",
35+
Channels: []string{"fast"},
3636
},
3737
{
3838
Repository: "url-2",
@@ -48,7 +48,7 @@ var testModules = []Module{
4848
{
4949
Repository: "url-1",
5050
Version: "0.1.1",
51-
Channel: "",
51+
Channels: []string{},
5252
},
5353
{
5454
Repository: "url-2",

0 commit comments

Comments
 (0)