Skip to content
This repository has been archived by the owner on Feb 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #69 from simonferquel/handle-delete-foreground
Browse files Browse the repository at this point in the history
Handle Deletes with propagation policy = foreground
  • Loading branch information
simonferquel authored Jan 29, 2019
2 parents 356b291 + cb0fdc2 commit 33d3550
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 81 deletions.
23 changes: 23 additions & 0 deletions api/client/informers/compose/v1alpha3/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,26 @@ func (f *stackInformer) Informer() cache.SharedIndexInformer {
func (f *stackInformer) Lister() v1alpha3.StackLister {
return v1alpha3.NewStackLister(f.Informer().GetIndexer())
}

// NewFilteredStackInformer creates a stack informer with specific list options
func NewFilteredStackInformer(client clientset.Interface, resyncPeriod time.Duration, tweakListOptions func(*v1.ListOptions)) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.ComposeV1alpha3().Stacks(v1.NamespaceAll).List(options)
},
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.ComposeV1alpha3().Stacks(v1.NamespaceAll).Watch(options)
},
},
&compose_v1alpha3.Stack{},
resyncPeriod,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
)
}
11 changes: 11 additions & 0 deletions e2e/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,17 @@ configs:
expectNoError(err)
waitUntil(ns.IsStackAvailable(s.Name))
})
It("Should delete stacks with propagation=Foreground", func() {
_, err := ns.CreateStack(cluster.StackOperationV1alpha3, "app", `version: '3.2'
services:
front:
image: nginx:1.12.1-alpine`)
Expect(err).NotTo(HaveOccurred())
waitUntil(ns.IsStackAvailable("app"))
err = ns.DeleteStackWithPropagation("app", metav1.DeletePropagationForeground)
Expect(err).NotTo(HaveOccurred())
waitUntil(ns.ContainsZeroStack())
})

})

Expand Down
8 changes: 5 additions & 3 deletions internal/controller/stacklistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"time"

"github.com/docker/compose-on-kubernetes/api/client/clientset"
"github.com/docker/compose-on-kubernetes/api/client/informers"
"github.com/docker/compose-on-kubernetes/api/client/informers/compose/v1alpha3"
"github.com/docker/compose-on-kubernetes/api/compose/latest"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"
)

Expand Down Expand Up @@ -87,8 +88,9 @@ func NewStackListener(clientSet clientset.Interface,
reconcileQueue chan<- string,
reconcileDeletionQueue chan<- *latest.Stack,
ownerCache StackOwnerCacher) *StackListener {
informersFactory := informers.NewSharedInformerFactory(clientSet, reconciliationInterval)
stacksInformer := informersFactory.Compose().V1alpha3().Stacks().Informer()
stacksInformer := v1alpha3.NewFilteredStackInformer(clientSet, reconciliationInterval, func(o *metav1.ListOptions) {
o.IncludeUninitialized = true
})
result := &StackListener{
stacks: stacksInformer,
reconcileQueue: reconcileQueue,
Expand Down
5 changes: 5 additions & 0 deletions internal/controller/stackreconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ func (r *StackReconciler) reconcileStack(key string) {
log.Errorf("Cannot reconcile stack %s: %s", key, err)
return
}
if stack.DeletionTimestamp != nil {
// pending deletion
r.deleteStackChildren(stack)
return
}
updater, err := r.resourceUpdater.getUpdater(stack, convert.IsStackDirty(stack))
if err != nil {
log.Errorf("Updater resolution failed: %s", err)
Expand Down
Loading

0 comments on commit 33d3550

Please sign in to comment.