Skip to content

Commit

Permalink
feat(upgrade_to_v3): add migration to remove sumologic.cluster.load_c…
Browse files Browse the repository at this point in the history
…onfig_file

Signed-off-by: Dominik Rosiek <drosiek@sumologic.com>
  • Loading branch information
sumo-drosiek committed Nov 28, 2022
1 parent c742c32 commit 054aba2
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/go/cmd/update-collection-v3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
eventsconfigmerge "github.com/SumoLogic/sumologic-kubernetes-collection/tools/cmd/update-collection-v3/migrations/events-config-merge"
kubestatemetricscollectors "github.com/SumoLogic/sumologic-kubernetes-collection/tools/cmd/update-collection-v3/migrations/kube-state-metrics-collectors"
"github.com/SumoLogic/sumologic-kubernetes-collection/tools/cmd/update-collection-v3/migrations/logsmetadataconfig"
removeloadconfigfile "github.com/SumoLogic/sumologic-kubernetes-collection/tools/cmd/update-collection-v3/migrations/remove-load-config-file"
tracingreplaces "github.com/SumoLogic/sumologic-kubernetes-collection/tools/cmd/update-collection-v3/migrations/tracing-replaces"
)

Expand Down Expand Up @@ -55,12 +56,13 @@ func migrateYamlFile(yamlV2FilePath string, yamlV3FilePath string) error {
}

var migrationDirectoriesAndFunctions = map[string]migrateFunc{
"kube-prometheus-stack": kubestatemetricscollectors.Migrate,
"events": events.Migrate,
"disable-thanos": disablethanos.Migrate,
"tracing-replaces": tracingreplaces.Migrate,
"events-config-merge": eventsconfigmerge.Migrate,
"logs-metadata-config": logsmetadataconfig.Migrate,
"kube-prometheus-stack": kubestatemetricscollectors.Migrate,
"events": events.Migrate,
"disable-thanos": disablethanos.Migrate,
"tracing-replaces": tracingreplaces.Migrate,
"events-config-merge": eventsconfigmerge.Migrate,
"logs-metadata-config": logsmetadataconfig.Migrate,
"remove-load-config-file": removeloadconfigfile.Migrate,
}

func migrateYaml(input string) (string, error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package removeloadconfigfile

import (
"bytes"
"fmt"

"gopkg.in/yaml.v3"
)

type Values struct {
Sumologic struct {
Cluster Cluster `yaml:"cluster,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
} `yaml:"sumologic,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
}

type Cluster struct {
LoadConfigFile *bool `yaml:"load_config_file,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
}

func Migrate(inputYaml string) (outputYaml string, err error) {
values, err := parseValues(inputYaml)
if err != nil {
return "", fmt.Errorf("error parsing input yaml: %v", err)
}

outputValues, err := migrate(&values)
if err != nil {
return "", fmt.Errorf("error migrating: %v", err)
}

buffer := bytes.Buffer{}
encoder := yaml.NewEncoder(&buffer)
encoder.SetIndent(2)
err = encoder.Encode(outputValues)
return buffer.String(), err
}

func parseValues(inputYaml string) (Values, error) {
var inputValues Values
err := yaml.Unmarshal([]byte(inputYaml), &inputValues)
return inputValues, err
}

func migrate(values *Values) (Values, error) {
values.Sumologic.Cluster.LoadConfigFile = nil
return *values, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sumologic:
a: b
cluster:
c: d
load_config_file: false
e: f
g: h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sumologic:
cluster:
c: d
e: f
a: b
g: h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sumologic:
cluster:
load_config_file: false
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit 054aba2

Please sign in to comment.