forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. support add-runtime in daemon 2. fix parse daemon flags twice, which make flags be set for twice 3. add runtime info in pouch info 4. fix slice-type flags merge not take effect, move merge flags operation in runDaemon, since(*cobra.Command).Execute() will do flags parse. Signed-off-by: Ace-Tang <[email protected]>
- Loading branch information
Showing
9 changed files
with
159 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package opt | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/alibaba/pouch/apis/types" | ||
) | ||
|
||
// Runtime defines runtimes information | ||
type Runtime struct { | ||
values *map[string]types.Runtime | ||
} | ||
|
||
// NewRuntime initials a Runtime struct | ||
func NewRuntime(rts *map[string]types.Runtime) *Runtime { | ||
if rts == nil { | ||
rts = &map[string]types.Runtime{} | ||
} | ||
|
||
if *rts == nil { | ||
*rts = map[string]types.Runtime{} | ||
} | ||
|
||
rt := &Runtime{values: rts} | ||
return rt | ||
} | ||
|
||
// Set implement Runtime as pflag.Value interface | ||
func (r *Runtime) Set(val string) error { | ||
splits := strings.Split(val, "=") | ||
if len(splits) != 2 || splits[0] == "" || splits[1] == "" { | ||
return fmt.Errorf("invalid runtime %s, correct format must be runtime=path", val) | ||
} | ||
|
||
name := splits[0] | ||
path := splits[1] | ||
if _, exist := (*r.values)[name]; exist { | ||
return fmt.Errorf("runtime %s already registers to daemon", name) | ||
} | ||
|
||
(*r.values)[name] = types.Runtime{Path: path} | ||
return nil | ||
} | ||
|
||
// String implement Runtime as pflag.Value interface | ||
func (r *Runtime) String() string { | ||
var str []string | ||
for k := range *r.values { | ||
str = append(str, fmt.Sprintf("%s", k)) | ||
} | ||
|
||
return fmt.Sprintf("%v", str) | ||
} | ||
|
||
// Type implement Runtime as pflag.Value interface | ||
func (r *Runtime) Type() string { | ||
return "value" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package opt | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/alibaba/pouch/apis/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewRuntime(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
for _, r := range []*map[string]types.Runtime{ | ||
nil, | ||
{}, | ||
{ | ||
"a": {}, | ||
"b": {Path: "foo"}, | ||
}, | ||
} { | ||
runtime := NewRuntime(r) | ||
// just test no panic here | ||
assert.NoError(runtime.Set("foo=bar")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters