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

liveness probe for vpa-admission #6248

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ spec:
- containerPort: 8000
- name: prometheus
containerPort: 8944
livenessProbe:
failureThreshold: 3
httpGet:
path: /health-check
port: prometheus
Copy link
Author

@jklaw90 jklaw90 Nov 6, 2023

Choose a reason for hiding this comment

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

not sure if we want to move this to the regular server port but this is where it is currently.

initialDelaySeconds: 3
periodSeconds: 10

volumes:
- name: tls-certs
secret:
Expand Down
22 changes: 18 additions & 4 deletions vertical-pod-autoscaler/pkg/admission-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ limitations under the License.
package main

import (
"context"
"errors"
"flag"
"fmt"
"net/http"
"os"
"os/signal"
"syscall"
"time"

apiv1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -75,6 +79,9 @@ func main() {
kube_flag.InitFlags()
klog.V(1).Infof("Vertical Pod Autoscaler %s Admission Controller", common.VerticalPodAutoscalerVersion)

ctx, done := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer done()

healthCheck := metrics.NewHealthCheck(time.Minute, false)
metrics.Initialize(*address, healthCheck)
metrics_admission.Register()
Expand Down Expand Up @@ -107,15 +114,13 @@ func main() {
if namespace != "" {
statusNamespace = namespace
}
stopCh := make(chan struct{})
statusUpdater := status.NewUpdater(
kubeClient,
status.AdmissionControllerStatusName,
statusNamespace,
statusUpdateInterval,
hostname,
)
defer close(stopCh)

calculators := []patch.Calculator{patch.NewResourceUpdatesCalculator(recommendationProvider), patch.NewObservedContainersCalculator()}
as := logic.NewAdmissionServer(podPreprocessor, vpaPreprocessor, limitRangeCalculator, vpaMatcher, calculators)
Expand All @@ -133,10 +138,19 @@ func main() {
selfRegistration(kubeClient, certs.caCert, namespace, *serviceName, url, *registerByURL, int32(*webhookTimeout))
}
// Start status updates after the webhook is initialized.
statusUpdater.Run(stopCh)
statusUpdater.Run(ctx.Done())
}()

if err = server.ListenAndServeTLS("", ""); err != nil {
go func() {
<-ctx.Done() // shutdown gracefully on detect SIGINT or SIGTERM
shutdownCtx, shutdownDone := context.WithTimeout(context.Background(), 10*time.Second) // allow 10 seconds to drain.
defer shutdownDone()
klog.V(1).Info("Server shutting down gracefully")
if err := server.Shutdown(shutdownCtx); err != nil {
klog.Fatalf("Graceful shutdown failed: %s", err)
}
}()
if err = server.ListenAndServeTLS("", ""); err != nil && !errors.Is(err, http.ErrServerClosed) {
klog.Fatalf("HTTPS Error: %s", err)
}
}
4 changes: 3 additions & 1 deletion vertical-pod-autoscaler/pkg/utils/status/status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ func NewUpdater(c clientset.Interface, statusName, statusNamespace string,
// Run starts status updates.
func (su *Updater) Run(stopCh <-chan struct{}) {
go func() {
ticker := time.NewTicker(su.updateInterval)
defer ticker.Stop()
for {
select {
case <-stopCh:
return
case <-time.After(su.updateInterval):
case <-ticker.C:
if err := su.client.UpdateStatus(); err != nil {
klog.Errorf("Status update by %s failed: %v", su.client.holderIdentity, err)
}
Expand Down
Loading