mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client/config: Use Config instead of Spec as field
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
// ConfigCreateOptions holds options for creating a config.
|
||||
type ConfigCreateOptions struct {
|
||||
Config swarm.ConfigSpec
|
||||
Spec swarm.ConfigSpec
|
||||
}
|
||||
|
||||
// ConfigCreateResult holds the result from the ConfigCreate method.
|
||||
@@ -19,7 +19,7 @@ type ConfigCreateResult struct {
|
||||
|
||||
// ConfigCreate creates a new config.
|
||||
func (cli *Client) ConfigCreate(ctx context.Context, options ConfigCreateOptions) (ConfigCreateResult, error) {
|
||||
resp, err := cli.post(ctx, "/configs/create", nil, options.Config, nil)
|
||||
resp, err := cli.post(ctx, "/configs/create", nil, options.Spec, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
if err != nil {
|
||||
return ConfigCreateResult{}, err
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestConfigCreateError(t *testing.T) {
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, err = client.ConfigCreate(context.Background(), ConfigCreateOptions{Config: swarm.ConfigSpec{}})
|
||||
_, err = client.ConfigCreate(context.Background(), ConfigCreateOptions{Spec: swarm.ConfigSpec{}})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestConfigCreate(t *testing.T) {
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
|
||||
r, err := client.ConfigCreate(context.Background(), ConfigCreateOptions{Config: swarm.ConfigSpec{}})
|
||||
r, err := client.ConfigCreate(context.Background(), ConfigCreateOptions{Spec: swarm.ConfigSpec{}})
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(r.ID, "test_config"))
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
// ConfigUpdateOptions holds options for updating a config.
|
||||
type ConfigUpdateOptions struct {
|
||||
Version swarm.Version
|
||||
Config swarm.ConfigSpec
|
||||
Spec swarm.ConfigSpec
|
||||
}
|
||||
|
||||
type ConfigUpdateResult struct{}
|
||||
@@ -23,7 +23,7 @@ func (cli *Client) ConfigUpdate(ctx context.Context, id string, options ConfigUp
|
||||
}
|
||||
query := url.Values{}
|
||||
query.Set("version", options.Version.String())
|
||||
resp, err := cli.post(ctx, "/configs/"+id+"/update", query, options.Config, nil)
|
||||
resp, err := cli.post(ctx, "/configs/"+id+"/update", query, options.Spec, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
if err != nil {
|
||||
return ConfigUpdateResult{}, err
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"testing"
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/moby/moby/api/types/swarm"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
)
|
||||
@@ -19,14 +18,14 @@ func TestConfigUpdateError(t *testing.T) {
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, err = client.ConfigUpdate(context.Background(), "config_id", ConfigUpdateOptions{Version: swarm.Version{}, Config: swarm.ConfigSpec{}})
|
||||
_, err = client.ConfigUpdate(context.Background(), "config_id", ConfigUpdateOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
|
||||
|
||||
_, err = client.ConfigUpdate(context.Background(), "", ConfigUpdateOptions{Version: swarm.Version{}, Config: swarm.ConfigSpec{}})
|
||||
_, err = client.ConfigUpdate(context.Background(), "", ConfigUpdateOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
|
||||
assert.Check(t, is.ErrorContains(err, "value is empty"))
|
||||
|
||||
_, err = client.ConfigUpdate(context.Background(), " ", ConfigUpdateOptions{Version: swarm.Version{}, Config: swarm.ConfigSpec{}})
|
||||
_, err = client.ConfigUpdate(context.Background(), " ", ConfigUpdateOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
|
||||
assert.Check(t, is.ErrorContains(err, "value is empty"))
|
||||
}
|
||||
@@ -47,6 +46,6 @@ func TestConfigUpdate(t *testing.T) {
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, err = client.ConfigUpdate(context.Background(), "config_id", ConfigUpdateOptions{Version: swarm.Version{}, Config: swarm.ConfigSpec{}})
|
||||
_, err = client.ConfigUpdate(context.Background(), "config_id", ConfigUpdateOptions{})
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ func TestConfigList(t *testing.T) {
|
||||
|
||||
func createConfig(ctx context.Context, t *testing.T, apiClient client.APIClient, name string, data []byte, labels map[string]string) string {
|
||||
result, err := apiClient.ConfigCreate(ctx, client.ConfigCreateOptions{
|
||||
Config: swarmtypes.ConfigSpec{
|
||||
Spec: swarmtypes.ConfigSpec{
|
||||
Annotations: swarmtypes.Annotations{
|
||||
Name: name,
|
||||
Labels: labels,
|
||||
@@ -127,8 +127,8 @@ func createConfig(ctx context.Context, t *testing.T, apiClient client.APIClient,
|
||||
},
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, result.Response.ID != "")
|
||||
return result.Response.ID
|
||||
assert.Check(t, result.ID != "")
|
||||
return result.ID
|
||||
}
|
||||
|
||||
func TestConfigsCreateAndDelete(t *testing.T) {
|
||||
@@ -187,7 +187,7 @@ func TestConfigsUpdate(t *testing.T) {
|
||||
|
||||
// test UpdateConfig with full ID
|
||||
insp.Config.Spec.Labels = map[string]string{"test": "test1"}
|
||||
_, err = c.ConfigUpdate(ctx, client.SwarmVersionedID{ID: configID, Version: insp.Config.Version}, client.ConfigUpdateOptions{Config: insp.Config.Spec})
|
||||
_, err = c.ConfigUpdate(ctx, configID, client.ConfigUpdateOptions{Version: insp.Config.Version, Spec: insp.Config.Spec})
|
||||
assert.NilError(t, err)
|
||||
|
||||
insp, err = c.ConfigInspect(ctx, configID, client.ConfigInspectOptions{})
|
||||
@@ -196,7 +196,7 @@ func TestConfigsUpdate(t *testing.T) {
|
||||
|
||||
// test UpdateConfig with full name
|
||||
insp.Config.Spec.Labels = map[string]string{"test": "test2"}
|
||||
_, err = c.ConfigUpdate(ctx, client.SwarmVersionedID{ID: testName, Version: insp.Config.Version}, client.ConfigUpdateOptions{Config: insp.Config.Spec})
|
||||
_, err = c.ConfigUpdate(ctx, testName, client.ConfigUpdateOptions{Version: insp.Config.Version, Spec: insp.Config.Spec})
|
||||
assert.NilError(t, err)
|
||||
|
||||
insp, err = c.ConfigInspect(ctx, configID, client.ConfigInspectOptions{})
|
||||
@@ -205,7 +205,7 @@ func TestConfigsUpdate(t *testing.T) {
|
||||
|
||||
// test UpdateConfig with prefix ID
|
||||
insp.Config.Spec.Labels = map[string]string{"test": "test3"}
|
||||
_, err = c.ConfigUpdate(ctx, client.SwarmVersionedID{ID: configID[:1], Version: insp.Config.Version}, client.ConfigUpdateOptions{Config: insp.Config.Spec})
|
||||
_, err = c.ConfigUpdate(ctx, configID[:1], client.ConfigUpdateOptions{Version: insp.Config.Version, Spec: insp.Config.Spec})
|
||||
assert.NilError(t, err)
|
||||
|
||||
insp, err = c.ConfigInspect(ctx, configID, client.ConfigInspectOptions{})
|
||||
@@ -215,7 +215,7 @@ func TestConfigsUpdate(t *testing.T) {
|
||||
// test UpdateConfig in updating Data which is not supported in daemon
|
||||
// this test will produce an error in func UpdateConfig
|
||||
insp.Config.Spec.Data = []byte("TESTINGDATA2")
|
||||
_, err = c.ConfigUpdate(ctx, client.SwarmVersionedID{ID: configID, Version: insp.Config.Version}, client.ConfigUpdateOptions{Config: insp.Config.Spec})
|
||||
_, err = c.ConfigUpdate(ctx, configID, client.ConfigUpdateOptions{Version: insp.Config.Version, Spec: insp.Config.Spec})
|
||||
assert.Check(t, cerrdefs.IsInvalidArgument(err))
|
||||
assert.Check(t, is.ErrorContains(err, "only updates to Labels are allowed"))
|
||||
}
|
||||
@@ -247,7 +247,7 @@ func TestTemplatedConfig(t *testing.T) {
|
||||
Data: []byte("this is a config"),
|
||||
}
|
||||
referencedConfigResult, err := c.ConfigCreate(ctx, client.ConfigCreateOptions{
|
||||
Config: referencedConfigSpec,
|
||||
Spec: referencedConfigSpec,
|
||||
})
|
||||
assert.Check(t, err)
|
||||
|
||||
@@ -266,7 +266,7 @@ func TestTemplatedConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
templatedConfigResult, err := c.ConfigCreate(ctx, client.ConfigCreateOptions{
|
||||
Config: configSpec,
|
||||
Spec: configSpec,
|
||||
})
|
||||
assert.Check(t, err)
|
||||
|
||||
@@ -280,7 +280,7 @@ func TestTemplatedConfig(t *testing.T) {
|
||||
GID: "0",
|
||||
Mode: 0o600,
|
||||
},
|
||||
ConfigID: templatedConfigResult.Response.ID,
|
||||
ConfigID: templatedConfigResult.ID,
|
||||
ConfigName: templatedConfigName,
|
||||
},
|
||||
),
|
||||
@@ -292,7 +292,7 @@ func TestTemplatedConfig(t *testing.T) {
|
||||
GID: "0",
|
||||
Mode: 0o600,
|
||||
},
|
||||
ConfigID: referencedConfigResult.Response.ID,
|
||||
ConfigID: referencedConfigResult.ID,
|
||||
ConfigName: referencedConfigName,
|
||||
},
|
||||
),
|
||||
|
||||
@@ -246,8 +246,8 @@ func TestTemplatedSecret(t *testing.T) {
|
||||
},
|
||||
Data: []byte("this is a config"),
|
||||
}
|
||||
referencedConfigResult, err := c.ConfigCreate(ctx, client.ConfigCreateOptions{
|
||||
Config: referencedConfigSpec,
|
||||
referencedConfig, err := c.ConfigCreate(ctx, client.ConfigCreateOptions{
|
||||
Spec: referencedConfigSpec,
|
||||
})
|
||||
assert.Check(t, err)
|
||||
|
||||
@@ -289,7 +289,7 @@ func TestTemplatedSecret(t *testing.T) {
|
||||
GID: "0",
|
||||
Mode: 0o600,
|
||||
},
|
||||
ConfigID: referencedConfigResult.Response.ID,
|
||||
ConfigID: referencedConfig.ID,
|
||||
ConfigName: referencedConfigName,
|
||||
},
|
||||
),
|
||||
|
||||
@@ -256,8 +256,8 @@ func TestCreateServiceConfigFileMode(t *testing.T) {
|
||||
defer apiClient.Close()
|
||||
|
||||
configName := "TestConfig_" + t.Name()
|
||||
configResp, err := apiClient.ConfigCreate(ctx, client.ConfigCreateOptions{
|
||||
Config: swarmtypes.ConfigSpec{
|
||||
resp, err := apiClient.ConfigCreate(ctx, client.ConfigCreateOptions{
|
||||
Spec: swarmtypes.ConfigSpec{
|
||||
Annotations: swarmtypes.Annotations{
|
||||
Name: configName,
|
||||
},
|
||||
@@ -279,7 +279,7 @@ func TestCreateServiceConfigFileMode(t *testing.T) {
|
||||
GID: "0",
|
||||
Mode: 0o777,
|
||||
},
|
||||
ConfigID: configResp.Response.ID,
|
||||
ConfigID: resp.ID,
|
||||
ConfigName: configName,
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -145,8 +145,8 @@ func TestServiceUpdateConfigs(t *testing.T) {
|
||||
|
||||
configName := "TestConfig_" + t.Name()
|
||||
configTarget := "targetName"
|
||||
configResp, err := apiClient.ConfigCreate(ctx, client.ConfigCreateOptions{
|
||||
Config: swarmtypes.ConfigSpec{
|
||||
resp, err := apiClient.ConfigCreate(ctx, client.ConfigCreateOptions{
|
||||
Spec: swarmtypes.ConfigSpec{
|
||||
Annotations: swarmtypes.Annotations{
|
||||
Name: configName,
|
||||
},
|
||||
@@ -154,7 +154,7 @@ func TestServiceUpdateConfigs(t *testing.T) {
|
||||
},
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, configResp.Response.ID != "")
|
||||
assert.Check(t, resp.ID != "")
|
||||
|
||||
serviceName := "TestService_" + t.Name()
|
||||
serviceID := swarm.CreateService(ctx, t, d, swarm.ServiceWithName(serviceName))
|
||||
@@ -169,7 +169,7 @@ func TestServiceUpdateConfigs(t *testing.T) {
|
||||
GID: "0",
|
||||
Mode: 0o600,
|
||||
},
|
||||
ConfigID: configResp.Response.ID,
|
||||
ConfigID: resp.ID,
|
||||
ConfigName: configName,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -19,10 +19,10 @@ func (d *Daemon) CreateConfig(t testing.TB, configSpec swarm.ConfigSpec) string
|
||||
defer cli.Close()
|
||||
|
||||
result, err := cli.ConfigCreate(context.Background(), client.ConfigCreateOptions{
|
||||
Config: configSpec,
|
||||
Spec: configSpec,
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
return result.Response.ID
|
||||
return result.ID
|
||||
}
|
||||
|
||||
// ListConfigs returns the list of the current swarm configs
|
||||
@@ -69,6 +69,6 @@ func (d *Daemon) UpdateConfig(t testing.TB, id string, f ...ConfigConstructor) {
|
||||
fn(config)
|
||||
}
|
||||
|
||||
_, err := cli.ConfigUpdate(context.Background(), client.SwarmVersionedID{ID: config.ID, Version: config.Version}, client.ConfigUpdateOptions{Config: config.Spec})
|
||||
_, err := cli.ConfigUpdate(context.Background(), config.ID, client.ConfigUpdateOptions{Version: config.Version, Spec: config.Spec})
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
4
vendor/github.com/moby/moby/client/config_create.go
generated
vendored
4
vendor/github.com/moby/moby/client/config_create.go
generated
vendored
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
// ConfigCreateOptions holds options for creating a config.
|
||||
type ConfigCreateOptions struct {
|
||||
Config swarm.ConfigSpec
|
||||
Spec swarm.ConfigSpec
|
||||
}
|
||||
|
||||
// ConfigCreateResult holds the result from the ConfigCreate method.
|
||||
@@ -19,7 +19,7 @@ type ConfigCreateResult struct {
|
||||
|
||||
// ConfigCreate creates a new config.
|
||||
func (cli *Client) ConfigCreate(ctx context.Context, options ConfigCreateOptions) (ConfigCreateResult, error) {
|
||||
resp, err := cli.post(ctx, "/configs/create", nil, options.Config, nil)
|
||||
resp, err := cli.post(ctx, "/configs/create", nil, options.Spec, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
if err != nil {
|
||||
return ConfigCreateResult{}, err
|
||||
|
||||
4
vendor/github.com/moby/moby/client/config_update.go
generated
vendored
4
vendor/github.com/moby/moby/client/config_update.go
generated
vendored
@@ -10,7 +10,7 @@ import (
|
||||
// ConfigUpdateOptions holds options for updating a config.
|
||||
type ConfigUpdateOptions struct {
|
||||
Version swarm.Version
|
||||
Config swarm.ConfigSpec
|
||||
Spec swarm.ConfigSpec
|
||||
}
|
||||
|
||||
type ConfigUpdateResult struct{}
|
||||
@@ -23,7 +23,7 @@ func (cli *Client) ConfigUpdate(ctx context.Context, id string, options ConfigUp
|
||||
}
|
||||
query := url.Values{}
|
||||
query.Set("version", options.Version.String())
|
||||
resp, err := cli.post(ctx, "/configs/"+id+"/update", query, options.Config, nil)
|
||||
resp, err := cli.post(ctx, "/configs/"+id+"/update", query, options.Spec, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
if err != nil {
|
||||
return ConfigUpdateResult{}, err
|
||||
|
||||
Reference in New Issue
Block a user