kapp icon indicating copy to clipboard operation
kapp copied to clipboard

Crash when attempting to rebase an object from an array

Open braunsonm opened this issue 4 years ago • 1 comments

What steps did you take:

  1. Deploy the following resource:
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: cc-kpack-registry-service-account
  namespace: cf-workloads-staging
secrets:
- name: cc-kpack-registry-auth-secret
- name: another-name-created-in-cluster
imagePullSecrets:
- name: cc-kpack-registry-auth-secret
  1. Try a rebase rule to ignore the second item from changes done in the cluster
- paths:
  - [secrets, {index: 1}]
  type: copy
  sources: [existing, new]
  resourceMatchers:
  - kindNamespaceNameMatcher:
      kind: ServiceAccount
      name: cc-kpack-registry-service-account
      namespace: cf-workloads-staging

NOTE using the path [secrets, {index: 1}, name] is not sufficient here. Kapp leaves behind an empty object {} at index position 1 which means it will always appear in the diff.

  1. Deploy and notice kapp crashes.

What happened: Kapp paniced and crashed when attempting to handle this rebase.

What did you expect: The rebase should use the object that is in array index 1 on the cluster. Which is an object of the structure { name: another-name-created-in-cluster }

Anything else you would like to add: Kapp should support rebasing whole objects from an array. If it does not then noise is created in diffs when a controller adds an object to the resources array.

This is important to us in our automated deployments as this noise cannot be removed from kapp which makes it hard to reason about actual changes being made to the cluster.

braunsonm avatar Feb 06 '21 01:02 braunsonm

When trying to deploy using the configuration files:

$ cat sa.yml
---
apiVersion: v1
kind: Namespace
metadata:
  name:  nice-namespace
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nice-sa
  namespace: nice-namespace
secrets:
- name: secret-1
- name: secret-2

$ cat cfg.yml
apiVersion: kapp.k14s.io/v1alpha1
kind: Config
rebaseRules:
- paths:
    - [secrets, {index: 1}]
  type: copy
  sources: [existing, new]
  resourceMatchers:
    - kindNamespaceNameMatcher:
        kind: ServiceAccount
        name: nice-sa
        namespace: nice-namespace

This is the stack trace of the panic:

goroutine 1 [running]:
github.com/k14s/kapp/pkg/kapp/resources.FieldCopyMod.apply(0x2137cc0, 0xc00041e900, 0xc000a469c0, 0x2, 0x4, 0xc000386040, 0x2, 0x4, 0x1dc8ba0, 0xc0004b34d0, ...)
	github.com/k14s/kapp/pkg/kapp/resources/mod_field_copy.go:77 +0xb85
github.com/k14s/kapp/pkg/kapp/resources.FieldCopyMod.ApplyFromMultiple(0x2137cc0, 0xc00041e900, 0xc000a469c0, 0x2, 0x4, 0xc000386040, 0x2, 0x4, 0x217e380, 0xc0009e3680, ...)
	github.com/k14s/kapp/pkg/kapp/resources/mod_field_copy.go:34 +0x168
github.com/k14s/kapp/pkg/kapp/diff.RebasedResource.Resource(0x217e380, 0xc0009e34a0, 0x217e380, 0xc0009e3590, 0xc0002da400, 0x17, 0x20, 0x217e380, 0xc0009e34a0, 0x217e380, ...)
	github.com/k14s/kapp/pkg/kapp/diff/rebased_resource.go:48 +0x202
github.com/k14s/kapp/pkg/kapp/diff.ChangeFactory.NewExactChange(0xc0002da400, 0x17, 0x20, 0xc00091a450, 0x1, 0x1, 0x217e380, 0xc0009e31d0, 0x217e380, 0xc0009e33b0, ...)
	github.com/k14s/kapp/pkg/kapp/diff/change_factory.go:83 +0xf5
github.com/k14s/kapp/pkg/kapp/diff.ResourceWithHistory.newExactHistorylessChange(0x217e380, 0xc0009e2d20, 0xc000550b40, 0xc00091a450, 0x1, 0x1, 0x217e380, 0xc0009e2f00, 0x217e380, 0xc0009e2e10, ...)
	github.com/k14s/kapp/pkg/kapp/diff/resource_with_history.go:177 +0x152
github.com/k14s/kapp/pkg/kapp/diff.ResourceWithHistory.recalculateLastAppliedChange(0x217e380, 0xc0009e2d20, 0xc000550b40, 0xc00091a450, 0x1, 0x1, 0x203000, 0xa, 0x8, 0x8, ...)
	github.com/k14s/kapp/pkg/kapp/diff/resource_with_history.go:150 +0x1e5
github.com/k14s/kapp/pkg/kapp/diff.ResourceWithHistory.LastAppliedResource(0x217e380, 0xc0009e2d20, 0xc000550b40, 0xc00091a450, 0x1, 0x1, 0xa6e28f0, 0xc0006c3e01)
	github.com/k14s/kapp/pkg/kapp/diff/resource_with_history.go:47 +0x5d
github.com/k14s/kapp/pkg/kapp/diff.ChangeFactory.NewChangeAgainstLastApplied(0xc0002da400, 0x17, 0x20, 0xc00091a450, 0x1, 0x1, 0x217e380, 0xc0004503c0, 0x217e380, 0xc0004500f0, ...)
	github.com/k14s/kapp/pkg/kapp/diff/change_factory.go:30 +0x4c5
github.com/k14s/kapp/pkg/kapp/diff.ChangeSet.Calculate(0xc00041e9e0, 0x2, 0x2, 0xc00041ea00, 0x2, 0x2, 0x1, 0xc0002da400, 0x17, 0x20, ...)
	github.com/k14s/kapp/pkg/kapp/diff/change_set.go:52 +0x784
github.com/k14s/kapp/pkg/kapp/diff.ChangeSetWithVersionedRs.Calculate(0xc000759e40, 0x2, 0x2, 0xc00055bc00, 0x2, 0x2, 0xc000b118c0, 0x2, 0x2, 0x1, ...)
	github.com/k14s/kapp/pkg/kapp/diff/change_set_with_versioned_rs.go:68 +0x578
github.com/k14s/kapp/pkg/kapp/cmd/app.(*DeployOptions).calculateAndPresentChanges(0xc00003ca00, 0xc000759e40, 0x2, 0x2, 0xc00055bc00, 0x2, 0x2, 0xc000a36900, 0x2, 0x2, ...)
	github.com/k14s/kapp/pkg/kapp/cmd/app/deploy.go:325 +0x418
github.com/k14s/kapp/pkg/kapp/cmd/app.(*DeployOptions).Run(0xc00003ca00, 0x0, 0x0)
	github.com/k14s/kapp/pkg/kapp/cmd/app/deploy.go:143 +0x7f9
github.com/k14s/kapp/pkg/kapp/cmd/app.NewDeployCmd.func1(0xc0000fd080, 0xc000012ea0, 0x0, 0x6, 0xc0006a6b80, 0x2158000)
	github.com/k14s/kapp/pkg/kapp/cmd/app/deploy.go:54 +0x2a
github.com/k14s/kapp/pkg/kapp/cmd.NewKappCmd.func1.1(0xc0000fd080, 0xc000012ea0, 0x0, 0x6, 0x0, 0x0)
	github.com/k14s/kapp/pkg/kapp/cmd/kapp.go:124 +0xb8
github.com/cppforlife/cobrautil.WrapRunEForCmd.func1.1(0xc0000fd080, 0xc000012ea0, 0x0, 0x6, 0x0, 0x0)
	github.com/cppforlife/[email protected]/misc.go:45 +0xaf
github.com/cppforlife/cobrautil.WrapRunEForCmd.func1.1(0xc0000fd080, 0xc000012ea0, 0x0, 0x6, 0x0, 0x0)
	github.com/cppforlife/[email protected]/misc.go:45 +0xaf
github.com/cppforlife/cobrautil.WrapRunEForCmd.func1.1(0xc0000fd080, 0xc000012ea0, 0x0, 0x6, 0x0, 0x0)
	github.com/cppforlife/[email protected]/misc.go:45 +0xaf
github.com/spf13/cobra.(*Command).execute(0xc0000fd080, 0xc000012e40, 0x6, 0x6, 0xc0000fd080, 0xc000012e40)
	github.com/spf13/[email protected]/command.go:850 +0x47c
github.com/spf13/cobra.(*Command).ExecuteC(0xc0000fc2c0, 0xc0000fc2c0, 0xc0000ba0c0, 0x0)
	github.com/spf13/[email protected]/command.go:958 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/[email protected]/command.go:895
main.nonExitingMain(0x0, 0x0)
	github.com/k14s/kapp/cmd/kapp/kapp.go:42 +0x166
main.main()
	github.com/k14s/kapp/cmd/kapp/kapp.go:21 +0x26

joaopapereira avatar Feb 10 '21 15:02 joaopapereira