Skip to content

Don't validate software/profile labels in dry run mode #28201

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 2 commits into from
Apr 17, 2025

Conversation

sgress454
Copy link
Contributor

@sgress454 sgress454 commented Apr 14, 2025

For #28154

This PR fixes a bug where GitOps dry runs would fail when software installers or profiles referenced labels that were created in the same run. The issue is that GitOps utilizes the real APIs for batch software/profile creation for validation, sending a dryRun flag to prevent those APIs from actually writing data. In dry run mode, no labels are actually created, so validation checks for "don't use labels that don't exist" will always fail when new labels are referenced. Recent updates to GitOps have given it the ability to validate the labels itself, removing the need to use the API for this check.

I added a new test for this in the mdm profiles tests. The test suite for software installers is a little more challenging to update for this case, and since it's not a happy path test I'm not prioritizing it, but will try to add one time permitting.

@sgress454 sgress454 requested a review from a team as a code owner April 14, 2025 14:53
Comment on lines -1504 to -1508
validatedLabels, err := ValidateSoftwareLabels(ctx, svc, payload.LabelsIncludeAny, payload.LabelsExcludeAny)
if err != nil {
return "", err
if !dryRun {
validatedLabels, err := ValidateSoftwareLabels(ctx, svc, payload.LabelsIncludeAny, payload.LabelsExcludeAny)
if err != nil {
return "", err
}
payload.ValidatedLabels = validatedLabels
}
payload.ValidatedLabels = validatedLabels
Copy link
Contributor Author

Choose a reason for hiding this comment

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

payload.ValidatedLabels is a pointer, and there's nil checks for it, so it's ok if this isn't populated in dry run mode.

@sgress454 sgress454 requested a review from lucasmrod April 14, 2025 14:56
Copy link

codecov bot commented Apr 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.99%. Comparing base (229b51f) to head (32b26ed).
Report is 69 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #28201      +/-   ##
==========================================
+ Coverage   63.97%   63.99%   +0.02%     
==========================================
  Files        1779     1780       +1     
  Lines      170499   170731     +232     
  Branches     4952     4952              
==========================================
+ Hits       109078   109261     +183     
- Misses      52830    52855      +25     
- Partials     8591     8615      +24     
Flag Coverage Δ
backend 65.04% <100.00%> (+0.02%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

Comment on lines 2121 to 2130
ds.LabelIDsByNameFunc = func(ctx context.Context, labels []string) (map[string]uint, error) {
m := map[string]uint{}
for _, label := range labels {
labelID++
m[label] = labelID
if label != "baddy" {
labelID++
m[label] = labelID
}
}
return m, nil
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this mock just spit out IDs for any label you asked for; adding a carveout for the "baddy" label so we can test what happens when an unknown label is supplied when adding a profile

Comment on lines -1236 to +1242
{"team BitLocker profile", 1,
{
"team BitLocker profile", 1,
`<Replace><Item><Target><LocURI>./Device/Vendor/MSFT/BitLocker/AllowStandardUserEncryption</LocURI></Target></Item></Replace>`, true,
syncml.DiskEncryptionProfileRestrictionErrMsg},
syncml.DiskEncryptionProfileRestrictionErrMsg,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this and the above are just formatting changes from prettier

Copy link
Member

@lucasmrod lucasmrod left a comment

Choose a reason for hiding this comment

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

Could fleetctl gitops verify with other API calls if new labels referenced in installers/profiles are actually being created on the same run?

Missing changes/ file :)

@sgress454
Copy link
Contributor Author

sgress454 commented Apr 14, 2025

Could fleetctl gitops verify with other API calls if new labels referenced in installers/profiles are actually being created on the same run?

The issue affects dry-run only, because the labels aren't actually created in the run (nothing is created, because it's a dry run). But fleetctl gitops always validates that any referenced labels will exist, either by pulling the existing labels from the API or by seeing which labels are set in the YAML file. The failed runs are passing the validation inside fleetctl gitops, which knows that the labels will exist, but failing the validation in the API which doesn't have that information. We already have a bunch of dryRun carveouts in these files (e.g.

fleet/server/service/client.go

Lines 2145 to 2155 in 11e8ed2

if config.Policies[i].InstallSoftware.AppStoreID != "" {
softwareTitleID, ok := softwareTitleIDsByAppStoreAppID[config.Policies[i].InstallSoftware.AppStoreID]
if !ok {
// Should not happen because app store apps are uploaded first.
if !dryRun {
logFn("[!] software app store app ID without software title ID: %s\n", config.Policies[i].InstallSoftware.AppStoreID)
}
continue
}
config.Policies[i].SoftwareTitleID = &softwareTitleID
}
), I just didn't realize it was a thing when implementing the labels-via-gitops feature.

@sgress454
Copy link
Contributor Author

Missing changes/ file :)

Thanks, updated!

@sgress454 sgress454 merged commit 47ac964 into main Apr 17, 2025
40 checks passed
@sgress454 sgress454 deleted the sgress454/28154-dont-validate-labels-in-dry-run-mode branch April 17, 2025 13:39
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.

2 participants