Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix goroutine leak and remove duplicate health #1246

Merged
merged 2 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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