-
Notifications
You must be signed in to change notification settings - Fork 673
Add support for templating Node.Hostname in docker executor #2266
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
Merged
aaronlehmann
merged 1 commit into
moby:master
from
mion00:feature/template-node-hostname
Jun 22, 2017
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,12 @@ import ( | |
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| // Platform holds information about the underlying platform of the node | ||
| type Platform struct { | ||
| Architecture string | ||
| OS string | ||
| } | ||
|
|
||
| // Context defines the strict set of values that can be injected into a | ||
| // template expression in SwarmKit data structure. | ||
| // NOTE: Be very careful adding any fields to this structure with types | ||
|
|
@@ -27,7 +33,9 @@ type Context struct { | |
| } | ||
|
|
||
| Node struct { | ||
| ID string | ||
| ID string | ||
| Hostname string | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While we're at it, would it make sense to add other properties from
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| Platform Platform | ||
| } | ||
|
|
||
| Task struct { | ||
|
|
@@ -41,16 +49,25 @@ type Context struct { | |
| } | ||
| } | ||
|
|
||
| // NewContextFromTask returns a new template context from the data available in | ||
| // task. The provided context can then be used to populate runtime values in a | ||
| // NewContext returns a new template context from the data available in the | ||
| // task and the node where it is scheduled to run. | ||
| // The provided context can then be used to populate runtime values in a | ||
| // ContainerSpec. | ||
| func NewContextFromTask(t *api.Task) (ctx Context) { | ||
| func NewContext(n *api.NodeDescription, t *api.Task) (ctx Context) { | ||
| ctx.Service.ID = t.ServiceID | ||
| ctx.Service.Name = t.ServiceAnnotations.Name | ||
| ctx.Service.Labels = t.ServiceAnnotations.Labels | ||
|
|
||
| ctx.Node.ID = t.NodeID | ||
|
|
||
| // Add node information to context only if we have them available | ||
| if n != nil { | ||
| ctx.Node.Hostname = n.Hostname | ||
| ctx.Node.Platform = Platform{ | ||
| Architecture: n.Platform.Architecture, | ||
| OS: n.Platform.OS, | ||
| } | ||
| } | ||
| ctx.Task.ID = t.ID | ||
| ctx.Task.Name = naming.Task(t) | ||
|
|
||
|
|
@@ -157,12 +174,13 @@ func (ctx PayloadContext) envGetter(variable string) (string, error) { | |
| } | ||
|
|
||
| // NewPayloadContextFromTask returns a new template context from the data | ||
| // available in the task. This context also provides access to the configs | ||
| // available in the task and the node where it is scheduled to run. | ||
| // This context also provides access to the configs | ||
| // and secrets that the task has access to. The provided context can then | ||
| // be used to populate runtime values in a templated config or secret. | ||
| func NewPayloadContextFromTask(t *api.Task, dependencies exec.DependencyGetter) (ctx PayloadContext) { | ||
| func NewPayloadContextFromTask(node *api.NodeDescription, t *api.Task, dependencies exec.DependencyGetter) (ctx PayloadContext) { | ||
| return PayloadContext{ | ||
| Context: NewContextFromTask(t), | ||
| Context: NewContext(node, t), | ||
| t: t, | ||
| restrictedSecrets: secrets.Restrict(dependencies.Secrets(), t), | ||
| restrictedConfigs: configs.Restrict(dependencies.Configs(), t), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 can use
api.Platforminstead of redefining the struct 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.
Forget I said that... realized this is going into a struct that will be accessable by templates, so no methods should be defined on the type.
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.
That's exactly what I thought 😉