Skip to content

Commit

Permalink
[ws-proxy] Configure readiness probe
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Mar 16, 2022
1 parent e202506 commit 772fd53
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
53 changes: 40 additions & 13 deletions components/ws-proxy/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,33 @@ package cmd
import (
"context"
"net"
"net/http"
"os"
"path/filepath"
"time"

"github.com/bombsimon/logrusr/v2"
common_grpc "github.com/gitpod-io/gitpod/common-go/grpc"
"github.com/gitpod-io/gitpod/common-go/log"
"github.com/gitpod-io/gitpod/common-go/pprof"
wsmanapi "github.com/gitpod-io/gitpod/ws-manager/api"
"github.com/gitpod-io/gitpod/ws-proxy/pkg/config"
"github.com/gitpod-io/gitpod/ws-proxy/pkg/proxy"
"github.com/gitpod-io/gitpod/ws-proxy/pkg/sshproxy"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
runtime_client "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"

common_grpc "github.com/gitpod-io/gitpod/common-go/grpc"
"github.com/gitpod-io/gitpod/common-go/log"
"github.com/gitpod-io/gitpod/common-go/pprof"
wsmanapi "github.com/gitpod-io/gitpod/ws-manager/api"
"github.com/gitpod-io/gitpod/ws-proxy/pkg/config"
"github.com/gitpod-io/gitpod/ws-proxy/pkg/proxy"
"github.com/gitpod-io/gitpod/ws-proxy/pkg/sshproxy"
)

var (
Expand Down Expand Up @@ -64,23 +70,26 @@ var runCmd = &cobra.Command{
log.WithError(err).Fatal(err, "unable to start manager")
}

workspaceInfoProvider := proxy.NewRemoteWorkspaceInfoProvider(mgr.GetClient(), mgr.GetScheme())
err = workspaceInfoProvider.SetupWithManager(mgr)
if err != nil {
log.WithError(err).Fatal(err, "unable to create controller", "controller", "Pod")
}

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
log.WithError(err).Fatal("unable to set up health check")
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
log.WithError(err).Fatal(err, "unable to set up ready check")
}
if err := mgr.AddReadyzCheck("readyz", readyCheck(mgr.GetClient(), cfg.Namespace)); err != nil {
log.WithError(err).Fatal(err, "unable to set up ready check")
}

if cfg.PProfAddr != "" {
go pprof.Serve(cfg.PProfAddr)
}

workspaceInfoProvider := proxy.NewRemoteWorkspaceInfoProvider(mgr.GetClient(), mgr.GetScheme())
err = workspaceInfoProvider.SetupWithManager(mgr)
if err != nil {
log.WithError(err).Fatal(err, "unable to create controller", "controller", "Pod")
}

log.Infof("workspace info provider started")

var heartbeat sshproxy.Heartbeat
Expand Down Expand Up @@ -159,3 +168,21 @@ func init() {
}

var scheme = runtime.NewScheme()

// Ready check that verify we can list pods
func readyCheck(client runtime_client.Client, namespace string) func(*http.Request) error {
return func(*http.Request) error {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()

var wsProxyPod corev1.Pod
err := client.Get(ctx, types.NamespacedName{Namespace: namespace, Name: "readyz-pod"}, &wsProxyPod)
if errors.IsNotFound(err) {
// readyz-pod is not a valid name
// we just need to check there are no errors reaching the API server
return nil
}

return err
}
}
1 change: 1 addition & 0 deletions components/ws-proxy/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
k8s.io/api v0.23.4
k8s.io/apimachinery v0.23.4
k8s.io/client-go v0.23.4
k8s.io/component-helpers v0.0.0-00010101000000-000000000000
sigs.k8s.io/controller-runtime v0.11.1
)

Expand Down
2 changes: 2 additions & 0 deletions components/ws-proxy/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,8 @@ k8s.io/client-go v0.23.4/go.mod h1:PKnIL4pqLuvYUK1WU7RLTMYKPiIh7MYShLshtRY9cj0=
k8s.io/code-generator v0.23.4/go.mod h1:S0Q1JVA+kSzTI1oUvbKAxZY/DYbA/ZUb4Uknog12ETk=
k8s.io/component-base v0.23.4 h1:SziYh48+QKxK+ykJ3Ejqd98XdZIseVBG7sBaNLPqy6M=
k8s.io/component-base v0.23.4/go.mod h1:8o3Gg8i2vnUXGPOwciiYlkSaZT+p+7gA9Scoz8y4W4E=
k8s.io/component-helpers v0.23.4 h1:zCLeBuo3Qs0BqtJu767RXJgs5S9ruFJZcbM1aD+cMmc=
k8s.io/component-helpers v0.23.4/go.mod h1:1Pl7L4zukZ054ElzRbvmZ1FJIU8roBXFOeRFu8zipa4=
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
Expand Down

0 comments on commit 772fd53

Please sign in to comment.