-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add support for configs to compose format #83
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
Conversation
5fab5a0 to
f9c4c81
Compare
I didn't really add any extra complexity here. |
|
cc @shin- since this affects docker-compose |
There are 3 new if statements which means the complexity increased by 3. I have a fix for this function in #61: https://github.com/docker/cli/pull/61/files#diff-4051eff50243f2cbcfa7172b42568ee0 which also removes a bunch of the duplication. You could grab that fix here, don't worry about cherry-picking it. |
dnephin
left a 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.
This generally looks correct
| secret, _, err := client.ConfigInspectWithRaw(ctx, configSpec.Name) | ||
| if err == nil { | ||
| // secret already exists, then we update that | ||
| if err := client.ConfigUpdate(ctx, secret.ID, secret.Meta.Version, configSpec); err != nil { |
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.
s/secret/config/
The variable above here, the comment, and the comment below this as well
| if err := client.ConfigUpdate(ctx, secret.ID, secret.Meta.Version, configSpec); err != nil { | ||
| return err | ||
| } | ||
| } else if apiclient.IsErrSecretNotFound(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.
There is a generic IsErrNotFound() we can use instead of this
cli/compose/convert/service.go
Outdated
|
|
||
| configSpec, exists := configSpecs[config.Source] | ||
| if !exists { | ||
| return nil, errors.Errorf("undefined secret %q", config.Source) |
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.
s/secret/config/
cli/compose/loader/loader.go
Outdated
| } | ||
| } | ||
|
|
||
| func transformServiceConfigObj(data interface{}) (interface{}, 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.
i think we can use the same function as secrets, since there is no type and the "string" version is the same?
cli/compose/types/types.go
Outdated
| } | ||
|
|
||
| // ServiceConfigObjConfig is the config obj configuration for a service | ||
| type ServiceConfigObjConfig struct { |
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 we use this instead these actually diverge:
type ServiceConfigObjConfig ServiceSecretConfigor
type ServiceConfigObjConfig struct {
ServiceSecretConfig
}
That might let us re-use some code as well?
And we could leave a comment about changing them when we need to
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'm not sure if this is worth the LOC saved.
These are separate objects that have totally different API's, use-cases, and in the future features.
I'd be more worried about real functional divergence getting automatically applied to both objects than accidental divergence in these types.
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.
Are they that separate? At the very least they share 5 fields! Even as other fields are added, these 5 fields will still overlap.
If not this solution, how about a common struct for these fields that gets included in both?
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'm really worried about doing this.
They happen to share similar code because they currently provide vary similar functionality, but I consider this coincidental duplication.
I would rather see where/how secrets and configs take off before trying to de-dup.
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'd like to experiment with extracting a common type before we merge this. I can look at it later today or tomorrow.
If it doesn't significantly remove code, I'll be ok with it like this.
I see what you're saying about different features, but I think that's more significant for the backend. From the client, where all we're doing is reading a config and converting to other types, I expect the code to stay quite similar.
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've updated to use a shared struct for now.
cli/compose/types/types.go
Outdated
| } | ||
|
|
||
| // ConfigObjConfig is the config for the swarm "Config" object | ||
| type ConfigObjConfig struct { |
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 questions about aliasing this to SecretConfig
| if err := client.ConfigUpdate(ctx, secret.ID, secret.Meta.Version, configSpec); err != nil { | ||
| return err | ||
| } | ||
| } else if apiclient.IsErrSecretNotFound(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.
apiclient.IsErrConfigNotFound(err)
cli/compose/convert/compose_test.go
Outdated
| func TestConfigs(t *testing.T) { | ||
| namespace := Namespace{name: "foo"} | ||
|
|
||
| configText := "this is the first secret" |
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.
not a secret
cli/compose/convert/service.go
Outdated
|
|
||
| configSpec, exists := configSpecs[config.Source] | ||
| if !exists { | ||
| return nil, errors.Errorf("undefined secret %q", config.Source) |
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.
undefined config %q
| client := dockerCli.Client() | ||
|
|
||
| for _, configSpec := range configs { | ||
| secret, _, err := client.ConfigInspectWithRaw(ctx, configSpec.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.
Change the variable name; it's not a secret
| for _, configSpec := range configs { | ||
| secret, _, err := client.ConfigInspectWithRaw(ctx, configSpec.Name) | ||
| if err == nil { | ||
| // secret already exists, then we update that |
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.
Not a secret
| return err | ||
| } | ||
| } else if apiclient.IsErrSecretNotFound(err) { | ||
| // secret does not exist, then we create a new one. |
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.
Not a secret
cli/compose/convert/compose_test.go
Outdated
| namespace := Namespace{name: "foo"} | ||
|
|
||
| configText := "this is the first secret" | ||
| secretFile := tempfile.NewTempFile(t, "convert-configs", configText) |
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 variable name
d30fc41 to
6195a21
Compare
|
Updated and all green. |
e0e0854 to
223b42f
Compare
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
223b42f to
e574286
Compare
dnephin
left a 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.
LGTM
shin-
left a 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.
FWIW
|
LGTM |
|
Opened docker/docs#3290 for tracking docs |
bump VERSION to 17.06.0-ce-rc5
Update to go 1.9.3 Upstream-commit: 7ea33ac7993e2abfd2404e147d95a3b41a29ccbe Component: packaging
Ping @aaronlehmann @vdemeester @dnephin