func (switches *ControlSwitches) setFeatureToState(featureName string, switchObj map[string]bool) {
	if featureState, available := switchObj[featureName]; available {
		state := switches.configuration[featureName]
		state.setActiveState(featureState)
		switches.configuration[featureName] = state
	} else {
		state := switches.configuration[featureName]
		state.setActiveToInitialState()
		switches.configuration[featureName] = state
	}
}
setFeatureToState set given feature to the state defined in the map object
package controlswitches
import (
	"encoding/json"
	"flag"
	"fmt"
	"strings"
	"github.com/golang/glog"
	corev1 "k8s.io/api/core/v1"
)
const (
	controlSwitchesFileKey = "config.json"
	controlSwitchesMainKey = "features"
	enableHugePageDownAPIKey = "enableHugePageDownApi"
	enableHonorExistingResourcesKey = "enableHonorExistingResources"
)
type controlSwitchesStates struct {
	active  bool
	initial bool
}
func (state *controlSwitchesStates) setActiveToInitialState() {
	state.active = state.initial
}
func (state *controlSwitchesStates) setActiveState(value bool) {
	state.active = value
}
type ControlSwitches struct {
	injectHugepageDownAPI *bool
	resourceNameKeysFlag  *string
	resourcesHonorFlag    *bool
	configuration    map[string]controlSwitchesStates
	resourceNameKeys []string
	isValid          bool
}
func SetupControlSwitchesFlags() *ControlSwitches {
	var initFlags ControlSwitches
	initFlags.injectHugepageDownAPI = flag.Bool("injectHugepageDownApi", false, "Enable hugepage requests and limits into Downward API.")
	initFlags.resourceNameKeysFlag = flag.String("network-resource-name-keys", "k8s.v1.cni.cncf.io/resourceName", "comma separated resource name keys --network-resource-name-keys.")
	initFlags.resourcesHonorFlag = flag.Bool("honor-resources", false, "Honor the existing requested resources requests & limits --honor-resources")
	return &initFlags
}
func (switches *ControlSwitches) InitControlSwitches() {
	switches.configuration = make(map[string]controlSwitchesStates)
	state := controlSwitchesStates{initial: *switches.injectHugepageDownAPI, active: *switches.injectHugepageDownAPI}
	switches.configuration[enableHugePageDownAPIKey] = state
	state = controlSwitchesStates{initial: *switches.resourcesHonorFlag, active: *switches.resourcesHonorFlag}
	switches.configuration[enableHonorExistingResourcesKey] = state
	switches.resourceNameKeys = setResourceNameKeys(*switches.resourceNameKeysFlag)
	switches.isValid = true
}
func setResourceNameKeys(keys string) []string {
	var resourceNameKeys []string
	for _, resourceNameKey := range strings.Split(keys, ",") {
		resourceNameKey = strings.TrimSpace(resourceNameKey)
		resourceNameKeys = append(resourceNameKeys, resourceNameKey)
	}
	return resourceNameKeys
}
func (switches *ControlSwitches) GetResourceNameKeys() []string {
	return switches.resourceNameKeys
}
func (switches *ControlSwitches) IsHugePagedownAPIEnabled() bool {
	return switches.configuration[enableHugePageDownAPIKey].active
}
func (switches *ControlSwitches) IsHonorExistingResourcesEnabled() bool {
	return switches.configuration[enableHonorExistingResourcesKey].active
}
func (switches *ControlSwitches) IsResourcesNameEnabled() bool {
	return len(*switches.resourceNameKeysFlag) > 0
}
func (switches *ControlSwitches) IsValid() bool {
	return switches.isValid
}
func (switches *ControlSwitches) GetAllFeaturesState() string {
	var output string
	output = fmt.Sprintf("HugePageInject: %t", switches.IsHugePagedownAPIEnabled())
	output = output + " / " + fmt.Sprintf("HonorExistingResources: %t", switches.IsHonorExistingResourcesEnabled())
	output = output + " / " + fmt.Sprintf("EnableResourceNames: %t", switches.IsResourcesNameEnabled())
	return output
}
func (switches *ControlSwitches) setAllFeaturesToInitialState() {
	state := switches.configuration[enableHugePageDownAPIKey]
	state.setActiveToInitialState()
	switches.configuration[enableHugePageDownAPIKey] = state
	state = switches.configuration[enableHonorExistingResourcesKey]
	state.setActiveToInitialState()
	switches.configuration[enableHonorExistingResourcesKey] = state
}