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

Avoid listing labeled resources for newly created app #659

Merged
merged 3 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion pkg/kapp/app/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type App interface {
UsedGKs() (*[]schema.GroupKind, error)
UpdateUsedGVsAndGKs([]schema.GroupVersion, []schema.GroupKind) error

CreateOrUpdate(map[string]string, bool) error
CreateOrUpdate(map[string]string, bool) (bool, error)
Exists() (bool, string, error)
Delete() error
Rename(string, string) error
Expand Down
6 changes: 4 additions & 2 deletions pkg/kapp/app/labeled_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ func (a *LabeledApp) UsedGVs() ([]schema.GroupVersion, error)
func (a *LabeledApp) UsedGKs() (*[]schema.GroupKind, error) { return nil, nil }
func (a *LabeledApp) UpdateUsedGVsAndGKs([]schema.GroupVersion, []schema.GroupKind) error { return nil }

func (a *LabeledApp) CreateOrUpdate(labels map[string]string, isDiffRun bool) error { return nil }
func (a *LabeledApp) Exists() (bool, string, error) { return true, "", nil }
func (a *LabeledApp) CreateOrUpdate(labels map[string]string, isDiffRun bool) (bool, error) {
return false, nil
}
func (a *LabeledApp) Exists() (bool, string, error) { return true, "", nil }

func (a *LabeledApp) Delete() error {
labelSelector, err := a.LabelSelector()
Expand Down
14 changes: 7 additions & 7 deletions pkg/kapp/app/recorded_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,32 +127,32 @@ func (a *RecordedApp) UpdateUsedGVsAndGKs(gvs []schema.GroupVersion, gks []schem
})
}

func (a *RecordedApp) CreateOrUpdate(labels map[string]string, isDiffRun bool) error {
func (a *RecordedApp) CreateOrUpdate(labels map[string]string, isDiffRun bool) (bool, error) {
defer a.logger.DebugFunc("CreateOrUpdate").Finish()

app, foundMigratedApp, err := a.find(a.fqName())
if err != nil {
return err
return false, err
}

if foundMigratedApp {
a.isMigrated = true
return a.updateApp(app, labels)
return false, a.updateApp(app, labels)
}

app, foundNonMigratedApp, err := a.find(a.name)
if err != nil {
return err
return false, err
}

if foundNonMigratedApp {
if a.isMigrationEnabled() {
return a.migrate(app, labels, a.fqName())
return false, a.migrate(app, labels, a.fqName())
}
return a.updateApp(app, labels)
return false, a.updateApp(app, labels)
}

return a.create(labels, isDiffRun)
return true, a.create(labels, isDiffRun)
}

func (a *RecordedApp) find(name string) (*corev1.ConfigMap, bool, error) {
Expand Down
8 changes: 5 additions & 3 deletions pkg/kapp/cmd/app/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func NewDeployCmd(o *DeployOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Co
}

func (o *DeployOptions) Run() error {
var newApp bool
kumaritanushree marked this conversation as resolved.
Show resolved Hide resolved
failingAPIServicesPolicy := o.ResourceTypesFlags.FailingAPIServicePolicy()

app, supportObjs, err := Factory(o.depsFactory, o.AppFlags, o.ResourceTypesFlags, o.logger)
Expand All @@ -107,7 +108,7 @@ func (o *DeployOptions) Run() error {
if o.PrevAppFlags.PrevAppName != "" {
err = app.RenamePrevApp(o.PrevAppFlags.PrevAppName, appLabels, o.DiffFlags.Run)
} else {
err = app.CreateOrUpdate(appLabels, o.DiffFlags.Run)
newApp, err = app.CreateOrUpdate(appLabels, o.DiffFlags.Run)
kumaritanushree marked this conversation as resolved.
Show resolved Hide resolved
}

if err != nil {
Expand Down Expand Up @@ -158,7 +159,7 @@ func (o *DeployOptions) Run() error {
}

existingResources, existingPodRs, err := o.existingResources(
newResources, labeledResources, resourceFilter, supportObjs.Apps, usedGKs, append(meta.LastChange.Namespaces, nsNames...))
newResources, labeledResources, resourceFilter, supportObjs.Apps, usedGKs, append(meta.LastChange.Namespaces, nsNames...), newApp)
kumaritanushree marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
Expand Down Expand Up @@ -352,7 +353,7 @@ func (o *DeployOptions) newResourcesFromFiles() ([]ctlres.Resource, error) {

func (o *DeployOptions) existingResources(newResources []ctlres.Resource,
labeledResources *ctlres.LabeledResources, resourceFilter ctlres.ResourceFilter,
apps ctlapp.Apps, usedGKs []schema.GroupKind, resourceNamespaces []string) ([]ctlres.Resource, []ctlres.Resource, error) {
apps ctlapp.Apps, usedGKs []schema.GroupKind, resourceNamespaces []string, newApp bool) ([]ctlres.Resource, []ctlres.Resource, error) {

labelErrorResolutionFunc := func(key string, val string) string {
items, _ := apps.List(nil)
Expand All @@ -378,6 +379,7 @@ func (o *DeployOptions) existingResources(newResources []ctlres.Resource,
IdentifiedResourcesListOpts: ctlres.IdentifiedResourcesListOpts{
GKsScope: usedGKs,
ResourceNamespaces: resourceNamespaces,
NewApp: newApp,
kumaritanushree marked this conversation as resolved.
Show resolved Hide resolved
},
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/kapp/resources/identified_resources_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type IdentifiedResourcesListOpts struct {
IgnoreCachedResTypes bool
GKsScope []schema.GroupKind
ResourceNamespaces []string
NewApp bool
}

func (r IdentifiedResources) List(labelSelector labels.Selector, resRefs []ResourceRef, opts IdentifiedResourcesListOpts) ([]Resource, error) {
Expand All @@ -25,6 +26,11 @@ func (r IdentifiedResources) List(labelSelector labels.Selector, resRefs []Resou
return nil, err
}

// avoid listing labeled resources for newly created app
if opts.NewApp {
return nil, nil
}
kumaritanushree marked this conversation as resolved.
Show resolved Hide resolved

// TODO non-listable types
resTypes = Listable(resTypes)

Expand Down