Files
kata-containers/virtcontainers/experimental/experimental.go
Wei Zhang 050f03bb36 config: Add config flag "experimental"
Fixes #1226

Add new flag "experimental" for supporting underworking features.
Some features are under developing which are not ready for release,
there're also some features which will break compatibility which is not
suitable to be merged into a kata minor release(x version in x.y.z)

For getting these features above merged earlier for more testing, we can
mark them as "experimental" features, and move them to formal features
when they are ready.

Signed-off-by: Wei Zhang <zhangwei555@huawei.com>
2019-03-12 11:03:28 +08:00

64 lines
1.3 KiB
Go

// Copyright (c) 2019 Huawei Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package experimental
import (
"fmt"
"regexp"
)
const (
nameRegStr = "^[a-z][a-z0-9_]*$"
)
// Feature to be experimental
type Feature struct {
Name string
Description string
// the expected release version to move out from experimental
ExpRelease string
}
var (
supportedFeatures = make(map[string]Feature)
)
// Register register a new experimental feature
func Register(feature Feature) error {
if err := validateFeature(feature); err != nil {
return err
}
if _, ok := supportedFeatures[feature.Name]; ok {
return fmt.Errorf("Feature %q had been registered before", feature.Name)
}
supportedFeatures[feature.Name] = feature
return nil
}
// Get returns Feature with requested name
func Get(name string) *Feature {
if f, ok := supportedFeatures[name]; ok {
return &f
}
return nil
}
func validateFeature(feature Feature) error {
if len(feature.Name) == 0 ||
len(feature.Description) == 0 ||
len(feature.ExpRelease) == 0 {
return fmt.Errorf("experimental feature must have valid name, description and expected release")
}
reg := regexp.MustCompile(nameRegStr)
if !reg.MatchString(feature.Name) {
return fmt.Errorf("feature name must in the format %q", nameRegStr)
}
return nil
}