mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-07-04 20:08:38 +00:00
Fix proxy retries (#718)
This commit is contained in:
parent
a5fef90781
commit
a4f7e61a6e
@ -23,8 +23,8 @@ type Provider struct {
|
|||||||
client *http.Client
|
client *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
const DefaultRetries = 20
|
const DefaultRetries = 3
|
||||||
const DefaultTimeout = 5 * time.Second
|
const DefaultTimeout = 2 * time.Second
|
||||||
|
|
||||||
func NewProvider(url string, retries int, timeout time.Duration) *Provider {
|
func NewProvider(url string, retries int, timeout time.Duration) *Provider {
|
||||||
return &Provider{
|
return &Provider{
|
||||||
@ -36,16 +36,6 @@ func NewProvider(url string, retries int, timeout time.Duration) *Provider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewProviderWithoutRetries(url string, timeout time.Duration) *Provider {
|
|
||||||
return &Provider{
|
|
||||||
url: url,
|
|
||||||
retries: 1,
|
|
||||||
client: &http.Client{
|
|
||||||
Timeout: timeout,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (provider *Provider) TestConnection() error {
|
func (provider *Provider) TestConnection() error {
|
||||||
retriesLeft := provider.retries
|
retriesLeft := provider.retries
|
||||||
for retriesLeft > 0 {
|
for retriesLeft > 0 {
|
||||||
|
@ -97,7 +97,7 @@ func checkServerConnection(kubernetesProvider *kubernetes.Provider) bool {
|
|||||||
|
|
||||||
serverUrl := GetApiServerUrl()
|
serverUrl := GetApiServerUrl()
|
||||||
|
|
||||||
apiServerProvider := apiserver.NewProviderWithoutRetries(serverUrl, apiserver.DefaultTimeout)
|
apiServerProvider := apiserver.NewProvider(serverUrl, 1, apiserver.DefaultTimeout)
|
||||||
if err := apiServerProvider.TestConnection(); err == nil {
|
if err := apiServerProvider.TestConnection(); err == nil {
|
||||||
logger.Log.Infof("%v found Mizu server tunnel available and connected successfully to API server", fmt.Sprintf(uiUtils.Green, "√"))
|
logger.Log.Infof("%v found Mizu server tunnel available and connected successfully to API server", fmt.Sprintf(uiUtils.Green, "√"))
|
||||||
return true
|
return true
|
||||||
|
@ -5,6 +5,10 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path"
|
||||||
|
"regexp"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/up9inc/mizu/cli/apiserver"
|
"github.com/up9inc/mizu/cli/apiserver"
|
||||||
"github.com/up9inc/mizu/cli/config/configStructs"
|
"github.com/up9inc/mizu/cli/config/configStructs"
|
||||||
"github.com/up9inc/mizu/cli/errormessage"
|
"github.com/up9inc/mizu/cli/errormessage"
|
||||||
@ -13,9 +17,6 @@ import (
|
|||||||
"github.com/up9inc/mizu/cli/resources"
|
"github.com/up9inc/mizu/cli/resources"
|
||||||
"github.com/up9inc/mizu/cli/uiUtils"
|
"github.com/up9inc/mizu/cli/uiUtils"
|
||||||
"github.com/up9inc/mizu/shared"
|
"github.com/up9inc/mizu/shared"
|
||||||
"path"
|
|
||||||
"regexp"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/up9inc/mizu/cli/config"
|
"github.com/up9inc/mizu/cli/config"
|
||||||
"github.com/up9inc/mizu/shared/kubernetes"
|
"github.com/up9inc/mizu/shared/kubernetes"
|
||||||
@ -35,10 +36,10 @@ func startProxyReportErrorIfAny(kubernetesProvider *kubernetes.Provider, ctx con
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiProvider = apiserver.NewProviderWithoutRetries(GetApiServerUrl(), time.Second) // short check for proxy
|
apiProvider = apiserver.NewProvider(GetApiServerUrl(), apiserver.DefaultRetries, apiserver.DefaultTimeout)
|
||||||
if err := apiProvider.TestConnection(); err != nil {
|
if err := apiProvider.TestConnection(); err != nil {
|
||||||
logger.Log.Debugf("Couldn't connect using proxy, stopping proxy and trying to create port-forward")
|
logger.Log.Debugf("Couldn't connect using proxy, stopping proxy and trying to create port-forward")
|
||||||
if err := httpServer.Shutdown(context.Background()); err != nil {
|
if err := httpServer.Shutdown(ctx); err != nil {
|
||||||
logger.Log.Debugf("Error occurred while stopping proxy %v", errormessage.FormatError(err))
|
logger.Log.Debugf("Error occurred while stopping proxy %v", errormessage.FormatError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ func startProxyReportErrorIfAny(kubernetesProvider *kubernetes.Provider, ctx con
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
apiProvider = apiserver.NewProvider(GetApiServerUrl(), apiserver.DefaultRetries, apiserver.DefaultTimeout) // long check for port-forward
|
apiProvider = apiserver.NewProvider(GetApiServerUrl(), apiserver.DefaultRetries, apiserver.DefaultTimeout)
|
||||||
if err := apiProvider.TestConnection(); err != nil {
|
if err := apiProvider.TestConnection(); err != nil {
|
||||||
logger.Log.Errorf(uiUtils.Error, fmt.Sprintf("Couldn't connect to API server, for more info check logs at %s", fsUtils.GetLogFilePath()))
|
logger.Log.Errorf(uiUtils.Error, fmt.Sprintf("Couldn't connect to API server, for more info check logs at %s", fsUtils.GetLogFilePath()))
|
||||||
cancel()
|
cancel()
|
||||||
|
Loading…
Reference in New Issue
Block a user