Skip to content

Commit

Permalink
Read info from yaml file and support to read multiple upstreams for c…
Browse files Browse the repository at this point in the history
…omponents
  • Loading branch information
Sara4994 committed Oct 29, 2024
1 parent 12889bd commit 89d0ef9
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,6 @@ spec:
properties:
displayname:
type: string
name:
type: string
repourl:
type: string
version:
Expand All @@ -673,8 +671,6 @@ spec:
properties:
displayname:
type: string
name:
type: string
repourl:
type: string
version:
Expand All @@ -689,8 +685,6 @@ spec:
properties:
displayname:
type: string
name:
type: string
repourl:
type: string
version:
Expand All @@ -705,8 +699,6 @@ spec:
properties:
displayname:
type: string
name:
type: string
repourl:
type: string
version:
Expand All @@ -721,8 +713,6 @@ spec:
properties:
displayname:
type: string
name:
type: string
repourl:
type: string
version:
Expand All @@ -737,8 +727,6 @@ spec:
properties:
displayname:
type: string
name:
type: string
repourl:
type: string
version:
Expand All @@ -755,8 +743,6 @@ spec:
properties:
displayname:
type: string
name:
type: string
repourl:
type: string
version:
Expand All @@ -771,8 +757,6 @@ spec:
properties:
displayname:
type: string
name:
type: string
repourl:
type: string
version:
Expand All @@ -787,8 +771,6 @@ spec:
properties:
displayname:
type: string
name:
type: string
repourl:
type: string
version:
Expand All @@ -803,8 +785,6 @@ spec:
properties:
displayname:
type: string
name:
type: string
repourl:
type: string
version:
Expand All @@ -819,8 +799,6 @@ spec:
properties:
displayname:
type: string
name:
type: string
repourl:
type: string
version:
Expand Down
52 changes: 34 additions & 18 deletions controllers/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ limitations under the License.
package status

import (
"os"
"path/filepath"

"github.com/blang/semver/v4"
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
"github.com/operator-framework/api/pkg/lib/version"
"gopkg.in/yaml.v2"
corev1 "k8s.io/api/core/v1"

"github.com/opendatahub-io/opendatahub-operator/v2/pkg/common"
)

// These constants represent the overall Phase as used by .Status.Phase.
Expand Down Expand Up @@ -218,7 +218,6 @@ func RemoveComponentCondition(conditions *[]conditionsv1.Condition, component st

// +k8s:deepcopy-gen=true
type ComponentReleaseStatus struct {
Name string `json:"name,omitempty"`
DisplayName string `json:"displayname,omitempty"`
Version version.OperatorVersion `json:"version,omitempty"`
RepoURL string `json:"repourl,omitempty"`
Expand Down Expand Up @@ -300,35 +299,52 @@ type ComponentsStatus struct {
Workbenches *WorkbenchesStatus `json:"workbenches,omitempty"`
}

// +k8s:deepcopy-gen=true
type ReleaseFileMeta struct {
Releases []ComponentReleaseStatusMeta `json:"releases,omitempty"`
}

// +k8s:deepcopy-gen=true
type ComponentReleaseStatusMeta struct {
DisplayName string `yaml:"displayname,omitempty"`
Version string `yaml:"version,omitempty"`
RepoURL string `yaml:"repourl,omitempty"`
}

// GetReleaseVersion read .env file and parse env variables delimiter by "=".
// If version is not set or set to "", return empty {}.
func GetReleaseVersion(defaultManifestPath string, componentName string) ComponentStatus {
var componentVersion semver.Version
var repositoryURL string
var displayName string

env, err := common.ParseParams(filepath.Join(defaultManifestPath, componentName, ".env"))
var releaseInfo ReleaseFileMeta
var releaseStatus ComponentReleaseStatus
componentReleaseStatus := make([]ComponentReleaseStatus, 0)

yamlData, err := os.ReadFile(filepath.Join(defaultManifestPath, componentName, "releases.yaml"))
if err != nil {
return ComponentStatus{}
}

componentVersion, err = semver.Parse(env["RHOAI_RELEASE_VERSION"])

err = yaml.Unmarshal(yamlData, &releaseInfo)
if err != nil {
return ComponentStatus{}
}
repositoryURL = env["REPOSITORY_URL"]

displayName = env["DISPLAY_NAME"]
for _, release := range releaseInfo.Releases {
componentVersion, err = semver.Parse(release.Version)

return ComponentStatus{
Releases: []ComponentReleaseStatus{{
Name: componentName,
DisplayName: displayName,
if err != nil {
return ComponentStatus{}
}

releaseStatus = ComponentReleaseStatus{
DisplayName: release.DisplayName,
Version: version.OperatorVersion{Version: componentVersion},
RepoURL: repositoryURL,
},
},
RepoURL: release.RepoURL,
}
componentReleaseStatus = append(componentReleaseStatus, releaseStatus)
}

return ComponentStatus{
Releases: componentReleaseStatus,
}
}
35 changes: 35 additions & 0 deletions controllers/status/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 89d0ef9

Please sign in to comment.