kubernetes/kops · error
failed to serialize kops-controller config: %v
Error message
failed to serialize kops-controller config: %v
What it means
After building the kops-controller config struct, KopsControllerConfig serializes it with json.Marshal (JSON is a subset of YAML). If marshaling fails, this error wraps it. In practice json.Marshal of a plain struct essentially never fails, so this indicates a marshaling edge case or corruption of the config struct (e.g. unsupported types reached via embedded options).
Source
Thrown at upup/pkg/fi/cloudup/template_functions.go:938
config.Server.Provider.Linode = &linode.LinodeVerifierOptions{}
case kops.CloudProviderMetal:
// Use crypto public/private keys for Metal
config.Server.PKI = &pkibootstrap.Options{}
default:
return "", fmt.Errorf("unsupported cloud provider %s", cluster.GetCloudProvider())
}
}
if cluster.Spec.IsKopsControllerIPAM() {
config.EnableCloudIPAM = true
}
// To avoid indentation problems, we marshal as json. json is a subset of yaml
b, err := json.Marshal(config)
if err != nil {
return "", fmt.Errorf("failed to serialize kops-controller config: %v", err)
}
return string(b), nil
}
// KopsControllerArgv returns the args to kops-controller
func (tf *TemplateFunctions) KopsControllerArgv() ([]string, error) {
var argv []string
// Verbose, but not excessive logging
argv = append(argv, "--v=2")
argv = append(argv, "--conf=/etc/kubernetes/kops-controller/config/config.yaml")
return argv, nil
}
func (tf *TemplateFunctions) ExternalDNSArgv() ([]string, error) {View on GitHub (pinned to 4c8573c808)
Solutions
- Inspect the wrapped error to identify the unmarshalable field/type.
- If you added a new field to the config struct, change its type to something JSON-marshalable (or add json:"-").
- Report upstream if hit on an unmodified kOps build.
Example fix
// before
Debug chan struct{} `json:"debug"`
// after
Debug bool `json:"debug"` Defensive patterns
Strategy: try-catch
Try / catch
// Go
b, err := json.Marshal(config)
if err != nil {
// log full config struct type to locate the offending field
klog.Errorf("kops-controller config marshal failed: %v", err)
return "", fmt.Errorf("failed to serialize kops-controller config: %v", err)
} Prevention
- Keep config struct fields JSON-marshalable
- Avoid channels/funcs/custom marshalers in config options structs
- Run unit tests rendering configs for all supported clouds
When it happens
Trigger: json.Marshal(config) returns an error inside KopsControllerConfig — effectively only if the config struct contains a value that cannot be marshaled (unsupported type, channel, func field, or a custom MarshalJSON returning an error).
Common situations: Extremely rare in normal use; mostly encountered when hacking on kOps itself, adding a new field of an unmarshalable type to pkibootstrap.Options or the kops-controller config struct.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- error building annotation patch: %v
- building node patch: %w
- error building node patch: %v
- marshalling nodeupConfig: %w
- error marshaling json: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/6d258f05b54af32d.
Report an issue: GitHub.