Skip to content

Declarative defaults should handle cases where a field is feature-gated  #128475

Open
@thockin

Description

@thockin

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

Metadata

Metadata

Assignees

Labels

area/code-generationkind/featureCategorizes issue or PR as related to a new feature.sig/api-machineryCategorizes an issue or PR as relevant to SIG API Machinery.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions