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

enable readiness reflector for Standalone NEG #927

Merged
merged 1 commit into from
Nov 14, 2019

Conversation

freehan
Copy link
Contributor

@freehan freehan commented Nov 4, 2019

Enable Pod Readiness Gate for Standalone NEG

@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 4, 2019
@@ -416,7 +416,7 @@ func (c *Controller) mergeStandaloneNEGsPortInfo(service *apiv1.Service, name ty
return err
}

if err := portInfoMap.Merge(negtypes.NewPortInfoMap(name.Namespace, name.Name, exposedNegSvcPort, c.namer, false)); err != nil {
if err := portInfoMap.Merge(negtypes.NewPortInfoMap(name.Namespace, name.Name, exposedNegSvcPort, c.namer, true)); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

/*readinessGate*/true

syncPod(key, negName string) error
// neg is the key of the NEG resource
// backendService is the key of the BackendService resource.
syncPod(key string, neg, backendService *meta.Key) error
Copy link
Member

Choose a reason for hiding this comment

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

// syncPod syncs the NEG readiness gate of the given pod.
key => podKey

}

// processHealthStatus processes the health status response from NEG API.
// It processed health status for each endpoint and signal patcher correspondingly in the following conditions:
Copy link
Member

Choose a reason for hiding this comment

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

// processHealthStatus updates Pod readiness gates in response to a health status update.
//
// We update the pod (using the patcher) when:
// 1. ...

// It returns true if retry is needed.
func (p *poller) processHealthStatus(key negMeta, healthStatuses []*composite.NetworkEndpointWithHealthStatus) (bool, error) {
var retry bool
errList := []error{}
Copy link
Member

Choose a reason for hiding this comment

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

var errList []error

// 2. if the NEG is not associated with any health checks
// It returns true if retry is needed.
func (p *poller) processHealthStatus(key negMeta, healthStatuses []*composite.NetworkEndpointWithHealthStatus) (bool, error) {
var retry bool
Copy link
Member

Choose a reason for hiding this comment

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

these var decls are kind of random, prefer putting locking at the top and grouping everything

p.lock.Lock()
defer p.lock.Unlock()
var (
  retry bool
  errList []error
  patchCount int
  unhealthyPods []types.NamespacedName
  // healthChecked indicates ...
  healthChecked bool
)

for _, hs := range healthStatus.Healths {
if hs == nil {
continue
}
if hs.BackendService == nil {
klog.Warningf("Backend service is nil in health status of network endpoint %v: %v", ne, hs)
klog.Warningf("Backend service is nil in health status of network endpoint %v", healthStatus)
Copy link
Member

Choose a reason for hiding this comment

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

this should be an Error


// getHealthyBackendService returns one of the backend service key where the endpoint is considered healthy.
func getHealthyBackendService(healthStatus *composite.NetworkEndpointWithHealthStatus) *meta.Key {
for _, hs := range healthStatus.Healths {
if hs == nil {
Copy link
Member

Choose a reason for hiding this comment

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

this should be an Error log.
Also, kind of strange to have to check for nils everywhere

if hs.HealthState == healthyState {
id, err := cloud.ParseResourceURL(hs.BackendService.BackendService)
if err != nil {
klog.Errorf("Failed to parse backend service reference from a Network Endpoint health status %v: %v", healthStatus, err)
Copy link
Member

Choose a reason for hiding this comment

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

continue?


// getHealthyBackendService returns one of the backend service key where the endpoint is considered healthy.
Copy link
Member

Choose a reason for hiding this comment

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

// ... returns the first healthy backend service key


// hasHealthStatus returns true if there is at least 1 health status associated with the endpoint.
func hasHealthStatus(healthStatus *composite.NetworkEndpointWithHealthStatus) bool {
if healthStatus != nil && len(healthStatus.Healths) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

return healthStatus != nil && len(...)

@freehan freehan force-pushed the standalone-neg-ga branch 3 times, most recently from 8fb6d48 to cd2dce2 Compare November 12, 2019 22:28
@freehan
Copy link
Contributor Author

freehan commented Nov 13, 2019

Fixed the comments

@bowei
Copy link
Member

bowei commented Nov 14, 2019

/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 Nov 14, 2019
@@ -416,7 +416,7 @@ func (c *Controller) mergeStandaloneNEGsPortInfo(service *apiv1.Service, name ty
return err
}

if err := portInfoMap.Merge(negtypes.NewPortInfoMap(name.Namespace, name.Name, exposedNegSvcPort, c.namer, false)); err != nil {
if err := portInfoMap.Merge(negtypes.NewPortInfoMap(name.Namespace, name.Name, exposedNegSvcPort, c.namer /*readinessGate*/, true)); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

you have this on the wrong parameter.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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 7a92145 into kubernetes:master Nov 14, 2019
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.

3 participants