Skip to content

Commit

Permalink
add waiting behavior for kapp-controller packagerepositories
Browse files Browse the repository at this point in the history
Co-Authored-By: Yash Sethiya <yashsethiya97@gmail.com>
  • Loading branch information
danielhelfand and sethiyash committed Jul 9, 2021
1 parent 7f1de75 commit f0aae58
Show file tree
Hide file tree
Showing 1,005 changed files with 198,075 additions and 74,075 deletions.
23 changes: 8 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,25 @@ module github.com/k14s/kapp
go 1.16

require (
github.com/Azure/go-autorest v10.15.0+incompatible // indirect
github.com/cppforlife/cobrautil v0.0.0-20200514214827-bb86e6965d72
github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835
github.com/cppforlife/go-cli-ui v0.0.0-20200716203538-1e47f820817f
github.com/cppforlife/go-patch v0.2.0
github.com/ghodss/yaml v1.0.0
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/gophercloud/gophercloud v0.0.0-20180727150635-f8826f28e31a // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/hashicorp/go-version v1.3.0
github.com/imdario/mergo v0.3.5 // indirect
github.com/k14s/difflib v0.0.0-20200108171459-b101e55e0592
github.com/k14s/kapp-controller v0.1.0
github.com/mitchellh/go-wordwrap v1.0.1
github.com/onsi/ginkgo v1.11.0 // indirect
github.com/onsi/gomega v1.7.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/spf13/cobra v1.1.1
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
github.com/vmware-tanzu/carvel-kapp-controller v0.20.0
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.2.8
k8s.io/api v0.0.0-20180628040859-072894a440bd // kubernetes-1.11.0
k8s.io/apimachinery v0.0.0-20180621070125-103fd098999d // kubernetes-1.11.0
k8s.io/client-go v8.0.0+incompatible // kubernetes-1.11.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.19.2 // kubernetes-1.11.0
k8s.io/apimachinery v0.19.2 // kubernetes-1.11.0
k8s.io/client-go v0.19.2 // kubernetes-1.11.0
)

replace github.com/spf13/cobra => github.com/spf13/cobra v1.1.1
895 changes: 855 additions & 40 deletions go.sum

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pkg/kapp/app/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package app

import (
"context"
"fmt"
"strings"

Expand Down Expand Up @@ -75,7 +76,7 @@ func (a Apps) list(additionalLabels map[string]string, nsName string) ([]App, er
LabelSelector: labels.Set(filterLabels).String(),
}

apps, err := a.coreClient.CoreV1().ConfigMaps(nsName).List(listOpts)
apps, err := a.coreClient.CoreV1().ConfigMaps(nsName).List(context.TODO(), listOpts)
if err != nil {
return nil, err
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/kapp/app/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package app

import (
"context"
"fmt"
"time"

Expand Down Expand Up @@ -45,7 +46,7 @@ func (c *ChangeImpl) Succeed() error {
}

func (c *ChangeImpl) Delete() error {
err := c.coreClient.CoreV1().ConfigMaps(c.nsName).Delete(c.name, &metav1.DeleteOptions{})
err := c.coreClient.CoreV1().ConfigMaps(c.nsName).Delete(context.TODO(), c.name, metav1.DeleteOptions{})
if err != nil {
return fmt.Errorf("Deleting app change: %s", err)
}
Expand All @@ -54,7 +55,7 @@ func (c *ChangeImpl) Delete() error {
}

func (c *ChangeImpl) update(doFunc func(*ChangeMeta)) error {
change, err := c.coreClient.CoreV1().ConfigMaps(c.nsName).Get(c.name, metav1.GetOptions{})
change, err := c.coreClient.CoreV1().ConfigMaps(c.nsName).Get(context.TODO(), c.name, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("Getting app change: %s", err)
}
Expand All @@ -65,7 +66,7 @@ func (c *ChangeImpl) update(doFunc func(*ChangeMeta)) error {
c.meta = meta
change.Data = meta.AsData()

_, err = c.coreClient.CoreV1().ConfigMaps(c.nsName).Update(change)
_, err = c.coreClient.CoreV1().ConfigMaps(c.nsName).Update(context.TODO(), change, metav1.UpdateOptions{})
if err != nil {
return fmt.Errorf("Updating app change: %s", err)
}
Expand Down
23 changes: 12 additions & 11 deletions pkg/kapp/app/recorded_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package app

import (
"context"
"fmt"
"time"

Expand Down Expand Up @@ -98,10 +99,10 @@ func (a *RecordedApp) CreateOrUpdate(labels map[string]string) error {
return err
}

_, err = a.coreClient.CoreV1().ConfigMaps(a.nsName).Create(configMap)
_, err = a.coreClient.CoreV1().ConfigMaps(a.nsName).Create(context.TODO(), configMap, metav1.CreateOptions{})
if err != nil {
if errors.IsAlreadyExists(err) {
existingConfigMap, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Get(a.name, metav1.GetOptions{})
existingConfigMap, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Get(context.TODO(), a.name, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("Getting app: %s", err)
}
Expand All @@ -111,7 +112,7 @@ func (a *RecordedApp) CreateOrUpdate(labels map[string]string) error {
return err
}

_, err = a.coreClient.CoreV1().ConfigMaps(a.nsName).Update(existingConfigMap)
_, err = a.coreClient.CoreV1().ConfigMaps(a.nsName).Update(context.TODO(), existingConfigMap, metav1.UpdateOptions{})
if err != nil {
return fmt.Errorf("Updating app: %s", err)
}
Expand Down Expand Up @@ -139,7 +140,7 @@ func (a *RecordedApp) mergeAppUpdates(cm *corev1.ConfigMap, labels map[string]st
}

func (a *RecordedApp) Exists() (bool, string, error) {
_, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Get(a.name, metav1.GetOptions{})
_, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Get(context.TODO(), a.name, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
desc := fmt.Sprintf("App '%s' (namespace: %s) does not exist%s",
Expand Down Expand Up @@ -168,7 +169,7 @@ func (a *RecordedApp) Delete() error {
return err
}

err = a.coreClient.CoreV1().ConfigMaps(a.nsName).Delete(a.name, &metav1.DeleteOptions{})
err = a.coreClient.CoreV1().ConfigMaps(a.nsName).Delete(context.TODO(), a.name, metav1.DeleteOptions{})
if err != nil {
return fmt.Errorf("Deleting app: %s", err)
}
Expand All @@ -177,7 +178,7 @@ func (a *RecordedApp) Delete() error {
}

func (a *RecordedApp) Rename(newName string) error {
app, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Get(a.name, metav1.GetOptions{})
app, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Get(context.TODO(), a.name, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return fmt.Errorf("App '%s' (namespace: %s) does not exist: %s%s",
Expand All @@ -194,12 +195,12 @@ func (a *RecordedApp) Rename(newName string) error {
Annotations: app.ObjectMeta.Annotations,
}

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

err = a.coreClient.CoreV1().ConfigMaps(a.nsName).Delete(a.name, &metav1.DeleteOptions{})
err = a.coreClient.CoreV1().ConfigMaps(a.nsName).Delete(context.TODO(), a.name, metav1.DeleteOptions{})
if err != nil {
// TODO Do not clean up new config map as there is no gurantee it can be deleted either
return fmt.Errorf("Deleting app: %s", err)
Expand Down Expand Up @@ -242,7 +243,7 @@ func (a *RecordedApp) meta() (Meta, error) {
return *a.memoizedMeta, nil
}

app, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Get(a.name, metav1.GetOptions{})
app, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Get(context.TODO(), a.name, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return Meta{}, fmt.Errorf("App '%s' (namespace: %s) does not exist: %s%s",
Expand Down Expand Up @@ -296,7 +297,7 @@ func (a *RecordedApp) BeginChange(meta ChangeMeta) (Change, error) {
}

func (a *RecordedApp) update(doFunc func(*Meta)) error {
change, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Get(a.name, metav1.GetOptions{})
change, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Get(context.TODO(), a.name, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("Getting app: %s", err)
}
Expand All @@ -310,7 +311,7 @@ func (a *RecordedApp) update(doFunc func(*Meta)) error {

change.Data = meta.AsData()

_, err = a.coreClient.CoreV1().ConfigMaps(a.nsName).Update(change)
_, err = a.coreClient.CoreV1().ConfigMaps(a.nsName).Update(context.TODO(), change, metav1.UpdateOptions{})
if err != nil {
return fmt.Errorf("Updating app: %s", err)
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/kapp/app/recorded_app_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package app

import (
"context"
"fmt"
"sort"
"time"
Expand Down Expand Up @@ -41,7 +42,7 @@ func (a RecordedAppChanges) List() ([]Change, error) {
}).String(),
}

changes, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).List(listOpts)
changes, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).List(context.TODO(), listOpts)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -73,13 +74,13 @@ func (a RecordedAppChanges) DeleteAll() error {
}).String(),
}

changes, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).List(listOpts)
changes, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).List(context.TODO(), listOpts)
if err != nil {
return err
}

for _, change := range changes.Items {
err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Delete(change.Name, &metav1.DeleteOptions{})
err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Delete(context.TODO(), change.Name, metav1.DeleteOptions{})
if err != nil {
return err
}
Expand Down Expand Up @@ -107,7 +108,7 @@ func (a RecordedAppChanges) Begin(meta ChangeMeta) (*ChangeImpl, error) {
Data: newMeta.AsData(),
}

createdChange, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Create(configMap)
createdChange, err := a.coreClient.CoreV1().ConfigMaps(a.nsName).Create(context.TODO(), configMap, metav1.CreateOptions{})
if err != nil {
return nil, fmt.Errorf("Creating app change: %s", err)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/kapp/clusterapply/converged_resource_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func (f ConvergedResourceFactory) New(res ctlres.Resource,
func(res ctlres.Resource, _ []ctlres.Resource) (SpecificResource, []ctlres.ResourceRef) {
return ctlresm.NewKappctrlK14sIoV1alpha1App(res), nil
},
func(res ctlres.Resource, _ []ctlres.Resource) (SpecificResource, []ctlres.ResourceRef) {
return ctlresm.NewPackagingCarvelDevV1alpha1PackageRepo(res), nil
},
// Deal with deletion generically since below resource waiters do not not know about that
// TODO shoud we make all of them deal with deletion internally?
func(res ctlres.Resource, _ []ctlres.Resource) (SpecificResource, []ctlres.ResourceRef) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/kapp/cmd/core/deps_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package core

import (
"context"
"fmt"
"sync"

Expand Down Expand Up @@ -79,7 +80,7 @@ func (f *DepsFactoryImpl) summarizeNodes(config *rest.Config) string {
return ""
}

nodes, err := clientset.CoreV1().Nodes().List(metav1.ListOptions{})
nodes, err := clientset.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
if err != nil {
return ""
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/kapp/logs/pod_container_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package logs

import (
"bufio"
"context"
"fmt"
"io"
"sync/atomic"
Expand Down Expand Up @@ -112,7 +113,7 @@ func (l PodContainerLog) obtainStream(ui ui.UI, linePrefix string, cancelCh chan
// TODO other options
})

stream, err := logs.Stream()
stream, err := logs.Stream(context.TODO())
if err == nil {
return stream, nil
}
Expand All @@ -135,7 +136,7 @@ func (l PodContainerLog) obtainStream(ui ui.UI, linePrefix string, cancelCh chan
}

func (l PodContainerLog) readyToGetLogs() bool {
pod, err := l.podsClient.Get(l.pod.Name, metav1.GetOptions{})
pod, err := l.podsClient.Get(context.TODO(), l.pod.Name, metav1.GetOptions{})
if err != nil {
return false
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/kapp/resources/identified_resource_config_maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package resources

import (
"context"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand All @@ -12,7 +14,7 @@ import (
func (r IdentifiedResources) ConfigMapResources(labelSelector labels.Selector) ([]corev1.ConfigMap, error) {
listOpts := metav1.ListOptions{LabelSelector: labelSelector.String()}

mapList, err := r.coreClient.CoreV1().ConfigMaps("").List(listOpts)
mapList, err := r.coreClient.CoreV1().ConfigMaps("").List(context.TODO(), listOpts)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/kapp/resources/pod_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package resources

import (
"context"
"fmt"

corev1 "k8s.io/api/core/v1"
Expand All @@ -25,7 +26,7 @@ func NewPodWatcher(
}

func (w PodWatcher) Watch(podsToWatchCh chan corev1.Pod, cancelCh chan struct{}) error {
podsList, err := w.podsClient.List(w.listOpts)
podsList, err := w.podsClient.List(context.TODO(), w.listOpts)
if err != nil {
return err
}
Expand Down Expand Up @@ -53,7 +54,7 @@ func (w PodWatcher) Watch(podsToWatchCh chan corev1.Pod, cancelCh chan struct{})
}

func (w PodWatcher) watch(podsToWatchCh chan corev1.Pod, cancelCh chan struct{}) (bool, error) {
watcher, err := w.podsClient.Watch(w.listOpts)
watcher, err := w.podsClient.Watch(context.TODO(), w.listOpts)
if err != nil {
return false, fmt.Errorf("Creating Pod watcher: %s", err)
}
Expand Down
Loading

0 comments on commit f0aae58

Please sign in to comment.