-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep preview environment context in sync #11202
Conversation
a876d21
to
37ccb49
Compare
d931d56
to
750bc1a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Mads, thanks for picking this up!
I like the decision of watching the VMI creation timestamp as the information we use to decide if a preview should be re-installed!
What I didn't understand was the need to implement the watch loops 馃.
@vulkoingim could probably elaborate more here, but my assumption is that when using informers (which we are), we're subscribing to specific events from kubernetes.
The events we're subscribed to are ADD and UPDATE from virtualmachines, but we decide to quit once we successfully install a context. Couldn't we just not quit, but keep watching for UPDATE instead?
Co-authored-by: Arthur Silva Sens <arthursens2005@gmail.com>
|
The "outer" watch loop serve two purposes
We could most likely fix (1) by changing The implementation in this branch has the following separation of concerns:
We could improve it slightly by moving the "VM was changed" logic into "preview.InstallContext" so that the outer loop only looks for changes to the branch. I can do a quick time-boxed attempt at that and see if the result is nicer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As agreed in our team sync, let's get this merged since the PR solves the problem!
I just found a new problem here, but feel free to leave this to another PR if you prefer. We should be including any logic in the cmd
package, all it is supposed to do is initialize commands and call functions 馃槵
Adding the /hold label so you can decide on tackling this now or in another PR
// Used to ensure that we only install contexts | ||
var lastSuccessfulPreviewEnvironment *preview.Preview = nil | ||
|
||
install := func(timeout time.Duration) error { | ||
p, err := preview.New("", logger) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
if lastSuccessfulPreviewEnvironment != nil && lastSuccessfulPreviewEnvironment.Same(p) { | ||
logger.Infof("The preview envrionment hasn't changed") | ||
return nil | ||
} | ||
|
||
err = p.InstallContext(true, timeout) | ||
if err == nil { | ||
lastSuccessfulPreviewEnvironment = p | ||
} | ||
return err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part looks a bit like an anti-pattern for the pattern we established 馃槵
To keep every logic testable, I believe we that code inside the cmd
package should do nothing more than declare the CLI commands and calling functions from other packages.
If we move this part to a separate function the preview
package, we can create tests for it 馃檪
if watch { | ||
for range time.Tick(15 * time.Second) { | ||
// We're using a short timeout here to handle the scenario where someone switches | ||
// to a branch that doens't have a preview envrionment. In that case the default | ||
// timeout would mean that we would block for 10 minutes, potentially missing | ||
// if the user changes to a new branch that does that a preview. | ||
err := install(30 * time.Second) | ||
if err != nil { | ||
logger.WithFields(logrus.Fields{"err": err}).Info("Failed to install context. Trying again soon.") | ||
} | ||
} | ||
} else { | ||
return install(timeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above 馃槄
/hold |
@ArthurSens Thanks! I'll merge this and follow-up on this in another PR
If I don't manage to get a PR open before I leave for the week I'll create an issue about this instead |
Sounds great!
from* cmd 馃槢 |
@ArthurSens haha, updated the comment to avoid confusion |
Follow-up issue created as I didn't get to it this week https://github.com/gitpod-io/ops/issues/3357 |
Description
This PR implements the
--watch
option and uses it in.gitpod.yaml
. I considered the following requirements:Implementation
This changes the behaviour of "--watch" so that it runs forever and polls the current branch and VM periodically to see if a new preview environment context should be installed.
Alternative implementation
If we wanted to avoid polling could've created a channel for changes to the preview environment. For changes to the VM we could (I think) have used an Informer. Branch changes would be a bit more tricky though but might be achievable using a git hook that sends a signal to the process. Or if the current branch is stored in the filesystem we might be able to be notified on changes to that file.
I went with polling as that seemed like a smaller 馃浌
Related Issue(s)
Fixes #11108
How to test
Release Notes
Documentation
Werft options:
N/A