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

Validate ports in PreInitChecks #815

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
21 changes: 20 additions & 1 deletion src/k8s/pkg/snap/snap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"net"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -329,7 +330,25 @@ func (s *snap) SnapctlSet(ctx context.Context, args ...string) error {
}

func (s *snap) PreInitChecks(ctx context.Context, config types.ClusterConfig) error {
// TODO: check for available ports for k8s-dqlite, apiserver, containerd, etc
// TODO(eac): Make these configurable or part of a Config struct
ports := []int{
config.APIServer.GetSecurePort(), // kubeAPIServerPort
config.Datastore.GetK8sDqlitePort(), // k8sDqlitePort
10248, // kubeletHealthzPort
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these ports can be set in the service extra args. We need to check from there for the right values.

10250, // kubeletPort
10256, // kubeProxyHealthzPort
10257, // kubeControllerManagerPort
10259, // kubeSchedulerPort
}
for _, port := range ports {
for _, address := range []string{"127.0.0.1", "0.0.0.0"} {
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", address, port))
if err != nil {
return fmt.Errorf("couldn't bind to required address %s:%d. Is it in use?", address, port)
}
listener.Close()
}
}

// NOTE(neoaggelos): in some environments the Kubernetes might hang when running for the first time
// This works around the issue by running them once during the install hook
Expand Down
Loading