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): check for conflicts between input and output yamls in migrations #574

Merged
merged 4 commits into from
Sep 6, 2023

Conversation

sumo-drosiek
Copy link
Contributor

@sumo-drosiek sumo-drosiek commented Sep 4, 2023

This PR resolves the following case:

inputStruct

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

values.yaml

out: test

outputStruct

type out struct {
  Out            string                 `yaml:"out,omitempty"`
  Rest           map[string]interface{} `yaml:",inline,omitempty"`
}

out is in both Rest and Outproperties ofout` structure which leads to panic:

e.g.

input.yaml

otelcolInstrumentation:
  enabled: false

stdout:

panic: cannot have key "otelcolInstrumentation" in inlined map: conflicts with struct field [recovered]
        panic: cannot have key "otelcolInstrumentation" in inlined map: conflicts with struct field

goroutine 1 [running]:
gopkg.in/yaml%2ev3.handleErr(0xc000133788)
        /home/drosiek/go/pkg/mod/gopkg.in/yaml.v3@v3.0.1/yaml.go:294 +0x6d
panic({0x55c340?, 0xc000031500?})
        /usr/lib/go/src/runtime/panic.go:914 +0x21f
gopkg.in/yaml%2ev3.(*encoder).structv.func1()
        /home/drosiek/go/pkg/mod/gopkg.in/yaml.v3@v3.0.1/encode.go:245 +0x479
gopkg.in/yaml%2ev3.(*encoder).mappingv(0xc000163800, {0x0?, 0x0}, 0xc000133528)
        /home/drosiek/go/pkg/mod/gopkg.in/yaml.v3@v3.0.1/encode.go:265 +0x14a
gopkg.in/yaml%2ev3.(*encoder).structv(0xc000163800, {0x0, 0x0}, {0x57d4c0?, 0xc00016d360?, 0x0?})
        /home/drosiek/go/pkg/mod/gopkg.in/yaml.v3@v3.0.1/encode.go:219 +0xe5
gopkg.in/yaml%2ev3.(*encoder).marshal(0xc000163800, {0x0, 0x0}, {0x57d4c0?, 0xc00016d360?, 0x5c6568?})
        /home/drosiek/go/pkg/mod/gopkg.in/yaml.v3@v3.0.1/encode.go:168 +0x8a8
gopkg.in/yaml%2ev3.(*encoder).marshalDoc(0xc000163800, {0x0, 0x0}, {0x57d4c0?, 0xc00016d360?, 0xc00016d360?})
        /home/drosiek/go/pkg/mod/gopkg.in/yaml.v3@v3.0.1/encode.go:105 +0x12e
gopkg.in/yaml%2ev3.(*Encoder).Encode(0x57d4c0?, {0x57d4c0?, 0xc00016d360?})
        /home/drosiek/go/pkg/mod/gopkg.in/yaml.v3@v3.0.1/yaml.go:251 +0xbe
github.com/SumoLogic/sumologic-kubernetes-collection/tools/cmd/update-collection-v3/migrations/tracing-config.Migrate({0xc00001c9c0?, 0x33?})
        /home/drosiek/projects/sumologic-kubernetes-tools/src/go/cmd/update-collection-v3/migrations/tracing-config/migrate.go:25 +0x4af
main.migrateYaml({0xc0000240f0, 0x2e})
        /home/drosiek/projects/sumologic-kubernetes-tools/src/go/cmd/update-collection-v3/main.go:156 +0x97
main.migrateYamlFile({0x7fff0c6abccd, 0xa}, {0x58fea0, 0xf})
        /home/drosiek/projects/sumologic-kubernetes-tools/src/go/cmd/update-collection-v3/main.go:63 +0x1aa
main.main()
        /home/drosiek/projects/sumologic-kubernetes-tools/src/go/cmd/update-collection-v3/main.go:45 +0x7c

@sumo-drosiek sumo-drosiek requested a review from a team as a code owner September 4, 2023 11:24
Copy link

@swiatekm swiatekm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to run the check in the migration loop instead of manually adding it to each migration?

src/go/cmd/update-collection-v3/helpers/helpers.go Outdated Show resolved Hide resolved
@sumo-drosiek
Copy link
Contributor Author

Wouldn't it be better to run the check in the migration loop instead of manually adding it to each migration?

We have strings as input and output of every Migration and issue is during serialization to output string.

… output yamls

Signed-off-by: Dominik Rosiek <drosiek@sumologic.com>
…put yamls in migrations

Signed-off-by: Dominik Rosiek <drosiek@sumologic.com>
Signed-off-by: Dominik Rosiek <drosiek@sumologic.com>
Signed-off-by: Dominik Rosiek <drosiek@sumologic.com>
@sumo-drosiek sumo-drosiek merged commit a35c279 into main Sep 6, 2023
4 checks passed
@sumo-drosiek sumo-drosiek deleted the drosiek-fix-update branch September 6, 2023 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants