Skip to content

Commit

Permalink
Support timeouts in Linkerd and nginx-ingress wizards (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Hodgetts committed Aug 19, 2021
1 parent 4877aca commit 11d5684
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions wizard/flow/linkerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package flow

import (
"fmt"
"log"
"strconv"

"github.com/kubeshop/kusk/generators/linkerd"
"github.com/kubeshop/kusk/options"
Expand All @@ -21,6 +23,17 @@ func (l linkerdFlow) Start() (Response, error) {

basePath := l.prompt.SelectOneOf("Base path prefix", basePathSuggestions, true)

var timeoutOptions options.TimeoutOptions

// Support only request timeout as linkerd generator doesn't support idle timeout
if requestTimeout := l.prompt.Input("Request timeout, leave empty to skip", ""); requestTimeout != "" {
if rTimeout, err := strconv.Atoi(requestTimeout); err != nil {
log.Printf("WARN: %s is not a valid request timeout value. Skipping\n", requestTimeout)
} else {
timeoutOptions.RequestTimeout = uint32(rTimeout)
}
}

opts := &options.Options{
Namespace: l.targetNamespace,
Path: options.PathOptions{
Expand All @@ -33,6 +46,7 @@ func (l linkerdFlow) Start() (Response, error) {
Cluster: options.ClusterOptions{
ClusterDomain: clusterDomain,
},
Timeouts: timeoutOptions,
}

cmd := fmt.Sprintf("kusk linkerd -i %s ", l.apiSpecPath)
Expand All @@ -42,6 +56,10 @@ func (l linkerdFlow) Start() (Response, error) {
cmd = cmd + fmt.Sprintf("--path.base=%s ", basePath)
cmd = cmd + fmt.Sprintf("--cluster.cluster_domain=%s ", clusterDomain)

if timeoutOptions.RequestTimeout > 0 {
cmd = cmd + fmt.Sprintf("--timeouts.request_timeout=%d", timeoutOptions.RequestTimeout)
}

var ld linkerd.Generator

serviceProfiles, err := ld.Generate(opts, l.apiSpec)
Expand Down
14 changes: 14 additions & 0 deletions wizard/flow/nginx_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package flow

import (
"fmt"
"log"
"strconv"
"strings"

"github.com/kubeshop/kusk/generators/nginx_ingress"
Expand All @@ -26,6 +28,17 @@ func (n nginxIngressFlow) Start() (Response, error) {
separateMappings = n.prompt.Confirm("Generate ingress resource for each endpoint separately?")
}

var timeoutOptions options.TimeoutOptions

// Support only request timeout as nginx-ingress generator doesn't support idle timeout
if requestTimeout := n.prompt.Input("Request timeout, leave empty to skip", ""); requestTimeout != "" {
if rTimeout, err := strconv.Atoi(requestTimeout); err != nil {
log.Printf("WARN: %s is not a valid request timeout value. Skipping\n", requestTimeout)
} else {
timeoutOptions.RequestTimeout = uint32(rTimeout)
}
}

opts := &options.Options{
Namespace: n.targetNamespace,
Service: options.ServiceOptions{
Expand All @@ -37,6 +50,7 @@ func (n nginxIngressFlow) Start() (Response, error) {
TrimPrefix: trimPrefix,
Split: separateMappings,
},
Timeouts: timeoutOptions,
}

var sb strings.Builder
Expand Down

0 comments on commit 11d5684

Please sign in to comment.