-
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 warnings for tailing-sidecar-opera…
…tor (#400) Signed-off-by: Dominik Rosiek <drosiek@sumologic.com> Signed-off-by: Dominik Rosiek <drosiek@sumologic.com>
- Loading branch information
1 parent
5c6976c
commit dfb0ff9
Showing
3 changed files
with
106 additions
and
0 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
54 changes: 54 additions & 0 deletions
54
src/go/cmd/update-collection-v3/migrations/tailing-sidecar-operator-upgrade/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,54 @@ | ||
package tailingsidecaroperatorupgrade | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type Values struct { | ||
TailingSidecarOperator struct { | ||
Rest map[string]interface{} `yaml:",inline"` | ||
} `yaml:"tailing-sidecar-operator,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) | ||
} | ||
|
||
values = migrate(&values) | ||
if err != nil { | ||
return "", fmt.Errorf("error migrating: %v", err) | ||
} | ||
|
||
return inputYaml, nil | ||
} | ||
|
||
func parseValues(inputYaml string) (Values, error) { | ||
var v Values | ||
err := yaml.Unmarshal([]byte(inputYaml), &v) | ||
return v, err | ||
} | ||
|
||
func migrate(values *Values) Values { | ||
log := migrateLog(values) | ||
|
||
if log != "" { | ||
fmt.Println(log) | ||
} | ||
|
||
return *values | ||
} | ||
|
||
func migrateLog(values *Values) string { | ||
if len(values.TailingSidecarOperator.Rest) == 0 { | ||
return "" | ||
} | ||
|
||
return "WARNING! Changes in tailing-sidecar-operator detected, which may require manual migration\n" + | ||
"For details please see the following documentations:\n - https://github.com/SumoLogic/sumologic-kubernetes-collection/blob/main/docs/v3-migration-doc.md\n" + | ||
" - https://github.com/SumoLogic/tailing-sidecar/blob/63e7c7f38e9e1edf1a105407b4aea8322101ab8a/CHANGELOG.md" | ||
} |
47 changes: 47 additions & 0 deletions
47
src/go/cmd/update-collection-v3/migrations/tailing-sidecar-operator-upgrade/migrate_test.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,47 @@ | ||
package tailingsidecaroperatorupgrade | ||
|
||
import ( | ||
"testing" | ||
|
||
"gotest.tools/assert" | ||
) | ||
|
||
var ( | ||
foo interface{} = "bar" | ||
) | ||
|
||
func TestMain(t *testing.T) { | ||
for _, tt := range []struct { | ||
input func() *Values | ||
expected string | ||
name string | ||
}{ | ||
{ | ||
name: "all", | ||
input: func() *Values { | ||
values := &Values{} | ||
values.TailingSidecarOperator.Rest = map[string]interface{}{ | ||
"foo": foo, | ||
} | ||
return values | ||
}, | ||
expected: `WARNING! Changes in tailing-sidecar-operator detected, which may require manual migration | ||
For details please see the following documentations: | ||
- https://github.com/SumoLogic/sumologic-kubernetes-collection/blob/main/docs/v3-migration-doc.md | ||
- https://github.com/SumoLogic/tailing-sidecar/blob/63e7c7f38e9e1edf1a105407b4aea8322101ab8a/CHANGELOG.md`, | ||
}, | ||
{ | ||
name: "no values", | ||
input: func() *Values { | ||
values := &Values{} | ||
return values | ||
}, | ||
expected: ``, | ||
}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
val := migrateLog(tt.input()) | ||
assert.Equal(t, tt.expected, val) | ||
}) | ||
} | ||
} |