Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Make timeout of any request to the broker globally configurable #2666

Merged
merged 1 commit into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions charts/catalog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ chart and their default values.
| `controllerManager.healthcheck.enabled` | Enable readiness and liveliness probes | `true` |
| `controllerManager.verbosity` | Log level; valid values are in the range 0 - 10 | `10` |
| `controllerManager.resyncInterval` | How often the controller should resync informers; duration format (`20m`, `1h`, etc) | `5m` |
| `controllerManager.osbApiRequestTimeout` | The maximum amount of timeout to any request to the broker; duration format (`60s`, `3m`, etc) | `60s` |
| `controllerManager.brokerRelistInterval` | How often the controller should relist the catalogs of ready brokers; duration format (`20m`, `1h`, etc) | `24h` |
| `controllerManager.brokerRelistIntervalActivated` | Whether or not the controller supports a --broker-relist-interval flag. If this is set to true, brokerRelistInterval will be used as the value for that flag. | `true` |
| `controllerManager.profiling.disabled` | Disable profiling via web interface host:port/debug/pprof/ | `false` |
Expand Down
4 changes: 4 additions & 0 deletions charts/catalog/templates/controller-manager-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ spec:
- --operation-polling-maximum-backoff-duration
- {{ .Values.controllerManager.operationPollingMaximumBackoffDuration }}
{{- end }}
{{ if .Values.controllerManager.osbApiRequestTimeout -}}
- --osb-api-request-timeout
- {{ .Values.controllerManager.osbApiRequestTimeout }}
{{- end }}
- --feature-gates
- OriginatingIdentity={{.Values.originatingIdentityEnabled}}
- --feature-gates
Expand Down
2 changes: 2 additions & 0 deletions charts/catalog/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ controllerManager:
brokerRelistIntervalActivated: true
# The maximum amount of time to back-off while polling an OSB API operation; format is a duration (`20m`, `1h`, etc)
operationPollingMaximumBackoffDuration: 20m
# The maximum amount of timeout to any request to the broker; format is a duration (`60s`, `3m`, etc)
osbApiRequestTimeout: 60s
# enables profiling via web interface host:port/debug/pprof/
profiling:
# Disable profiling via web interface host:port/debug/pprof/
Expand Down
1 change: 1 addition & 0 deletions cmd/controller-manager/app/controller_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ func StartControllers(s *options.ControllerManagerServer,
s.OperationPollingMaximumBackoffDuration,
s.ClusterIDConfigMapName,
s.ClusterIDConfigMapNamespace,
s.OSBAPITimeOut,
)
if err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions cmd/controller-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const (
defaultLeaderElectionNamespace = "kube-system"
defaultReconciliationRetryDuration = 7 * 24 * time.Hour
defaultOperationPollingMaximumBackoffDuration = 20 * time.Minute
defaultOSBAPITimeOut = 60 * time.Second
)

var defaultOSBAPIPreferredVersion = osb.LatestAPIVersion().HeaderValue()
Expand All @@ -78,6 +79,7 @@ func NewControllerManagerServer() *ControllerManagerServer {
ServiceBrokerRelistInterval: defaultServiceBrokerRelistInterval,
OSBAPIContextProfile: defaultOSBAPIContextProfile,
OSBAPIPreferredVersion: defaultOSBAPIPreferredVersion,
OSBAPITimeOut: defaultOSBAPITimeOut,
ConcurrentSyncs: defaultConcurrentSyncs,
LeaderElection: leaderelectionconfig.DefaultLeaderElectionConfiguration(),
LeaderElectionNamespace: defaultLeaderElectionNamespace,
Expand Down Expand Up @@ -119,6 +121,7 @@ func (s *ControllerManagerServer) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.LeaderElectionNamespace, "leader-election-namespace", s.LeaderElectionNamespace, "Namespace to use for leader election lock")
fs.DurationVar(&s.ReconciliationRetryDuration, "reconciliation-retry-duration", s.ReconciliationRetryDuration, "The maximum amount of time to retry reconciliations on a resource before failing")
fs.DurationVar(&s.OperationPollingMaximumBackoffDuration, "operation-polling-maximum-backoff-duration", s.OperationPollingMaximumBackoffDuration, "The maximum amount of time to back-off while polling an OSB API operation")
fs.DurationVar(&s.OSBAPITimeOut, "osb-api-request-timeout", s.OSBAPITimeOut, "The maximum amount of timeout to any request to the broker.")
s.SecureServingOptions.AddFlags(fs)
utilfeature.DefaultMutableFeatureGate.AddFlag(fs)
fs.StringVar(&s.ClusterIDConfigMapName, "cluster-id-configmap-name", controller.DefaultClusterIDConfigMapName, "k8s name for clusterid configmap")
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/componentconfig/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ type ControllerManagerConfiguration struct {
OSBAPIContextProfile bool
OSBAPIPreferredVersion string

// OSBAPITimeOut the length of the timeout of any request to the broker.
OSBAPITimeOut time.Duration

// ConcurrentSyncs is the number of resources, per resource type,
// that are allowed to sync concurrently. Larger number = more responsive
// SC operations, but more CPU (and network) load.
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/case_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func newControllerTest(t *testing.T) *controllerTest {
7*24*time.Hour,
"DefaultClusterIDConfigMapName",
"DefaultClusterIDConfigMapNamespace",
60*time.Second,
)
if err != nil {
t.Fatal(err)
Expand Down
6 changes: 5 additions & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ func NewController(
operationPollingMaximumBackoffDuration time.Duration,
clusterIDConfigMapName string,
clusterIDConfigMapNamespace string,
osbAPITimeOut time.Duration,
) (Controller, error) {
controller := &controller{
kubeClient: kubeClient,
secretLister: secretInformer.Lister(),
serviceCatalogClient: serviceCatalogClient,
brokerRelistInterval: brokerRelistInterval,
OSBAPIPreferredVersion: osbAPIPreferredVersion,
OSBAPITimeOut: osbAPITimeOut,
recorder: recorder,
reconciliationRetryDuration: reconciliationRetryDuration,
clusterServiceBrokerQueue: workqueue.NewNamedRateLimitingQueue(workqueue.NewItemExponentialFailureRateLimiter(pollingStartInterval, operationPollingMaximumBackoffDuration), "cluster-service-broker"),
Expand Down Expand Up @@ -205,6 +207,7 @@ type controller struct {
secretLister v1.SecretLister
brokerRelistInterval time.Duration
OSBAPIPreferredVersion string
OSBAPITimeOut time.Duration
recorder record.EventRecorder
reconciliationRetryDuration time.Duration
clusterServiceBrokerQueue workqueue.RateLimitingInterface
Expand Down Expand Up @@ -1271,14 +1274,15 @@ func isServiceInstanceOrphanMitigation(instance *v1beta1.ServiceInstance) bool {

// NewClientConfigurationForBroker creates a new ClientConfiguration for connecting
// to the specified Broker
func NewClientConfigurationForBroker(meta metav1.ObjectMeta, commonSpec *v1beta1.CommonServiceBrokerSpec, authConfig *osb.AuthConfig) *osb.ClientConfiguration {
func NewClientConfigurationForBroker(meta metav1.ObjectMeta, commonSpec *v1beta1.CommonServiceBrokerSpec, authConfig *osb.AuthConfig, osbAPITimeOut time.Duration) *osb.ClientConfiguration {
clientConfig := osb.DefaultClientConfiguration()
clientConfig.Name = meta.Name
clientConfig.URL = commonSpec.URL
clientConfig.AuthConfig = authConfig
clientConfig.EnableAlphaFeatures = true
clientConfig.Insecure = commonSpec.InsecureSkipTLSVerify
clientConfig.CAData = commonSpec.CABundle
clientConfig.TimeoutSeconds = int(osbAPITimeOut.Seconds())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like that this is a float, but it's what we got.

return clientConfig
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/controller_clusterservicebroker.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (c *controller) clusterServiceBrokerClient(broker *v1beta1.ClusterServiceBr
}
return nil, err
}
clientConfig := NewClientConfigurationForBroker(broker.ObjectMeta, &broker.Spec.CommonServiceBrokerSpec, authConfig)
clientConfig := NewClientConfigurationForBroker(broker.ObjectMeta, &broker.Spec.CommonServiceBrokerSpec, authConfig, c.OSBAPITimeOut)
brokerClient, err := c.brokerClientManager.UpdateBrokerClient(NewClusterServiceBrokerKey(broker.Name), clientConfig)
if err != nil {
s := fmt.Sprintf("Error creating client for broker %q: %s", broker.Name, err)
Expand Down
15 changes: 15 additions & 0 deletions pkg/controller/controller_clusterservicebroker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,21 @@ func TestShouldReconcileClusterServiceBroker(t *testing.T) {
}
}

// TestReconcileClusterServiceBrokerSetOSBTimeOut
// verifies that timeout of any request to the
// broker takes effect.
func TestReconcileClusterServiceBrokerSetOSBTimeOut(t *testing.T) {
_, _, _, testController, _ := newTestController(t, getTestCatalogConfig())
testController.OSBAPITimeOut = time.Second * 80
if err := reconcileClusterServiceBroker(t, testController, getTestClusterServiceBroker()); err != nil {
t.Fatalf("This should not fail : %v", err)
}
createdClient := testController.brokerClientManager.clients[NewClusterServiceBrokerKey(getTestClusterServiceBroker().Name)]
if createdClient.clientConfig.TimeoutSeconds != int(testController.OSBAPITimeOut.Seconds()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this match the constant on 239? both client.config/timeoutseconds and testcontroller.osbapitimeout.seconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it should not be the same. It is just a test case. Thanks for review it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you set them to be the same on line 241. why bother having the const then?

t.Errorf("Unexpected OSBTimeOut: got %v, expeted %v", createdClient.clientConfig.TimeoutSeconds, int(testController.OSBAPITimeOut.Seconds()))
}
}

// TestReconcileClusterServiceBrokerExistingServiceClassAndServicePlan
// verifies a simple, successful run of reconcileClusterServiceBroker() when a
// ClusterServiceClass and plan already exist. This test will cause
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/controller_servicebroker.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (c *controller) serviceBrokerClient(broker *v1beta1.ServiceBroker) (osb.Cli
return nil, err
}

clientConfig := NewClientConfigurationForBroker(broker.ObjectMeta, &broker.Spec.CommonServiceBrokerSpec, authConfig)
clientConfig := NewClientConfigurationForBroker(broker.ObjectMeta, &broker.Spec.CommonServiceBrokerSpec, authConfig, c.OSBAPITimeOut)

brokerClient, err := c.brokerClientManager.UpdateBrokerClient(NewServiceBrokerKey(broker.Namespace, broker.Name), clientConfig)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2354,6 +2354,7 @@ func newTestController(t *testing.T, config fakeosb.FakeClientConfiguration) (
7*24*time.Hour,
DefaultClusterIDConfigMapName,
DefaultClusterIDConfigMapNamespace,
60*time.Second,
)

if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions test/integration/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ func newControllerTestTestController(ct *controllerTest) (
7*24*time.Hour,
controller.DefaultClusterIDConfigMapName,
controller.DefaultClusterIDConfigMapNamespace,
60*time.Second,
)
t.Log("controller start")
if err != nil {
Expand Down Expand Up @@ -957,6 +958,7 @@ func newTestController(t *testing.T) (
7*24*time.Hour,
controller.DefaultClusterIDConfigMapName,
controller.DefaultClusterIDConfigMapNamespace,
60*time.Second,
)
t.Log("controller start")
if err != nil {
Expand Down