Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic in featuregate if a requested feature is unknown #84865

Merged
merged 3 commits into from Nov 8, 2019

Conversation

deads2k
Copy link
Contributor

@deads2k deads2k commented Nov 6, 2019

featuregates.Enabled should not silently return false if a request feature is not registered. This PR updates the code to panic so that coding error is noticed at the point of usage instead of silently going down unexpected branches.

You get items like

	panic: feature "IPv6DualStack" is not registered in FeatureGate "k8s.io/apiserver/pkg/util/feature/feature_gate.go:28"

/kind bug
/priority important-soon
@kubernetes/sig-api-machinery-bugs

NONE

@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Nov 6, 2019
@liggitt
Copy link
Member

liggitt commented Nov 6, 2019

Checking for enablement of a feature that is not registered is a programming error. I'm generally in favor of this. Will be interesting to see what in CI complains about this.

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Nov 6, 2019
@deads2k
Copy link
Contributor Author

deads2k commented Nov 6, 2019

Will be interesting to see what in CI complains about this.

Surely it will all work fine....

@liggitt
Copy link
Member

liggitt commented Nov 6, 2019

/approve

needs a release note, since this is consumable by external components

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 6, 2019
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. area/cloudprovider sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 6, 2019
@deads2k
Copy link
Contributor Author

deads2k commented Nov 6, 2019

/retest

@k8s-ci-robot k8s-ci-robot removed the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 6, 2019
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 6, 2019
@deads2k
Copy link
Contributor Author

deads2k commented Nov 6, 2019

needs a release note, since this is consumable by external components

we agree on slack that the message is very clear.

}
}()

ipv6DualStackEnabled = utilfeature.DefaultFeatureGate.Enabled(IPv6DualStack)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it still possible to change the value? I don't understand how this can work, flags won't have been parsed while init functions are running?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, this can't be initialized in init. could make it a member of the Cloud struct and set it in NewCloud

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, yeah, I asked for that exact thing in my other comment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where's @liggittlamp when you need him

@@ -104,6 +104,26 @@ const (
clusterNameKey = "kubernetes-cluster-name"
)

var (
// ipv6DualStack allows overriding for unit testing. It's normally initialized from featuregates
ipv6DualStackEnabled bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make it a member variable of something and set it on construction.

@@ -128,6 +132,10 @@ func setUnsetAlphaGates(known map[Feature]FeatureSpec, enabled map[Feature]bool,
// Set, String, and Type implement pflag.Value
var _ pflag.Value = &featureGate{}

// internalPackages are packages that ignored when creating a name for featureGates These packages are in the common
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run-on sentence.

@@ -128,6 +132,10 @@ func setUnsetAlphaGates(known map[Feature]FeatureSpec, enabled map[Feature]bool,
// Set, String, and Type implement pflag.Value
var _ pflag.Value = &featureGate{}

// internalPackages are packages that ignored when creating a name for featureGates These packages are in the common
// call chains, so they'd be low entropy names for reflectors
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/low entropy/unhelpful/

... this way I don't have to debate with myself any more if "low" or "high" entropy is more technically correct

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 6, 2019
@deads2k
Copy link
Contributor Author

deads2k commented Nov 6, 2019

comments addressed

func() {
// this allows the code ot launch without featuregates defined. It is currently required for unit tests where the
// featuregates are not registered. This is effectively coding by side effect and an explicit register should
// be eventually created instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open a follow up issue for cloud-controller-manager/providers to resolve this?

// this allows the code ot launch without featuregates defined. It is currently required for unit tests where the
// featuregates are not registered. This is effectively coding by side effect and an explicit register should
// be eventually created instead.
defer func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you split the NewCloud function so that test code doesn't have to execute this, do you still need to catch the panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you split the NewCloud function so that test code doesn't have to execute this, do you still need to catch the panic?

And let it straight die instead? That's not consistent with existing behavior. I'm honestly unsure if this ever worked properly when it really ran. Are you sure you want to change behavior?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And let it straight die instead?

Yup, that's the goal of the change, isn't it? :)

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: deads2k, liggitt

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deads2k
Copy link
Contributor Author

deads2k commented Nov 7, 2019

@khenidak This update makes the azure cloud provider require the definition of IPv6DualStack feature gate or it will fail with a message saying the featuregate is not defined. It can be defined as false (this is the default in the cloud-controller-manager).

@k8s-ci-robot k8s-ci-robot added the sig/storage Categorizes an issue or PR as relevant to SIG Storage. label Nov 7, 2019
@deads2k
Copy link
Contributor Author

deads2k commented Nov 7, 2019

/retest

1 similar comment
@deads2k
Copy link
Contributor Author

deads2k commented Nov 7, 2019

/retest

return az, nil
}

// NewCloudWithoutFeatureGates returns a Cloud without trying to wire the feature gates. This is used by the unit tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Looks like it can't be made private, or I would definitely ask for that. Oh well.

@lavalamp
Copy link
Member

lavalamp commented Nov 7, 2019

/lgtm

@khenidak If you run this cloud provider in alternative environments, you'll definitely want to take a look at this.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 7, 2019
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@k8s-ci-robot k8s-ci-robot merged commit bae8f56 into kubernetes:master Nov 8, 2019
@k8s-ci-robot k8s-ci-robot added this to the v1.17 milestone Nov 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/cloudprovider cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. sig/storage Categorizes an issue or PR as relevant to SIG Storage. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants