|
8 | 8 | "crypto/x509" |
9 | 9 | "errors" |
10 | 10 | "fmt" |
| 11 | + ntoconfig "github.com/openshift/cluster-node-tuning-operator/pkg/config" |
11 | 12 | "io" |
12 | 13 | "net/http" |
13 | 14 | "os" |
@@ -47,7 +48,11 @@ func init() { |
47 | 48 | // it does so only if the CA bundle changed from the current CA bundle on record. |
48 | 49 | func DumpCA(caBundle string) { |
49 | 50 | if caBundle != server.caBundle { |
50 | | - server.caBundleCh <- caBundle |
| 51 | + select { |
| 52 | + case server.caBundleCh <- caBundle: |
| 53 | + default: |
| 54 | + klog.Infof("Metrics server CA channel not ready, skipping CA bundle update") |
| 55 | + } |
51 | 56 | } |
52 | 57 | } |
53 | 58 |
|
@@ -126,6 +131,27 @@ func (Server) Start(ctx context.Context) error { |
126 | 131 | // and restarted with the current files. Every non-nil return from this function is fatal |
127 | 132 | // and will restart the whole operator. |
128 | 133 | func RunServer(port int, ctx context.Context) error { |
| 134 | + if ntoconfig.InHyperShift() { |
| 135 | + klog.Info("starting metrics server.") |
| 136 | + handler := promhttp.HandlerFor(registry, promhttp.HandlerOpts{}) |
| 137 | + router := http.NewServeMux() |
| 138 | + router.Handle("/metrics", handler) |
| 139 | + srv := &http.Server{ |
| 140 | + Addr: fmt.Sprintf(":%d", port), |
| 141 | + Handler: router, |
| 142 | + } |
| 143 | + go func() { |
| 144 | + if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { |
| 145 | + klog.Errorf("error from metrics server: %v", err) |
| 146 | + } |
| 147 | + }() |
| 148 | + <-ctx.Done() |
| 149 | + klog.Info("stopping insecure metrics server") |
| 150 | + |
| 151 | + shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 152 | + defer cancel() |
| 153 | + return srv.Shutdown(shutdownCtx) |
| 154 | + } |
129 | 155 | // Set up and start the file watcher. |
130 | 156 | watcher, err := fsnotify.NewWatcher() |
131 | 157 | if watcher == nil || err != nil { |
|
0 commit comments