From 5f736115d5734b07b9f66514e0ef4db0f03b2dfb Mon Sep 17 00:00:00 2001 From: Ugo Giordano Date: Wed, 29 Jan 2025 17:52:50 +0100 Subject: [PATCH] skipping the component versions if "version" field is empty --- .../releases/action_fetch_releases_status.go | 18 +++++++++++------- .../action_fetch_releases_status_test.go | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/controller/actions/status/releases/action_fetch_releases_status.go b/pkg/controller/actions/status/releases/action_fetch_releases_status.go index d4a7f84ab58..e9602a1065e 100644 --- a/pkg/controller/actions/status/releases/action_fetch_releases_status.go +++ b/pkg/controller/actions/status/releases/action_fetch_releases_status.go @@ -2,12 +2,12 @@ package releases import ( "context" - "encoding/json" "fmt" "os" "path/filepath" "strings" + "gopkg.in/yaml.v3" logf "sigs.k8s.io/controller-runtime/pkg/log" "github.com/opendatahub-io/opendatahub-operator/v2/apis/common" @@ -122,7 +122,7 @@ func (a *Action) render(ctx context.Context, rr *types.ReconciliationRequest) ([ // Unmarshal YAML into defined struct var componentMeta common.ComponentReleaseStatus - if err := json.Unmarshal(yamlData, &componentMeta); err != nil { + if err := yaml.Unmarshal(yamlData, &componentMeta); err != nil { return nil, fmt.Errorf("error unmarshaling YAML: %w", err) } @@ -130,11 +130,15 @@ func (a *Action) render(ctx context.Context, rr *types.ReconciliationRequest) ([ componentReleasesStatus := make([]common.ComponentRelease, 0, len(componentMeta.Releases)) for _, release := range componentMeta.Releases { componentVersion := strings.TrimSpace(release.Version) - componentReleasesStatus = append(componentReleasesStatus, common.ComponentRelease{ - Name: release.Name, - Version: componentVersion, - RepoURL: release.RepoURL, - }) + + // Appending the component version only if it's not empty + if componentVersion != "" { + componentReleasesStatus = append(componentReleasesStatus, common.ComponentRelease{ + Name: release.Name, + Version: componentVersion, + RepoURL: release.RepoURL, + }) + } } return componentReleasesStatus, nil diff --git a/pkg/controller/actions/status/releases/action_fetch_releases_status_test.go b/pkg/controller/actions/status/releases/action_fetch_releases_status_test.go index b274ea06f8a..613fef1369d 100644 --- a/pkg/controller/actions/status/releases/action_fetch_releases_status_test.go +++ b/pkg/controller/actions/status/releases/action_fetch_releases_status_test.go @@ -75,7 +75,7 @@ releases: repoUrl: https://github.com/kubeflow/kfp-tekton `, expectedReleases: 0, - expectedError: true, + expectedError: false, }, { name: "should handle empty metadata file path gracefully",