Fix spurious config validation errors for unset optional fields
What does this MR do?
Adds a json tag with omitempty to six nil-able fields in common/config.go that previously had only a toml tag, and adds a test covering each of them.
| Line | Struct | Field |
|---|---|---|
| 370 | AutoscalerConfig |
PluginConfig AutoscalerSettingsMap |
| 483 | AutoscalerPolicyConfig |
PreemptiveMode *bool |
| 879 | KubernetesDNSConfigOption |
Value *string |
| 906 | KubernetesHostPath |
MountPropagation *string |
| 914 | KubernetesPVC |
MountPropagation *string |
| 931 | KubernetesEmptyDir |
MountPropagation *string |
Why was this MR needed?
commands/internal/configfile/validation.go reflects common.Config{} to build the schema and then validates json.Marshal(config). Both read the same struct tags. Without a json tag the reflector types the field concretely, while json.Marshal writes an explicit null for it when unset, so schema and instance contradict each other by construction and valid configs fail validation.
The most visible symptom is a Kubernetes empty_dir, host_path or pvc volume that omits mount_propagation:
at '/runners/0/kubernetes/Volumes/EmptyDirs/0/MountPropagation': got null, want stringValidation is best-effort so the runner continues, but this fires on every start for a common configuration, and through config lint. Note the property name in the path is the Go field name rather than the documented TOML key, which is the same missing tag showing through.
The test is the more durable half of this change. It validates a config that exercises each affected field, so a field added this way in future fails CI rather than shipping.
What's the best way to test this MR?
go test ./commands/internal/configfile/ -run TestValidate_UnsetOptionalFields -vAll six subtests fail on main and pass with this change. TestBuildVariablesAsFileType in common fails on main independently of this MR.
Worth knowing for anyone tempted by the smaller workaround: setting mount_propagation = "" silences the warning but breaks jobs. executors/kubernetes/kubernetes.go casts the pointer through unchecked, so the build pod is submitted with mountPropagation: "" and the API server rejects it with Unsupported value: "". Not addressed here, but treating an empty string as unset in the executor would be worth a follow-up.
What are the relevant issue numbers?
Closes #39688 (closed)