Fix duplicate proto error in kubectl 1.8.0-alpha.
- Remove vendor'ed package go.pedge.io/pb/go/google/protobuf. - Update vendor'ed package github.com/libopenstorage/openstorage.
This commit is contained in:
1
vendor/github.com/libopenstorage/openstorage/api/spec/BUILD
generated
vendored
1
vendor/github.com/libopenstorage/openstorage/api/spec/BUILD
generated
vendored
@@ -6,6 +6,7 @@ go_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//vendor/github.com/libopenstorage/openstorage/api:go_default_library",
|
||||
"//vendor/github.com/libopenstorage/openstorage/pkg/parser:go_default_library",
|
||||
"//vendor/github.com/libopenstorage/openstorage/pkg/units:go_default_library",
|
||||
],
|
||||
)
|
||||
|
225
vendor/github.com/libopenstorage/openstorage/api/spec/spec_handler.go
generated
vendored
225
vendor/github.com/libopenstorage/openstorage/api/spec/spec_handler.go
generated
vendored
@@ -4,8 +4,10 @@ import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/libopenstorage/openstorage/api"
|
||||
"github.com/libopenstorage/openstorage/pkg/parser"
|
||||
"github.com/libopenstorage/openstorage/pkg/units"
|
||||
)
|
||||
|
||||
@@ -16,54 +18,92 @@ type SpecHandler interface {
|
||||
// If the scheduler was unable to pass in the volume spec via the API,
|
||||
// the spec can be passed in via the name in the format:
|
||||
// "key=value;key=value;name=volname"
|
||||
// source is populated if key parent=<volume_id> is specified.
|
||||
// If the spec was parsed, it returns:
|
||||
// (true, parsed_spec, parsed_name)
|
||||
// (true, parsed_spec, locator, source, parsed_name)
|
||||
// If the input string didn't contain the string, it returns:
|
||||
// (false, DefaultSpec(), inputString)
|
||||
SpecFromString(inputString string) (bool, *api.VolumeSpec, string)
|
||||
// (false, DefaultSpec(), nil, nil, inputString)
|
||||
SpecFromString(inputString string) (
|
||||
bool,
|
||||
*api.VolumeSpec,
|
||||
*api.VolumeLocator,
|
||||
*api.Source,
|
||||
string,
|
||||
)
|
||||
|
||||
// SpecFromOpts parses in docker options passed in the the docker run
|
||||
// command of the form --opt name=value
|
||||
// source is populated if --opt parent=<volume_id> is specified.
|
||||
// If the options are validated then it returns:
|
||||
// (resultant_VolumeSpec, nil)
|
||||
// (resultant_VolumeSpec, source, locator, nil)
|
||||
// If the options have invalid values then it returns:
|
||||
// (nil, error)
|
||||
// (nil, nil, nil, error)
|
||||
|
||||
SpecFromOpts(opts map[string]string) (
|
||||
*api.VolumeSpec,
|
||||
*api.VolumeLocator,
|
||||
*api.Source,
|
||||
error,
|
||||
)
|
||||
|
||||
// UpdateSpecFromOpts parses in volume options passed through the opts map and updates given spec, locator & source
|
||||
// If the options are validated then it returns:
|
||||
// (resultant_VolumeSpec, source, locator, nil)
|
||||
// If the options have invalid values then it returns:
|
||||
// (nil, nil, nil, error)
|
||||
UpdateSpecFromOpts(opts map[string]string, spec *api.VolumeSpec, locator *api.VolumeLocator, source *api.Source) (
|
||||
*api.VolumeSpec,
|
||||
*api.VolumeLocator,
|
||||
*api.Source,
|
||||
error,
|
||||
)
|
||||
|
||||
SpecFromOpts(opts map[string]string) (*api.VolumeSpec, error)
|
||||
// Returns a default VolumeSpec if no docker options or string encoding
|
||||
// was provided.
|
||||
DefaultSpec() *api.VolumeSpec
|
||||
}
|
||||
|
||||
var (
|
||||
nameRegex = regexp.MustCompile(api.Name + "=([0-9A-Za-z]+),?")
|
||||
nameRegex = regexp.MustCompile(api.Name + "=([0-9A-Za-z_-]+),?")
|
||||
nodesRegex = regexp.MustCompile(api.SpecNodes + "=([0-9A-Za-z_-]+),?")
|
||||
sizeRegex = regexp.MustCompile(api.SpecSize + "=([0-9A-Za-z]+),?")
|
||||
scaleRegex = regexp.MustCompile(api.SpecScale + "=([0-9A-Za-z]+),?")
|
||||
scaleRegex = regexp.MustCompile(api.SpecScale + "=([0-9]+),?")
|
||||
fsRegex = regexp.MustCompile(api.SpecFilesystem + "=([0-9A-Za-z]+),?")
|
||||
bsRegex = regexp.MustCompile(api.SpecBlockSize + "=([0-9]+),?")
|
||||
haRegex = regexp.MustCompile(api.SpecHaLevel + "=([0-9]+),?")
|
||||
cosRegex = regexp.MustCompile(api.SpecPriority + "=([A-Za-z]+),?")
|
||||
sharedRegex = regexp.MustCompile(api.SpecShared + "=([A-Za-z]+),?")
|
||||
passphraseRegex = regexp.MustCompile(api.SpecPassphrase + "=([0-9A-Za-z_@./#&+-]+),?")
|
||||
stickyRegex = regexp.MustCompile(api.SpecSticky + "=([A-Za-z]+),?")
|
||||
secureRegex = regexp.MustCompile(api.SpecSecure + "=([A-Za-z]+),?")
|
||||
zonesRegex = regexp.MustCompile(api.SpecZones + "=([A-Za-z]+),?")
|
||||
racksRegex = regexp.MustCompile(api.SpecRacks + "=([A-Za-z]+),?")
|
||||
aggrRegex = regexp.MustCompile(api.SpecAggregationLevel + "=([0-9]+|" +
|
||||
api.SpecAutoAggregationValue + "),?")
|
||||
compressedRegex = regexp.MustCompile(api.SpecCompressed + "=([A-Za-z]+),?")
|
||||
snapScheduleRegex = regexp.MustCompile(api.SpecSnapshotSchedule +
|
||||
`=([A-Za-z0-9:;@=#]+),?`)
|
||||
)
|
||||
|
||||
type specHandler struct {
|
||||
}
|
||||
|
||||
// NewSpecHandler returns a new SpecHandler interface
|
||||
func NewSpecHandler() SpecHandler {
|
||||
return &specHandler{}
|
||||
}
|
||||
|
||||
func (d *specHandler) cosLevel(cos string) (uint32, error) {
|
||||
func (d *specHandler) cosLevel(cos string) (api.CosType, error) {
|
||||
cos = strings.ToLower(cos)
|
||||
switch cos {
|
||||
case "high", "3":
|
||||
return uint32(api.CosType_HIGH), nil
|
||||
return api.CosType_HIGH, nil
|
||||
case "medium", "2":
|
||||
return uint32(api.CosType_MEDIUM), nil
|
||||
return api.CosType_MEDIUM, nil
|
||||
case "low", "1", "":
|
||||
return uint32(api.CosType_LOW), nil
|
||||
return api.CosType_LOW, nil
|
||||
}
|
||||
return uint32(api.CosType_LOW),
|
||||
return api.CosType_NONE,
|
||||
fmt.Errorf("Cos must be one of %q | %q | %q", "high", "medium", "low")
|
||||
}
|
||||
|
||||
@@ -91,30 +131,58 @@ func (d *specHandler) DefaultSpec() *api.VolumeSpec {
|
||||
}
|
||||
}
|
||||
|
||||
func (d *specHandler) SpecFromOpts(
|
||||
opts map[string]string,
|
||||
) (*api.VolumeSpec, error) {
|
||||
spec := d.DefaultSpec()
|
||||
func (d *specHandler) UpdateSpecFromOpts(opts map[string]string, spec *api.VolumeSpec, locator *api.VolumeLocator,
|
||||
source *api.Source) (*api.VolumeSpec, *api.VolumeLocator, *api.Source, error) {
|
||||
nodeList := make([]string, 0)
|
||||
|
||||
if spec == nil {
|
||||
spec = d.DefaultSpec()
|
||||
}
|
||||
|
||||
if source == nil {
|
||||
source = &api.Source{}
|
||||
}
|
||||
|
||||
if locator == nil {
|
||||
locator = &api.VolumeLocator{
|
||||
VolumeLabels: make(map[string]string),
|
||||
}
|
||||
}
|
||||
|
||||
for k, v := range opts {
|
||||
switch k {
|
||||
case api.SpecNodes:
|
||||
inputNodes := strings.Split(v, ",")
|
||||
for _, node := range inputNodes {
|
||||
if len(node) != 0 {
|
||||
nodeList = append(nodeList, node)
|
||||
}
|
||||
}
|
||||
spec.ReplicaSet = &api.ReplicaSet{Nodes: nodeList}
|
||||
case api.SpecParent:
|
||||
source.Parent = v
|
||||
case api.SpecEphemeral:
|
||||
spec.Ephemeral, _ = strconv.ParseBool(v)
|
||||
case api.SpecSize:
|
||||
if size, err := units.Parse(v); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, nil, err
|
||||
} else {
|
||||
spec.Size = uint64(size)
|
||||
}
|
||||
case api.SpecScale:
|
||||
if scale, err := strconv.ParseUint(v, 10, 64); err == nil {
|
||||
spec.Scale = uint32(scale)
|
||||
}
|
||||
|
||||
case api.SpecFilesystem:
|
||||
if value, err := api.FSTypeSimpleValueOf(v); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, nil, err
|
||||
} else {
|
||||
spec.Format = value
|
||||
}
|
||||
case api.SpecBlockSize:
|
||||
if blockSize, err := units.Parse(v); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, nil, err
|
||||
} else {
|
||||
spec.BlockSize = blockSize
|
||||
}
|
||||
@@ -122,39 +190,108 @@ func (d *specHandler) SpecFromOpts(
|
||||
haLevel, _ := strconv.ParseInt(v, 10, 64)
|
||||
spec.HaLevel = haLevel
|
||||
case api.SpecPriority:
|
||||
cos, _ := api.CosTypeSimpleValueOf(v)
|
||||
cos, err := d.cosLevel(v)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
spec.Cos = cos
|
||||
case api.SpecPriorityAlias:
|
||||
cos, err := d.cosLevel(v)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
spec.Cos = cos
|
||||
case api.SpecDedupe:
|
||||
spec.Dedupe, _ = strconv.ParseBool(v)
|
||||
case api.SpecSnapshotInterval:
|
||||
snapshotInterval, _ := strconv.ParseUint(v, 10, 32)
|
||||
spec.SnapshotInterval = uint32(snapshotInterval)
|
||||
case api.SpecSnapshotSchedule:
|
||||
spec.SnapshotSchedule = v
|
||||
case api.SpecAggregationLevel:
|
||||
aggregationLevel, _ := strconv.ParseUint(v, 10, 32)
|
||||
spec.AggregationLevel = uint32(aggregationLevel)
|
||||
if v == api.SpecAutoAggregationValue {
|
||||
spec.AggregationLevel = api.AutoAggregation
|
||||
} else {
|
||||
aggregationLevel, _ := strconv.ParseUint(v, 10, 32)
|
||||
spec.AggregationLevel = uint32(aggregationLevel)
|
||||
}
|
||||
case api.SpecShared:
|
||||
if shared, err := strconv.ParseBool(v); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, nil, err
|
||||
} else {
|
||||
spec.Shared = shared
|
||||
}
|
||||
case api.SpecSticky:
|
||||
if sticky, err := strconv.ParseBool(v); err != nil {
|
||||
return nil, nil, nil, err
|
||||
} else {
|
||||
spec.Sticky = sticky
|
||||
}
|
||||
case api.SpecSecure:
|
||||
if secure, err := strconv.ParseBool(v); err != nil {
|
||||
return nil, nil, nil, err
|
||||
} else {
|
||||
spec.Encrypted = secure
|
||||
}
|
||||
case api.SpecPassphrase:
|
||||
spec.Encrypted = true
|
||||
spec.Passphrase = v
|
||||
case api.SpecGroup:
|
||||
spec.Group = &api.Group{Id: v}
|
||||
case api.SpecGroupEnforce:
|
||||
if groupEnforced, err := strconv.ParseBool(v); err != nil {
|
||||
return nil, nil, nil, err
|
||||
} else {
|
||||
spec.GroupEnforced = groupEnforced
|
||||
}
|
||||
case api.SpecZones, api.SpecRacks:
|
||||
locator.VolumeLabels[k] = v
|
||||
case api.SpecCompressed:
|
||||
if compressed, err := strconv.ParseBool(v); err != nil {
|
||||
return nil, nil, nil, err
|
||||
} else {
|
||||
spec.Compressed = compressed
|
||||
}
|
||||
case api.SpecLabels:
|
||||
if labels, err := parser.LabelsFromString(v); err != nil {
|
||||
return nil, nil, nil, err
|
||||
} else {
|
||||
for k, v := range labels {
|
||||
locator.VolumeLabels[k] = v
|
||||
}
|
||||
}
|
||||
case api.SpecIoProfile:
|
||||
if ioProfile, err := api.IoProfileSimpleValueOf(v); err != nil {
|
||||
return nil, nil, nil, err
|
||||
} else {
|
||||
spec.IoProfile = ioProfile
|
||||
}
|
||||
default:
|
||||
spec.VolumeLabels[k] = v
|
||||
}
|
||||
}
|
||||
return spec, nil
|
||||
return spec, locator, source, nil
|
||||
}
|
||||
|
||||
func (d *specHandler) SpecFromOpts(
|
||||
opts map[string]string,
|
||||
) (*api.VolumeSpec, *api.VolumeLocator, *api.Source, error) {
|
||||
source := &api.Source{}
|
||||
locator := &api.VolumeLocator{
|
||||
VolumeLabels: make(map[string]string),
|
||||
}
|
||||
|
||||
spec := d.DefaultSpec()
|
||||
return d.UpdateSpecFromOpts(opts, spec, locator, source)
|
||||
}
|
||||
|
||||
func (d *specHandler) SpecFromString(
|
||||
str string,
|
||||
) (bool, *api.VolumeSpec, string) {
|
||||
) (bool, *api.VolumeSpec, *api.VolumeLocator, *api.Source, string) {
|
||||
// If we can't parse the name, the rest of the spec is invalid.
|
||||
ok, name := d.getVal(nameRegex, str)
|
||||
if !ok {
|
||||
return false, d.DefaultSpec(), str
|
||||
return false, d.DefaultSpec(), nil, nil, str
|
||||
}
|
||||
|
||||
opts := make(map[string]string)
|
||||
@@ -162,6 +299,9 @@ func (d *specHandler) SpecFromString(
|
||||
if ok, sz := d.getVal(sizeRegex, str); ok {
|
||||
opts[api.SpecSize] = sz
|
||||
}
|
||||
if ok, nodes := d.getVal(nodesRegex, str); ok {
|
||||
opts[api.SpecNodes] = nodes
|
||||
}
|
||||
if ok, scale := d.getVal(scaleRegex, str); ok {
|
||||
opts[api.SpecScale] = scale
|
||||
}
|
||||
@@ -180,13 +320,34 @@ func (d *specHandler) SpecFromString(
|
||||
if ok, shared := d.getVal(sharedRegex, str); ok {
|
||||
opts[api.SpecShared] = shared
|
||||
}
|
||||
if ok, sticky := d.getVal(stickyRegex, str); ok {
|
||||
opts[api.SpecSticky] = sticky
|
||||
}
|
||||
if ok, secure := d.getVal(secureRegex, str); ok {
|
||||
opts[api.SpecSecure] = secure
|
||||
}
|
||||
if ok, passphrase := d.getVal(passphraseRegex, str); ok {
|
||||
opts[api.SpecPassphrase] = passphrase
|
||||
}
|
||||
|
||||
spec, err := d.SpecFromOpts(opts)
|
||||
if err != nil {
|
||||
return false, d.DefaultSpec(), name
|
||||
if ok, zones := d.getVal(zonesRegex, str); ok {
|
||||
opts[api.SpecZones] = zones
|
||||
}
|
||||
return true, spec, name
|
||||
if ok, racks := d.getVal(racksRegex, str); ok {
|
||||
opts[api.SpecRacks] = racks
|
||||
}
|
||||
if ok, aggregationLvl := d.getVal(aggrRegex, str); ok {
|
||||
opts[api.SpecAggregationLevel] = aggregationLvl
|
||||
}
|
||||
if ok, compressed := d.getVal(compressedRegex, str); ok {
|
||||
opts[api.SpecCompressed] = compressed
|
||||
}
|
||||
if ok, sched := d.getVal(snapScheduleRegex, str); ok {
|
||||
opts[api.SpecSnapshotSchedule] = strings.Replace(sched, "#", ",", -1)
|
||||
}
|
||||
|
||||
spec, locator, source, err := d.SpecFromOpts(opts)
|
||||
if err != nil {
|
||||
return false, d.DefaultSpec(), nil, nil, name
|
||||
}
|
||||
return true, spec, locator, source, name
|
||||
}
|
||||
|
Reference in New Issue
Block a user