-
Notifications
You must be signed in to change notification settings - Fork 297
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
examine nil pointer before applying backend protocol configurations #678
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,11 @@ const ( | |
// backends, the port or named port specified in the Backend Service is | ||
// used for health checking. | ||
UseServingPortSpecification = "USE_SERVING_PORT" | ||
|
||
// TODO: revendor the GCE API go client so that this error will not be hit. | ||
newHealthCheckErrorMessageTemplate = "the %v health check configuration on the existing health check %v is nil. " + | ||
"This is usually caused by an application protocol change on the k8s service spec. " + | ||
"Please revert the change on application protocol to avoid this error message." | ||
) | ||
|
||
// HealthChecks manages health checks. | ||
|
@@ -241,7 +246,10 @@ func (h *HealthChecks) Get(name string, version meta.Version) (*HealthCheck, err | |
default: | ||
return nil, fmt.Errorf("unknown version %v", version) | ||
} | ||
return NewHealthCheck(hc), err | ||
if err != nil { | ||
return nil, err | ||
} | ||
return NewHealthCheck(hc) | ||
} | ||
|
||
// DefaultHealthCheck simply returns the default health check. | ||
|
@@ -304,18 +312,30 @@ type HealthCheck struct { | |
} | ||
|
||
// NewHealthCheck creates a HealthCheck which abstracts nested structs away | ||
func NewHealthCheck(hc *computealpha.HealthCheck) *HealthCheck { | ||
func NewHealthCheck(hc *computealpha.HealthCheck) (*HealthCheck, error) { | ||
if hc == nil { | ||
return nil | ||
return nil, nil | ||
} | ||
|
||
v := &HealthCheck{HealthCheck: *hc} | ||
var err error | ||
switch annotations.AppProtocol(hc.Type) { | ||
case annotations.ProtocolHTTP: | ||
if hc.HttpHealthCheck == nil { | ||
err = fmt.Errorf(newHealthCheckErrorMessageTemplate, annotations.ProtocolHTTP, hc.Name) | ||
return nil, err | ||
} | ||
v.HTTPHealthCheck = *hc.HttpHealthCheck | ||
case annotations.ProtocolHTTPS: | ||
if hc.HttpsHealthCheck == nil { | ||
err = fmt.Errorf(newHealthCheckErrorMessageTemplate, annotations.ProtocolHTTPS, hc.Name) | ||
return nil, err | ||
} | ||
v.HTTPHealthCheck = computealpha.HTTPHealthCheck(*hc.HttpsHealthCheck) | ||
case annotations.ProtocolHTTP2: | ||
if hc.Http2HealthCheck == nil { | ||
err = fmt.Errorf(newHealthCheckErrorMessageTemplate, annotations.ProtocolHTTP2, hc.Name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we not return immediately (same in all case above) |
||
return nil, err | ||
} | ||
v.HTTPHealthCheck = computealpha.HTTPHealthCheck(*hc.Http2HealthCheck) | ||
} | ||
|
||
|
@@ -325,7 +345,7 @@ func NewHealthCheck(hc *computealpha.HealthCheck) *HealthCheck { | |
v.HealthCheck.HttpsHealthCheck = nil | ||
v.HealthCheck.Http2HealthCheck = nil | ||
|
||
return v | ||
return v, err | ||
} | ||
|
||
// Protocol returns the type cased to AppProtocol | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"...revert the change on the application..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a lot of insight into how the ingress-gce works internally, but I think a TODO on handling this type of change would be helpful. I think progressing from HTTP-1.1 to HTTP-2 (soon HTTP-3) or introducing changes on the protocol to adopt a service mesh will be a common occurrence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. Agreed. In the long run we want to support this. But currently, due to GCE api changes, it was broken. So we need to put this short term fix in place so that it can be cherry picked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add the TODO just so we remember to do it?