Skip to content

Commit

Permalink
fix: Minor style/copy changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yiannistri committed Oct 17, 2023
1 parent ed0f65c commit a665b2f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
2 changes: 1 addition & 1 deletion cmd/gitops/beta/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ gitops beta run ./charts/podinfo --timeout 3m --port-forward namespace=flux-syst
cmdFlags.BoolVar(&flags.SkipResourceCleanup, "skip-resource-cleanup", false, "Skip resource cleanup. If not specified, the GitOps Run resources will be deleted by default.")
cmdFlags.StringVar(&flags.DecryptionKeyFile, "decryption-key-file", "", "Path to an age key file used for decrypting Secrets using SOPS.")

cmdFlags.StringSliceVar(&flags.DashboardValuesFiles, "values", nil, "local path to values.yaml files for HelmRelease, also accepts comma-separated values")
cmdFlags.StringSliceVar(&flags.DashboardValuesFiles, "values", nil, "Local path to values.yaml files for HelmRelease, also accepts comma-separated values.")
cmdFlags.StringVar(&flags.DashboardImage, "dashboard-image", "", "Override GitOps Dashboard image")
_ = cmdFlags.MarkHidden("dashboard-image")

Expand Down
8 changes: 4 additions & 4 deletions cmd/gitops/create/dashboard/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type DashboardCommandFlags struct {
// Create command flags.
Export bool
Timeout time.Duration
valuesFiles []string
ValuesFiles []string
// Overridden global flags.
Username string
Password string
Expand Down Expand Up @@ -64,7 +64,7 @@ gitops create dashboard ww-gitops \

cmdFlags.StringVar(&flags.Username, "username", "admin", "The username of the dashboard admin user.")
cmdFlags.StringVar(&flags.Password, "password", "", "The password of the dashboard admin user.")
cmdFlags.StringSliceVar(&flags.valuesFiles, "values", nil, "local path to values.yaml files for HelmRelease, also accepts comma-separated values")
cmdFlags.StringSliceVar(&flags.ValuesFiles, "values", nil, "Local path to values.yaml files for HelmRelease, also accepts comma-separated values.")

kubeConfigArgs = run.GetKubeConfigArgs()

Expand Down Expand Up @@ -120,7 +120,7 @@ func createDashboardCommandRunE(opts *config.Options) func(*cobra.Command, []str
return err
}

if flags.valuesFiles, err = cmd.Flags().GetStringSlice("values"); err != nil {
if flags.ValuesFiles, err = cmd.Flags().GetStringSlice("values"); err != nil {
return err
}

Expand Down Expand Up @@ -153,7 +153,7 @@ func createDashboardCommandRunE(opts *config.Options) func(*cobra.Command, []str
adminUsername = defaultAdminUsername
}

dashboardObjects, err := install.CreateDashboardObjects(log, dashboardName, flags.Namespace, adminUsername, passwordHash, "", "", flags.valuesFiles)
dashboardObjects, err := install.CreateDashboardObjects(log, dashboardName, flags.Namespace, adminUsername, passwordHash, "", "", flags.ValuesFiles)
if err != nil {
return fmt.Errorf("error creating dashboard objects: %w", err)
}
Expand Down
41 changes: 19 additions & 22 deletions pkg/run/install/install_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (
"strings"
"time"

helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
"github.com/fluxcd/pkg/runtime/transform"
sourcev1b2 "github.com/fluxcd/source-controller/api/v1beta2"

helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
coretypes "github.com/weaveworks/weave-gitops/core/server/types"
"github.com/weaveworks/weave-gitops/pkg/config"
"github.com/weaveworks/weave-gitops/pkg/logger"
Expand Down Expand Up @@ -83,25 +82,23 @@ func CreateDashboardObjects(log logger.Logger, name, namespace, username, passwo
log.Actionf("Creating GitOps Dashboard objects ...")

valuesFromFiles := make(map[string]interface{})
if len(valuesFiles) > 0 {
for _, v := range valuesFiles {
data, err := os.ReadFile(v)
if err != nil {
return nil, fmt.Errorf("reading values from %s failed: %w", v, err)
}

jsonBytes, err := yaml.YAMLToJSON(data)
if err != nil {
return nil, fmt.Errorf("converting values to JSON from %s failed: %w", v, err)
}
for _, v := range valuesFiles {
data, err := os.ReadFile(v)
if err != nil {
return nil, fmt.Errorf("failed to read YAML values from %q: %w", v, err)
}

jsonMap := make(map[string]interface{})
if err := json.Unmarshal(jsonBytes, &jsonMap); err != nil {
return nil, fmt.Errorf("unmarshaling values from %s failed: %w", v, err)
}
jsonBytes, err := yaml.YAMLToJSON(data)
if err != nil {
return nil, fmt.Errorf("failed to convert YAML values from %q to JSON values: %w", v, err)
}

valuesFromFiles = transform.MergeMaps(valuesFromFiles, jsonMap)
jsonMap := make(map[string]interface{})
if err := json.Unmarshal(jsonBytes, &jsonMap); err != nil {
return nil, fmt.Errorf("failed to unmarshal JSON values from %q: %w", v, err)
}

valuesFromFiles = transform.MergeMaps(valuesFromFiles, jsonMap)
}

helmRepository := makeHelmRepository(name, namespace)
Expand Down Expand Up @@ -353,7 +350,7 @@ func makeHelmRepository(name, namespace string) *sourcev1b2.HelmRepository {
}

// makeHelmRelease creates a HelmRelease object for installing the GitOps Dashboard.
func makeHelmRelease(log logger.Logger, name, namespace, username, passwordHash, chartVersion, dashboardImage string, valuesFromFile map[string]interface{}) (*helmv2.HelmRelease, error) {
func makeHelmRelease(log logger.Logger, name, namespace, username, passwordHash, chartVersion, dashboardImage string, valuesFromFiles map[string]interface{}) (*helmv2.HelmRelease, error) {
helmRelease := &helmv2.HelmRelease{
TypeMeta: metav1.TypeMeta{
Kind: helmv2.HelmReleaseKind,
Expand Down Expand Up @@ -386,7 +383,7 @@ func makeHelmRelease(log logger.Logger, name, namespace, username, passwordHash,
helmRelease.Spec.Chart.Spec.Version = chartVersion
}

values, err := makeValues(username, passwordHash, dashboardImage, valuesFromFile)
values, err := makeValues(username, passwordHash, dashboardImage, valuesFromFiles)
if err != nil {
log.Failuref("Error generating chart values")
return nil, err
Expand Down Expand Up @@ -442,7 +439,7 @@ func parseImageRepository(input string) (repository, image, tag string, err erro
}

// makeValues creates a values object for installing the GitOps Dashboard.
func makeValues(username, passwordHash, dashboardImage string, valuesFromFile map[string]interface{}) ([]byte, error) {
func makeValues(username, passwordHash, dashboardImage string, valuesFromFiles map[string]interface{}) ([]byte, error) {
valuesMap := make(map[string]interface{})
if username != "" && passwordHash != "" {
valuesMap["adminUser"] =
Expand Down Expand Up @@ -473,7 +470,7 @@ func makeValues(username, passwordHash, dashboardImage string, valuesFromFile ma
}
}

finalValues := transform.MergeMaps(valuesMap, valuesFromFile)
finalValues := transform.MergeMaps(valuesMap, valuesFromFiles)

if len(finalValues) > 0 {
jsonRaw, err := json.Marshal(finalValues)
Expand Down

0 comments on commit a665b2f

Please sign in to comment.