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

Add namespace scoped ParametersReference to IngressClass #99275

Merged

Conversation

hbagdi
Copy link
Contributor

@hbagdi hbagdi commented Feb 20, 2021

What type of PR is this?

/kind feature
/kind api-change

What this PR does / why we need it:

This PR adds two new field Scope and Namespace to IngressClass.spec.Parameters (feature gated).

Which issue(s) this PR fixes:

Fixes #97396

Does this PR introduce a user-facing change?

IngressClass resource can now reference a resource in a specific namespace 
for implementation-specific configuration(previously only Cluster-level resources were allowed). 
This feature can be enabled using the IngressClassNamespacedParams feature gate.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

/sig network
/cc @robscott
/priority important-soon

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API sig/network Categorizes an issue or PR as relevant to SIG Network. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Feb 20, 2021
@hbagdi hbagdi force-pushed the feat/ingress-class-namespaced-params branch from a9198c6 to 0118acd Compare February 20, 2021 20:18
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 20, 2021
@hbagdi hbagdi force-pushed the feat/ingress-class-namespaced-params branch from 0118acd to 127f554 Compare February 20, 2021 20:20
Copy link
Member

@robscott robscott left a comment

Choose a reason for hiding this comment

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

Thanks for your work on this @hbagdi! I took a quick look at this and I think you're headed in the right direction, just a few comments but likely missed some things. Will try to take a more thorough look later this week.

pkg/apis/networking/v1/defaults_test.go Outdated Show resolved Hide resolved
pkg/apis/networking/v1/defaults_test.go Outdated Show resolved Hide resolved
return allErrs
// ValidateIngressClassCreate ensures that IngressClass resources are valid as they are created.
func ValidateIngressClassCreate(ingressClass *networking.IngressClass) field.ErrorList {
allowScope := utilfeature.DefaultFeatureGate.Enabled(features.IngressClassNamespacedParams)
Copy link
Member

Choose a reason for hiding this comment

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

Although I know this has been done in validation (including by me), I think the proper way to do this is in strategy like what NetworkPolicy is doing (https://github.com/kubernetes/kubernetes/blob/master/pkg/registry/networking/networkpolicy/strategy.go#L52)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@robscott I tried taking up the strategy route but ran into a problem in validation code:
Scope is a new field with a default value. If Scope is force reset in strategy and validation package performs validation on the field, then the validation fails because Scope is an empty string.
We can update the validation code to run only if Scope is not empty but that doesn't seem correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went ahead and updated the code as per #97058 with one exception that validation for Scope field is feature gated. Does that seem reasonable?

@hbagdi hbagdi force-pushed the feat/ingress-class-namespaced-params branch from 127f554 to adb13ce Compare February 25, 2021 10:00
@hbagdi
Copy link
Contributor Author

hbagdi commented Feb 25, 2021

/retest

@hbagdi hbagdi force-pushed the feat/ingress-class-namespaced-params branch from adb13ce to 9bd1697 Compare February 25, 2021 11:32
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 25, 2021
@hbagdi hbagdi force-pushed the feat/ingress-class-namespaced-params branch 2 times, most recently from 08bcbb5 to cfa029e Compare February 25, 2021 12:58
Copy link
Member

@robscott robscott left a comment

Choose a reason for hiding this comment

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

Thanks for all your work on this!

pkg/apis/networking/types.go Outdated Show resolved Hide resolved
pkg/apis/networking/v1/defaults.go Outdated Show resolved Hide resolved
pkg/apis/networking/v1/defaults_test.go Outdated Show resolved Hide resolved
pkg/apis/networking/v1/defaults_test.go Outdated Show resolved Hide resolved
pkg/apis/networking/v1/defaults_test.go Outdated Show resolved Hide resolved
pkg/features/kube_features.go Outdated Show resolved Hide resolved
pkg/apis/networking/types.go Outdated Show resolved Hide resolved
pkg/apis/networking/types.go Outdated Show resolved Hide resolved
staging/src/k8s.io/api/networking/v1/types.go Outdated Show resolved Hide resolved
staging/src/k8s.io/api/networking/v1beta1/types.go Outdated Show resolved Hide resolved
@hbagdi hbagdi force-pushed the feat/ingress-class-namespaced-params branch 2 times, most recently from 0f8d184 to 88f6bb8 Compare February 26, 2021 09:02
@k8s-ci-robot k8s-ci-robot removed the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Feb 26, 2021
@hbagdi hbagdi force-pushed the feat/ingress-class-namespaced-params branch 2 times, most recently from f6f6508 to 2ae2f10 Compare March 5, 2021 08:28
@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Mar 5, 2021
@hbagdi hbagdi force-pushed the feat/ingress-class-namespaced-params branch 2 times, most recently from 8dd9aec to dba3cd9 Compare March 5, 2021 11:52
@hbagdi
Copy link
Contributor Author

hbagdi commented Mar 5, 2021

@thockin Thanks for the review. I've updated the PR, except #99275 (comment), where I've a question. PTAL when you get a chance.

// Scope represents if this refers to a cluster or namespace scoped resource.
// This may be set to "Cluster" (default) or "Namespace".
// Field can be enabled with IngressClassNamespacedParams feature gate.
// +optional
Copy link
Member

Choose a reason for hiding this comment

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

minor: We're adding a +featureGate=IngressClassNamespacedParams tag for gated fields, which would be both of these

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A quick grep revealed no prior art.
I added the tag here as well as in k8s.io/api/networking/*. Let me know if we only need this in pkg/apis.

Copy link
Member

Choose a reason for hiding this comment

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

We really only needed in the versioned files, but most people sync those comments to the unversioned

@@ -43,3 +46,12 @@ func SetDefaults_NetworkPolicy(obj *networkingv1.NetworkPolicy) {
}
}
}

func SetDefaults_IngressClass(obj *networkingv1.IngressClass) {
Copy link
Member

Choose a reason for hiding this comment

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

minor: you could make this named and typed for the Params struct, so you don't need the additional nil-check (I think)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried but this didn't work. I'm not familiar with codegen here but based on some reading of a few zz_generated.defaults.go that's not the case.
Furthermore, scheme.AddTypeDefaultingFunc() requires a type which implements runtime.Object.

pkg/apis/networking/validation/validation.go Show resolved Hide resolved
@hbagdi hbagdi force-pushed the feat/ingress-class-namespaced-params branch from dba3cd9 to ae7a13b Compare March 5, 2021 19:16
@hbagdi
Copy link
Contributor Author

hbagdi commented Mar 5, 2021

/test pull-kubernetes-unit
/test pull-kubernetes-e2e-ubuntu-gce-network-policies

// Scope represents if this refers to a cluster or namespace scoped resource.
// This may be set to "Cluster" (default) or "Namespace".
// Field can be enabled with IngressClassNamespacedParams feature gate.
// +optional
Copy link
Member

Choose a reason for hiding this comment

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

We really only needed in the versioned files, but most people sync those comments to the unversioned

}, fldPath)...)

if utilfeature.DefaultFeatureGate.Enabled(features.IngressClassNamespacedParams) && params.Scope == nil {
allErrs = append(allErrs, field.Required(fldPath.Child("scope"), "scope is required"))
Copy link
Member

Choose a reason for hiding this comment

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

nit: the last arg should be "" - the field name and error are encoded in the type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for this comment. I came to the same conclusion but then my confidence gave way to the code already in this file. Changing it back.

} else {

if scope == networking.IngressClassParametersReferenceScopeNamespace {
if namespace == "" {
Copy link
Member

Choose a reason for hiding this comment

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

minor: the downside of using DerefOr is that you will return a "required" error when you should return an "invalid". If the user went out of their way to specify namespace: "" that is different than not specifying anything (nil)

Copy link
Member

Choose a reason for hiding this comment

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

DerefOr is OK for scope because you check the set of allowed values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I got rid off DerefOr for namespace.


if scope == networking.IngressClassParametersReferenceScopeNamespace {
if namespace == "" {
allErrs = append(allErrs, field.Required(fldPath.Child("namespace"), "namespace is required when spec.parameters.scope is set to Namespace"))
Copy link
Member

Choose a reason for hiding this comment

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

last arg should be (note the quoting)

"`parameters.scope` is set to 'Namespace'"

}

if scope == networking.IngressClassParametersReferenceScopeCluster && namespace != "" {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("namespace"), "namespace is forbidden when spec.parameters.scope is set to Cluster"))
Copy link
Member

Choose a reason for hiding this comment

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

last arg should be

"`parameters.scope` is set to 'Cluster'"

Copy link
Member

Choose a reason for hiding this comment

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

The rest of the human-friendly error will be assembed from the error type and field path

}
}

if scope == networking.IngressClassParametersReferenceScopeCluster && namespace != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Even worse than above, this will allow a user to set scope: Cluster and namespace: "" and it will pass validation. namespace must be nil, not "".

expectedErrs: field.ErrorList{field.Required(field.NewPath("spec.parameters.namespace"),
"namespace is required when spec.parameters.scope is set to Namespace")},
},
"namespace is forbidden when scope is Cluster": {
Copy link
Member

Choose a reason for hiding this comment

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

Add another - same this case but set namespace to "" - it should fail

@hbagdi hbagdi force-pushed the feat/ingress-class-namespaced-params branch from ae7a13b to 967aa14 Compare March 5, 2021 21:33
@thockin
Copy link
Member

thockin commented Mar 5, 2021

I can't find anything left to complain about. No fun!

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 5, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hbagdi, thockin

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

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Mar 5, 2021
@hbagdi hbagdi force-pushed the feat/ingress-class-namespaced-params branch from 967aa14 to a7fc920 Compare March 6, 2021 19:15
@k8s-ci-robot k8s-ci-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Mar 6, 2021
@hbagdi
Copy link
Contributor Author

hbagdi commented Mar 6, 2021

@thockin @robscott Could I get a /lgtm again? I had to rebase due to a conflict in pkg/features/kube_features.go.

@robscott
Copy link
Member

robscott commented Mar 6, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 6, 2021
@hbagdi
Copy link
Contributor Author

hbagdi commented Mar 6, 2021

/test pull-kubernetes-e2e-kind-ipv6

@k8s-ci-robot
Copy link
Contributor

@hbagdi: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-kubernetes-integration a7fc920 link /test pull-kubernetes-integration

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@robscott
Copy link
Member

robscott commented Mar 6, 2021

/retest

@k8s-ci-robot k8s-ci-robot merged commit 4bf8503 into kubernetes:master Mar 6, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.21 milestone Mar 6, 2021
@hbagdi hbagdi deleted the feat/ingress-class-namespaced-params branch March 7, 2021 07:28
@liggitt liggitt moved this from Assigned to API review completed, 1.21 in API Reviews Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review Categorizes an issue or PR as actively needing an API review. approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. 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 Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/network Categorizes an issue or PR as relevant to SIG Network. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: API review completed, 1.21
Development

Successfully merging this pull request may close these issues.

Add the ability to target an IngressClass controller in a specific namespace
5 participants