enable karmada-controller-manager health check endpoint /healthz (#154)
Signed-off-by: RainbowMango <renhongcai@huawei.com>
This commit is contained in:
parent
bca72a58fb
commit
d13875b2c3
|
@ -26,6 +26,8 @@ spec:
|
|||
command:
|
||||
- /bin/karmada-controller-manager
|
||||
- --kubeconfig=/etc/kubeconfig
|
||||
- --bind-address=0.0.0.0
|
||||
- --secure-port=10357
|
||||
volumeMounts:
|
||||
- name: kubeconfig
|
||||
subPath: kubeconfig
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"k8s.io/component-base/logs"
|
||||
"k8s.io/klog/v2"
|
||||
"sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/healthz"
|
||||
|
||||
"github.com/karmada-io/karmada/cmd/controller-manager/app/options"
|
||||
"github.com/karmada-io/karmada/pkg/controllers/binding"
|
||||
|
@ -42,6 +43,7 @@ func NewControllerManagerCommand(stopChan <-chan struct{}) *cobra.Command {
|
|||
}
|
||||
|
||||
cmd.Flags().AddGoFlagSet(flag.CommandLine)
|
||||
opts.AddFlags(cmd.Flags())
|
||||
return cmd
|
||||
}
|
||||
|
||||
|
@ -55,15 +57,22 @@ func Run(opts *options.Options, stopChan <-chan struct{}) error {
|
|||
panic(err)
|
||||
}
|
||||
controllerManager, err := controllerruntime.NewManager(config, controllerruntime.Options{
|
||||
Scheme: gclient.NewSchema(),
|
||||
LeaderElection: true, // TODO(RainbowMango): Add a flag '--enable-leader-election' for this option.
|
||||
LeaderElectionID: "41db11fa.karmada.io",
|
||||
Scheme: gclient.NewSchema(),
|
||||
LeaderElection: true, // TODO(RainbowMango): Add a flag '--enable-leader-election' for this option.
|
||||
LeaderElectionID: "41db11fa.karmada.io",
|
||||
HealthProbeBindAddress: fmt.Sprintf("%s:%d", opts.BindAddress, opts.SecurePort),
|
||||
LivenessEndpointName: "/healthz",
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("failed to build controller manager: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err = controllerManager.AddHealthzCheck("ping", healthz.Ping); err != nil {
|
||||
klog.Errorf("failed to add health check endpoint: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
setupControllers(controllerManager, stopChan)
|
||||
|
||||
// blocks until the stop channel is closed.
|
||||
|
|
|
@ -3,6 +3,7 @@ package options
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/tools/leaderelection/resourcelock"
|
||||
componentbaseconfig "k8s.io/component-base/config"
|
||||
|
@ -15,10 +16,20 @@ var (
|
|||
defaultElectionRetryPeriod = metav1.Duration{Duration: 2 * time.Second}
|
||||
)
|
||||
|
||||
const (
|
||||
defaultBindAddress = "0.0.0.0"
|
||||
defaultPort = 10357
|
||||
)
|
||||
|
||||
// Options contains everything necessary to create and run controller-manager.
|
||||
type Options struct {
|
||||
HostNamespace string
|
||||
LeaderElection componentbaseconfig.LeaderElectionConfiguration
|
||||
// BindAddress is the IP address on which to listen for the --secure-port port.
|
||||
BindAddress string
|
||||
// SecurePort is the port that the the server serves at.
|
||||
// Note: We hope support https in the future once controller-runtime provides the functionality.
|
||||
SecurePort int
|
||||
}
|
||||
|
||||
// NewOptions builds an empty options.
|
||||
|
@ -53,3 +64,11 @@ func (o *Options) Complete() {
|
|||
klog.Infof("Set default value: Options.LeaderElection.RetryPeriod = %s", defaultElectionRetryPeriod.Duration.String())
|
||||
}
|
||||
}
|
||||
|
||||
// AddFlags adds flags to the specified FlagSet.
|
||||
func (o *Options) AddFlags(flags *pflag.FlagSet) {
|
||||
flags.StringVar(&o.BindAddress, "bind-address", defaultBindAddress,
|
||||
"The IP address on which to listen for the --secure-port port.")
|
||||
flags.IntVar(&o.SecurePort, "secure-port", defaultPort,
|
||||
"The secure port on which to serve HTTPS.")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue