Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(update-collection-v3): migrate otelevents.config.override #389

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/go/cmd/update-collection-v3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

disablethanos "github.com/SumoLogic/sumologic-kubernetes-collection/tools/cmd/update-collection-v3/migrations/disable-thanos"
"github.com/SumoLogic/sumologic-kubernetes-collection/tools/cmd/update-collection-v3/migrations/events"
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"
tracingreplaces "github.com/SumoLogic/sumologic-kubernetes-collection/tools/cmd/update-collection-v3/migrations/tracing-replaces"
)
Expand Down Expand Up @@ -57,6 +58,7 @@ var migrationDirectoriesAndFunctions = map[string]migrateFunc{
"events": events.Migrate,
"disable-thanos": disablethanos.Migrate,
"tracing-replaces": tracingreplaces.Migrate,
"events-config-merge": eventsconfigmerge.Migrate,
}

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

import (
"bytes"
"fmt"

"gopkg.in/yaml.v3"
)

type InputValues struct {
Otelevents struct {
Config struct {
Override map[string]interface{} `yaml:"override,omitempty"`
} `yaml:"config,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
} `yaml:"otelevents,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
}

type OutputValues struct {
Otelevents Otelevents `yaml:"otelevents,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
}

type Otelevents struct {
Config Config `yaml:"config,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
}

type Config struct {
Merge map[string]interface{} `yaml:"merge,omitempty"`
Override map[string]interface{} `yaml:"override,omitempty"`
}

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

outputValues, err := migrate(&inputValues)
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) (InputValues, error) {
var inputValues InputValues
err := yaml.Unmarshal([]byte(inputYaml), &inputValues)
return inputValues, err
}

func migrate(inputValues *InputValues) (OutputValues, error) {
outputValues := OutputValues{
Rest: inputValues.Rest,
Otelevents: Otelevents{
Config: Config{
Merge: inputValues.Otelevents.Config.Override,
},
Rest: inputValues.Otelevents.Rest,
},
}
return outputValues, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
otelevents:
config:
override:
key: value
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
otelevents:
config:
merge:
key: value
4 changes: 4 additions & 0 deletions src/go/cmd/update-collection-v3/testdata/simple.input.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ kube-prometheus-stack:
resources:
limits:
cpu: 20m
otelevents:
config:
override:
key: value
sumologic:
accessId: xxx
accessKey: yyy
4 changes: 4 additions & 0 deletions src/go/cmd/update-collection-v3/testdata/simple.output.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
otelevents:
config:
merge:
key: value
sumologic:
accessId: xxx
accessKey: yyy
Expand Down