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

Do not remove usedGKs when all resources are deleted #928

Merged
merged 1 commit into from
Apr 17, 2024
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
11 changes: 6 additions & 5 deletions pkg/kapp/app/recorded_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,13 @@ func (a *RecordedApp) UpdateUsedGVsAndGKs(gvs []schema.GroupVersion, gks []schem
}
}

sort.Slice(uniqGVs, func(i int, j int) bool {
return uniqGVs[i].Group+uniqGVs[i].Version < uniqGVs[j].Group+uniqGVs[j].Version
})

gksByGK := map[schema.GroupKind]struct{}{}
var uniqGKs []schema.GroupKind
// Initialize with an empty slice so that we do not remove `usedGKs` from meta configmap
uniqGKs := []schema.GroupKind{}
100mik marked this conversation as resolved.
Show resolved Hide resolved

for _, gk := range gks {
if _, found := gksByGK[gk]; !found {
Expand All @@ -115,10 +120,6 @@ func (a *RecordedApp) UpdateUsedGVsAndGKs(gvs []schema.GroupVersion, gks []schem
}
}

sort.Slice(uniqGVs, func(i int, j int) bool {
return uniqGVs[i].Group+uniqGVs[i].Version < uniqGVs[j].Group+uniqGVs[j].Version
})

sort.Slice(uniqGKs, func(i int, j int) bool {
return uniqGKs[i].Group+uniqGKs[i].Kind < uniqGKs[j].Group+uniqGKs[j].Kind
})
Expand Down
19 changes: 19 additions & 0 deletions test/e2e/app_metadata_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,18 @@ metadata:
assert.NoError(t, err)
thirdDeploy, err := os.CreateTemp(os.TempDir(), "output3")
assert.NoError(t, err)
fourthDeploy, err := os.CreateTemp(os.TempDir(), "output4")
assert.NoError(t, err)

tmpDir, err := os.MkdirTemp("", "")
assert.NoError(t, err)
defer os.RemoveAll(tmpDir)

defer func() {
os.Remove(firstDeploy.Name())
os.Remove(secondDeploy.Name())
os.Remove(thirdDeploy.Name())
os.Remove(fourthDeploy.Name())
}()

logger.Section("deploy app", func() {
Expand All @@ -73,6 +81,10 @@ metadata:
kapp.RunWithOpts([]string{"deploy", "--app-metadata-file-output", thirdDeploy.Name(), "-f", "-", "-a", name}, RunOpts{IntoNs: true, StdinReader: strings.NewReader(yaml2)})
})

logger.Section("deploy with no changes", func() {
kapp.RunWithOpts([]string{"deploy", "--app-metadata-file-output", fourthDeploy.Name(), "-f", tmpDir, "-a", name, "--dangerous-allow-empty-list-of-resources"}, RunOpts{IntoNs: true})
})

configMapFirstDeploy, err := os.ReadFile(firstDeploy.Name())
assert.NoError(t, err)

Expand All @@ -93,4 +105,11 @@ metadata:
thirdConfigMap := yamlSubset{}
require.NoError(t, yaml.Unmarshal(configMapThirdDeploy, &thirdConfigMap))
require.Equal(t, yamlSubset{LastChange: lastChange{Namespaces: []string{env.Namespace}}, UsedGKs: []usedGK{{Group: "", Kind: "Secret"}}}, thirdConfigMap)

configMapFourthDeploy, err := os.ReadFile(fourthDeploy.Name())
assert.NoError(t, err)

fourthConfigMap := yamlSubset{}
require.NoError(t, yaml.Unmarshal(configMapFourthDeploy, &fourthConfigMap))
require.Equal(t, yamlSubset{LastChange: lastChange{Namespaces: nil}, UsedGKs: []usedGK{}}, fourthConfigMap)
}
Loading