Repository navigation
Add oap render: a GitOps-ready kustomize overlay for the install
#33
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
Open
josephschorr
wants to merge
1
commit into
main
Choose a base branch
from
worktree-oap-render-gitops
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package health | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
||
| "github.com/authzed/openagentprimitives/cmd/oap/internal/kube" | ||
| "github.com/authzed/openagentprimitives/pkg/platform/bootstrap" | ||
| ) | ||
|
|
||
| func init() { | ||
| // Verifies the memory-token Secrets exist. This is the GitOps-specific check: | ||
| // `oap install` creates these imperatively, but a bundle synced by Argo/Flux | ||
| // relies on the pre-start bootstrap Job (the operator image's | ||
| // `bootstrap-secrets` entrypoint) to mint them — so their absence is the | ||
| // signal that the Job never completed (wrong image, backoff exhausted, or the | ||
| // operator ServiceAccount is missing Secret RBAC). | ||
| Register(memoryTokenSecrets{}) | ||
| } | ||
|
|
||
| // memoryTokenSecrets checks that each memory-token Secret exists and carries a | ||
| // non-empty token. It covers the three memory tokens (bootstrap.MemoryTokenSecretNames) | ||
| // the bootstrap Job mints; the other app-internal secrets the Job mints (admind, | ||
| // passthrough, NATS, spicedb/postgres) are verified indirectly by the workload | ||
| // health checks that mount them. | ||
| type memoryTokenSecrets struct{} | ||
|
|
||
| func (memoryTokenSecrets) Name() string { return "memory-token-secrets" } | ||
|
|
||
| func (memoryTokenSecrets) Check(ctx context.Context, b *kube.Bundle) Result { | ||
| var missing []string | ||
| present := 0 | ||
| for _, name := range bootstrap.MemoryTokenSecretNames { | ||
| sec, err := b.Typed.CoreV1().Secrets(namespace).Get(ctx, name, metav1.GetOptions{}) | ||
| switch { | ||
| case apierrors.IsNotFound(err): | ||
| missing = append(missing, name) | ||
| case err != nil: | ||
| return Result{Status: Failed, Detail: fmt.Sprintf("get %s: %v", name, err)} | ||
| case len(sec.Data[bootstrap.TokenSecretKey]) == 0: | ||
| missing = append(missing, name+" (empty token)") | ||
| default: | ||
| present++ | ||
| } | ||
| } | ||
| total := len(bootstrap.MemoryTokenSecretNames) | ||
| switch { | ||
| case len(missing) == 0: | ||
| return Result{Status: OK, Detail: fmt.Sprintf("%d/%d memory tokens present", present, total)} | ||
| case present == 0: | ||
| // None present: the bootstrap Job has not minted them. NotFound lets a | ||
| // trimmed profile skip, matching the workload checks. | ||
| return Result{Status: Failed, Detail: "no memory tokens present (the bootstrap Job has not minted them)", NotFound: true} | ||
| default: | ||
| return Result{Status: Failed, Detail: "missing memory tokens: " + strings.Join(missing, ", ")} | ||
| } | ||
| } | ||
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,70 @@ | ||
| package health | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/client-go/kubernetes/fake" | ||
|
|
||
| "github.com/authzed/openagentprimitives/cmd/oap/internal/kube" | ||
| "github.com/authzed/openagentprimitives/pkg/platform/bootstrap" | ||
| ) | ||
|
|
||
| func tokenSecret(name string, token string) *corev1.Secret { | ||
| s := &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace}} | ||
| if token != "" { | ||
| s.Data = map[string][]byte{bootstrap.TokenSecretKey: []byte(token)} | ||
| } | ||
| return s | ||
| } | ||
|
|
||
| func bundleWith(objs ...runtime.Object) *kube.Bundle { | ||
| return &kube.Bundle{Typed: fake.NewSimpleClientset(objs...)} | ||
| } | ||
|
|
||
| func TestMemoryTokenSecrets_AllPresentOK(t *testing.T) { | ||
| var objs []runtime.Object | ||
| for _, n := range bootstrap.MemoryTokenSecretNames { | ||
| objs = append(objs, tokenSecret(n, "deadbeef")) | ||
| } | ||
| res := memoryTokenSecrets{}.Check(context.Background(), bundleWith(objs...)) | ||
| assert.Equal(t, OK, res.Status) | ||
| assert.False(t, res.NotFound) | ||
| } | ||
|
|
||
| func TestMemoryTokenSecrets_MissingOneFails(t *testing.T) { | ||
| var objs []runtime.Object | ||
| for _, n := range bootstrap.MemoryTokenSecretNames[1:] { // omit the first | ||
| objs = append(objs, tokenSecret(n, "deadbeef")) | ||
| } | ||
| res := memoryTokenSecrets{}.Check(context.Background(), bundleWith(objs...)) | ||
| assert.Equal(t, Failed, res.Status) | ||
| assert.Contains(t, res.Detail, bootstrap.MemoryTokenSecretNames[0], "names the missing Secret") | ||
| assert.False(t, res.NotFound, "some present → not a clean NotFound") | ||
| } | ||
|
|
||
| func TestMemoryTokenSecrets_EmptyTokenFails(t *testing.T) { | ||
| var objs []runtime.Object | ||
| objs = append(objs, tokenSecret(bootstrap.MemoryTokenSecretNames[0], "")) // present but empty | ||
| for _, n := range bootstrap.MemoryTokenSecretNames[1:] { | ||
| objs = append(objs, tokenSecret(n, "deadbeef")) | ||
| } | ||
| res := memoryTokenSecrets{}.Check(context.Background(), bundleWith(objs...)) | ||
| assert.Equal(t, Failed, res.Status) | ||
| assert.Contains(t, res.Detail, "empty token") | ||
| } | ||
|
|
||
| func TestMemoryTokenSecrets_AllAbsentNotFound(t *testing.T) { | ||
| res := memoryTokenSecrets{}.Check(context.Background(), bundleWith()) | ||
| assert.Equal(t, Failed, res.Status) | ||
| assert.True(t, res.NotFound, "none present → NotFound so trimmed profiles can skip") | ||
| // The tokens are minted by the pre-start bootstrap Job, NOT the operator | ||
| // runnable (that design was abandoned). A cold-start diagnosis must point at | ||
| // the Job so an operator doesn't hunt for operator mint logs that never exist. | ||
| assert.Contains(t, res.Detail, "bootstrap Job", "attributes a cold-start miss to the Job, not the operator") | ||
| assert.NotContains(t, res.Detail, "operator bootstrap", "must not misdirect to the abandoned operator-mint design") | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[minor]
oap checkverifies only the default memory-token Secret names, never the linked onesProblem: The loop iterates
bootstrap.MemoryTokenSecretNames. With--channelsd-memory-token-secret=my-tokthe Deployment mountsmy-tok(render_overlay.go:60-64) but the Job still mints the default names (render.go:173), sooap checkreports "3/3 memory tokens present" while channelsd sits in CreateContainerConfigError ifmy-tokis missing.render_validate.go:27andgitops.mdx:101-103sayoap checkcovers linked Secrets.Fix: Resolve the names from the live channelsd, webd and authzd Deployments (the
secretKeyRef/volume Secret name used for the memory token) instead of the constant, falling back toMemoryTokenSecretNameswhen a Deployment is absent (keep the existing NotFound behavior for trimmed profiles). Never log token values.Test: Add cases in the health secrets test (same package,
secrets_test.go): a Deployment linked to a Secret that is missing reports Failed naming it; a linked present Secret passes. Rungo test ./cmd/oap/internal/health/.