Skip to content

Commit

Permalink
restored parseParams methods and removed manager file
Browse files Browse the repository at this point in the history
  • Loading branch information
Sara4994 committed Nov 1, 2024
1 parent 89d0ef9 commit 99da1f1
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,9 @@ spec:
releases:
items:
properties:
displayname:
name:
type: string
repourl:
repoURL:
type: string
version:
type: string
Expand All @@ -669,9 +669,9 @@ spec:
releases:
items:
properties:
displayname:
name:
type: string
repourl:
repoURL:
type: string
version:
type: string
Expand All @@ -683,9 +683,9 @@ spec:
releases:
items:
properties:
displayname:
name:
type: string
repourl:
repoURL:
type: string
version:
type: string
Expand All @@ -697,9 +697,9 @@ spec:
releases:
items:
properties:
displayname:
name:
type: string
repourl:
repoURL:
type: string
version:
type: string
Expand All @@ -711,9 +711,9 @@ spec:
releases:
items:
properties:
displayname:
name:
type: string
repourl:
repoURL:
type: string
version:
type: string
Expand All @@ -725,9 +725,9 @@ spec:
releases:
items:
properties:
displayname:
name:
type: string
repourl:
repoURL:
type: string
version:
type: string
Expand All @@ -741,9 +741,9 @@ spec:
releases:
items:
properties:
displayname:
name:
type: string
repourl:
repoURL:
type: string
version:
type: string
Expand All @@ -755,9 +755,9 @@ spec:
releases:
items:
properties:
displayname:
name:
type: string
repourl:
repoURL:
type: string
version:
type: string
Expand All @@ -769,9 +769,9 @@ spec:
releases:
items:
properties:
displayname:
name:
type: string
repourl:
repoURL:
type: string
version:
type: string
Expand All @@ -783,9 +783,9 @@ spec:
releases:
items:
properties:
displayname:
name:
type: string
repourl:
repoURL:
type: string
version:
type: string
Expand All @@ -797,9 +797,9 @@ spec:
releases:
items:
properties:
displayname:
name:
type: string
repourl:
repoURL:
type: string
version:
type: string
Expand Down
22 changes: 11 additions & 11 deletions controllers/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ func RemoveComponentCondition(conditions *[]conditionsv1.Condition, component st

// +k8s:deepcopy-gen=true
type ComponentReleaseStatus struct {
DisplayName string `json:"displayname,omitempty"`
Version version.OperatorVersion `json:"version,omitempty"`
RepoURL string `json:"repourl,omitempty"`
Name string `json:"name,omitempty"`
Version version.OperatorVersion `json:"version,omitempty"`
RepoURL string `json:"repoURL,omitempty"`
}

// +k8s:deepcopy-gen=true
Expand Down Expand Up @@ -306,20 +306,20 @@ type ReleaseFileMeta struct {

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

// GetReleaseVersion read .env file and parse env variables delimiter by "=".
// GetReleaseVersion reads odh_metadata.yaml file and parses release information.
// If version is not set or set to "", return empty {}.
func GetReleaseVersion(defaultManifestPath string, componentName string) ComponentStatus {
var componentVersion semver.Version
var releaseInfo ReleaseFileMeta
var releaseStatus ComponentReleaseStatus
componentReleaseStatus := make([]ComponentReleaseStatus, 0)

yamlData, err := os.ReadFile(filepath.Join(defaultManifestPath, componentName, "releases.yaml"))
yamlData, err := os.ReadFile(filepath.Join(defaultManifestPath, componentName, "odh_metadata.yaml"))
if err != nil {
return ComponentStatus{}
}
Expand All @@ -337,9 +337,9 @@ func GetReleaseVersion(defaultManifestPath string, componentName string) Compone
}

releaseStatus = ComponentReleaseStatus{
DisplayName: release.DisplayName,
Version: version.OperatorVersion{Version: componentVersion},
RepoURL: release.RepoURL,
Name: release.name,
Version: version.OperatorVersion{Version: componentVersion},
RepoURL: release.RepoURL,
}
componentReleaseStatus = append(componentReleaseStatus, releaseStatus)
}
Expand Down
Binary file removed manager
Binary file not shown.
24 changes: 0 additions & 24 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ limitations under the License.
package common

import (
"bufio"
"crypto/sha256"
b64 "encoding/base64"
"fmt"
Expand Down Expand Up @@ -117,26 +116,3 @@ func GetMonitoringData(data string) (string, error) {

return encodedData, nil
}

func ParseParams(fileName string) (map[string]string, error) {
paramsEnv, err := os.Open(fileName)
if err != nil {
return nil, err
}
defer paramsEnv.Close()

paramsEnvMap := make(map[string]string)
scanner := bufio.NewScanner(paramsEnv)
for scanner.Scan() {
line := scanner.Text()
parts := strings.SplitN(line, "=", 2)
if len(parts) == 2 {
paramsEnvMap[parts[0]] = parts[1]
}
}
if err := scanner.Err(); err != nil {
return nil, err
}

return paramsEnvMap, nil
}
28 changes: 25 additions & 3 deletions pkg/deploy/envParams.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,32 @@ import (
"fmt"
"os"
"path/filepath"

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

func parseParams(fileName string) (map[string]string, error) {
paramsEnv, err := os.Open(fileName)
if err != nil {
return nil, err
}
defer paramsEnv.Close()

paramsEnvMap := make(map[string]string)
scanner := bufio.NewScanner(paramsEnv)
for scanner.Scan() {
line := scanner.Text()
parts := strings.SplitN(line, "=", 2)
if len(parts) == 2 {
paramsEnvMap[parts[0]] = parts[1]
}
}
if err := scanner.Err(); err != nil {
return nil, err
}

return paramsEnvMap, nil
}

func writeParamsToTmp(params map[string]string, tmpDir string) (string, error) {
tmp, err := os.CreateTemp(tmpDir, "params.env-")
if err != nil {
Expand Down Expand Up @@ -54,7 +76,7 @@ func ApplyParams(componentPath string, imageParamsMap map[string]string, extraPa
paramsFile := filepath.Join(componentPath, "params.env")
// Require params.env at the root folder

paramsEnvMap, err := common.ParseParams(paramsFile)
paramsEnvMap, err := parseParams(paramsFile)
if err != nil {
if os.IsNotExist(err) {
// params.env doesn't exist, do not apply any changes
Expand Down

0 comments on commit 99da1f1

Please sign in to comment.