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

fix and refactor on NEG annotation handling #452

Merged
merged 1 commit into from
Aug 29, 2018

Conversation

freehan
Copy link
Contributor

@freehan freehan commented Aug 28, 2018

Refactor NEG annotation handling
Fix a problem where NEG annotation mal format errors are eaten.

cc: @agau4779

@k8s-ci-robot k8s-ci-robot added 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 28, 2018

// NegAnnotation returns the value of the NEG annotation key
func (svc *Service) NegAnnotation() (NegAnnotation, error) {
// GetNEGAnnotation returns if NEG annotation is found.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit - returns true, the NEG annotation if the NEG annotation is found

func (svc *Service) NegAnnotation() (NegAnnotation, error) {
// GetNEGAnnotation returns if NEG annotation is found.
// If found, it also returns NEG annotation struct.
func (svc *Service) GetNEGAnnotation() (bool, *NegAnnotation, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think go style is to just have it as NEGAnnotation() rather than GetNEGAnnotation()

@agau4779
Copy link
Contributor

LGTM

var (
ErrBackendConfigNoneFound = errors.New("no BackendConfig's found in annotation")
ErrBackendConfigInvalidJSON = errors.New("BackendConfig annotation is invalid json")
ErrBackendConfigAnnotationMissing = errors.New("BackendConfig annotation is missing")
NEGAnnotationErrorFmt = "NEG annotation is invalid: %v"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think its worth surfacing the actual formatting error to users. They can easily figure out what's wrong by throwing it into a json parser. That way, in your tests, you don't have to check for a specific error string.

@@ -79,7 +79,11 @@ func (t *Translator) getServicePort(id utils.ServicePortID) (*utils.ServicePort,
return nil, errors.ErrSvcPortNotFound{ServicePortID: id}
}

negEnabled := annotations.FromService(svc).NEGEnabled()
var negEnabled bool
ok, negAnnotation, err := annotations.FromService(svc).GetNEGAnnotation()
Copy link
Contributor

Choose a reason for hiding this comment

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

What if there is an error? Where is that handled?

@freehan
Copy link
Contributor Author

freehan commented Aug 28, 2018

Fixed. PTAL

@rramkumar1
Copy link
Contributor

/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: freehan, rramkumar1

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 55429c8 into kubernetes:master Aug 29, 2018
k8s-ci-robot added a commit that referenced this pull request Aug 29, 2018
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/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.

4 participants