mirror of https://github.com/docker/cli.git
getEngineConfigFilePath is only used during test…
… so moving it in test files for now.
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 37ca5d6813
)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
649e4916bb
commit
62aed95bc1
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -92,35 +91,6 @@ func (c *baseClient) getEngineImage(engine containerd.Container) (string, error)
|
||||||
return image.Name(), nil
|
return image.Name(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getEngineConfigFilePath will extract the config file location from the engine flags
|
|
||||||
func (c baseClient) getEngineConfigFilePath(ctx context.Context, engine containerd.Container) (string, error) {
|
|
||||||
spec, err := engine.Spec(ctx)
|
|
||||||
configFile := ""
|
|
||||||
if err != nil {
|
|
||||||
return configFile, err
|
|
||||||
}
|
|
||||||
for i := 0; i < len(spec.Process.Args); i++ {
|
|
||||||
arg := spec.Process.Args[i]
|
|
||||||
if strings.HasPrefix(arg, "--config-file") {
|
|
||||||
if strings.Contains(arg, "=") {
|
|
||||||
split := strings.SplitN(arg, "=", 2)
|
|
||||||
configFile = split[1]
|
|
||||||
} else {
|
|
||||||
if i+1 >= len(spec.Process.Args) {
|
|
||||||
return configFile, ErrMalformedConfigFileParam
|
|
||||||
}
|
|
||||||
configFile = spec.Process.Args[i+1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if configFile == "" {
|
|
||||||
// TODO - any more diagnostics to offer?
|
|
||||||
return configFile, ErrEngineConfigLookupFailure
|
|
||||||
}
|
|
||||||
return configFile, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
engineWaitInterval = 500 * time.Millisecond
|
engineWaitInterval = 500 * time.Millisecond
|
||||||
engineWaitTimeout = 60 * time.Second
|
engineWaitTimeout = 60 * time.Second
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -538,3 +539,32 @@ func TestGetEngineConfigFilePathMalformed1(t *testing.T) {
|
||||||
_, err := client.getEngineConfigFilePath(ctx, container)
|
_, err := client.getEngineConfigFilePath(ctx, container)
|
||||||
assert.Assert(t, err == ErrMalformedConfigFileParam)
|
assert.Assert(t, err == ErrMalformedConfigFileParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getEngineConfigFilePath will extract the config file location from the engine flags
|
||||||
|
func (c baseClient) getEngineConfigFilePath(ctx context.Context, engine containerd.Container) (string, error) {
|
||||||
|
spec, err := engine.Spec(ctx)
|
||||||
|
configFile := ""
|
||||||
|
if err != nil {
|
||||||
|
return configFile, err
|
||||||
|
}
|
||||||
|
for i := 0; i < len(spec.Process.Args); i++ {
|
||||||
|
arg := spec.Process.Args[i]
|
||||||
|
if strings.HasPrefix(arg, "--config-file") {
|
||||||
|
if strings.Contains(arg, "=") {
|
||||||
|
split := strings.SplitN(arg, "=", 2)
|
||||||
|
configFile = split[1]
|
||||||
|
} else {
|
||||||
|
if i+1 >= len(spec.Process.Args) {
|
||||||
|
return configFile, ErrMalformedConfigFileParam
|
||||||
|
}
|
||||||
|
configFile = spec.Process.Args[i+1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if configFile == "" {
|
||||||
|
// TODO - any more diagnostics to offer?
|
||||||
|
return configFile, ErrEngineConfigLookupFailure
|
||||||
|
}
|
||||||
|
return configFile, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue