-
Notifications
You must be signed in to change notification settings - Fork 17
feat: promote ingress settings to public #177
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
3 commits
Select commit
Hold shift + click to select a range
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
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
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,127 @@ | ||
| package tests | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| netv1 "k8s.io/api/networking/v1" | ||
| "k8s.io/utils/pointer" | ||
|
|
||
| "github.com/jinzhu/copier" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestIngress(t *testing.T) { | ||
| chart := LoadChart(t) | ||
|
|
||
| pathTypePrefix := netv1.PathTypePrefix | ||
| coderdIngressRule := netv1.IngressRuleValue{ | ||
| HTTP: &netv1.HTTPIngressRuleValue{ | ||
| Paths: []netv1.HTTPIngressPath{ | ||
| { | ||
| Path: "/", | ||
| PathType: &pathTypePrefix, | ||
| Backend: netv1.IngressBackend{ | ||
| Service: &netv1.IngressServiceBackend{ | ||
| Name: "coderd", | ||
| Port: netv1.ServiceBackendPort{ | ||
| Name: "tcp-coderd", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| tests := []struct { | ||
| Name string | ||
| // ValuesFunc is called to configure the values used in this test. | ||
| // The function should override the CoderValues as appropriate for | ||
| // the test in question. | ||
| ValuesFunc func(v *CoderValues) | ||
| // AssertFunc is called after rendering the chart, with the resulting | ||
| // Ingress object. You can use it to assert properties about the | ||
| // Ingress object. | ||
| AssertFunc func(t *testing.T, ingress *netv1.Ingress) | ||
| }{ | ||
| { | ||
| Name: "simple-ingress", | ||
| ValuesFunc: func(v *CoderValues) { | ||
| v.Ingress.Enable = pointer.Bool(true) | ||
| v.Ingress.Host = pointer.String("install.coder.com") | ||
| v.Coderd.DevURLsHost = pointer.String("*.install.coder.app") | ||
| }, | ||
| AssertFunc: func(t *testing.T, ingress *netv1.Ingress) { | ||
| defaultAnnotations := map[string]string{ | ||
| "nginx.ingress.kubernetes.io/proxy-body-size": "0", | ||
| } | ||
| require.Equal(t, defaultAnnotations, ingress.Annotations) | ||
|
|
||
| expectedRules := []netv1.IngressRule{ | ||
| { | ||
| Host: "install.coder.com", | ||
| IngressRuleValue: coderdIngressRule, | ||
| }, | ||
| { | ||
| Host: "*.install.coder.app", | ||
| IngressRuleValue: coderdIngressRule, | ||
| }, | ||
| } | ||
| require.Equal(t, expectedRules, ingress.Spec.Rules, "expected ingress spec to match") | ||
| }, | ||
| }, | ||
| { | ||
| Name: "devurl-suffix", | ||
| ValuesFunc: func(v *CoderValues) { | ||
| v.Ingress.Enable = pointer.Bool(true) | ||
| v.Ingress.Host = pointer.String("install.coder.com") | ||
| v.Coderd.DevURLsHost = pointer.String("*-dev.install.coder.app") | ||
| }, | ||
| AssertFunc: func(t *testing.T, ingress *netv1.Ingress) { | ||
| defaultAnnotations := map[string]string{ | ||
| "nginx.ingress.kubernetes.io/proxy-body-size": "0", | ||
| } | ||
| require.Equal(t, defaultAnnotations, ingress.Annotations) | ||
| expectedRules := []netv1.IngressRule{ | ||
| { | ||
| Host: "install.coder.com", | ||
| IngressRuleValue: coderdIngressRule, | ||
| }, | ||
| { | ||
| Host: "*.install.coder.app", | ||
| IngressRuleValue: coderdIngressRule, | ||
| }, | ||
| } | ||
| require.Equal(t, expectedRules, ingress.Spec.Rules, "expected ingress spec to match") | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| test := test | ||
|
|
||
| t.Run(test.Name, func(t *testing.T) { | ||
| // Clone the original values | ||
| values := &CoderValues{} | ||
| copier.Copy(values, chart.OriginalValues) | ||
|
|
||
| // Run function to perform test-specific modifications of defaults | ||
| test.ValuesFunc(values) | ||
|
|
||
| // Verify the results using AssertFunc | ||
| objs, err := chart.Render(values, nil, nil) | ||
| require.NoError(t, err, "chart render failed") | ||
|
|
||
| var found bool | ||
| for _, obj := range objs { | ||
| ingress, ok := obj.(*netv1.Ingress) | ||
| if ok && ingress.Name == "coderd-ingress" { | ||
| found = true | ||
| test.AssertFunc(t, ingress) | ||
| break | ||
| } | ||
| } | ||
| require.True(t, found, "expected ingress in manifests") | ||
| }) | ||
| } | ||
| } | ||
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
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.