Merge pull request #717 from kragniz/disable-ingress-shim
Add --controllers flag to set which controllers are run
This commit is contained in:
commit
caae0cc48a
@ -24,6 +24,7 @@ import (
|
||||
"github.com/jetstack/cert-manager/pkg/controller"
|
||||
"github.com/jetstack/cert-manager/pkg/issuer"
|
||||
dnsutil "github.com/jetstack/cert-manager/pkg/issuer/acme/dns/util"
|
||||
"github.com/jetstack/cert-manager/pkg/util"
|
||||
"github.com/jetstack/cert-manager/pkg/util/kube"
|
||||
kubeinformers "k8s.io/client-go/informers"
|
||||
)
|
||||
@ -40,10 +41,16 @@ func Run(opts *options.ControllerOptions, stopCh <-chan struct{}) {
|
||||
run := func(_ <-chan struct{}) {
|
||||
var wg sync.WaitGroup
|
||||
for n, fn := range controller.Known() {
|
||||
// only run a controller if it's been enabled
|
||||
if !util.Contains(opts.EnabledControllers, n) {
|
||||
glog.Infof("%s controller is not in list of controllers to enable, so not enabling it", n)
|
||||
continue
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go func(n string, fn controller.Interface) {
|
||||
defer wg.Done()
|
||||
glog.V(4).Infof("Starting %s controller", n)
|
||||
glog.Infof("Starting %s controller", n)
|
||||
|
||||
err := fn(5, stopCh)
|
||||
|
||||
|
||||
@ -8,6 +8,11 @@ import (
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"github.com/jetstack/cert-manager/pkg/util"
|
||||
|
||||
certificatescontroller "github.com/jetstack/cert-manager/pkg/controller/certificates"
|
||||
clusterissuerscontroller "github.com/jetstack/cert-manager/pkg/controller/clusterissuers"
|
||||
ingressshimcontroller "github.com/jetstack/cert-manager/pkg/controller/ingress-shim"
|
||||
issuerscontroller "github.com/jetstack/cert-manager/pkg/controller/issuers"
|
||||
)
|
||||
|
||||
type ControllerOptions struct {
|
||||
@ -20,6 +25,8 @@ type ControllerOptions struct {
|
||||
LeaderElectionRenewDeadline time.Duration
|
||||
LeaderElectionRetryPeriod time.Duration
|
||||
|
||||
EnabledControllers []string
|
||||
|
||||
ACMEHTTP01SolverImage string
|
||||
|
||||
ClusterIssuerAmbientCredentials bool
|
||||
@ -56,6 +63,13 @@ const (
|
||||
|
||||
var (
|
||||
defaultACMEHTTP01SolverImage = fmt.Sprintf("quay.io/jetstack/cert-manager-acmesolver:%s", util.AppVersion)
|
||||
|
||||
defaultEnabledControllers = []string{
|
||||
issuerscontroller.ControllerName,
|
||||
clusterissuerscontroller.ControllerName,
|
||||
certificatescontroller.ControllerName,
|
||||
ingressshimcontroller.ControllerName,
|
||||
}
|
||||
)
|
||||
|
||||
func NewControllerOptions() *ControllerOptions {
|
||||
@ -67,6 +81,7 @@ func NewControllerOptions() *ControllerOptions {
|
||||
LeaderElectionLeaseDuration: defaultLeaderElectionLeaseDuration,
|
||||
LeaderElectionRenewDeadline: defaultLeaderElectionRenewDeadline,
|
||||
LeaderElectionRetryPeriod: defaultLeaderElectionRetryPeriod,
|
||||
EnabledControllers: defaultEnabledControllers,
|
||||
ClusterIssuerAmbientCredentials: defaultClusterIssuerAmbientCredentials,
|
||||
IssuerAmbientCredentials: defaultIssuerAmbientCredentials,
|
||||
DefaultIssuerName: defaultTLSACMEIssuerName,
|
||||
@ -103,6 +118,9 @@ func (s *ControllerOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
"The duration the clients should wait between attempting acquisition and renewal "+
|
||||
"of a leadership. This is only applicable if leader election is enabled.")
|
||||
|
||||
fs.StringSliceVar(&s.EnabledControllers, "controllers", defaultEnabledControllers, ""+
|
||||
"The set of controllers to enable.")
|
||||
|
||||
fs.StringVar(&s.ACMEHTTP01SolverImage, "acme-http01-solver-image", defaultACMEHTTP01SolverImage, ""+
|
||||
"The docker image to use to solve ACME HTTP01 challenges. You most likely will not "+
|
||||
"need to change this parameter unless you are testing a new feature or developing cert-manager.")
|
||||
|
||||
@ -49,3 +49,13 @@ func RandStringRunes(n int) string {
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// Contains returns true if a string is contained in a string slice
|
||||
func Contains(ss []string, s string) bool {
|
||||
for _, v := range ss {
|
||||
if v == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@ -53,3 +53,41 @@ func TestEqualUnsorted(t *testing.T) {
|
||||
}(test))
|
||||
}
|
||||
}
|
||||
|
||||
func TestContains(t *testing.T) {
|
||||
type testT struct {
|
||||
desc string
|
||||
slice []string
|
||||
value string
|
||||
equal bool
|
||||
}
|
||||
tests := []testT{
|
||||
{
|
||||
desc: "slice containing value",
|
||||
slice: []string{"a", "b", "c"},
|
||||
value: "a",
|
||||
equal: true,
|
||||
},
|
||||
{
|
||||
desc: "slice not containing value",
|
||||
slice: []string{"a", "b", "c"},
|
||||
value: "x",
|
||||
equal: false,
|
||||
},
|
||||
{
|
||||
desc: "empty slice",
|
||||
slice: []string{},
|
||||
value: "x",
|
||||
equal: false,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.desc, func(test testT) func(*testing.T) {
|
||||
return func(t *testing.T) {
|
||||
if actual := Contains(test.slice, test.value); actual != test.equal {
|
||||
t.Errorf("Contains(%+v, %+v) = %t, but expected %t", test.slice, test.value, actual, test.equal)
|
||||
}
|
||||
}
|
||||
}(test))
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user