Skip to content

Commit 98fdeb5

Browse files
sgress454ksykulev
authored andcommitted
Clean up Gitops tests and add deprecation tests (#43039)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** For #40015 * Moves repeated empty mocks into a new `setupEmptyGitOpsMocks` method * Adds new "deprecation" tests: * In TestGitOpsFullGlobal, TestGitOpsFullTeam and TestGitOpsFullGlobalAndTeam tests "kitchen sink" with both new and deprecated keys * Added keys and checks to verify `setup_experience`, `apple_business_manager` and `volume_purchasing_program` configs * Consolidated map of deprecated -> new GitOps keys in one place
1 parent bf1f7fd commit 98fdeb5

13 files changed

Lines changed: 1247 additions & 1584 deletions

cmd/fleetctl/fleetctl/generate_gitops.go

Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -118,50 +118,32 @@ func jsonFieldName(t reflect.Type, fieldName string) string {
118118
return name
119119
}
120120

121-
// aliasRules maps deprecated JSON key names (from `json` struct tags) to their
122-
// new canonical names (from `renameto` struct tags). Used by replaceAliasKeys
123-
// and yamlMarshalRenamed to rename keys in serialized output.
124-
var aliasRules = map[string]string{
125-
"available_teams": "available_fleets",
126-
"default_team": "default_fleet",
127-
"host_team_id": "host_fleet_id",
128-
"inherited_query_count": "inherited_report_count",
129-
"ios_team_id": "ios_fleet_id",
130-
"ios_team": "ios_fleet",
131-
"ipados_team_id": "ipados_fleet_id",
132-
"ipados_team": "ipados_fleet",
133-
"live_query_disabled": "live_reporting_disabled",
134-
"live_query_results": "discard_reports_data",
135-
"macos_team_id": "macos_fleet_id",
136-
"macos_team": "macos_fleet",
137-
"queries": "reports",
138-
"query_count": "report_count",
139-
"query_id": "report_id",
140-
"query_ids": "report_ids",
141-
"query_name": "report_name",
142-
"query_report_cap": "report_cap",
143-
"query_reports_disabled": "discard_reports_data",
144-
"query_stats": "report_stats",
145-
// Deliberately not aliasing "query" as it is used exclusively to refer to SQL in GitOps.
146-
// "query": "report",
147-
"scheduled_query_id": "scheduled_report_id",
148-
"scheduled_query_name": "scheduled_report_name",
149-
"team": "fleet",
150-
"team_id": "fleet_id",
151-
"team_ids_by_name": "fleet_ids_by_name",
152-
"team_ids": "fleet_ids",
153-
"team_name": "fleet_name",
154-
"teams": "fleets",
155-
156-
// MDM settings renames
157-
"bootstrap_package": "macos_bootstrap_package",
158-
"custom_settings": "configuration_profiles",
159-
"enable_release_device_manually": "apple_enable_release_device_manually",
160-
"macos_settings": "apple_settings",
161-
"macos_setup": "setup_experience",
162-
"macos_setup_assistant": "apple_setup_assistant",
163-
"manual_agent_install": "macos_manual_agent_install",
164-
"script": "macos_script",
121+
// aliasRules maps deprecated JSON key names to their new canonical names.
122+
// Used by replaceAliasKeys and yamlMarshalRenamed to rename keys in serialized output
123+
// for generate_gitops, fleetctl get (via printSpec), and fleetctl apply.
124+
// Derived entirely from spec.DeprecatedGitOpsKeyMappings using leaf key segments.
125+
var aliasRules = buildAliasRules()
126+
127+
func buildAliasRules() map[string]string {
128+
rules := make(map[string]string)
129+
for _, m := range spec.DeprecatedGitOpsKeyMappings {
130+
// Take the last segment of the old and new paths as the leaf key names.
131+
// Remove any array indicators (e.g. "[]") in case an array key is renamed.
132+
oldLeaf := m.OldPath
133+
if i := strings.LastIndex(oldLeaf, "."); i >= 0 {
134+
oldLeaf = oldLeaf[i+1:]
135+
}
136+
oldLeaf = strings.TrimSuffix(oldLeaf, "[]")
137+
138+
newLeaf := m.NewPath
139+
if i := strings.LastIndex(newLeaf, "."); i >= 0 {
140+
newLeaf = newLeaf[i+1:]
141+
}
142+
newLeaf = strings.TrimSuffix(newLeaf, "[]")
143+
144+
rules[oldLeaf] = newLeaf
145+
}
146+
return rules
165147
}
166148

167149
// Replace deprecated keys with their new canonical names.

0 commit comments

Comments
 (0)