From f9ce81f5d7cb1d433e2659ca93203a17de1bcbbb Mon Sep 17 00:00:00 2001 From: Piotr Halama Date: Tue, 31 Dec 2024 13:10:26 +0100 Subject: [PATCH] fix: don't fail getting state on not installed modules --- internal/modules/list.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/internal/modules/list.go b/internal/modules/list.go index 1afee0e95..844466050 100644 --- a/internal/modules/list.go +++ b/internal/modules/list.go @@ -76,11 +76,16 @@ func List(ctx context.Context, client kube.Client) (ModulesList, error) { ), } - state, err := getModuleState(ctx, client, moduleTemplate, defaultKyma) - if err != nil { - return nil, err + moduleInstalled := getModuleInstalledState(defaultKyma, moduleName) + + state := "" + if moduleInstalled { + // only get state of installed modules + state, err = getModuleState(ctx, client, moduleTemplate, defaultKyma) + if err != nil { + return nil, err + } } - if i := getModuleIndex(modulesList, moduleName); i != -1 { // append version if module with same name is in the list modulesList[i].Versions = append(modulesList[i].Versions, version) @@ -168,7 +173,6 @@ func getResourceState(ctx context.Context, client kube.Client, manager *kyma.Man apiVersion := fmt.Sprintf("%s/%s", manager.Group, manager.Version) unstruct := generateUnstruct(apiVersion, manager.Kind, manager.Name, namespace) - result, err := client.RootlessDynamic().Get(ctx, &unstruct) if err != nil { if errors.IsNotFound(err) { @@ -245,6 +249,19 @@ func getStateFromConditions(conditions []interface{}) string { return "" } +func getModuleInstalledState(kyma *kyma.Kyma, moduleName string) bool { + if kyma != nil { + for _, module := range kyma.Status.Modules { + if module.Name == moduleName { + return true + } + } + } + + // module is not installed + return false +} + func getInstallDetails(kyma *kyma.Kyma, releaseMetas kyma.ModuleReleaseMetaList, moduleName, state string) ModuleInstallDetails { if kyma != nil { for _, module := range kyma.Status.Modules {