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

Proposal/Feature add flag --skip-empty-annotation to honor only annotated resources. #664

Merged
merged 10 commits into from
Jul 7, 2020

Conversation

nutellinoit
Copy link
Contributor

What this PR does / why we need it:
This PR addresses the need to limit kong ingress controller on only the annotated resources. Mainly when using multiple ingress controller in a Kubernetes cluster.

Special notes for your reviewer:
I added only a flag on the ingress controller --skip-empty-annotation that when set to true skips the evaluation of all non annotated resources.

I tried the setup on minikube with some ingresses and kong CRDs and everything is working. Also make test-all is passing and I added some new test case on internal/ingress/annotations/annotations_test.go test suite.

Thank you!

@CLAassistant
Copy link

CLAassistant commented May 14, 2020

CLA assistant check
All committers have signed the CLA.

@hbagdi
Copy link
Member

hbagdi commented May 19, 2020

We are discussing this internally if this should be added or not. This is something that has been asked for quite a bit. We need to figure out what would be a good default value and what would be the recommendation going forward, especially with Ingress V1 in Kubernetes 1.18 which changes how class should be interpreted. We will look into this post 0.9 release which is scheduled for next week.

@nutellinoit
Copy link
Contributor Author

Thank you @hbagdi !

Copy link
Member

@hbagdi hbagdi 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 the PR. We need to polish this up a little bit but this is a step in the right direction.

@@ -264,6 +264,7 @@ There are a few different ways of accomplishing this:
where any ingress resource that is not annotated is picked up.
Therefore with different ingress class then `kong`, you have to use that
ingress class with every Kong CRD object (plugin, consumer) which you use.
You can force the honoring of only `kong` ingress class using the flag `--skip-empty-annotation=true`.
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the doc update from this PR. We will do doc updates later.

go.mod Outdated
@@ -26,7 +26,9 @@ require (
github.com/tidwall/gjson v1.2.1
github.com/tidwall/match v1.0.1 // indirect
github.com/tidwall/pretty v0.0.0-20190325153808-1166b9ac2b65 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
Copy link
Member

Choose a reason for hiding this comment

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

These dependencies shouldn't be added. Please clean go.mod and go.sum files.

@@ -46,15 +46,15 @@ const (
DefaultIngressClass = "kong"
)

func validIngress(ingressAnnotationValue, ingressClass string) bool {
func validIngress(ingressAnnotationValue, ingressClass string, skipEmptyAnnotation bool) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Can you rename the variable to skipClasslessIngress?
Ingress class is a formalized concept in Ingress v1 and we would like to reuse parts of this PR for that as well.

@@ -158,6 +159,8 @@ Kong's Admin SSL certificate.`)
// Resource filtering
flags.String("watch-namespace", apiv1.NamespaceAll,
`Namespace to watch for Ingress. Default is to watch all namespaces`)
flags.Bool("skip-empty-annotation", false,
Copy link
Member

Choose a reason for hiding this comment

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

Please rename this flag to skip-classless-ingress-v1beta1.
We plan to introduce another flag to control this behavior for Ingress v1 as well.

IngressClass string
ElectionID string
WatchNamespace string
SkipEmptyAnnotation 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 rename this field to SkipClasslessIngressV1beta1. Please rename other fields accordingly.

// we have 2 valid combinations
// 1 - ingress with default class | blank annotation on ingress
// 2 - ingress with specific class | same annotation on ingress
//
// and 2 invalid combinations
// 3 - ingress with default class | fixed annotation on ingress
// 4 - ingress with specific class | different annotation on ingress
if ingressAnnotationValue == "" && ingressClass == DefaultIngressClass {
if ingressAnnotationValue == "" && !skipEmptyAnnotation && ingressClass == DefaultIngressClass {
Copy link
Member

Choose a reason for hiding this comment

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

Can you please update the code comments according to this change?
This is a tricky logic and we should document it for future-selves.

controller string
isValid bool
ingress string
forceIngress 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 rename forceIngress to something meaningful.
How about SkipClasslessIngress?

{"custom", false, "custom", true},
{"", false, "killer", false},
{"custom", false, "kong", false},
{"custom", true, "kong", false},
Copy link
Member

Choose a reason for hiding this comment

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

Can we add {"", true, "custom", false}?

@@ -102,11 +104,12 @@ type CacheStores struct {
}

// New creates a new object store to be used in the ingress controller
func New(cs CacheStores, ingressClass string) Storer {
func New(cs CacheStores, ingressClass string, skipEmptyAnnotation bool) Storer {
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be refactored away but let's keep that out of scope for this PR.

@hbagdi hbagdi changed the base branch from master to next June 2, 2020 20:35
@hbagdi
Copy link
Member

hbagdi commented Jun 2, 2020

Also, please rebase on latest next branch.

@nutellinoit
Copy link
Contributor Author

Hi @hbagdi , i will make the requested changes as soon as possible, thank you for the feedback!

…/skip-empty-annotation/skip-classless-ingress-v1beta1/g, s/skipEmptyAnnotation/skipClasslessIngress/g, s/forceIngress/skipClasslessIngress/g, go fmt, added one more test
@nutellinoit
Copy link
Contributor Author

Hi @hbagdi , i did all the requested changes!

Copy link
Member

@hbagdi hbagdi left a comment

Choose a reason for hiding this comment

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

This needs an integration test. Please look in parser_test.go to add that and then this should be good to go.

@@ -140,7 +140,7 @@ func NewFakeStore(

KnativeIngress: knativeIngressStore,
},
isValidIngresClass: annotations.IngressClassValidatorFuncFromObjectMeta("kong"),
isValidIngresClass: annotations.IngressClassValidatorFuncFromObjectMeta("kong", false),
Copy link
Member

Choose a reason for hiding this comment

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

Can you make this configurable and tweak NewFakeStore to pass this in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!

@hbagdi
Copy link
Member

hbagdi commented Jun 24, 2020

Friendly ping on an update on this.

@nutellinoit
Copy link
Contributor Author

Friendly ping on an update on this.

I will look into it this week! Thanks for the ping

@nutellinoit
Copy link
Contributor Author

Hi @hbagdi , i did the requested changes!

Copy link
Member

@hbagdi hbagdi left a comment

Choose a reason for hiding this comment

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

This a good step towards where we want to be but it is not the final state. We will do a few changes before this is actually released. The updated plan is documented in a Google doc in #690.

@hbagdi hbagdi merged commit 4bf2405 into Kong:next Jul 7, 2020
@hbagdi
Copy link
Member

hbagdi commented Jul 8, 2020

Thank you for your contribution. Please fill out the following form to claim your contributor swag:
https://github.com/Kong/kong/blob/master/CONTRIBUTING.md#contributor-t-shirt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants