diff --git a/pkg/kapp/app/recorded_app.go b/pkg/kapp/app/recorded_app.go index 368526aa1..5d4e76163 100644 --- a/pkg/kapp/app/recorded_app.go +++ b/pkg/kapp/app/recorded_app.go @@ -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 { @@ -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 }) diff --git a/test/e2e/app_metadata_output_test.go b/test/e2e/app_metadata_output_test.go index 61405cacb..b0e0368c2 100644 --- a/test/e2e/app_metadata_output_test.go +++ b/test/e2e/app_metadata_output_test.go @@ -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() { @@ -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) @@ -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) }