Skip to content

Commit

Permalink
Be able to customize some timeouts for openshift auth (#5652)
Browse files Browse the repository at this point in the history
* Be able to customize some timeouts for openshift auth
fixes: #5650

* add trace log to confirm what the timeout is being set to.
The log message will look like this:

  2022-11-29T19:02:39Z TRC OpenShift auth timeout is set to [13s]
  • Loading branch information
jmazzitelli committed Nov 29, 2022
1 parent 2eb542b commit a23e3ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 7 additions & 2 deletions business/openshift_oauth.go
Expand Up @@ -59,7 +59,7 @@ type OAuthRouteTLSSpec struct {
Termination string `json:"termination"`
}

const defaultRequestTimeout = 10 * time.Second
var defaultAuthRequestTimeout = 0 * time.Second // will be determined by config first time it is needed

var kialiNamespace string

Expand Down Expand Up @@ -205,7 +205,12 @@ func (in *OpenshiftOAuthService) Logout(token string) error {
}

func request(method string, serverPrefix string, url string, auth *string, useSystemCA bool, customCA string) ([]byte, error) {
return requestWithTimeout(method, serverPrefix, url, auth, time.Duration(defaultRequestTimeout), useSystemCA, customCA)
if defaultAuthRequestTimeout == (0 * time.Second) {
config := config.Get().Auth.OpenShift
defaultAuthRequestTimeout = time.Duration(config.AuthTimeout) * time.Second
log.Tracef("OpenShift auth timeout is set to [%v]", defaultAuthRequestTimeout)
}
return requestWithTimeout(method, serverPrefix, url, auth, time.Duration(defaultAuthRequestTimeout), useSystemCA, customCA)
}

func requestWithTimeout(method string, serverPrefix string, url string, auth *string, timeout time.Duration, useSystemCA bool, customCA string) ([]byte, error) {
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Expand Up @@ -324,6 +324,7 @@ type AuthConfig struct {

// OpenShiftConfig contains specific configuration for authentication when on OpenShift
type OpenShiftConfig struct {
AuthTimeout int `yaml:"auth_timeout,omitempty"`
ClientIdPrefix string `yaml:"client_id_prefix,omitempty"`
ClientId string `yaml:"client_id,omitempty"`
ServerPrefix string `yaml:"server_prefix,omitempty"`
Expand Down Expand Up @@ -547,6 +548,7 @@ func NewConfig() (c *Config) {
UsernameClaim: "sub",
},
OpenShift: OpenShiftConfig{
AuthTimeout: 10,
ClientIdPrefix: "kiali",
ServerPrefix: "https://kubernetes.default.svc/",
},
Expand Down

0 comments on commit a23e3ae

Please sign in to comment.