Skip to content

Commit

Permalink
Remove running the endpoints controller in this PR.
Browse files Browse the repository at this point in the history
This will be a part of a future PR that enables endpoints-controller and
removes the old method of service registration.
  • Loading branch information
ndhanushkodi committed Mar 22, 2021
1 parent 0f69d7d commit 715854a
Showing 1 changed file with 46 additions and 48 deletions.
94 changes: 46 additions & 48 deletions subcommand/inject-connect/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/hashicorp/consul-k8s/subcommand/flags"
"github.com/hashicorp/consul/api"
"github.com/mitchellh/cli"
"go.uber.org/zap/zapcore"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand All @@ -37,9 +36,7 @@ import (
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/client-go/rest"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

type Command struct {
Expand Down Expand Up @@ -457,52 +454,53 @@ func (c *Command) Run(args []string) int {
// Create a channel for all controllers' exits.
ctrlExitCh := make(chan error)

// TODO: future PR to enable this and disable the old service registration path
// Create a manager for endpoints controller and the mutating webhook.
zapLogger := zap.New(zap.UseDevMode(true), zap.Level(zapcore.InfoLevel))
ctrl.SetLogger(zapLogger)
klog.SetLogger(zapLogger)
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
LeaderElection: false,
Logger: zapLogger,
MetricsBindAddress: "0.0.0.0:9444",
})
if err != nil {
setupLog.Error(err, "unable to start manager")
return 1
}
// Start the endpoints controller.
if err = (&connectinject.EndpointsController{
Client: mgr.GetClient(),
ConsulClient: c.consulClient,
ConsulScheme: consulURL.Scheme,
ConsulPort: consulURL.Port(),
AllowK8sNamespacesSet: allowK8sNamespaces,
DenyK8sNamespacesSet: denyK8sNamespaces,
Log: ctrl.Log.WithName("controller").WithName("endpoints-controller"),
Scheme: mgr.GetScheme(),
Ctx: ctx,
ReleaseName: c.flagReleaseName,
ReleaseNamespace: c.flagReleaseNamespace,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", connectinject.EndpointsController{})
return 1
}

// todo: Add tests in case it's not refactored to not have any signal handling
// (In the future, we plan to only have the manager and rely on it to do signal handling for us).
go func() {
// Pass existing context's done channel so that the controller
// will stop when this context is canceled.
// This could be due to an interrupt signal or if any other component did not start
// successfully. In those cases, we want to make sure that this controller is no longer
// running.
if err := mgr.Start(ctx.Done()); err != nil {
setupLog.Error(err, "problem running manager")
// Use an existing channel for ctrl exists in case manager failed to start properly.
ctrlExitCh <- fmt.Errorf("endpoints controller exited unexpectedly")
}
}()
//zapLogger := zap.New(zap.UseDevMode(true), zap.Level(zapcore.InfoLevel))
//ctrl.SetLogger(zapLogger)
//klog.SetLogger(zapLogger)
//mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
// Scheme: scheme,
// LeaderElection: false,
// Logger: zapLogger,
// MetricsBindAddress: "0.0.0.0:9444",
//})
//if err != nil {
// setupLog.Error(err, "unable to start manager")
// return 1
//}
//// Start the endpoints controller.
//if err = (&connectinject.EndpointsController{
// Client: mgr.GetClient(),
// ConsulClient: c.consulClient,
// ConsulScheme: consulURL.Scheme,
// ConsulPort: consulURL.Port(),
// AllowK8sNamespacesSet: allowK8sNamespaces,
// DenyK8sNamespacesSet: denyK8sNamespaces,
// Log: ctrl.Log.WithName("controller").WithName("endpoints-controller"),
// Scheme: mgr.GetScheme(),
// Ctx: ctx,
// ReleaseName: c.flagReleaseName,
// ReleaseNamespace: c.flagReleaseNamespace,
//}).SetupWithManager(mgr); err != nil {
// setupLog.Error(err, "unable to create controller", "controller", connectinject.EndpointsController{})
// return 1
//}
//
//// todo: Add tests in case it's not refactored to not have any signal handling
//// (In the future, we plan to only have the manager and rely on it to do signal handling for us).
//go func() {
// // Pass existing context's done channel so that the controller
// // will stop when this context is canceled.
// // This could be due to an interrupt signal or if any other component did not start
// // successfully. In those cases, we want to make sure that this controller is no longer
// // running.
// if err := mgr.Start(ctx.Done()); err != nil {
// setupLog.Error(err, "problem running manager")
// // Use an existing channel for ctrl exists in case manager failed to start properly.
// ctrlExitCh <- fmt.Errorf("endpoints controller exited unexpectedly")
// }
//}()

// Start the cleanup controller that cleans up Consul service instances
// still registered after the pod has been deleted (usually due to a force delete).
Expand Down

0 comments on commit 715854a

Please sign in to comment.