-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(upgrade_to_v3): add migration to remove sumologic.cluster.load_c…
…onfig_file Signed-off-by: Dominik Rosiek <drosiek@sumologic.com>
- Loading branch information
1 parent
c742c32
commit 054aba2
Showing
6 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/go/cmd/update-collection-v3/migrations/remove-load-config-file/migrate.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
7 changes: 7 additions & 0 deletions
7
...pdate-collection-v3/migrations/remove-load-config-file/testdata/complex_config.input.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
6 changes: 6 additions & 0 deletions
6
...date-collection-v3/migrations/remove-load-config-file/testdata/complex_config.output.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
sumologic: | ||
cluster: | ||
c: d | ||
e: f | ||
a: b | ||
g: h |
3 changes: 3 additions & 0 deletions
3
...ollection-v3/migrations/remove-load-config-file/testdata/load_config_file_only.input.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
sumologic: | ||
cluster: | ||
load_config_file: false |
1 change: 1 addition & 0 deletions
1
...llection-v3/migrations/remove-load-config-file/testdata/load_config_file_only.output.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |