Repository navigation
feat: API-surface trigger gating, Redis key prefix, pkg/manifestanalyzer + scan-folder/scan-repo rename #221
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
6 commits
Select commit
Hold shift + click to select a range
5260cd6
feat(watch): start API-surface trigger informers only for served reso…
sunib 0f16a06
feat(queue): add --redis-key-prefix so reversers can share one Redis
sunib cd48a4c
feat(pkg): publish pkg/manifestanalyzer as the stable adoption contract
sunib 1de3e05
fix(chart): quote the whole --redis-username arg, not its value
sunib cb43d27
chore(coverage): raise the unit baseline to 75.4%
sunib f7499c1
refactor(manifest-analyzer)!: name the scan modes after the question …
sunib 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 75.3 | ||
| 75.4 |
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
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,108 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "flag" | ||
| "os" | ||
| "os/exec" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| appsv1 "k8s.io/api/apps/v1" | ||
| "sigs.k8s.io/yaml" | ||
| ) | ||
|
|
||
| // chartInputs are read by the test process itself so `go test` records them as cache | ||
| // inputs. helm reads the chart in a subprocess, which the test log cannot see, so without | ||
| // these reads a chart-only edit would replay a cached PASS. | ||
| var chartInputs = []string{ | ||
| "../charts/gitops-reverser/values.yaml", | ||
| "../charts/gitops-reverser/templates/deployment.yaml", | ||
| } | ||
|
|
||
| // renderManagerArgs renders the chart's Deployment and returns the manager container's | ||
| // argv, exactly as the kubelet would hand it to the binary. | ||
| func renderManagerArgs(t *testing.T, setValues ...string) []string { | ||
| t.Helper() | ||
|
|
||
| for _, path := range chartInputs { | ||
| _, err := os.ReadFile(path) | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| args := []string{ | ||
| "template", "gitops-reverser", "../charts/gitops-reverser", | ||
| "--show-only", "templates/deployment.yaml", | ||
| } | ||
| for _, sv := range setValues { | ||
| args = append(args, "--set", sv) | ||
| } | ||
| out, err := exec.Command("helm", args...).CombinedOutput() | ||
| require.NoErrorf(t, err, "helm template failed: %s", out) | ||
|
|
||
| var deploy appsv1.Deployment | ||
| require.NoError(t, yaml.Unmarshal(out, &deploy)) | ||
|
|
||
| for _, c := range deploy.Spec.Template.Spec.Containers { | ||
| if c.Name == "manager" { | ||
| return c.Args | ||
| } | ||
| } | ||
| t.Fatalf("no manager container in rendered Deployment:\n%s", out) | ||
| return nil | ||
| } | ||
|
|
||
| // The chart writes the manager's argv and the binary parses it; nothing else enforces that | ||
| // the two agree. A value interpolated as a bare `{{ . | quote }}` inside a YAML plain scalar | ||
| // keeps its double quotes as literal characters, so the flag arrives with them attached and | ||
| // a validating flag rejects it — the manager then CrashLoopBackOffs on a chart that renders, | ||
| // lints and packages cleanly. Parse what the chart actually emits. | ||
| func TestChartRendersArgsTheBinaryAccepts(t *testing.T) { | ||
| tests := map[string]struct { | ||
| setValues []string | ||
| wantKeyPrefix string | ||
| wantRedisAddr string | ||
| wantRedisDBSet int | ||
| wantUsername string | ||
| }{ | ||
| "chart defaults": { | ||
| wantKeyPrefix: "gitops-reverser", | ||
| }, | ||
| "nested tenant prefix": { | ||
| setValues: []string{"queue.redis.keyPrefix=cell-a:tenant-7"}, | ||
| wantKeyPrefix: "cell-a:tenant-7", | ||
| }, | ||
| "redis enabled with auth": { | ||
| setValues: []string{ | ||
| "queue.redis.addr=redis.example.com:6379", | ||
| "queue.redis.auth.username=reverser", | ||
| "queue.redis.db=3", | ||
| "queue.redis.keyPrefix=tenant-7", | ||
| }, | ||
| wantKeyPrefix: "tenant-7", | ||
| wantRedisAddr: "redis.example.com:6379", | ||
| wantRedisDBSet: 3, | ||
| wantUsername: "reverser", | ||
| }, | ||
| } | ||
|
|
||
| for name, tc := range tests { | ||
| t.Run(name, func(t *testing.T) { | ||
| argv := renderManagerArgs(t, tc.setValues...) | ||
|
|
||
| cfg, err := parseFlagsWithArgs(flag.NewFlagSet("manager", flag.ContinueOnError), argv) | ||
| require.NoError(t, err, "the binary must accept the argv the chart renders") | ||
|
|
||
| require.Equal(t, tc.wantKeyPrefix, cfg.redisKeyPrefix) | ||
| if tc.wantRedisAddr != "" { | ||
| require.Equal(t, tc.wantRedisAddr, cfg.redisAddr) | ||
| require.Equal(t, tc.wantRedisDBSet, cfg.redisDB) | ||
| } | ||
| if tc.wantUsername != "" { | ||
| // A quoted-value render would reach Redis as `"reverser"` and fail ACL auth. | ||
| require.Equal(t, tc.wantUsername, cfg.redisUsername) | ||
| } | ||
| }) | ||
| } | ||
| } |
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.