Skip to content

Commit

Permalink
fix: don't fail getting state on not installed modules (#2304)
Browse files Browse the repository at this point in the history
  • Loading branch information
halamix2 authored Jan 2, 2025
1 parent 9d16ef4 commit b921015
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions internal/modules/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := isModuleInstalled(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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -245,6 +249,19 @@ func getStateFromConditions(conditions []interface{}) string {
return ""
}

func isModuleInstalled(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 {
Expand Down

0 comments on commit b921015

Please sign in to comment.