Skip to content

Commit

Permalink
Do not remove usedGKs when all resources are deleted
Browse files Browse the repository at this point in the history
Signed-off-by: Praveen Rewar <[email protected]>
  • Loading branch information
praveenrewar authored and 100mik committed Apr 17, 2024
1 parent 8b5e6a3 commit 6321d10
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
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{}

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)
}

0 comments on commit 6321d10

Please sign in to comment.