Skip to content

[WIP] Auto reload the local operator for code changes #1489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

baijum
Copy link

@baijum baijum commented May 26, 2019

When running the operator using operator-sdk up local command,
restart the operator whenever there is a change in Go source code
in the file-system.

Fixes #1484

  • Flag to disable auto-reload
  • Tests
  • Flag to set ignore directories (default: .git,build)

@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 26, 2019
@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 26, 2019
@baijum baijum force-pushed the local-auto-reload branch 8 times, most recently from 3e21593 to 3b3c108 Compare May 27, 2019 05:38
When running the operator using `operator-sdk up local` command,
restart the operator whenever there is a change in Go source code
in the file-system.

Fixes operator-framework#1484
@baijum baijum force-pushed the local-auto-reload branch from 3b3c108 to ecbc8fd Compare May 27, 2019 06:19
@baijum baijum marked this pull request as ready for review May 27, 2019 09:34
@joelanford
Copy link
Member

@baijum This looks like a good start. Just a couple of other ideas to think about:

  1. Can you make this work for the helm and ansible operator types as well?
  2. It would be interesting to see this implemented using the functional options pattern entirely behind the exsting API of projutil.ExecCmd, where the function could be updated to something along the lines of:
func ExecCmd(cmd *exec.Cmd, opts ...func(*ExecOptions) error) error {
    execOptions := ExecOptions{}
    for _, opt := range opts {
        if err := opt(&execOptions); err != nil {
            return err
        }
    }
    ...
}

Then could export a new RestartOnChange function that configures ExecCmd to watch a directory and restart the passed cmd on change:

func RestartOnChange(rootDir string, ignorePaths []string) func(*ExecOption) error {
    return func(opt *ExecOption) error {
        opt.RestartOnChange = true
        opt.WatchRootDir = rootDir
        opt.WatchIgnorePaths = ignorePaths
        return nil
    }
}

With this pattern, existing usages would be unchanged:

projutil.ExecCmd(myOneShotCmd)

But to restart a command based on a watch, it could look like:

projutil.ExecCmd(
    myRestartableCmd, 
    projutil.RestartOnChange(".", []string{".git", "deploy", "build"})
)

I think doing something along these lines would make it easy to extend this to other commands (like ansible and helm), and it would make it easy to extend the ExecCmd function in other ways in the future.

Thoughts?

@baijum
Copy link
Author

baijum commented May 28, 2019

@joelanford Thanks for the idea. I will study that pattern.
I agree that helm and ansible should be covered.

@baijum
Copy link
Author

baijum commented May 29, 2019

@joelanford Looks like ansible and helm operators are not using ExecCmd to start the operator.

done <- mgr.Start(c)

if err = mgr.Start(signals.SetupSignalHandler()); err != nil {

@joelanford
Copy link
Member

@baijum Oh, right. In that case, we probably need an abstraction that handles each case. In fact, the entire ansible.Run and helm.Run commands would need to be wrapped so that the watches.yaml file could be reloaded.

It looks like the projutil.ExecCmd, ansible.Run, and helm.Run commands all have the same signature, but it also looks like we'd have to have two different ways to stop them.

We might have to have something like the following with a couple of struct implementations (one for ExecCmd and another for the Run functions, perhaps):

type Runnable interface {
   Run() error
   Stop() error
}

@joelanford
Copy link
Member

@baijum Before you get too far with this, I want to make sure this is something we're likely to accept.

/cc @hasbro17 @lilic @shawn-hurley @estroz @AlexNPavel @theishshah

Thoughts on including this functionality in operator-sdk? Would we be better off documenting how to do this with inotify or fswatch?

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 4, 2019
@openshift-ci-robot
Copy link

@baijum: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@lilic
Copy link
Member

lilic commented Jun 7, 2019

@joelanford I think this is very useful and right now I think users just assume this is already working and run into problems when changes are not applied, thinking the problem is in their code. So this is very much needed 👍

@openshift-ci-robot
Copy link

@baijum: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/prow/images ecbc8fd link /test images
ci/prow/e2e-aws-ansible ecbc8fd link /test e2e-aws-ansible
ci/prow/e2e-aws-helm ecbc8fd link /test e2e-aws-helm
ci/prow/e2e-aws-go ecbc8fd link /test e2e-aws-go
ci/prow/e2e-aws-subcommand ecbc8fd link /test e2e-aws-subcommand

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-bot
Copy link

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

@openshift-ci-robot openshift-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 7, 2019
@estroz
Copy link
Member

estroz commented Nov 9, 2019

@baijum thanks again for opening this PR. Do you plan on working on this going forward? If not, one of the SDK main contributors can potentially pick it up.

@openshift-bot
Copy link

Stale issues rot after 30d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle rotten
/remove-lifecycle stale

@openshift-ci-robot openshift-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Dec 9, 2019
@openshift-bot
Copy link

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

@openshift-ci-robot
Copy link

@openshift-bot: Closed this PR.

In response to this:

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs discussion needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto reload the local operator for code changes
6 participants