Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

Commit

Permalink
Add readyz and healthz addresses (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
travisgroth authored Feb 8, 2020
1 parent 8a13cd3 commit 9c9d330
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
14 changes: 9 additions & 5 deletions cmd/pomerium-operator/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ var (
)

type cmdConfig struct {
BaseConfigFile string
Debug bool
Election bool
ElectionConfigMap string
ElectionNamespace string
BaseConfigFile string
Debug bool
Election bool
ElectionConfigMap string
ElectionNamespace string

IngressClass string
MetricsAddress string
HealthAddress string
Namespace string
PomeriumConfigMap string
PomeriumNamespace string
Expand Down Expand Up @@ -123,6 +125,7 @@ func init() {
rootCmd.PersistentFlags().String("election-configmap", "operator-leader-pomerium", "Name of ConfigMap to use for leader election")
rootCmd.PersistentFlags().String("election-namespace", "kube-system", "Namespace to use for leader election")
rootCmd.PersistentFlags().String("metrics-address", "0", "Address for metrics listener. Default disabled")
rootCmd.PersistentFlags().String("health-address", "0", "Address for health check endpoint. Default disabled")
rootCmd.PersistentFlags().StringSlice("pomerium-deployments", []string{}, "List of Deployments in the pomerium-namespace to update when the [base-config-file] changes")

err := bindViper(vcfg, rootCmd.PersistentFlags())
Expand Down Expand Up @@ -206,6 +209,7 @@ func createOperator(kcfg *rest.Config) (*operator.Operator, error) {
ServiceClass: operatorCfg.ServiceClass,
IngressClass: operatorCfg.IngressClass,
MetricsBindAddress: operatorCfg.MetricsAddress,
HealthAddress: operatorCfg.HealthAddress,
LeaderElection: operatorCfg.Election,
LeaderElectionID: operatorCfg.ElectionConfigMap,
LeaderElectionNamespace: operatorCfg.ElectionNamespace,
Expand Down
15 changes: 15 additions & 0 deletions internal/operator/operator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package operator

import (
"net/http"

"github.com/pomerium/pomerium-operator/internal/log"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -12,6 +14,7 @@ import (
)

var logger = log.L.WithValues("component", "operator")
var zHandler = func(_ *http.Request) error { return nil }

// Options represents the configuration of an Operator. Used in NewOperator()
type Options struct {
Expand All @@ -23,6 +26,7 @@ type Options struct {
KubeConfig *rest.Config
MapperProvider func(*rest.Config) (meta.RESTMapper, error)
MetricsBindAddress string
HealthAddress string
LeaderElection bool
LeaderElectionID string
LeaderElectionNamespace string
Expand Down Expand Up @@ -52,6 +56,7 @@ func NewOperator(opts Options) (*Operator, error) {
NewClient: opts.Client,
MapperProvider: opts.MapperProvider,
MetricsBindAddress: opts.MetricsBindAddress,
HealthProbeBindAddress: opts.HealthAddress,
}

logger.V(1).Info("creating manager for operator")
Expand All @@ -63,6 +68,16 @@ func NewOperator(opts Options) (*Operator, error) {
}
logger.V(1).Info("manager created")

err = mgr.AddHealthzCheck("alive", zHandler)
if err != nil {
return nil, err
}

err = mgr.AddReadyzCheck("alive", zHandler)
if err != nil {
return nil, err
}

operator := Operator{opts: opts, mgr: mgr, builder: builder.ControllerManagedBy(mgr), stopCh: opts.StopCh}

return &operator, nil
Expand Down

0 comments on commit 9c9d330

Please sign in to comment.