nais diff: show what an apply would change
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- go, kubernetes
- Domain
- backend-api-design, cli
Research direction
Start by examining the existing apply logic in nais/cli/internal/naisapi/apply.go to add the ChangedFields field to ResourceResult. Then, look at nais/api/internal/apply/ to understand the diff generation in diff.go and how to add a dry-run query parameter to the apply endpoint. The goal is to produce a deterministic diff output that can be rendered in the CLI, matching the behavior of the existing apply command.
Written by the indexing model from the issue text.
Description
Background
Today nais apply is a one-way door: you send manifests and find out what happened
afterwards. There is no way to see what would change before changing it — neither
interactively nor in a pull request. A nais diff command would close that gap and
make manifest changes reviewable.
The good news: most of it already exists server-side
Verified in nais/api (internal/apply/):
ApplyResource(client.go) does a real Kubernetes server-side apply
(types.ApplyPatchType,FieldManager: "nais-api",Force: true), and it already
fetches the object before patching, returning{Before, After, Created}.Diff(before, after)(diff.go) already produces a structured, deterministically
sorted field diff —[]ResourceChangedField{Field, OldValue, NewValue}— with
server-managed noise (status,managedFields,resourceVersion,uid,
creationTimestamp, …) filtered out.changedFieldsis already part of the HTTP response contract
(model.go:ResourceResult.ChangedFields).
So the diff engine exists. It is currently only used to write activity log entries.
What is missing
nais/api:
- No dry-run.
PatchOptionshas noDryRun: []string{metav1.DryRunAll}, and the
handler (apply.go) reads no query parameter for it. - Activity log writing must be skipped when dry-running.
nais/cli:
3. internal/naisapi/apply.go ResourceResult does not even declare ChangedFields —
the server sends the diff and the client throws it away.
4. No rendering of changed fields, and no diff command.
Proposed scope
- Show changes in
nais applytoday. AddChangedFieldsto the CLI's
ResourceResultand print them after a successful apply. Requires no API change —
the data is already on the wire. Good standalone first step. - Dry-run in nais/api. Accept
?dryRun=trueon
POST /api/v1/teams/{team}/environments/{env}/apply, passDryRunAllthrough to
PatchOptions, skip the activity log, return the samechangedFields. nais diffin the CLI. Same argument and flag handling asnais apply— a
positional<path>that is a single file or a directory,--team/--environment,
and the same mixin semantics:<base>.<env>.yamlauto-loaded per file in directory
mode,--mixin/--setaccepted only for a single file. Calls the endpoint with
dryRun=trueand renders the result.
Parity with apply matters: the whole point is that you can swap apply for diff
in a command line and have it work. That includes rendering the manifests through the
exact same mixin path, so the diff reflects what apply would actually send.
Why server-side and not client-side
A client-side diff was considered and rejected:
- The native Valkey/OpenSearch path uses bespoke GraphQL mutations with
replace semantics (UpdateValkeyInputrequirestierandmemory, the rest are
nullable pointers), while the read queryGetAllValkeysonly returns
name/memory/tier/maxMemoryPolicy/state— notdatabases,notifyKeyspaceEvents,
persistenceDisabledor labels. A client-side diff would be systematically
incomplete and would need API changes anyway. - A server-side dry-run reflects reality: CRD defaulting, mutating/validating webhooks
and admission errors are all included. A client-side reconstruction is a guess.
CI/PR usage (the main motivation)
- run: nais diff .nais --team pensjon --environment prod-gcp > diff.txt
- uses: marocchino/sticky-pull-request-comment@v2
with: { path: diff.txt }
where .nais/ holds valkey.yaml, valkey.prod-gcp.yaml, postgres.yaml, … and the
per-environment mixins are auto-loaded,
giving a reviewable comment on the PR:
Valkey valkey-pensjon-cache (prod-gcp)
~ spec.memory: 1GB → 4GB
~ spec.tier: HighAvailability → SingleNode
Postgres pensjon-db (prod-gcp)
+ spec.extensions: [postgis]
Valkey valkey-pensjon-sessions (prod-gcp)
+ will be created
This catches things nothing else does today: that a change silently lowers
availability, that a PR creates a resource in prod nobody mentioned, and — when run
periodically on main — drift introduced outside of git.
Design notes / open questions
- Exit code. Exit 0 even when there is a diff, with an opt-in
--exit-codefor
gating (same convention asgit diff --exit-code/terraform plan -detailed-exitcode). Failing the job on every change would get the check disabled. - Deterministic output.
Diffalready sorts by field path; keep it that way or
sticky PR comments will churn on every push. - Auth.
diffneeds authentication against nais-api, unlike schema validation in
nais apply --dry-runwhich needs no credentials. That difference matters for fork
PRs and is a reason to keep both. - Coverage.
whitelist.goin nais-api allows many kinds; diff quality is bounded
by what SSA returns, which is fine, but dry-run does not catch asynchronous failures
in the operators (Aiven capacity etc.). Should be communicated in output. - Native manifest shape. The diff is computed on the CRD object. Field paths will
read asspec.memoryetc., which maps closely to the nais manifestspec, but it is
worth checking how it reads for the flat native envelope before settling on the
rendering. - Naming of the flag/command relative to
nais apply --dry-run, which does local
schema validation without contacting the API.
- Dominant language
- Go
- Stars
- 2
- Forks
- 5
- Avg merge
- 3h 49m
- Merged PRs (30d)
- 34
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nais/cli
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 56/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 57/100
Maintainers usually reply within 1 day
-
mcp: mock schema is invalid GraphQL, so schema_* tests pass on a parse errorPossibly taken @Starefossen claimed this 1 day ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
mcp: schema_list_queries returns an array as structuredContent, and its outputSchema is invalidPossibly taken @Starefossen claimed this 1 day ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 68/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
slavakurilyak/awesome-ai-agents#888 ·
Maintainers usually reply within 1 day
-
enhancement nav-pilot
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
kind/enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 1 day
-
feat(gmail): make gmail get --format raw text output the exact message, like drafts get --format rawOpenclawsweeper:needs-product-decision clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
openclaw/gogcli#1276 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Seed a JRNYAx price before the last close so asset-detail S1.3 doesn't fail from 08:00Z to the openOpenbug tests
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
lognorman20/monaco#7231 ·