Skip to content

Commit

Permalink
feat: add health Probe (ratify-project#1058)
Browse files Browse the repository at this point in the history
Signed-off-by: Susan Shi <[email protected]>
  • Loading branch information
susanshi authored Sep 7, 2023
1 parent f990031 commit aca86af
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
12 changes: 12 additions & 0 deletions charts/ratify/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ spec:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
livenessProbe:
httpGet:
path: /healthz
port: {{ .Values.healthPort }}
readinessProbe:
httpGet:
path: /readyz
port: {{ .Values.healthPort }}
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down Expand Up @@ -70,11 +78,15 @@ spec:
- --metrics-enabled={{ .Values.instrumentation.metricsEnabled }}
- --metrics-type={{ .Values.instrumentation.metricsType }}
- --metrics-port={{ .Values.instrumentation.metricsPort }}
- --health-port=:{{ .Values.healthPort }}
ports:
- containerPort: 6001
{{- if .Values.instrumentation.metricsEnabled }}
- containerPort: {{ required "You must provide .Values.instrumentation.metricsPort" .Values.instrumentation.metricsPort }}
{{- end }}
- containerPort: {{ required "You must provide .Values.healthPort" .Values.healthPort }}
name: healthz
protocol: TCP
volumeMounts:
{{- if .Values.cosign.enabled }}
- mountPath: "/usr/local/ratify-certs/cosign"
Expand Down
1 change: 1 addition & 0 deletions charts/ratify/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ provider:
podAnnotations: {}
podLabels: {}
enableRuntimeDefaultSeccompProfile: true
healthPort: 9099

rbac:
create: true
Expand Down
4 changes: 3 additions & 1 deletion cmd/ratify/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type serveCmdOptions struct {
metricsEnabled bool
metricsType string
metricsPort int
healthPort string
}

func NewCmdServe(_ ...string) *cobra.Command {
Expand Down Expand Up @@ -77,6 +78,7 @@ func NewCmdServe(_ ...string) *cobra.Command {
flags.BoolVar(&opts.metricsEnabled, "metrics-enabled", false, "Enable metrics exporter if enabled (default: false)")
flags.StringVar(&opts.metricsType, "metrics-type", httpserver.DefaultMetricsType, fmt.Sprintf("Metrics exporter type to use (default: %s)", httpserver.DefaultMetricsType))
flags.IntVar(&opts.metricsPort, "metrics-port", httpserver.DefaultMetricsPort, fmt.Sprintf("Metrics exporter port to use (default: %d)", httpserver.DefaultMetricsPort))
flags.StringVar(&opts.healthPort, "health-port", httpserver.DefaultHealthPort, fmt.Sprintf("Health port to use (default: %s)", httpserver.DefaultHealthPort))
return cmd
}

Expand All @@ -100,7 +102,7 @@ func serve(opts serveCmdOptions) error {
if opts.enableCrdManager {
certRotatorReady := make(chan struct{})
logrus.Infof("starting crd manager")
go manager.StartManager(certRotatorReady)
go manager.StartManager(certRotatorReady, opts.healthPort)
manager.StartServer(opts.httpServerAddress, opts.configFilePath, opts.certDirectory, opts.caCertFile, opts.cacheTTL, opts.metricsEnabled, opts.metricsType, opts.metricsPort, certRotatorReady)

return nil
Expand Down
1 change: 1 addition & 0 deletions httpserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (

DefaultMetricsType = "prometheus"
DefaultMetricsPort = 8888
DefaultHealthPort = ":9099"
)

type Server struct {
Expand Down
7 changes: 4 additions & 3 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,11 @@ func StartServer(httpServerAddress, configFilePath, certDirectory, caCertFile st
}
}

func StartManager(certRotatorReady chan struct{}) {
func StartManager(certRotatorReady chan struct{}, probeAddr string) {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string

flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
Expand Down Expand Up @@ -179,6 +178,8 @@ func StartManager(certRotatorReady chan struct{}) {
os.Exit(1)
}

setupLog.Debugf("setting up probeAddr at %s", probeAddr)

// Make sure certs are generated and valid if cert rotation is enabled.
if featureflag.CertRotation.Enabled {
// Make sure TLS cert watcher is already set up.
Expand Down

0 comments on commit aca86af

Please sign in to comment.