Skip to content

Add patch_when_closed to GitOps and generate-gitops - #49844

Merged
cdcme merged 7 commits into
feat/39962-patch-when-closedfrom
49418-patch-when-closed-gitops
Jul 28, 2026
Merged

Add patch_when_closed to GitOps and generate-gitops#49844
cdcme merged 7 commits into
feat/39962-patch-when-closedfrom
49418-patch-when-closed-gitops

Conversation

@cdcme

@cdcme cdcme commented Jul 23, 2026

Copy link
Copy Markdown
Member

Related issue: Resolves #49418

Adds patch_when_closed support to GitOps for patch policies and round-trips it through fleetctl generate-gitops.

  • Validate patch_when_closed in the patch-policy YAML: reject an explicit continuous_automations_enabled: false alongside it (GitOps is declarative — the datastore would otherwise silently force it on), auto-set it when omitted, and reject a pre_install_query on the referenced Fleet-maintained app (Fleet manages that query).
  • Emit patch_when_closed from fleetctl generate-gitops.

Checklist for submitter

  • Input data is properly validated, SELECT * is avoided, SQL injection is prevented (using placeholders for values in statements), JS inline code is prevented especially for url redirects, and untrusted data interpolated into shell scripts/commands is validated against shell metacharacters.

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

New Fleet configuration settings

Follow this checklist for GitOps-enabled settings:

jkatz01 added 4 commits July 22, 2026 18:37
…install query

Thread patch_when_closed through the team-policy create/update API and the
update-package endpoint, and resolve the Fleet-managed "is app open" query at
install time.

Policy create/update:
- Add patch_when_closed to the create request, payload mapping, and modify path.
- Require type=patch (with a patch_software_title_id) when enabling it.
- Auto-set continuous_automations_enabled when patch_when_closed is on, and
  reject an explicit continuous_automations_enabled=false in the same request.
- Persist the column in the INSERT, UPDATE, ApplyPolicySpecs upsert, and the
  shared policy read column list; add PatchWhenClosed to PolicySpec.

Update-package:
- Add patch and patch_when_closed (FMA-only) to the request/payload.
- Reconcile the title's patch policy: create/update on patch=true, delete on
  patch=false, keyed on patch_software_title_id.
- Reject a direct pre_install_query edit while the managed query owns it.
- Return patch_when_closed from GetPatchPolicy.

GetSoftwareInstallDetails:
- Join the triggering policy and return app_open_query as the pre-install
  condition only on the policy-automation path when patch_when_closed is set;
  self-service, manual, and setup-experience installs keep the user query.
Collapse the two-phase planPatchPolicy/applyPatchPolicyPlan (struct, managed
method, and both functions) into one reconcilePatchPolicy call. It validates,
rejects a managed pre-install query edit, and creates, updates, or deletes the
title's patch policy.

Keep the FMA-only guard as an early fail-fast at the call site, and run the
reconcile at the "persist changes" boundary so a validation error can't leave a
stray policy behind. Reconcile re-derives state from the datastore, so a retry
after a partial failure converges without special conflict handling.

Consolidate the plan/apply tests into TestReconcilePatchPolicy and cover the
FMA-only rejection through the update-package flow.
… query in Go

Update-package: a newly created patch policy defaults patch_when_closed on (Force
patch is the explicit false), matching the documented default. An existing policy
keeps its value.

GetSoftwareInstallDetails: select the raw pre_install_query, app_open_query, and
the triggering policy's patch_when_closed, and pick the managed query in Go
instead of a SQL CASE. Policy-automation installs of a patch-when-closed policy
get the managed app-open query; every other path keeps the user query.
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.60656% with 20 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (feat/39962-patch-when-closed@61bae56). Learn more about missing BASE report.

Files with missing lines Patch % Lines
server/service/software_installers.go 16.66% 8 Missing and 2 partials ⚠️
ee/server/service/software_installers.go 86.66% 3 Missing and 3 partials ⚠️
server/fleet/policies.go 33.33% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@                       Coverage Diff                       @@
##             feat/39962-patch-when-closed   #49844   +/-   ##
===============================================================
  Coverage                                ?   67.91%           
===============================================================
  Files                                   ?     3891           
  Lines                                   ?   248602           
  Branches                                ?    13022           
===============================================================
  Hits                                    ?   168840           
  Misses                                  ?    64547           
  Partials                                ?    15215           
Flag Coverage Δ
backend 69.30% <83.60%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cdcme
cdcme changed the base branch from 49416-patch-when-closed-policy-package-api to feat/39962-patch-when-closed July 23, 2026 20:09
@cdcme
cdcme force-pushed the 49418-patch-when-closed-gitops branch from 4dddf8c to 1de95db Compare July 23, 2026 20:17
…ackage-api' into 49418-patch-when-closed-gitops
@cdcme
cdcme marked this pull request as ready for review July 23, 2026 21:04
@cdcme
cdcme requested a review from a team as a code owner July 23, 2026 21:04
return updatedInstaller, nil
}

func (svc *Service) reconcilePatchPolicy(ctx context.Context, payload *fleet.UpdateSoftwareInstallerPayload, installer *fleet.SoftwareInstaller) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up that I changed this a lot on the 49416-... branch so there will be a merge conflict here for this or the other PR.

@jkatz01 jkatz01 linked an issue Jul 24, 2026 that may be closed by this pull request
@cdcme
cdcme merged commit 31a096e into feat/39962-patch-when-closed Jul 28, 2026
50 of 52 checks passed
@cdcme
cdcme deleted the 49418-patch-when-closed-gitops branch July 28, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Patch when closed: GitOps support and generate-gitops

2 participants