Skip to content

Conversation

@cpuguy83
Copy link
Collaborator

@cpuguy83 cpuguy83 force-pushed the add_configs_to_compose branch 2 times, most recently from 5fab5a0 to f9c4c81 Compare May 15, 2017 15:32
@cpuguy83
Copy link
Collaborator Author

cli/compose/loader/loader.go:44::warning: cyclomatic complexity 22 of function Load() is high (> 19) (gocyclo)

I didn't really add any extra complexity here.

@dnephin
Copy link
Contributor

dnephin commented May 15, 2017

cc @shin- since this affects docker-compose

@dnephin
Copy link
Contributor

dnephin commented May 15, 2017

I didn't really add any extra complexity here.

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.

Copy link
Contributor

@dnephin dnephin left a 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 {
Copy link
Contributor

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) {
Copy link
Contributor

@dnephin dnephin May 15, 2017

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


configSpec, exists := configSpecs[config.Source]
if !exists {
return nil, errors.Errorf("undefined secret %q", config.Source)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/secret/config/

}
}

func transformServiceConfigObj(data interface{}) (interface{}, error) {
Copy link
Contributor

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?

}

// ServiceConfigObjConfig is the config obj configuration for a service
type ServiceConfigObjConfig struct {
Copy link
Contributor

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 ServiceSecretConfig

or

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

Copy link
Collaborator Author

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.

Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

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.

Copy link
Collaborator Author

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.

}

// ConfigObjConfig is the config for the swarm "Config" object
type ConfigObjConfig struct {
Copy link
Contributor

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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apiclient.IsErrConfigNotFound(err)

func TestConfigs(t *testing.T) {
namespace := Namespace{name: "foo"}

configText := "this is the first secret"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a secret


configSpec, exists := configSpecs[config.Source]
if !exists {
return nil, errors.Errorf("undefined secret %q", config.Source)

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)

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

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a secret

namespace := Namespace{name: "foo"}

configText := "this is the first secret"
secretFile := tempfile.NewTempFile(t, "convert-configs", configText)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the variable name

@cpuguy83 cpuguy83 force-pushed the add_configs_to_compose branch 2 times, most recently from d30fc41 to 6195a21 Compare May 15, 2017 17:50
@cpuguy83
Copy link
Collaborator Author

Updated and all green.

@cpuguy83 cpuguy83 added this to the 17.06.0 milestone May 16, 2017
@cpuguy83 cpuguy83 force-pushed the add_configs_to_compose branch 2 times, most recently from e0e0854 to 223b42f Compare May 16, 2017 21:09
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
@cpuguy83 cpuguy83 force-pushed the add_configs_to_compose branch from 223b42f to e574286 Compare May 16, 2017 21:10
Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@shin- shin- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW

@aaronlehmann
Copy link

LGTM

@thaJeztah
Copy link
Member

Opened docker/docs#3290 for tracking docs

nobiit pushed a commit to nobidev/docker-cli that referenced this pull request Nov 19, 2025
nobiit pushed a commit to nobidev/docker-cli that referenced this pull request Nov 19, 2025
Update to go 1.9.3
Upstream-commit: 7ea33ac7993e2abfd2404e147d95a3b41a29ccbe
Component: packaging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants