diff --git a/cmd/controller-manager/app/controllermanager.go b/cmd/controller-manager/app/controllermanager.go index bfa7fb235..5b4c8576e 100644 --- a/cmd/controller-manager/app/controllermanager.go +++ b/cmd/controller-manager/app/controllermanager.go @@ -3,8 +3,9 @@ package app import ( "context" "flag" - "fmt" + "net" "os" + "strconv" "github.com/spf13/cobra" "k8s.io/client-go/discovery" @@ -77,7 +78,7 @@ func Run(ctx context.Context, opts *options.Options) error { LeaderElectionID: opts.LeaderElection.ResourceName, LeaderElectionNamespace: opts.LeaderElection.ResourceNamespace, LeaderElectionResourceLock: opts.LeaderElection.ResourceLock, - HealthProbeBindAddress: fmt.Sprintf("%s:%d", opts.BindAddress, opts.SecurePort), + HealthProbeBindAddress: net.JoinHostPort(opts.BindAddress, strconv.Itoa(opts.SecurePort)), LivenessEndpointName: "/healthz", }) if err != nil { diff --git a/cmd/scheduler-estimator/app/scheduler-estimator.go b/cmd/scheduler-estimator/app/scheduler-estimator.go index 8e63db17d..94f0a4d23 100644 --- a/cmd/scheduler-estimator/app/scheduler-estimator.go +++ b/cmd/scheduler-estimator/app/scheduler-estimator.go @@ -4,8 +4,10 @@ import ( "context" "flag" "fmt" + "net" "net/http" "os" + "strconv" "github.com/spf13/cobra" "k8s.io/client-go/kubernetes" @@ -45,7 +47,7 @@ func NewSchedulerEstimatorCommand(ctx context.Context) *cobra.Command { func run(ctx context.Context, opts *options.Options) error { klog.Infof("karmada-scheduler-estimator version: %s", version.Get()) - go serveHealthz(fmt.Sprintf("%s:%d", opts.BindAddress, opts.SecurePort)) + go serveHealthz(net.JoinHostPort(opts.BindAddress, strconv.Itoa(opts.SecurePort))) restConfig, err := clientcmd.BuildConfigFromFlags(opts.Master, opts.KubeConfig) if err != nil { diff --git a/cmd/scheduler/app/scheduler.go b/cmd/scheduler/app/scheduler.go index 5228ad5da..d2d5b0e91 100644 --- a/cmd/scheduler/app/scheduler.go +++ b/cmd/scheduler/app/scheduler.go @@ -4,8 +4,10 @@ import ( "context" "flag" "fmt" + "net" "net/http" "os" + "strconv" "github.com/google/uuid" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -60,7 +62,7 @@ func NewSchedulerCommand(stopChan <-chan struct{}) *cobra.Command { func run(opts *options.Options, stopChan <-chan struct{}) error { klog.Infof("karmada-scheduler version: %s", version.Get()) - go serveHealthzAndMetrics(fmt.Sprintf("%s:%d", opts.BindAddress, opts.SecurePort)) + go serveHealthzAndMetrics(net.JoinHostPort(opts.BindAddress, strconv.Itoa(opts.SecurePort))) restConfig, err := clientcmd.BuildConfigFromFlags(opts.Master, opts.KubeConfig) if err != nil {