-
Notifications
You must be signed in to change notification settings - Fork 72
Switch out the envoy reverse proxy for caddy #905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4dc9330
Replace envoy reverse proxy with caddy
SteveHNH 931d336
feat: replace envoy with caddy container
SteveHNH b64d37b
test: Update tests for tls web services
SteveHNH f58482d
update generate server logic to be more concise
SteveHNH e34aff5
update deploy and deploy-mutate
SteveHNH e68dcea
fix: test for tls
SteveHNH 97b92cb
fix: make command an array in tls test
SteveHNH 72ae92a
Fixed tests
psav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
controllers/cloud.redhat.com/providers/web/caddy_reverse_proxy.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package web | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| crd "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1" | ||
|
|
||
| caddy "github.com/caddyserver/caddy/v2" | ||
| caddyconfig "github.com/caddyserver/caddy/v2/caddyconfig" | ||
| caddyhttp "github.com/caddyserver/caddy/v2/modules/caddyhttp" | ||
| "github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy" | ||
| caddytls "github.com/caddyserver/caddy/v2/modules/caddytls" | ||
| ) | ||
|
|
||
| func generateServers(pub bool, priv bool, pubPort uint32, privPort uint32, appPubPort int32, appPrivPort int32) (map[string]*caddyhttp.Server, error) { | ||
| servers := make(map[string]*caddyhttp.Server) | ||
|
|
||
| tlsConnPolicy := []*caddytls.ConnectionPolicy{{ | ||
| CertSelection: &caddytls.CustomCertSelectionPolicy{ | ||
| AnyTag: []string{"cert0"}, | ||
| }, | ||
| }} | ||
|
|
||
| if pub { | ||
| pubServer := generateServer(pubPort, appPubPort, tlsConnPolicy) | ||
| servers["pubServer"] = pubServer | ||
| } | ||
|
|
||
| if priv { | ||
| privServer := generateServer(privPort, appPrivPort, tlsConnPolicy) | ||
| servers["privServer"] = privServer | ||
| } | ||
|
|
||
| return servers, nil | ||
| } | ||
|
|
||
| func generateServer(port uint32, appPort int32, tlsConnPolicy []*caddytls.ConnectionPolicy) *caddyhttp.Server { | ||
|
|
||
| var warnings []caddyconfig.Warning | ||
|
|
||
| reverseProxy := reverseproxy.Handler{ | ||
| Upstreams: []*reverseproxy.Upstream{{ | ||
| Dial: fmt.Sprintf("localhost:%d", appPort), | ||
| }}, | ||
| } | ||
|
|
||
| server := &caddyhttp.Server{ | ||
| Listen: []string{fmt.Sprintf(":%d", port)}, | ||
| Routes: caddyhttp.RouteList{{ | ||
| HandlersRaw: []json.RawMessage{ | ||
| caddyconfig.JSONModuleObject(reverseProxy, "handler", "reverse_proxy", &warnings), | ||
| }, | ||
| }}, | ||
| TLSConnPolicies: tlsConnPolicy, | ||
| } | ||
|
|
||
| return server | ||
| } | ||
|
|
||
| func generateCaddyConfig(pub bool, priv bool, pubPort uint32, privPort uint32, env *crd.ClowdEnvironment) (string, error) { | ||
| var warnings []caddyconfig.Warning | ||
|
|
||
| var servers map[string]*caddyhttp.Server | ||
| var err error | ||
|
|
||
| appPubPort := env.Spec.Providers.Web.Port | ||
| appPrivPort := env.Spec.Providers.Web.PrivatePort | ||
|
|
||
| servers, err = generateServers(pub, priv, pubPort, privPort, appPubPort, appPrivPort) | ||
| if err != nil { | ||
| fmt.Print("error generating caddy server config. Server generation failed") | ||
| } | ||
|
|
||
| appConfig := caddyhttp.App{ | ||
| Servers: servers, | ||
| } | ||
|
|
||
| fl := caddytls.FileLoader{{ | ||
| Certificate: "/certs/tls.crt", | ||
| Key: "/certs/tls.key", | ||
| Tags: []string{"cert0"}, | ||
| }} | ||
|
|
||
| tlsConfig := caddytls.TLS{ | ||
| CertificatesRaw: caddy.ModuleMap{"load_files": caddyconfig.JSON(fl, &warnings)}, | ||
| } | ||
|
|
||
| v := caddy.Config{ | ||
| StorageRaw: []byte{}, | ||
| AppsRaw: map[string]json.RawMessage{ | ||
| "http": caddyconfig.JSON(appConfig, &warnings), | ||
| "tls": caddyconfig.JSON(tlsConfig, &warnings), | ||
| }, | ||
| } | ||
|
|
||
| pretty, _ := json.MarshalIndent(v, "", " ") | ||
| return string(pretty), nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.