Merge pull request #717 from kragniz/disable-ingress-shim

Add --controllers flag to set which controllers are run
This commit is contained in:
jetstack-bot 2018-07-12 15:49:13 +01:00 committed by GitHub
commit caae0cc48a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 1 deletions

View File

@ -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)

View File

@ -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.")

View File

@ -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
}

View File

@ -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))
}
}