Skip to content

Commit

Permalink
Support Base path in Linkerd wizard and Support timeouts in Ambassado…
Browse files Browse the repository at this point in the history
…r wizard (#129)

* support path.base option in linkerd wizard
* add support for timeouts in ambassador wizard
  • Loading branch information
Kyle Hodgetts committed Aug 19, 2021
1 parent d49f07a commit 13161e8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
3 changes: 1 addition & 2 deletions generators/ambassador/ambassador.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ func (g *Generator) Generate(opts *options.Options, spec *openapi3.T) (string, e
TrimPrefix: opts.Path.TrimPrefix,
RequestTimeout: opts.Timeouts.RequestTimeout * 1000,
IdleTimeout: opts.Timeouts.IdleTimeout * 1000,
Host: opts.Host,

Host: opts.Host,
}

// if global CORS options are defined, take them
Expand Down
2 changes: 1 addition & 1 deletion generators/ambassador/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type mappingTemplateData struct {
Regex bool
Rewrite bool

Host string
Host string
HostRegex bool

CORSEnabled bool
Expand Down
2 changes: 1 addition & 1 deletion options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
type SubOptions struct {
Disabled bool `yaml:"disabled,omitempty" json:"disabled,omitempty"`

Host string `yaml:"host,omitempty" json:"host,omitempty"`
Host string `yaml:"host,omitempty" json:"host,omitempty"`
CORS CORSOptions `yaml:"cors,omitempty" json:"cors,omitempty"`
Timeouts TimeoutOptions `yaml:"timeouts,omitempty" json:"timeouts,omitempty"`
}
Expand Down
27 changes: 27 additions & 0 deletions wizard/flow/ambassador.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/ambassador"
"github.com/kubeshop/kusk/options"
Expand All @@ -26,12 +28,31 @@ func (a ambassadorFlow) Start() (Response, error) {
separateMappings = a.prompt.Confirm("Generate mapping for each endpoint separately?")
}

var timeoutOptions options.TimeoutOptions

if requestTimeout := a.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)
}
}

if idleTimeout := a.prompt.Input("Idle timeout, leave empty to skip", ""); idleTimeout != "" {
if iTimeout, err := strconv.Atoi(idleTimeout); err != nil {
log.Printf("WARN: %s is not a valid idle timeout value. Skipping\n", idleTimeout)
} else {
timeoutOptions.RequestTimeout = uint32(iTimeout)
}
}

opts := &options.Options{
Namespace: a.targetNamespace,
Service: options.ServiceOptions{
Namespace: a.targetNamespace,
Name: a.targetService,
},
Timeouts: timeoutOptions,
Path: options.PathOptions{
Base: basePath,
TrimPrefix: trimPrefix,
Expand All @@ -50,6 +71,12 @@ func (a ambassadorFlow) Start() (Response, error) {
if separateMappings {
cmd = cmd + fmt.Sprintf("--path.split ")
}
if timeoutOptions.RequestTimeout > 0 {
cmd = cmd + fmt.Sprintf("--timeouts.request_timeout=%d", timeoutOptions.RequestTimeout)
}
if timeoutOptions.IdleTimeout > 0 {
cmd = cmd + fmt.Sprintf("--timeouts.idle_timeout=%d", timeoutOptions.IdleTimeout)
}

var ag ambassador.Generator

Expand Down
11 changes: 11 additions & 0 deletions wizard/flow/linkerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ type linkerdFlow struct {
func (l linkerdFlow) Start() (Response, error) {
clusterDomain := l.prompt.InputNonEmpty("Cluster domain", "cluster.local")

var basePathSuggestions []string
for _, server := range l.apiSpec.Servers {
basePathSuggestions = append(basePathSuggestions, server.URL)
}

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

opts := &options.Options{
Namespace: l.targetNamespace,
Path: options.PathOptions{
Base: basePath,
},
Service: options.ServiceOptions{
Namespace: l.targetNamespace,
Name: l.targetService,
Expand All @@ -29,6 +39,7 @@ func (l linkerdFlow) Start() (Response, error) {
cmd = cmd + fmt.Sprintf("--namespace=%s ", l.targetNamespace)
cmd = cmd + fmt.Sprintf("--service.namespace=%s ", l.targetNamespace)
cmd = cmd + fmt.Sprintf("--service.name=%s ", l.targetService)
cmd = cmd + fmt.Sprintf("--path.base=%s ", basePath)
cmd = cmd + fmt.Sprintf("--cluster.cluster_domain=%s ", clusterDomain)

var ld linkerd.Generator
Expand Down

0 comments on commit 13161e8

Please sign in to comment.