Skip to content

Commit

Permalink
WIP: timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtCoDFish committed Jun 20, 2022
1 parent afaee34 commit d42892b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions pkg/controller/BUILD.bazel
Expand Up @@ -8,6 +8,7 @@ go_library(
"controller.go",
"helper.go",
"register.go",
"timeout.go",
"util.go",
],
importpath = "github.com/cert-manager/cert-manager/pkg/controller",
Expand Down
5 changes: 2 additions & 3 deletions pkg/controller/clusterissuers/sync.go
Expand Up @@ -18,7 +18,6 @@ package clusterissuers

import (
"context"
"time"

corev1 "k8s.io/api/core/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
Expand All @@ -28,6 +27,7 @@ import (
"github.com/cert-manager/cert-manager/internal/controller/feature"
internalissuers "github.com/cert-manager/cert-manager/internal/controller/issuers"
cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
"github.com/cert-manager/cert-manager/pkg/controller"
logf "github.com/cert-manager/cert-manager/pkg/logs"
utilfeature "github.com/cert-manager/cert-manager/pkg/util/feature"
)
Expand All @@ -41,8 +41,7 @@ const (
func (c *controller) Sync(ctx context.Context, iss *cmapi.ClusterIssuer) (err error) {
log := logf.FromContext(ctx)

// allow a maximum of 90s
ctx, cancel := context.WithTimeout(ctx, time.Second*90)
ctx, cancel := context.WithTimeout(ctx, controller.DefaultControllerContextTimeout)
defer cancel()

issuerCopy := iss.DeepCopy()
Expand Down
5 changes: 2 additions & 3 deletions pkg/controller/issuers/sync.go
Expand Up @@ -18,7 +18,6 @@ package issuers

import (
"context"
"time"

corev1 "k8s.io/api/core/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
Expand All @@ -28,6 +27,7 @@ import (
"github.com/cert-manager/cert-manager/internal/controller/feature"
internalissuers "github.com/cert-manager/cert-manager/internal/controller/issuers"
cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
"github.com/cert-manager/cert-manager/pkg/controller"
logf "github.com/cert-manager/cert-manager/pkg/logs"
utilfeature "github.com/cert-manager/cert-manager/pkg/util/feature"
)
Expand All @@ -41,8 +41,7 @@ const (
func (c *controller) Sync(ctx context.Context, iss *cmapi.Issuer) (err error) {
log := logf.FromContext(ctx)

// allow a maximum of 90s
ctx, cancel := context.WithTimeout(ctx, time.Second*90)
ctx, cancel := context.WithTimeout(ctx, controller.DefaultControllerContextTimeout)
defer cancel()

issuerCopy := iss.DeepCopy()
Expand Down
27 changes: 27 additions & 0 deletions pkg/controller/timeout.go
@@ -0,0 +1,27 @@
/*
Copyright 2022 The cert-manager Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package controller

import "time"

const (
// DefaultControllerContextTimeout is the default maximum amount of time which a single synchronize action in some controllers
// may take before the sync will be cancelled by a context timeout.
// This timeout might not be respected on all controllers thanks to backwards compatibility concerns, but it's a goal to have
// all issuers have some default timeout which represents a default upper bound on the time they're permitted to take.
DefaultControllerContextTimeout = 2 * time.Minute
)

0 comments on commit d42892b

Please sign in to comment.