-
Notifications
You must be signed in to change notification settings - Fork 14
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
Enable setting environment variables via Hooks #27
Conversation
2640253
to
a3a0329
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.
It will not work - hook recives copy of TaskInfo. You have to modify Hook interface so it will allow to return values.
a3a0329
to
aae731b
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.
Change commit message. You add only test now.
aae731b
to
42947c0
Compare
@AlfredBroda why I see "Fix Travis configuration for releses #22" in this PR? |
816e858
to
bd84cbe
Compare
Fixed all the conflicts... for now. |
command.go
Outdated
@@ -121,7 +122,7 @@ func (c *cancellableCommand) Stop(gracePeriod time.Duration) { | |||
} | |||
|
|||
// NewCommand returns a new command based on passed CommandInfo. | |||
func NewCommand(commandInfo mesos.CommandInfo, env []string, options ...func(*exec.Cmd) error) (Command, error) { | |||
func NewCommand(commandInfo mesos.CommandInfo, env hook.Env, options ...func(*exec.Cmd) error) (Command, error) { |
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.
Env
should not be defined in hook
package
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.
Where do you suggest to put it? executor.go? command.go?
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.
Reverted back to []string
hook/consul/hook.go
Outdated
default: | ||
log.Debugf("Received unsupported event type %s - ignoring", event.Type) | ||
return nil // ignore unsupported events | ||
return hook.Env{}, nil // ignore unsupported events |
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.
IMO nil
will be better than hook.Env{}
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.
It's not a problem really - you have to perform error check before you will use that value.
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.
And deal with mocking in tests. Will try that approach (again).
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.
I mean, it does not make sense to return pointer here.
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.
Returning nil then.
executor.go
Outdated
Type: hook.BeforeTaskStartEvent, | ||
TaskInfo: mesosutils.TaskInfo{TaskInfo: taskInfo}, | ||
} | ||
additionalEnv, err := e.hookManager.HandleEvent(beforeStartEvent, false) |
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.
You have to merge env
and additionalEnv
slices or services will not have access to certificate or MESOS_
variables.
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.
Also add test case for this - the current ones did not catch this problem (os.Environ()
is not copied into command env)
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.
Correct the submitted comments.
bd84cbe
to
7b2fad2
Compare
@AlfredBroda explain in commit message why we are enabling this. |
hook/hook.go
Outdated
@@ -25,12 +25,15 @@ type Event struct { | |||
TaskInfo mesosutils.TaskInfo | |||
} | |||
|
|||
// Env is a container type for environment variables. |
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.
Add info about format. Most people will expect map here - not slice.
mesosutils/taskinfo_test.go
Outdated
|
||
returnedValue := taskInfo.FindEnvValue(key) | ||
|
||
require.Equal(t, returnedValue, expectedValue) |
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.
Signature of Equal
is:
func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{})
(switch returnedValue
and expectedValue
)
cce9fd0
to
910c347
Compare
910c347
to
de3e296
Compare
de3e296
to
2474a3b
Compare
Fixes done, no time to wait for your ok. :P
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.
We could make use of named return values. E.g., when it's alywas nil we can call it ignore
.
I'd like to make code cleanup in separated commits.
@@ -405,8 +414,8 @@ func (e *Executor) shutDown(taskInfo mesos.TaskInfo, cmd Command) { | |||
Type: hook.BeforeTerminateEvent, | |||
TaskInfo: mesosutils.TaskInfo{TaskInfo: taskInfo}, | |||
} | |||
_ = e.hookManager.HandleEvent(beforeTerminateEvent, true) // ignore errors here, so every hook will have a chance to be called | |||
cmd.Stop(gracePeriod) // blocking call | |||
_, _ = e.hookManager.HandleEvent(beforeTerminateEvent, true) // ignore errors here, so every hook will have a chance to be called |
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.
I think we should log errors
@@ -46,15 +46,15 @@ type Config struct { | |||
|
|||
// HandleEvent calls appropriate hook functions that correspond to supported | |||
// event types. Unsupported events are ignored. | |||
func (h *Hook) HandleEvent(event hook.Event) error { | |||
func (h *Hook) HandleEvent(event hook.Event) (hook.Env, error) { |
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.
Please document when HandleEvent returns hook.Env
@@ -25,12 +25,15 @@ type Event struct { | |||
TaskInfo mesosutils.TaskInfo | |||
} | |||
|
|||
// Env is a container for os.Environ style list of combined environment variable strings. | |||
type Env []string |
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.
I think this should not be in this package
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.
Suggest another then 😄
// Hook is an interface for various executor extensions, that can add some actions | ||
// during task lifecycle events. | ||
type Hook interface { | ||
// HandleEvent is called when any of defined executor task events occurs. | ||
// Received events may be handled in any way, but hook should ignore unknown or | ||
// unsupported ones. Call to this function will block executor process until | ||
// it returns. Order of received event types is undefined. | ||
HandleEvent(Event) error | ||
HandleEvent(Event) (Env, error) |
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.
Update the godoc
This allows for setting application environment via Hooks (for remote configuration retrieval purposes).