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

fix: don't fail getting state on not installed modules #2304

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Changes from all commits
Commits
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
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
Loading