Open
Description
Given a non-gated field, I can say // +default=12345
, which will generate code like:
if obj.Field == nil {
var val int64 = 12345
obj.Field = &val
}
If I have a feature-gated field, I want the default value ONLY IF allowed by the gate. For example:
pkg/apis/core/v1/defaults.go:
if utilfeature.DefaultFeatureGate.Enabled(features.ImageVolume) && obj.Image != nil && obj.Image.PullPolicy == "" {
// PullPolicy defaults to Always if :latest tag is specified, or IfNotPresent otherwise.
_, tag, _, _ := parsers.ParseImageName(obj.Image.Reference)
if tag == "latest" {
obj.Image.PullPolicy = v1.PullAlways
} else {
obj.Image.PullPolicy = v1.PullIfNotPresent
}
}
It would be nice if I could say something like:
// +default=12345
// +featureGate=MyGateName
Field *int64
And have the generator produce:
if utilfeature.DefaultFeatureGate.Enabled(features.MyGateName) && obj.Field == nil {
var val int64 = 12345
obj.Field = &val
}
xref #120847
cc @jpbetz