Skip to content
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
20 changes: 17 additions & 3 deletions controlplane/kubeadm/internal/proxy/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,30 @@ func (d *Dialer) DialContextWithAddr(ctx context.Context, addr string) (net.Conn
}

// DialContext creates proxied port-forwarded connections.
// ctx is currently unused, but fulfils the type signature used by GRPC.
func (d *Dialer) DialContext(_ context.Context, _ string, addr string) (net.Conn, error) {
func (d *Dialer) DialContext(ctx context.Context, _ string, addr string) (net.Conn, error) {
// Check if context is already cancelled or timed out
select {
case <-ctx.Done():
return nil, errors.Wrap(ctx.Err(), "context cancelled before establishing connection")
default:
}

req := d.clientset.CoreV1().RESTClient().
Post().
Resource(d.proxy.Kind).
Namespace(d.proxy.Namespace).
Name(addr).
SubResource("portforward")

dialer := spdy.NewDialer(d.upgrader, &http.Client{Transport: d.proxyTransport}, "POST", req.URL())
httpClient := &http.Client{
Transport: d.proxyTransport,
}

if deadline, ok := ctx.Deadline(); ok {
httpClient.Timeout = time.Until(deadline)
}

dialer := spdy.NewDialer(d.upgrader, httpClient, "POST", req.URL())

// Create a new connection from the dialer.
//
Expand Down
4 changes: 4 additions & 0 deletions controlplane/kubeadm/internal/workload_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ func (w *Workload) ClusterStatus(ctx context.Context) (ClusterStatus, error) {

// GetAPIServerCertificateExpiry returns the certificate expiry of the apiserver on the given node.
func (w *Workload) GetAPIServerCertificateExpiry(ctx context.Context, kubeadmConfig *bootstrapv1.KubeadmConfig, nodeName string) (*time.Time, error) {
// Create a context with 15 second timeout
ctx, cancel := context.WithTimeoutCause(ctx, 15*time.Second, errors.New("timeout getting API server certificate expiry"))
defer cancel()

// Create a proxy.
p := proxy.Proxy{
Kind: "pods",
Expand Down