-
Notifications
You must be signed in to change notification settings - Fork 31
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
docker.network resource #477
Conversation
2af7f77
to
2a769da
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.
Mostly nitpicks on adjusting comments and could change "present"/"absent" to the StatePresent/StateAbsent
@@ -66,6 +66,12 @@ type Preparer struct { | |||
// list of DNS servers for the container to use | |||
DNS []string `hcl:"dns"` | |||
|
|||
// the mode of the container network |
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.
should you indicate the default if not specified?
|
||
// Prepare a docker network | ||
func (p *Preparer) Prepare(ctx context.Context, render resource.Renderer) (resource.Task, error) { | ||
if p.Name == "" { |
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 is handled for you by the preparer with required
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 is needed to prevent someone from manually specifying name = ""
in the hcl
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.
yes, that is correct
// driver specific options | ||
Options map[string]interface{} `hcl:"options"` | ||
|
||
// ip address management driver |
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.
maybe want to indicate the default in comments
// enable ipv6 networking | ||
IPv6 bool `hcl:"ipv6"` | ||
|
||
// indicates whether the volume should exist. |
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 that "present" is default
// ip address management driver | ||
IPAMDriver string `hcl:"ipam_driver"` | ||
|
||
// custom IPAM configuration. multiple IPAM configurations are permitted. Each |
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.
What if no configurations are specified? Probably good to add something to the comments.
DefaultIPAMDriver = "default" | ||
) | ||
|
||
// Network is responsible for managing docker volumes |
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.
managing docker networks
type IPAMConfigs []dc.IPAMConfig | ||
|
||
// Len implements the sort interface for IPAMConfigs | ||
func (ic IPAMConfigs) Len() int { return len(ic) } |
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 looks like Len, Swap, Less, and String (and ipamConfigString) are not used
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.
these are used to implement the sort interface: https://golang.org/pkg/sort/
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 see
|
||
// TestPreparerPrepare tests the Prepare function | ||
func TestPreparerPrepare(t *testing.T) { | ||
t.Run("name is required", func(t *testing.T) { |
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.
can remove this test with change in network/preparer.go (handled in resource/preparer.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.
see #477 (comment)
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.
yes, this is ok
} | ||
|
||
if p.State == "" { | ||
p.State = "present" |
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.
could use StatePresent instead of "present"
require.NoError(t, err) | ||
assert.True(t, status.HasChanges()) | ||
assert.Equal(t, 1, len(status.Diffs())) | ||
comparison.AssertDiff(t, status.Diffs(), nwName, "present", "absent") |
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.
could use StatePresent and StateAbsent throughout
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.
true but it requires a cast (otherwise, I get cannot use network.StatePresent (type network.State) as type string in argument to comparison.AssertDiff
). makes the lines really long and harder to read (imo). worth it?
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.
actually wasn't so bad - went ahead and fixed these
missing some options
ac8ff25
to
fe6a2a9
Compare
LGTM! |
fixes #298