Skip to content

Commit

Permalink
Merge branch 'carvel-dev:develop' into issue-472-2
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmadhankumar authored Sep 21, 2023
2 parents 02514c7 + 5dc9ceb commit 54941da
Show file tree
Hide file tree
Showing 268 changed files with 19,207 additions and 8,204 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.20.7
go-version: 1.21.1
- uses: actions/checkout@v2
with:
fetch-depth: '0'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.20.7
go-version: 1.21.1
- name: Retrieve version
run: |
echo "TAG_NAME=$(echo ${{ github.ref }} | grep -Eo 'v[0-9].*')" >> $GITHUB_OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-gh-k8s-1.16.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.20.7
go-version: 1.21.1
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-gh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.20.7
go-version: 1.21.1
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/trivy-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
with:
repo: carvel-dev/kapp
tool: kapp
goVersion: 1.20.7
goVersion: 1.21.1
secrets:
githubToken: ${{ secrets.GITHUB_TOKEN }}
slackWebhookURL: ${{ secrets.SLACK_WEBHOOK_URL }}
34 changes: 17 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/vmware-tanzu/carvel-kapp

go 1.20
go 1.21

require (
github.com/cppforlife/cobrautil v0.0.0-20221130162803-acdfead391ef
Expand All @@ -16,24 +16,24 @@ require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
github.com/vmware-tanzu/carvel-kapp-controller v0.46.2
golang.org/x/net v0.14.0
golang.org/x/net v0.15.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.27.4
k8s.io/apimachinery v0.27.4
k8s.io/client-go v0.27.4
k8s.io/api v0.28.2
k8s.io/apimachinery v0.28.2
k8s.io/client-go v0.28.2
sigs.k8s.io/yaml v1.3.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
Expand All @@ -51,18 +51,18 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/vito/go-interact v1.0.1 // indirect
github.com/vmware-tanzu/carvel-vendir v0.33.1 // indirect
golang.org/x/oauth2 v0.1.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)
100 changes: 46 additions & 54 deletions go.sum

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions pkg/kapp/app/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type ChangeImpl struct {
meta ChangeMeta

createdAt time.Time

appChangesMaxToKeep int
}

var _ Change = &ChangeImpl{}
Expand Down Expand Up @@ -55,6 +57,11 @@ func (c *ChangeImpl) Delete() error {
}

func (c *ChangeImpl) update(doFunc func(*ChangeMeta)) error {
if c.appChangesMaxToKeep == 0 {
doFunc(&c.meta)
return nil
}

change, err := c.coreClient.CoreV1().ConfigMaps(c.nsName).Get(context.TODO(), c.name, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("Getting app change: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kapp/app/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type App interface {
// Sorted as first is oldest
Changes() ([]Change, error)
LastChange() (Change, error)
BeginChange(ChangeMeta) (Change, error)
BeginChange(ChangeMeta, int) (Change, error)
GCChanges(max int, reviewFunc func(changesToDelete []Change) error) (int, int, error)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/kapp/app/labeled_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ func (a *LabeledApp) Rename(_ string, _ string) error { return fmt.Errorf("Not s

func (a *LabeledApp) Meta() (Meta, error) { return Meta{}, nil }

func (a *LabeledApp) Changes() ([]Change, error) { return nil, nil }
func (a *LabeledApp) LastChange() (Change, error) { return nil, nil }
func (a *LabeledApp) BeginChange(ChangeMeta) (Change, error) { return NoopChange{}, nil }
func (a *LabeledApp) Changes() ([]Change, error) { return nil, nil }
func (a *LabeledApp) LastChange() (Change, error) { return nil, nil }
func (a *LabeledApp) BeginChange(ChangeMeta, int) (Change, error) { return NoopChange{}, nil }
func (a *LabeledApp) GCChanges(_ int, _ func(changesToDelete []Change) error) (int, int, error) {
return 0, 0, nil
}
6 changes: 3 additions & 3 deletions pkg/kapp/app/recorded_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ func (a *RecordedApp) LastChange() (Change, error) {
return nil, err
}

if len(meta.LastChangeName) == 0 {
if meta.LastChange.Successful == nil {
return nil, nil
}

Expand All @@ -524,13 +524,13 @@ func (a *RecordedApp) LastChange() (Change, error) {
return change, nil
}

func (a *RecordedApp) BeginChange(meta ChangeMeta) (Change, error) {
func (a *RecordedApp) BeginChange(meta ChangeMeta, appChangesMaxToKeep int) (Change, error) {
appMeta, err := a.meta()
if err != nil {
return nil, err
}

change, err := NewRecordedAppChanges(a.nsName, a.name, appMeta.LabelValue, a.appChangesUseAppLabel, a.coreClient).Begin(meta)
change, err := NewRecordedAppChanges(a.nsName, a.name, appMeta.LabelValue, a.appChangesUseAppLabel, a.coreClient).Begin(meta, appChangesMaxToKeep)
if err != nil {
return nil, err
}
Expand Down
22 changes: 14 additions & 8 deletions pkg/kapp/app/recorded_app_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (a RecordedAppChanges) DeleteAll() error {
return nil
}

func (a RecordedAppChanges) Begin(meta ChangeMeta) (*ChangeImpl, error) {
func (a RecordedAppChanges) Begin(meta ChangeMeta, appChangesMaxToKeep int) (*ChangeImpl, error) {
newMeta := ChangeMeta{
StartedAt: time.Now().UTC(),
Description: meta.Description,
Expand All @@ -137,16 +137,22 @@ func (a RecordedAppChanges) Begin(meta ChangeMeta) (*ChangeImpl, error) {
configMap.ObjectMeta.Labels[legacyChangeLabelKey] = a.appName
}

createdChange, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Create(context.TODO(), configMap, metav1.CreateOptions{})
if err != nil {
return nil, fmt.Errorf("Creating app change: %w", err)
changeName := ""

if appChangesMaxToKeep > 0 {
createdChange, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Create(context.TODO(), configMap, metav1.CreateOptions{})
if err != nil {
return nil, fmt.Errorf("Creating app change: %w", err)
}
changeName = createdChange.Name
}

change := &ChangeImpl{
name: createdChange.Name,
nsName: createdChange.Namespace,
coreClient: a.coreClient,
meta: newMeta,
name: changeName,
nsName: a.nsName,
coreClient: a.coreClient,
meta: newMeta,
appChangesMaxToKeep: appChangesMaxToKeep,
}

return change, nil
Expand Down
4 changes: 3 additions & 1 deletion pkg/kapp/app/touch.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ type Touch struct {
Description string
Namespaces []string
IgnoreSuccessErr bool

AppChangesMaxToKeep int
}

func (t Touch) Do(doFunc func() error) error {
Expand All @@ -16,7 +18,7 @@ func (t Touch) Do(doFunc func() error) error {
Namespaces: t.Namespaces,
}

change, err := t.App.BeginChange(meta)
change, err := t.App.BeginChange(meta, t.AppChangesMaxToKeep)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/kapp/cmd/app/app_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import (
type Flags struct {
NamespaceFlags cmdcore.NamespaceFlags
Name string
AppNamespace string
}

func (s *Flags) Set(cmd *cobra.Command, flagsFactory cmdcore.FlagsFactory) {
s.NamespaceFlags.Set(cmd, flagsFactory)

cmd.Flags().StringVarP(&s.Name, "app", "a", s.Name, "Set app name (or label selector) (format: name, label:key=val, !key)")
cmd.Flags().StringVar(&s.AppNamespace, "app-namespace", s.AppNamespace, "Set app namespace (to store app state)")
}
9 changes: 5 additions & 4 deletions pkg/kapp/cmd/app/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,11 @@ func (o *DeployOptions) Run() error {
}()

touch := ctlapp.Touch{
App: app,
Description: "update: " + changeSummary,
Namespaces: nsNames,
IgnoreSuccessErr: true,
App: app,
Description: "update: " + changeSummary,
Namespaces: nsNames,
IgnoreSuccessErr: true,
AppChangesMaxToKeep: o.DeployFlags.AppChangesMaxToKeep,
}

err = touch.Do(func() error {
Expand Down
10 changes: 7 additions & 3 deletions pkg/kapp/cmd/app/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ type FactorySupportObjs struct {
Apps ctlapp.Apps
}

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

if appNamespace == "" {
appNamespace = nsFlags.Name
}

coreClient, err := depsFactory.CoreClient()
if err != nil {
return FactorySupportObjs{}, err
Expand Down Expand Up @@ -56,7 +60,7 @@ func FactoryClients(depsFactory cmdcore.DepsFactory, nsFlags cmdcore.NamespaceFl
CoreClient: coreClient,
ResourceTypes: resTypes,
IdentifiedResources: identifiedResources,
Apps: ctlapp.NewApps(nsFlags.Name, coreClient, identifiedResources, logger),
Apps: ctlapp.NewApps(appNamespace, coreClient, identifiedResources, logger),
}

return result, nil
Expand All @@ -65,7 +69,7 @@ func FactoryClients(depsFactory cmdcore.DepsFactory, nsFlags cmdcore.NamespaceFl
func Factory(depsFactory cmdcore.DepsFactory, appFlags Flags,
resTypesFlags ResourceTypesFlags, logger logger.Logger) (ctlapp.App, FactorySupportObjs, error) {

supportingObjs, err := FactoryClients(depsFactory, appFlags.NamespaceFlags, resTypesFlags, logger)
supportingObjs, err := FactoryClients(depsFactory, appFlags.NamespaceFlags, appFlags.AppNamespace, resTypesFlags, logger)
if err != nil {
return nil, FactorySupportObjs{}, 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 @@ -56,7 +56,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)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/kapp/cmd/appgroup/app_group_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import (
type Flags struct {
NamespaceFlags cmdcore.NamespaceFlags
Name string
AppNamespace string
}

func (s *Flags) Set(cmd *cobra.Command, flagsFactory cmdcore.FlagsFactory) {
s.NamespaceFlags.Set(cmd, flagsFactory)

cmd.Flags().StringVarP(&s.Name, "group", "g", "", "Set app group name")
cmd.Flags().StringVar(&s.AppNamespace, "app-namespace", s.AppNamespace, "Set app namespace (to store app state)")
}
12 changes: 10 additions & 2 deletions pkg/kapp/cmd/appgroup/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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, o.AppGroupFlags.AppNamespace, cmdapp.ResourceTypesFlags{}, o.logger)
if err != nil {
return err
}
Expand All @@ -77,15 +77,23 @@ func (o *DeleteOptions) Run() error {

func (o *DeleteOptions) deleteApp(name string) error {
o.ui.PrintLinef("--- deleting app '%s' (namespace: %s)",
name, o.AppGroupFlags.NamespaceFlags.Name)
name, o.appNamespace())

deleteOpts := cmdapp.NewDeleteOptions(o.ui, o.depsFactory, o.logger)
deleteOpts.AppFlags = cmdapp.Flags{
Name: name,
NamespaceFlags: o.AppGroupFlags.NamespaceFlags,
AppNamespace: o.AppGroupFlags.AppNamespace,
}
deleteOpts.DiffFlags = o.AppFlags.DiffFlags
deleteOpts.ApplyFlags = o.AppFlags.ApplyFlags

return deleteOpts.Run()
}

func (o *DeleteOptions) appNamespace() string {
if o.AppGroupFlags.AppNamespace != "" {
return o.AppGroupFlags.AppNamespace
}
return o.AppGroupFlags.NamespaceFlags.Name
}
Loading

0 comments on commit 54941da

Please sign in to comment.