-
Notifications
You must be signed in to change notification settings - Fork 303
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
Add Liveness Probe for NEG controller #349
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -35,6 +35,7 @@ import ( | |
"k8s.io/client-go/util/workqueue" | ||
"k8s.io/ingress-gce/pkg/annotations" | ||
"k8s.io/ingress-gce/pkg/context" | ||
"k8s.io/ingress-gce/pkg/utils" | ||
) | ||
|
||
const ( | ||
|
@@ -54,6 +55,8 @@ type Controller struct { | |
manager negSyncerManager | ||
resyncPeriod time.Duration | ||
recorder record.EventRecorder | ||
namer networkEndpointGroupNamer | ||
zoneGetter zoneGetter | ||
|
||
ingressSynced cache.InformerSynced | ||
serviceSynced cache.InformerSynced | ||
|
@@ -63,8 +66,9 @@ type Controller struct { | |
|
||
// serviceQueue takes service key as work item. Service key with format "namespace/name". | ||
serviceQueue workqueue.RateLimitingInterface | ||
zoneGetter zoneGetter | ||
namer networkEndpointGroupNamer | ||
|
||
// syncTracker tracks the latest time that service and endpoint changes are processed | ||
syncTracker utils.TimeTracker | ||
} | ||
|
||
// NewController returns a network endpoint group controller. | ||
|
@@ -96,14 +100,15 @@ func NewController( | |
manager: manager, | ||
resyncPeriod: resyncPeriod, | ||
recorder: recorder, | ||
zoneGetter: zoneGetter, | ||
namer: namer, | ||
ingressSynced: ctx.IngressInformer.HasSynced, | ||
serviceSynced: ctx.ServiceInformer.HasSynced, | ||
endpointSynced: ctx.EndpointInformer.HasSynced, | ||
ingressLister: ctx.IngressInformer.GetIndexer(), | ||
serviceLister: ctx.ServiceInformer.GetIndexer(), | ||
serviceQueue: workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()), | ||
zoneGetter: zoneGetter, | ||
namer: namer, | ||
syncTracker: utils.NewTimeTracker(), | ||
} | ||
|
||
ctx.ServiceInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ | ||
|
@@ -133,6 +138,7 @@ func NewController( | |
negController.processEndpoint(cur) | ||
}, | ||
}) | ||
ctx.AddHealthCheck("neg-controller", negController.IsHealthy) | ||
return negController, nil | ||
} | ||
|
||
|
@@ -154,6 +160,16 @@ func (c *Controller) Run(stopCh <-chan struct{}) { | |
<-stopCh | ||
} | ||
|
||
func (c *Controller) IsHealthy() error { | ||
// check if last seen service and endpoint processing is more than an hour ago | ||
if c.syncTracker.Get().Before(time.Now().Add(-time.Hour)) { | ||
msg := fmt.Sprintf("NEG controller has not proccessed any service and endpoint updates for more than an hour. Something went wrong. Last sync was on %v", c.syncTracker.Get()) | ||
glog.Error(msg) | ||
return fmt.Errorf(msg) | ||
} | ||
return nil | ||
} | ||
|
||
func (c *Controller) stop() { | ||
glog.V(2).Infof("Shutting down network endpoint group controller") | ||
c.serviceQueue.ShutDown() | ||
|
@@ -162,7 +178,11 @@ func (c *Controller) stop() { | |
|
||
// processEndpoint finds the related syncers and signal it to sync | ||
func (c *Controller) processEndpoint(obj interface{}) { | ||
defer lastSyncTimestamp.WithLabelValues().Set(float64(time.Now().UTC().UnixNano())) | ||
defer func() { | ||
now := c.syncTracker.Track() | ||
lastSyncTimestamp.WithLabelValues().Set(float64(now.UTC().UnixNano())) | ||
}() | ||
|
||
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj) | ||
if err != nil { | ||
glog.Errorf("Failed to generate endpoint key: %v", err) | ||
|
@@ -191,7 +211,11 @@ func (c *Controller) serviceWorker() { | |
|
||
// processService takes a service and determines whether it needs NEGs or not. | ||
func (c *Controller) processService(key string) error { | ||
defer lastSyncTimestamp.WithLabelValues().Set(float64(time.Now().UTC().UnixNano())) | ||
defer func() { | ||
now := c.syncTracker.Track() | ||
lastSyncTimestamp.WithLabelValues().Set(float64(now.UTC().UnixNano())) | ||
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. What if no services or endpoints. It could happen. |
||
}() | ||
|
||
namespace, name, err := cache.SplitMetaNamespaceKey(key) | ||
if err != nil { | ||
return err | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package utils | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
) | ||
|
||
type TimeTracker struct { | ||
lock sync.Mutex | ||
timestamp time.Time | ||
} | ||
|
||
// Track records the current time and returns it | ||
func (t *TimeTracker) Track() time.Time { | ||
t.lock.Lock() | ||
defer t.lock.Unlock() | ||
t.timestamp = time.Now() | ||
return t.timestamp | ||
} | ||
|
||
// Get returns previous recorded time | ||
func (t *TimeTracker) Get() time.Time { | ||
t.lock.Lock() | ||
defer t.lock.Unlock() | ||
return t.timestamp | ||
} | ||
|
||
// Set records input timestamp | ||
func (t *TimeTracker) Set(timestamp time.Time) { | ||
t.lock.Lock() | ||
defer t.lock.Unlock() | ||
t.timestamp = timestamp | ||
return | ||
} | ||
|
||
func NewTimeTracker() TimeTracker { | ||
return TimeTracker{ | ||
timestamp: time.Now(), | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package utils | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestTimeTracker(t *testing.T) { | ||
tt := NewTimeTracker() | ||
trials := 3 | ||
for i := 0; i < trials; i++ { | ||
timestamp := tt.Track() | ||
result := tt.Get() | ||
if timestamp != result { | ||
t.Errorf("In trial %d, expect %v == %v", i, timestamp, result) | ||
} | ||
now := time.Now() | ||
tt.Set(now) | ||
result = tt.Get() | ||
if now != result { | ||
t.Errorf("In trial %d, expect %v == %v", i, now, result) | ||
} | ||
} | ||
|
||
} |
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.
proccessed