diff --git a/charts/podinfo/templates/deployment.yaml b/charts/podinfo/templates/deployment.yaml index dbe4a48..d8160e3 100644 --- a/charts/podinfo/templates/deployment.yaml +++ b/charts/podinfo/templates/deployment.yaml @@ -54,6 +54,9 @@ spec: - --level={{ .Values.logLevel }} - --random-delay={{ .Values.faults.delay }} - --random-error={{ .Values.faults.error }} + {{- if .Values.h2c.enabled }} + - --h2c + {{- end }} env: {{- if .Values.ui.message }} - name: PODINFO_UI_MESSAGE diff --git a/charts/podinfo/values.yaml b/charts/podinfo/values.yaml index 918bcb1..b358c98 100644 --- a/charts/podinfo/values.yaml +++ b/charts/podinfo/values.yaml @@ -14,6 +14,9 @@ faults: delay: false error: false +h2c: + enabled: false + image: repository: stefanprodan/podinfo tag: 3.1.3 diff --git a/cmd/podinfo/main.go b/cmd/podinfo/main.go index 2f1aeff..a53db35 100644 --- a/cmd/podinfo/main.go +++ b/cmd/podinfo/main.go @@ -39,6 +39,7 @@ func main() { fs.String("ui-logo", "", "UI logo") fs.String("ui-color", "cyan", "UI color") fs.String("ui-message", fmt.Sprintf("greetings from podinfo v%v", version.VERSION), "UI message") + fs.Bool("h2c", false, "Allow upgrading to H2C") fs.Bool("random-delay", false, "between 0 and 5 seconds random delay") fs.Bool("random-error", false, "1/3 chances of a random response error") fs.Int("stress-cpu", 0, "Number of CPU cores with 100 load") diff --git a/go.mod b/go.mod index 0ce6c67..e22818e 100644 --- a/go.mod +++ b/go.mod @@ -47,6 +47,6 @@ require ( go.uber.org/atomic v1.3.2 // indirect go.uber.org/multierr v1.1.0 // indirect go.uber.org/zap v1.9.1 - golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect + golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 google.golang.org/grpc v1.23.0 ) diff --git a/pkg/api/server.go b/pkg/api/server.go index df71f6a..b5aa67d 100644 --- a/pkg/api/server.go +++ b/pkg/api/server.go @@ -4,6 +4,9 @@ import ( "context" "fmt" "github.com/swaggo/swag" + "golang.org/x/net/http2" + "golang.org/x/net/http2/h2c" + "net/http" _ "net/http/pprof" "os" @@ -59,6 +62,7 @@ type Config struct { Port string `mapstructure:"port"` PortMetrics int `mapstructure:"port-metrics"` Hostname string `mapstructure:"hostname"` + H2C bool `mapstructure:"h2c"` RandomDelay bool `mapstructure:"random-delay"` RandomError bool `mapstructure:"random-error"` JWTSecret string `mapstructure:"jwt-secret"` @@ -141,12 +145,19 @@ func (s *Server) ListenAndServe(stopCh <-chan struct{}) { s.registerHandlers() s.registerMiddlewares() + var handler http.Handler + if s.config.H2C { + handler = h2c.NewHandler(s.router, &http2.Server{}) + } else { + handler = s.router + } + srv := &http.Server{ Addr: ":" + s.config.Port, WriteTimeout: s.config.HttpServerTimeout, ReadTimeout: s.config.HttpServerTimeout, IdleTimeout: 2 * s.config.HttpServerTimeout, - Handler: s.router, + Handler: handler, } //s.printRoutes()