Skip to content

Commit

Permalink
Fix goroutine leak and remove duplicate health (#1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
alenkacz authored and kensipe committed Jan 6, 2020
1 parent fa80cbd commit 0aeb801
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 64 deletions.
4 changes: 2 additions & 2 deletions pkg/kudoctl/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ func (initCmd *initCmd) run() error {

if initCmd.wait {
clog.Printf("⌛Waiting for KUDO controller to be ready in your cluster...")
finished := setup.WatchKUDOUntilReady(initCmd.client.KubeClient, opts, initCmd.timeout)
if !finished {
err := setup.WatchKUDOUntilReady(initCmd.client.KubeClient, opts, initCmd.timeout)
if err != nil {
return errors.New("watch timed out, readiness uncertain")
}
}
Expand Down
37 changes: 0 additions & 37 deletions pkg/kudoctl/kube/pod.go

This file was deleted.

39 changes: 14 additions & 25 deletions pkg/kudoctl/kudoinit/setup/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,34 @@ import (
"errors"
"time"

"github.com/kudobuilder/kudo/pkg/engine/health"

"k8s.io/apimachinery/pkg/util/wait"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/kubernetes"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"

"github.com/kudobuilder/kudo/pkg/kudoctl/kube"
"github.com/kudobuilder/kudo/pkg/kudoctl/kudoinit"
"github.com/kudobuilder/kudo/pkg/kudoctl/kudoinit/manager"
)

// WatchKUDOUntilReady waits for the KUDO pod to become available.
//
// Returns true if it exists. If the timeout was reached and it could not find the pod, it returns false.
func WatchKUDOUntilReady(client kubernetes.Interface, opts kudoinit.Options, timeout int64) bool {
deadlineChan := time.NewTimer(time.Duration(timeout) * time.Second).C
checkPodTicker := time.NewTicker(500 * time.Millisecond)
doneChan := make(chan bool)

defer checkPodTicker.Stop()

go func() {
for range checkPodTicker.C {
image, err := getKUDOPodImage(client.CoreV1(), opts.Namespace)
if err == nil && image == opts.Image {
doneChan <- true
break
}
}
}()
func WatchKUDOUntilReady(client kubernetes.Interface, opts kudoinit.Options, timeout int64) error {
return wait.PollImmediate(500*time.Millisecond, time.Duration(timeout)*time.Second,
func() (bool, error) { return verifyKudoDeployment(client.CoreV1(), opts.Namespace, opts.Image) })
}

for {
select {
case <-deadlineChan:
return false
case <-doneChan:
return true
}
func verifyKudoDeployment(client corev1.PodsGetter, namespace, expectedImage string) (bool, error) {
image, err := getKUDOPodImage(client, namespace)
if err == nil && image == expectedImage {
return true, nil
}
return false, nil
}

// getKUDOPodImage fetches the image of KUDO pod running in the given namespace.
Expand Down Expand Up @@ -70,7 +59,7 @@ func getFirstRunningPod(client corev1.PodsGetter, namespace string, selector lab
return nil, errors.New("could not find KUDO manager")
}
for _, p := range pods.Items {
if kube.IsPodReady(&p) {
if health.IsHealthy(&p) == nil {
return &p, nil
}
}
Expand Down

0 comments on commit 0aeb801

Please sign in to comment.