mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2024-12-14 11:57:51 +00:00
nfd-worker: replace --metrics with --port
Use a single port for serving http. In addition to metrics we will have the healthz endpoint.
This commit is contained in:
parent
e104b87277
commit
d831fcbdf9
6 changed files with 32 additions and 23 deletions
|
@ -106,8 +106,8 @@ func initFlags(flagset *flag.FlagSet) (*worker.Args, *worker.ConfigOverrideArgs)
|
|||
"Kubeconfig to use")
|
||||
flagset.BoolVar(&args.Oneshot, "oneshot", false,
|
||||
"Do not publish feature labels")
|
||||
flagset.IntVar(&args.MetricsPort, "metrics", 8081,
|
||||
"Port on which to expose metrics.")
|
||||
flagset.IntVar(&args.Port, "port", 8080,
|
||||
"Port on which to metrics and healthz endpoints are served")
|
||||
flagset.StringVar(&args.Options, "options", "",
|
||||
"Specify config options from command line. Config options are specified "+
|
||||
"in the same format as in the config file (i.e. json or yaml). These options")
|
||||
|
|
|
@ -38,5 +38,5 @@ spec:
|
|||
args:
|
||||
- "-server=nfd-master:8080"
|
||||
ports:
|
||||
- name: metrics
|
||||
containerPort: 8081
|
||||
- name: http
|
||||
containerPort: 8080
|
||||
|
|
|
@ -103,13 +103,13 @@ spec:
|
|||
{{- range $key, $value := .Values.featureGates }}
|
||||
- "-feature-gates={{ $key }}={{ $value }}"
|
||||
{{- end }}
|
||||
- "-metrics={{ .Values.worker.metricsPort | default "8081"}}"
|
||||
- "-port={{ .Values.worker.port | default "8080"}}"
|
||||
{{- with .Values.gc.extraArgs }}
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
ports:
|
||||
- containerPort: {{ .Values.worker.metricsPort | default "8081"}}
|
||||
name: metrics
|
||||
- containerPort: {{ .Values.worker.port | default "8080"}}
|
||||
name: http
|
||||
volumeMounts:
|
||||
- name: host-boot
|
||||
mountPath: "/host-boot"
|
||||
|
|
|
@ -419,7 +419,7 @@ worker:
|
|||
# matchName: {op: In, value: ["SWAP", "X86", "ARM"]}
|
||||
### <NFD-WORKER-CONF-END-DO-NOT-REMOVE>
|
||||
|
||||
metricsPort: 8081
|
||||
port: 8080
|
||||
daemonsetAnnotations: {}
|
||||
podSecurityContext: {}
|
||||
# fsGroup: 2000
|
||||
|
|
|
@ -230,7 +230,7 @@ API's you need to install the prometheus operator in your cluster.
|
|||
| `worker.*` | dict | | NFD worker daemonset configuration |
|
||||
| `worker.enable` | bool | true | Specifies whether nfd-worker should be deployed |
|
||||
| `worker.hostNetwork` | bool | false | Specifies whether to enable or disable running the container in the host's network namespace |
|
||||
| `worker.metricsPort` | int | 8081 | Port on which to expose metrics from components to prometheus operator |
|
||||
| `worker.port` | int | 8080 | Port on which to serve http for metrics and healthz endpoints. |
|
||||
| `worker.config` | dict | | NFD worker [configuration](../reference/worker-configuration-reference) |
|
||||
| `worker.podSecurityContext` | dict | {} | [PodSecurityContext](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod) holds pod-level security attributes and common container settins |
|
||||
| `worker.securityContext` | dict | {} | Container [security settings](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container) |
|
||||
|
|
|
@ -19,6 +19,7 @@ package nfdworker
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
@ -26,6 +27,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"golang.org/x/exp/maps"
|
||||
"golang.org/x/net/context"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
|
@ -87,12 +90,12 @@ type Labels map[string]string
|
|||
|
||||
// Args are the command line arguments of NfdWorker.
|
||||
type Args struct {
|
||||
ConfigFile string
|
||||
Klog map[string]*utils.KlogFlagVal
|
||||
Kubeconfig string
|
||||
Oneshot bool
|
||||
Options string
|
||||
MetricsPort int
|
||||
ConfigFile string
|
||||
Klog map[string]*utils.KlogFlagVal
|
||||
Kubeconfig string
|
||||
Oneshot bool
|
||||
Options string
|
||||
Port int
|
||||
|
||||
Overrides ConfigOverrideArgs
|
||||
}
|
||||
|
@ -283,15 +286,13 @@ func (w *nfdWorker) Run() error {
|
|||
|
||||
w.ownerReference = ownerReference
|
||||
|
||||
httpMux := http.NewServeMux()
|
||||
|
||||
// Register to metrics server
|
||||
if w.args.MetricsPort > 0 {
|
||||
m := utils.CreateMetricsServer(w.args.MetricsPort,
|
||||
buildInfo,
|
||||
featureDiscoveryDuration)
|
||||
go m.Run()
|
||||
registerVersion(version.Get())
|
||||
defer m.Stop()
|
||||
}
|
||||
promRegistry := prometheus.NewRegistry()
|
||||
promRegistry.MustRegister(buildInfo, featureDiscoveryDuration)
|
||||
httpMux.Handle("/metrics", promhttp.HandlerFor(promRegistry, promhttp.HandlerOpts{}))
|
||||
registerVersion(version.Get())
|
||||
|
||||
err = w.runFeatureDiscovery()
|
||||
if err != nil {
|
||||
|
@ -305,6 +306,14 @@ func (w *nfdWorker) Run() error {
|
|||
|
||||
// Start readiness probe (at this point we're "ready and live")
|
||||
|
||||
// Start HTTP server
|
||||
httpServer := http.Server{Addr: fmt.Sprintf(":%d", w.args.Port), Handler: httpMux}
|
||||
go func() {
|
||||
klog.InfoS("http server starting", "port", httpServer.Addr)
|
||||
klog.InfoS("http server stopped", "exitCode", httpServer.ListenAndServe())
|
||||
}()
|
||||
defer httpServer.Close()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-labelTrigger.C:
|
||||
|
|
Loading…
Reference in a new issue