Skip to content

Commit

Permalink
Merge CM update calls being made for GVs and GKs
Browse files Browse the repository at this point in the history
  • Loading branch information
100mik committed Feb 16, 2022
1 parent 7685e7b commit a00b486
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 39 deletions.
3 changes: 1 addition & 2 deletions pkg/kapp/app/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ type App interface {

LabelSelector() (labels.Selector, error)
UsedGVs() ([]schema.GroupVersion, error)
UpdateUsedGVs([]schema.GroupVersion) error
UsedGKs() (*[]schema.GroupKind, error)
UpdateUsedGKs([]schema.GroupKind) error
UpdateUsedGVsAndGKs([]schema.GroupVersion, []schema.GroupKind) error

CreateOrUpdate(map[string]string) error
Exists() (bool, string, error)
Expand Down
9 changes: 3 additions & 6 deletions pkg/kapp/app/labeled_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,9 @@ func (a *LabeledApp) LabelSelector() (labels.Selector, error) {
return a.labelSelector, nil
}

func (a *LabeledApp) UsedGVs() ([]schema.GroupVersion, error) { return nil, nil }
func (a *LabeledApp) UpdateUsedGVs(gvs []schema.GroupVersion) error { return nil }
func (a *LabeledApp) UsedGKs() (*[]schema.GroupKind, error) { return nil, nil }
func (a *LabeledApp) UpdateUsedGKs([]schema.GroupKind) error {
return nil
}
func (a *LabeledApp) UsedGVs() ([]schema.GroupVersion, error) { return nil, nil }
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) error { return nil }
func (a *LabeledApp) Exists() (bool, string, error) { return true, "", nil }
Expand Down
29 changes: 12 additions & 17 deletions pkg/kapp/app/recorded_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,6 @@ func (a *RecordedApp) UsedGVs() ([]schema.GroupVersion, error) {
return meta.UsedGVs, nil
}

func (a *RecordedApp) UpdateUsedGVs(gvs []schema.GroupVersion) error {
gvsByGV := map[schema.GroupVersion]struct{}{}
var uniqGVs []schema.GroupVersion

for _, gv := range gvs {
if _, found := gvsByGV[gv]; !found {
gvsByGV[gv] = struct{}{}
uniqGVs = append(uniqGVs, gv)
}
}

return a.update(func(meta *Meta) {
meta.UsedGVs = uniqGVs
})
}

func (a *RecordedApp) usedGKs() (*[]schema.GroupKind, error) {
meta, err := a.meta()
if err != nil {
Expand All @@ -92,7 +76,17 @@ func (a *RecordedApp) usedGKs() (*[]schema.GroupKind, error) {

func (a *RecordedApp) UsedGKs() (*[]schema.GroupKind, error) { return a.usedGKs() }

func (a *RecordedApp) UpdateUsedGKs(gks []schema.GroupKind) error {
func (a *RecordedApp) UpdateUsedGVsAndGKs(gvs []schema.GroupVersion, gks []schema.GroupKind) error {
gvsByGV := map[schema.GroupVersion]struct{}{}
var uniqGVs []schema.GroupVersion

for _, gv := range gvs {
if _, found := gvsByGV[gv]; !found {
gvsByGV[gv] = struct{}{}
uniqGVs = append(uniqGVs, gv)
}
}

gksByGK := map[schema.GroupKind]struct{}{}
var uniqGKs []schema.GroupKind

Expand All @@ -108,6 +102,7 @@ func (a *RecordedApp) UpdateUsedGKs(gks []schema.GroupKind) error {
})

return a.update(func(meta *Meta) {
meta.UsedGVs = uniqGVs
meta.UsedGKs = &uniqGKs
})
}
Expand Down
20 changes: 6 additions & 14 deletions pkg/kapp/cmd/app/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,9 @@ func (o *DeployOptions) Run() error {
return err
}

err = app.UpdateUsedGVs(failingAPIServicesPolicy.GVs(newResources, existingResources))
if err != nil {
return err
}

// Cache possibly untracked GKs in existing resources (handles older apps)
err = app.UpdateUsedGKs(NewUsedGKsScope(append(newResources, existingResources...)).GKs())
// Track newly added GVs and GKs
err = app.UpdateUsedGVsAndGKs(failingAPIServicesPolicy.GVs(newResources, existingResources),
NewUsedGKsScope(append(newResources, existingResources...)).GKs())
if err != nil {
return err
}
Expand Down Expand Up @@ -217,13 +213,9 @@ func (o *DeployOptions) Run() error {
return err
}

// Prunes unused GKs
err = app.UpdateUsedGKs(NewUsedGKsScope(newResources).GKs())
if err != nil {
return err
}

return app.UpdateUsedGVs(failingAPIServicesPolicy.GVs(newResources, nil))
// Remove unused GVs and GKs
return app.UpdateUsedGVsAndGKs(failingAPIServicesPolicy.GVs(newResources, nil),
NewUsedGKsScope(newResources).GKs())
})
if err != nil {
return err
Expand Down

0 comments on commit a00b486

Please sign in to comment.