mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-04 23:14:19 +01:00
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>
64 lines
1.3 KiB
Go
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
|
|
}
|