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

Support for server side apply #392

Open
wants to merge 49 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
fd0f790
Adds e2e test for simple server side apply merge case
redbaron Dec 10, 2021
176ebb5
Embeddable E2E tests
redbaron Dec 13, 2021
20bd0a6
First basic SSA support
redbaron Dec 13, 2021
27e77f8
Fix tests compilation
redbaron Dec 14, 2021
6884b1e
Make linter happy
redbaron Dec 14, 2021
7de82bd
Fix diffing logic so that it never diffs managed fields
redbaron Dec 14, 2021
1f77748
Cosmetic changes to address feedback
redbaron Dec 15, 2021
5ff0cd5
Remove unused field
redbaron Dec 15, 2021
a1b7202
Don't strip history in ChangeFactory.NewChangeSSA because it won't sh…
redbaron Dec 15, 2021
e7b4682
Another fix for NewChangeAgainstLastApplied to prevent history showin…
redbaron Dec 16, 2021
d17a09e
Move dryRun to PatchOpts struct
redbaron Dec 16, 2021
868d362
Make RunEmbedded to fail tests on error
redbaron Dec 16, 2021
6a42593
Adjust tests to reflect that history is not passed to rebasing rules
redbaron Dec 16, 2021
3c0ba71
Add SSA support for diff command. Check CLI flags for conflicts
redbaron Dec 16, 2021
1e81fce
Add copyright and license header
redbaron Dec 16, 2021
df4a333
Run all e2e tests as kapp subprocess. Remove unnecessary error check.
redbaron Dec 16, 2021
307bbe9
Fix diff generation for versioned renamed objects
redbaron Dec 16, 2021
8eb9d07
Support enabling SSA for E2E tests via env var globally
redbaron Dec 17, 2021
c11badb
Fix panic in delete
redbaron Dec 17, 2021
5a5d997
When SSA enabled, dry run object creation to get most accurate diff
redbaron Jan 7, 2022
5b6b056
Enable SSA during tests only if KAPPP_E2E_SSA is set to 1
redbaron Jan 7, 2022
d2a434b
Make IdentifierResources.Patch method to return Resource with strippe…
redbaron Jan 7, 2022
7745d81
Persist history using Patch instead of Update call.
redbaron Jan 7, 2022
9a6b41f
FIXME: Temporarily remove Create dry run, because it wasn't dry run a…
redbaron Jan 7, 2022
8488060
Fixme IdentifierResources.Patch method
redbaron Jan 7, 2022
de9dca5
Fixme Persist history using Patch
redbaron Jan 7, 2022
a135136
Add support for SSA to 'Add*' strategies
redbaron Jan 10, 2022
f203cec
Clear history when creating SSA change
redbaron Jan 10, 2022
977df6f
Drop ChangeSSA as it becomes exactly like ChangeImpl. Use latter inst…
redbaron Jan 10, 2022
c97d804
env.Namespace some of the tests
redbaron Jan 10, 2022
e8bcfcb
Skip diff comparison in template test.
redbaron Jan 10, 2022
1033a23
Carry on generating SSA change even if attempting to make an invalid …
redbaron Jan 10, 2022
632638e
env.Namespace more tests
redbaron Jan 10, 2022
6af080b
Skip conflict rebasing test in SSA mode
redbaron Jan 10, 2022
c01292c
env.Namespace more tests
redbaron Jan 10, 2022
c6d868e
Use JSON merge patch when recording history
redbaron Jan 10, 2022
527553b
Add SSASkip and comments
redbaron Jan 11, 2022
c98601d
Run E2E tests in SSA and non-SSA mode
redbaron Jan 11, 2022
4301a35
Fix nil panic in tests
redbaron Jan 11, 2022
2c4cb43
Remove RunEmbedded leftovers in e2e tests
redbaron Jan 11, 2022
6fd31bd
Use FieldManagerName from CLI args in the AddPlainStrategy
redbaron Jan 11, 2022
c9be433
Add support for ssa-force flag
redbaron Jan 11, 2022
8a952e0
Make linter happy
redbaron Jan 11, 2022
3a9a9fc
Remove unused file
redbaron Jan 11, 2022
389316e
Smallest nits
redbaron Jan 20, 2022
96fb26c
Localize force param value calculation
redbaron Jan 20, 2022
9795527
Duplicate SSAFlags in SSAOpts and move them back to cmd/tools
redbaron Jan 20, 2022
f94e5b3
Remove dead code
redbaron Jan 20, 2022
9c5d0ea
Don't try to resolve update conflict when using SSA
redbaron Jan 20, 2022
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
36 changes: 31 additions & 5 deletions pkg/kapp/clusterapply/add_or_update_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
package clusterapply

import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/types"
"time"

ctldiff "github.com/k14s/kapp/pkg/kapp/diff"
Expand All @@ -26,7 +28,9 @@ const (
)

type AddOrUpdateChangeOpts struct {
DefaultUpdateStrategy string
DefaultUpdateStrategy string
ServerSideApply bool
ServerSideForceConflict bool
}

type AddOrUpdateChange struct {
Expand Down Expand Up @@ -131,7 +135,7 @@ func (c AddOrUpdateChange) tryToResolveUpdateConflict(
changeSet := c.changeSetFactory.New([]ctlres.Resource{latestExistingRes},
[]ctlres.Resource{c.change.AppliedResource()})

recalcChanges, err := changeSet.Calculate()
recalcChanges, err := changeSet.Calculate(context.TODO())
if err != nil {
return err
}
Expand Down Expand Up @@ -172,7 +176,7 @@ func (c AddOrUpdateChange) tryToUpdateAfterCreateConflict() error {
changeSet := c.changeSetFactory.New([]ctlres.Resource{latestExistingRes},
[]ctlres.Resource{c.change.AppliedResource()})

recalcChanges, err := changeSet.Calculate()
recalcChanges, err := changeSet.Calculate(context.TODO())
if err != nil {
return err
}
Expand Down Expand Up @@ -295,7 +299,17 @@ type UpdatePlainStrategy struct {
func (c UpdatePlainStrategy) Op() ClusterChangeApplyStrategyOp { return updateStrategyPlainAnnValue }

func (c UpdatePlainStrategy) Apply() error {
updatedRes, err := c.aou.identifiedResources.Update(c.newRes)
var updatedRes ctlres.Resource
var err error

if c.aou.opts.ServerSideApply {
updatedRes, err = ctlres.WithIdentityAnnotation(c.newRes, func(r ctlres.Resource) (ctlres.Resource, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems that we have two types of Patch operations: one where we are working with a resource, and one where we are working with some "minimal/raw" patch. instead of exposing WithIdentityAnnotation outside of IdentifiedResources resources class, lets keep existing Patch method to work with Resource class (instead of []byte) and change it so that it can add annotation on the fly. lets also add PatchRaw which does take []byte. this should result in keeping WithIdentityAnnotation as private.

resBytes, _ := r.AsYAMLBytes()
redbaron marked this conversation as resolved.
Show resolved Hide resolved
return c.aou.identifiedResources.Patch(r, types.ApplyPatchType, resBytes)
})
} else {
updatedRes, err = c.aou.identifiedResources.Update(c.newRes)
Copy link
Contributor

Choose a reason for hiding this comment

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

should we be tryToResolveUpdateConflict doing when SSA is on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. tryToResolveUpdateConflict recalculates Change from a new existing resource. In case of SSA only conflict we can have is when we are conflicting with another fieldManager, no amount of new diffing going to help here.

}
if err != nil {
if errors.IsConflict(err) {
return c.aou.tryToResolveUpdateConflict(err, func(err error) error { return err })
Expand Down Expand Up @@ -323,8 +337,20 @@ func (c UpdateOrFallbackOnReplaceStrategy) Apply() error {
return err
}

updatedRes, err := c.aou.identifiedResources.Update(c.newRes)
var updatedRes ctlres.Resource
var err error

if c.aou.opts.ServerSideApply {
updatedRes, err = ctlres.WithIdentityAnnotation(c.newRes, func(r ctlres.Resource) (ctlres.Resource, error) {
resBytes, _ := r.AsYAMLBytes()
return c.aou.identifiedResources.Patch(r, types.ApplyPatchType, resBytes)
})
} else {
updatedRes, err = c.aou.identifiedResources.Update(c.newRes)
}

if err != nil {
//TODO: find out if SSA conflicts worth retrying
if errors.IsConflict(err) {
return c.aou.tryToResolveUpdateConflict(err, replaceIfIsInvalidErrFunc)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/kapp/cmd/app/apply_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type ApplyFlags struct {
ctlcap.ClusterChangeSetOpts
ctlcap.ClusterChangeOpts

FieldManagerName string

ExitStatus bool
}

Expand Down Expand Up @@ -62,6 +64,10 @@ func (s *ApplyFlags) SetWithDefaults(prefix string, defaults ApplyFlags, cmd *co
cmd.Flags().IntVar(&s.WaitingChangesOpts.Concurrency, prefix+"wait-concurrency",
5, "Maximum number of concurrent wait operations")

cmd.Flags().BoolVar(&s.ServerSideApply, prefix+"server-side", false, "If true, apply runs in the server instead of the client")
cmd.Flags().StringVar(&s.FieldManagerName, prefix+"field-manager", "kapp-server-side-apply", "Name of the manager used to track field ownership")
cmd.Flags().BoolVar(&s.ServerSideForceConflict, prefix+"force-conflicts", false, "If true, server-side apply will force the changes against conflicts.")
redbaron marked this conversation as resolved.
Show resolved Hide resolved

cmd.Flags().BoolVar(&s.ExitStatus, prefix+"apply-exit-status", false, "Return specific exit status based on number of changes")
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/kapp/cmd/app/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewDeleteCmd(o *DeleteOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Co
func (o *DeleteOptions) Run() error {
failingAPIServicesPolicy := o.ResourceTypesFlags.FailingAPIServicePolicy()

app, supportObjs, err := Factory(o.depsFactory, o.AppFlags, o.ResourceTypesFlags, o.logger)
app, supportObjs, err := Factory(o.depsFactory, o.AppFlags, o.ResourceTypesFlags, o.logger, &o.ApplyFlags.FieldManagerName)
if err != nil {
return err
}
Expand Down Expand Up @@ -189,10 +189,10 @@ func (o *DeleteOptions) calculateAndPresentChanges(existingResources []ctlres.Re
)

{ // Figure out changes for X existing resources -> 0 new resources
changeFactory := ctldiff.NewChangeFactory(nil, nil)
changeFactory := ctldiff.NewChangeFactory(nil, nil, supportObjs.Resources)
changeSetFactory := ctldiff.NewChangeSetFactory(o.DiffFlags.ChangeSetOpts, changeFactory)

changes, err := changeSetFactory.New(existingResources, nil).Calculate()
changes, err := changeSetFactory.New(existingResources, nil).Calculate(nil)
if err != nil {
return ctlcap.ClusterChangeSet{}, nil, changesSummary{}, err
}
Expand Down
23 changes: 16 additions & 7 deletions pkg/kapp/cmd/app/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package app

import (
"context"
"fmt"
"sort"
"strings"
Expand Down Expand Up @@ -51,7 +52,12 @@ func NewDeployCmd(o *DeployOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Co
Use: "deploy",
Aliases: []string{"d", "dep"},
Short: "Deploy app",
RunE: func(_ *cobra.Command, _ []string) error { return o.Run() },
RunE: func(_ *cobra.Command, _ []string) error {
if o.ApplyFlags.ServerSideApply {
o.DiffFlags.ChangeSetOpts.Mode = ctldiff.ServerSideApplyChangeSetMode
}
Copy link
Contributor

Choose a reason for hiding this comment

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

not a fan of doing it in RunE, lets move this into Run()... (also going to see if there is a better place for this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I plan to add flag validation step and return error, rather than silently overwriting values provided by user, so it should be a RunE I believe because it can return error.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we could move these validations to the Run()function as it returns an error and let the command initialisation have

RunE:    func(_ *cobra.Command, _ []string) error { return o.Run() }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to PreRunE

return o.Run()
},
Annotations: map[string]string{
cmdcore.AppHelpGroup.Key: cmdcore.AppHelpGroup.Value,
},
Expand All @@ -72,9 +78,10 @@ func NewDeployCmd(o *DeployOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Co

o.AppFlags.Set(cmd, flagsFactory)
o.FileFlags.Set(cmd)
o.DiffFlags.SetWithPrefix("diff", cmd)
o.ResourceFilterFlags.Set(cmd)
o.ApplyFlags.SetWithDefaults("", ApplyFlagsDeployDefaults, cmd)
o.DiffFlags.SetWithPrefix("diff", cmd)

o.DeployFlags.Set(cmd)
o.ResourceTypesFlags.Set(cmd)
o.LabelFlags.Set(cmd)
Expand All @@ -83,9 +90,11 @@ func NewDeployCmd(o *DeployOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Co
}

func (o *DeployOptions) Run() error {
ctx := context.Background()

failingAPIServicesPolicy := o.ResourceTypesFlags.FailingAPIServicePolicy()

app, supportObjs, err := Factory(o.depsFactory, o.AppFlags, o.ResourceTypesFlags, o.logger)
app, supportObjs, err := Factory(o.depsFactory, o.AppFlags, o.ResourceTypesFlags, o.logger, &o.ApplyFlags.FieldManagerName)
if err != nil {
return err
}
Expand Down Expand Up @@ -140,7 +149,7 @@ func (o *DeployOptions) Run() error {
}

clusterChangeSet, clusterChangesGraph, hasNoChanges, changeSummary, err :=
o.calculateAndPresentChanges(existingResources, newResources, conf, supportObjs)
o.calculateAndPresentChanges(ctx, existingResources, newResources, conf, supportObjs)
if err != nil {
if o.DiffFlags.UI && clusterChangesGraph != nil {
return o.presentDiffUI(clusterChangesGraph)
Expand Down Expand Up @@ -315,19 +324,19 @@ func (o *DeployOptions) existingResources(newResources []ctlres.Resource,
return resourceFilter.Apply(existingResources), o.existingPodResources(existingResources), nil
}

func (o *DeployOptions) calculateAndPresentChanges(existingResources,
func (o *DeployOptions) calculateAndPresentChanges(ctx context.Context, existingResources,
newResources []ctlres.Resource, conf ctlconf.Conf, supportObjs FactorySupportObjs) (
ctlcap.ClusterChangeSet, *ctldgraph.ChangeGraph, bool, string, error) {

var clusterChangeSet ctlcap.ClusterChangeSet

{ // Figure out changes for X existing resources -> X new resources
changeFactory := ctldiff.NewChangeFactory(conf.RebaseMods(), conf.DiffAgainstLastAppliedFieldExclusionMods())
changeFactory := ctldiff.NewChangeFactory(conf.RebaseMods(), conf.DiffAgainstLastAppliedFieldExclusionMods(), supportObjs.Resources)
changeSetFactory := ctldiff.NewChangeSetFactory(o.DiffFlags.ChangeSetOpts, changeFactory)

changes, err := ctldiff.NewChangeSetWithVersionedRs(
existingResources, newResources, conf.TemplateRules(),
o.DiffFlags.ChangeSetOpts, changeFactory).Calculate()
o.DiffFlags.ChangeSetOpts, changeFactory).Calculate(ctx)
if err != nil {
return clusterChangeSet, nil, false, "", err
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/kapp/cmd/app/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ type FactorySupportObjs struct {
CoreClient kubernetes.Interface
ResourceTypes *ctlres.ResourceTypesImpl
IdentifiedResources ctlres.IdentifiedResources
Resources ctlres.Resources
redbaron marked this conversation as resolved.
Show resolved Hide resolved
Apps ctlapp.Apps
}

func FactoryClients(depsFactory cmdcore.DepsFactory, nsFlags cmdcore.NamespaceFlags,
resTypesFlags ResourceTypesFlags, logger logger.Logger) (FactorySupportObjs, error) {
resTypesFlags ResourceTypesFlags, logger logger.Logger, fieldManagerName *string) (FactorySupportObjs, error) {

coreClient, err := depsFactory.CoreClient()
if err != nil {
Expand All @@ -44,6 +45,7 @@ func FactoryClients(depsFactory cmdcore.DepsFactory, nsFlags cmdcore.NamespaceFl
resourcesImplOpts := ctlres.ResourcesImplOpts{
FallbackAllowedNamespaces: []string{nsFlags.Name},
ScopeToFallbackAllowedNamespaces: resTypesFlags.ScopeToFallbackAllowedNamespaces,
FieldManagerName: fieldManagerName,
}

resources := ctlres.NewResourcesImpl(
Expand All @@ -56,16 +58,17 @@ func FactoryClients(depsFactory cmdcore.DepsFactory, nsFlags cmdcore.NamespaceFl
CoreClient: coreClient,
ResourceTypes: resTypes,
IdentifiedResources: identifiedResources,
Resources: resources,
redbaron marked this conversation as resolved.
Show resolved Hide resolved
Apps: ctlapp.NewApps(nsFlags.Name, coreClient, identifiedResources, logger),
}

return result, nil
}

func Factory(depsFactory cmdcore.DepsFactory, appFlags Flags,
resTypesFlags ResourceTypesFlags, logger logger.Logger) (ctlapp.App, FactorySupportObjs, error) {
resTypesFlags ResourceTypesFlags, logger logger.Logger, fieldManagerName *string) (ctlapp.App, FactorySupportObjs, error) {

supportingObjs, err := FactoryClients(depsFactory, appFlags.NamespaceFlags, resTypesFlags, logger)
supportingObjs, err := FactoryClients(depsFactory, appFlags.NamespaceFlags, resTypesFlags, logger, fieldManagerName)
if err != nil {
return nil, FactorySupportObjs{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kapp/cmd/app/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewInspectCmd(o *InspectOptions, flagsFactory cmdcore.FlagsFactory) *cobra.
func (o *InspectOptions) Run() error {
failingAPIServicesPolicy := o.ResourceTypesFlags.FailingAPIServicePolicy()

app, supportObjs, err := Factory(o.depsFactory, o.AppFlags, o.ResourceTypesFlags, o.logger)
app, supportObjs, err := Factory(o.depsFactory, o.AppFlags, o.ResourceTypesFlags, o.logger, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kapp/cmd/app/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewLabelCmd(o *LabelOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Comm
}

func (o *LabelOptions) Run() error {
app, _, err := Factory(o.depsFactory, o.AppFlags, ResourceTypesFlags{}, o.logger)
app, _, err := Factory(o.depsFactory, o.AppFlags, ResourceTypesFlags{}, o.logger, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kapp/cmd/app/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (o *ListOptions) Run() error {
nsHeader.Hidden = false
}

supportObjs, err := FactoryClients(o.depsFactory, o.NamespaceFlags, ResourceTypesFlags{}, o.logger)
supportObjs, err := FactoryClients(o.depsFactory, o.NamespaceFlags, ResourceTypesFlags{}, o.logger, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kapp/cmd/app/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (o *LogsOptions) Run() error {
return err
}

app, supportObjs, err := Factory(o.depsFactory, o.AppFlags, ResourceTypesFlags{}, o.logger)
app, supportObjs, err := Factory(o.depsFactory, o.AppFlags, ResourceTypesFlags{}, o.logger, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kapp/cmd/app/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewRenameCmd(o *RenameOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Co
}

func (o *RenameOptions) Run() error {
app, _, err := Factory(o.depsFactory, o.AppFlags, ResourceTypesFlags{}, o.logger)
app, _, err := Factory(o.depsFactory, o.AppFlags, ResourceTypesFlags{}, o.logger, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kapp/cmd/appchange/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewGCCmd(o *GCOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Command {
}

func (o *GCOptions) Run() error {
app, _, err := cmdapp.Factory(o.depsFactory, o.AppFlags, cmdapp.ResourceTypesFlags{}, o.logger)
app, _, err := cmdapp.Factory(o.depsFactory, o.AppFlags, cmdapp.ResourceTypesFlags{}, o.logger, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kapp/cmd/appchange/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewListCmd(o *ListOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Comman
}

func (o *ListOptions) Run() error {
app, _, err := cmdapp.Factory(o.depsFactory, o.AppFlags, cmdapp.ResourceTypesFlags{}, o.logger)
app, _, err := cmdapp.Factory(o.depsFactory, o.AppFlags, cmdapp.ResourceTypesFlags{}, o.logger, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kapp/cmd/appgroup/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (o *DeleteOptions) Run() error {
return fmt.Errorf("Expected group name to be non-empty")
}

supportObjs, err := cmdapp.FactoryClients(o.depsFactory, o.AppGroupFlags.NamespaceFlags, cmdapp.ResourceTypesFlags{}, o.logger)
supportObjs, err := cmdapp.FactoryClients(o.depsFactory, o.AppGroupFlags.NamespaceFlags, cmdapp.ResourceTypesFlags{}, o.logger, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kapp/cmd/appgroup/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (o *DeployOptions) Run() error {
}
}

supportObjs, err := cmdapp.FactoryClients(o.depsFactory, o.AppGroupFlags.NamespaceFlags, cmdapp.ResourceTypesFlags{}, o.logger)
supportObjs, err := cmdapp.FactoryClients(o.depsFactory, o.AppGroupFlags.NamespaceFlags, cmdapp.ResourceTypesFlags{}, o.logger, &o.AppFlags.ApplyFlags.FieldManagerName)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kapp/cmd/configmap/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewListCmd(o *ListOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Comman
}

func (o *ListOptions) Run() error {
app, supportObjs, err := cmdapp.Factory(o.depsFactory, o.AppFlags, cmdapp.ResourceTypesFlags{}, o.logger)
app, supportObjs, err := cmdapp.Factory(o.depsFactory, o.AppFlags, cmdapp.ResourceTypesFlags{}, o.logger, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kapp/cmd/serviceaccount/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewListCmd(o *ListOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Comman
}

func (o *ListOptions) Run() error {
app, supportObjs, err := cmdapp.Factory(o.depsFactory, o.AppFlags, cmdapp.ResourceTypesFlags{}, o.logger)
app, supportObjs, err := cmdapp.Factory(o.depsFactory, o.AppFlags, cmdapp.ResourceTypesFlags{}, o.logger, nil)
if err != nil {
return err
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/kapp/cmd/tools/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package tools

import (
"context"
"github.com/cppforlife/go-cli-ui/ui"
ctlcap "github.com/k14s/kapp/pkg/kapp/clusterapply"
cmdcore "github.com/k14s/kapp/pkg/kapp/cmd/core"
Expand Down Expand Up @@ -33,11 +34,15 @@ func NewDiffCmd(o *DiffOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Comman
}
o.FileFlags.Set(cmd)
o.FileFlags2.Set(cmd)

//TODO: support for the server side apply in diff command
o.DiffFlags.SetWithPrefix("", cmd)
return cmd
}

func (o *DiffOptions) Run() error {
ctx := context.Background()

newResources, err := o.fileResources(o.FileFlags.Files)
if err != nil {
return err
Expand All @@ -48,9 +53,9 @@ func (o *DiffOptions) Run() error {
return err
}

changeFactory := ctldiff.NewChangeFactory(nil, nil)
changeFactory := ctldiff.NewChangeFactory(nil, nil, nil)

changes, err := ctldiff.NewChangeSet(existingResources, newResources, o.DiffFlags.ChangeSetOpts, changeFactory).Calculate()
changes, err := ctldiff.NewChangeSet(existingResources, newResources, o.DiffFlags.ChangeSetOpts, changeFactory).Calculate(ctx)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/kapp/cmd/tools/diff_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ func (s *DiffFlags) SetWithPrefix(prefix string, cmd *cobra.Command) {
cmd.Flags().BoolVar(&s.LineNumbers, prefix+"line-numbers", true, "Show line numbers")
cmd.Flags().BoolVar(&s.Mask, prefix+"mask", true, "Apply masking rules")

cmd.Flags().BoolVar(&s.AgainstLastApplied, prefix+"against-last-applied", true, "Show changes against last applied copy when possible")
if *cmd.Flags().Bool(prefix+"against-last-applied", true, "Show changes against last applied copy when possible. (Conflicts with server-side apply)") {
s.ChangeSetOpts.Mode = ctldiff.AgainstLastAppliedChangeSetMode
} else {
s.ChangeSetOpts.Mode = ctldiff.ExactChangeSetMode
}

cmd.Flags().StringVar(&s.Filter, prefix+"filter", "", `Set changes filter (example: {"and":[{"ops":["update"]},{"existingResource":{"kinds":["Deployment"]}]})`)
}
Loading