Skip to content

Conversation

@codeblooded
Copy link
Owner

This change adds an options struct for the Controller and Watcher types, allowing them to be configured. Previously, they used magic constants.

@codeblooded codeblooded added feature New feature or request P2 Normal priority; prioritized over P3+ issues labels May 8, 2020
@codeblooded codeblooded added this to the v0.2-prealpha milestone May 8, 2020
@codeblooded codeblooded self-assigned this May 8, 2020
@codeblooded codeblooded linked an issue May 8, 2020 that may be closed by this pull request
2 tasks
Ben Reed added 2 commits May 8, 2020 09:27
This change adds an options struct for the Controller and Watcher
types, allowing them to be configured. Previously, they used magic
constants.
The Stop method of the orch.Controller type accepted a time.Duration. It
would wait for a graceful shutdown for this amount of time. Then, it
would return an error if the graceful shutdown did not occur.

This commit replaces the time.Duration with a context.Context,
permitting more flexibility.
@codeblooded codeblooded force-pushed the feature/controller-options branch from c6600db to c3458e1 Compare May 8, 2020 16:27
@codeblooded codeblooded changed the title Add options struct for Controller and Watcher Add options structs and timeouts to orch package May 8, 2020
@codeblooded codeblooded linked an issue May 8, 2020 that may be closed by this pull request
@codeblooded codeblooded marked this pull request as draft May 8, 2020 16:28
@codeblooded codeblooded force-pushed the feature/controller-options branch 3 times, most recently from 4f323e1 to d45f281 Compare May 8, 2020 23:08
// The options value allows the controller to be customized. Specifying nil will
// configure the controller to sane defaults described in the ControllerOptions
// documentation.
func NewController(clientset kubernetes.Interface, store store.Store, options *ControllerOptions) (*Controller, error) {
Copy link
Owner Author

Choose a reason for hiding this comment

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

I'm not sure if it is best to make the ControllerOptions parameter a pointer. It allows someone to specify nil and inherit defaults, but it decreases the readability of function calls. It may be better to have callers specify ControllerOptions{} to inherit the defaults. I believe I have seen both with Kubernetes. Would love input here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it is too important. If it is not a pointer you would write ControllerOptions{} where you now write nil, and it avoids some logic inside the controller, so it may be a reasonable thing to do.

func TestNewController(t *testing.T) {
t.Run("nil clientset returns error", func(t *testing.T) {
controller, err := NewController(nil, nil)
controller, err := NewController(nil, nil, nil)
Copy link
Owner Author

Choose a reason for hiding this comment

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

All tests currently use the default options. In the future, we may want to add tests to experiment with multiple combinations. The defaults are very sane, so I doubt we will deviate much.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume that means testing scheduling with two executors or with a timeout or with different watcher options. It may be ok to defer these, although eventually it would be good to test for instance that a second test can be scheduled when you have two executors, and so on.

@codeblooded codeblooded force-pushed the feature/controller-options branch from fa9bd72 to 65465d2 Compare May 8, 2020 23:59
This change implements timeouts on orchestration events, preventing
rouge operations from blocking indefinitely. Specifically, it:

 - Switches the Executor.Execute method to accept a context.Context

 - Modifies (*kubeExecutor).provision and (*kubeExecutor).monitor to
   use a context.Context. They now return an error when the context
   is cancelled before completion.

 - Adds a TestTimeout field to ControllerOptions. This sets the
   timeout on the Executor's context.

It also performs a handful of clean-up tasks, including:

 - Using UUIDs to name executors

 - Making TestKubeExecutorProvision a table-driven test
@codeblooded codeblooded force-pushed the feature/controller-options branch 2 times, most recently from 7ca9edc to 679826d Compare May 11, 2020 18:21
Ben Reed added 2 commits May 11, 2020 11:22
The flag -testTimeout specifies the maximum duration a session can take
to provision resources and run a test. If this duration is exceeded,
the session is killed and an error is returned.
Previously, the ControllerOptions struct copied a field from the
WatcherOptions struct, leading to duplicated logic. This change adds a
pointer to WatcherOptions in the ControllerOptions. This allows the
watcher's options to be handled in one place.
@codeblooded codeblooded force-pushed the feature/controller-options branch from 679826d to 31e741a Compare May 11, 2020 18:25
@codeblooded codeblooded requested a review from paulosjca May 11, 2020 18:38
The TestExecutorProvision function includes a test case to ensure an
error is returned when the context is cancelled.

The case lacked a driver and client. The server was in an unhealthy
status. In a future version, the provision function may have returned
errors for these issues, not the cancelled context.

This change adds all necessary components with a healthy status,
ensuring the error is due to the cancelled context.
@codeblooded codeblooded marked this pull request as ready for review May 11, 2020 18:49
@codeblooded codeblooded added bug Something isn't working security and removed bug Something isn't working labels May 11, 2020
@codeblooded codeblooded changed the base branch from v0.2 to master May 11, 2020 19:40
// The options value allows the controller to be customized. Specifying nil will
// configure the controller to sane defaults described in the ControllerOptions
// documentation.
func NewController(clientset kubernetes.Interface, store store.Store, options *ControllerOptions) (*Controller, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it is too important. If it is not a pointer you would write ControllerOptions{} where you now write nil, and it avoids some logic inside the controller, so it may be a reasonable thing to do.

func TestNewController(t *testing.T) {
t.Run("nil clientset returns error", func(t *testing.T) {
controller, err := NewController(nil, nil)
controller, err := NewController(nil, nil, nil)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume that means testing scheduling with two executors or with a timeout or with different watcher options. It may be ok to defer these, although eventually it would be good to test for instance that a second test can be scheduled when you have two executors, and so on.

@codeblooded codeblooded merged commit e11c486 into master May 11, 2020
@codeblooded codeblooded deleted the feature/controller-options branch May 11, 2020 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request P2 Normal priority; prioritized over P3+ issues security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create options structs to override defaults Add orchestration timeouts

3 participants