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

Improve parsing of annotations and use of Ingress wrapper #3474

Merged
merged 3 commits into from
Dec 5, 2018

Conversation

aledbf
Copy link
Member

@aledbf aledbf commented Nov 28, 2018

What this PR does / why we need it:

Continues the work started in #3437 and introduce a new local store that contains the original Ingress and the parsed annotations.

Which issue this PR fixes:

fixes #2494
fixes #3473
fixes #3468
fixes #3489

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 28, 2018
@aledbf aledbf force-pushed the improve-parsing branch 3 times, most recently from e2517c0 to 08ace5a Compare November 28, 2018 01:53
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 28, 2018
// IngressAnnotationsLister makes a Store that lists annotations in Ingress rules.
type IngressAnnotationsLister struct {
// IngressWithAnnotationsLister makes a Store that lists Ingress rules with annotations already parsed
type IngressWithAnnotationsLister struct {
cache.Store
}

// ByKey returns the Ingress annotations matching key in the local Ingress annotations Store.
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 adjust this comment as well

@ElvinEfendi
Copy link
Member

ElvinEfendi commented Nov 28, 2018

Why are you making all those internal/ingress/annotations/* changes? Can you give high level overview of what's the source of problem (and why #3437 was not enough) and how are you fixing it?

@aledbf
Copy link
Member Author

aledbf commented Nov 28, 2018

Why are you making all those internal/ingress/annotations/* changes?

Consistency in the parsing method and also simplify the validations to set the defaults

Can you give high level overview of what's the source of problem (and why #3437 was not enough) and how are you fixing it?

The change in #3437 is not enough because at the end we are still joining the ingress and annotations when we build the model. The change here ensures we only extract the annotations when there's an event and we always use a single store, without any logic to get the ingresses

@aledbf aledbf force-pushed the improve-parsing branch 4 times, most recently from 37d992f to 8cefb74 Compare November 30, 2018 22:56
@aledbf
Copy link
Member Author

aledbf commented Dec 1, 2018

@ElvinEfendi I used #3479 for the last commit

@aledbf aledbf force-pushed the improve-parsing branch 3 times, most recently from 664a1d9 to f8ae100 Compare December 1, 2018 01:49
var ingresses []*ingress.Ingress
for _, item := range s.listers.Ingress.List() {
ing := item.(*extensions.Ingress)
if !class.IsValid(ing) {
Copy link
Member

Choose a reason for hiding this comment

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

How's this case handled now? I don't see this function being used in new changes.

Copy link
Member

Choose a reason for hiding this comment

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

hmm looks like this is being handled in ingress event handlers and this was redundant

@@ -597,9 +594,26 @@ func (s *k8sStore) extractAnnotations(ing *extensions.Ingress) {
key := k8s.MetaNamespaceKey(ing)
Copy link
Member

Choose a reason for hiding this comment

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

The comment seems to be outdated - it does not describe what the function does.

Also should we call this function syncIngress now?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -39,24 +39,24 @@ func TestParse(t *testing.T) {

testCases := []struct {
annotations map[string]string
expected Config
Copy link
Member

Choose a reason for hiding this comment

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

why are you switching this to pointer?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

}

pb, err := parser.GetStringAnnotation("proxy-buffering", ing)
if err != nil || pb == "" {
Copy link
Member

Choose a reason for hiding this comment

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

why did you change all these to not check for == ""?

Copy link
Member Author

Choose a reason for hiding this comment

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

I just added a new commit that avoids empty annotations

i, exists, err := il.GetByKey(key)
if err != nil {
return nil, err
}
if !exists {
return nil, NotExistsError(key)
}
return i.(*annotations.Ingress), nil
Copy link
Member

Choose a reason for hiding this comment

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

Is annotations.Ingress being used anywhere after this PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

Only in the Ingress struct (ParsedAnnotations *annotations.Ingress)

@@ -132,13 +129,13 @@ type Informer struct {

// Lister contains object listers (stores).
type Lister struct {
Ingress IngressLister
Copy link
Member

Choose a reason for hiding this comment

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

Why do we still need this?

Copy link
Member Author

Choose a reason for hiding this comment

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

We cannot get rid of this because the informer still needs this type.

Copy link
Member

Choose a reason for hiding this comment

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

Does this mean we will be storing extensions.Ingress objects in both here and IngressWithAnnotation? That sounds like unnecessary duplication.

I'm not too familiar with how k8s go client works, but it does not make sense to not be able to configure informer without storing the objects. We should not need IngressLister, since all the ingress objects are already going to be stored in IngressWithAnnotation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Does this mean we will be storing extensions.Ingress objects in both here and IngressWithAnnotation? That sounds like unnecessary duplication.

I know but there is no way to have a custom type (IngressWithAnnotation) in the informer.

I'm not too familiar with how k8s go client works, but it does not make sense to not be able to configure informer without storing the objects

You need to use a store to be able to handle deltas.

@aledbf aledbf force-pushed the improve-parsing branch 2 times, most recently from 7b205a8 to 733f9a7 Compare December 2, 2018 18:52
@ElvinEfendi
Copy link
Member

/lgtm

https://github.com/kubernetes/ingress-nginx/pull/3474/files#r239025364 can be addressed later if it's an actual concern.

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aledbf, ElvinEfendi

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 merged commit c4ba238 into kubernetes:master Dec 5, 2018
@ElvinEfendi
Copy link
Member

How's this PR fixing #3489?

@aledbf aledbf deleted the improve-parsing branch December 5, 2018 12:02
@ElvinEfendi
Copy link
Member

How's this PR fixing #3489?

#3489 was reopened, this PR isn't fixing it.

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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
3 participants