Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #402 from StrongMonkey/fix-stack-up
Browse files Browse the repository at this point in the history
Reenqueue the stack after 10s
  • Loading branch information
ibuildthecloud authored Aug 27, 2019
2 parents 72cab14 + 4062eff commit a8d35ef
Showing 1 changed file with 47 additions and 10 deletions.
57 changes: 47 additions & 10 deletions modules/service/controllers/stack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package stack

import (
"context"
"fmt"
"sync"

riov1 "github.com/rancher/rio/pkg/apis/rio.cattle.io/v1"
"github.com/rancher/rio/pkg/stack"
"github.com/rancher/rio/pkg/stackobject"
"github.com/rancher/rio/types"
"github.com/rancher/wrangler/pkg/kv"
"github.com/rancher/wrangler/pkg/objectset"
"github.com/rancher/wrangler/pkg/relatedresource"
corev1 "k8s.io/api/core/v1"
Expand All @@ -27,29 +30,63 @@ func Register(ctx context.Context, rContext *types.Context) error {

c.Populator = p.populate

relatedresource.Watch(ctx, "stack-reenqueue-changes", resolve,
h := handler{
stackMap: &sync.Map{},
}
relatedresource.Watch(ctx, "stack-reenqueue-changes", h.resolve,
rContext.Rio.Rio().V1().Stack(),
rContext.Rio.Rio().V1().Service(),
rContext.Rio.Rio().V1().ExternalService(),
rContext.Rio.Rio().V1().Router(),
rContext.Core.Core().V1().ConfigMap())

return nil
}

func resolve(namespace, name string, obj runtime.Object) ([]relatedresource.Key, error) {
type handler struct {
stackMap *sync.Map
}

func (h handler) resolve(namespace, name string, obj runtime.Object) ([]relatedresource.Key, error) {
key := fmt.Sprintf("%s/%s", namespace, name)
if obj != nil {
n, ns := ownedByStack(obj)
if n == "" || ns == "" {
return nil, nil
}
h.stackMap.Store(key, fmt.Sprintf("%s/%s", ns, n))
}

value, ok := h.stackMap.Load(key)
if ok {
stackNs, stackName := kv.Split(value.(string), "/")
if obj == nil {
h.stackMap.Delete(key)
}

if stackNs != "" && stackName != "" {
return []relatedresource.Key{
{
Namespace: stackNs,
Name: stackName,
},
}, nil
}
}

return nil, nil
}

func ownedByStack(obj runtime.Object) (string, string) {
meta, err := meta.Accessor(obj)
if err != nil {
return nil, nil
return "", ""
}

if meta.GetAnnotations()["objectset.rio.cattle.io/owner-gvk"] == "rio.cattle.io/v1, Kind=Stack" {
return []relatedresource.Key{
{
Namespace: meta.GetAnnotations()["objectset.rio.cattle.io/owner-namespace"],
Name: meta.GetAnnotations()["objectset.rio.cattle.io/owner-name"],
},
}, nil
return meta.GetAnnotations()["objectset.rio.cattle.io/owner-name"], meta.GetAnnotations()["objectset.rio.cattle.io/owner-namespace"]
}
return nil, nil
return "", ""
}

type stackPopulator struct{}
Expand Down

0 comments on commit a8d35ef

Please sign in to comment.