// translateHPASpec translates HPA related configurations from helm values.yaml tree.
translateHPASpec translates HPA related configurations from helm values.yaml tree.
// translateHPASpec translates HPA related configurations from helm values . yaml tree .
func translateHPASpec(inPath string, outPath string, value interface{}, valueTree map[string]interface{}, cpSpecTree map[string]interface{}) error {
	asEnabled, ok := value.(bool)
	if !ok {
		return fmt.Errorf("expect autoscaleEnabled node type to be bool but got: %T", value)
	}
	if !asEnabled {
		return nil
	}
	newP := util.PathFromString(inPath)
	newPS := newP[:len(newP)-1].String()
	valMap := map[string]string{
		".autoscaleMin": ".minReplicas",
		".autoscaleMax": ".maxReplicas",
	}
	for key, newVal := range valMap {
		valPath := newPS + key
		asVal, found, err := tpath.GetFromTreePath(valueTree, util.ToYAMLPath(valPath))
		if found && err == nil {
			if err := setOutputAndClean(valPath, outPath+newVal, asVal, valueTree, cpSpecTree, true); err != nil {
				return err
			}
		}
	}
	valPath := newPS + ".cpu.targetAverageUtilization"
	asVal, found, err := tpath.GetFromTreePath(valueTree, util.ToYAMLPath(valPath))
	if found && err == nil {
		rs := make([]interface{}, 1)
		rsVal := `
- type: Resource
  resource:
    name: cpu
    targetAverageUtilization: %f`
		rsString := fmt.Sprintf(rsVal, asVal)
		if err = yaml.Unmarshal([]byte(rsString), &rs); err != nil {
			return err
		}
		if err := setOutputAndClean(valPath, outPath+".metrics", rs, valueTree, cpSpecTree, true); err != nil {
			return err
		}
	}
	st := make(map[string]interface{})
	stVal := `
apiVersion: apps/v1
kind: Deployment
name: istio-%s`
	if specialComponentPath[newPS] && len(newP) > 2 {
		newPS = newP[1 : len(newP)-1].String()
	}
	stString := fmt.Sprintf(stVal, newPS)
	if err := yaml.Unmarshal([]byte(stString), &st); err != nil {
		return err
	}
	if err := setOutputAndClean(valPath, outPath+".scaleTargetRef", st, valueTree, cpSpecTree, false); err != nil {
		return err
	}
	return nil
}
func translateHPASpec ( inPath string , outPath string , value interface { } , valueTree map [ string ] interface { } , cpSpecTree map [ string ] interface { } ) error { asEnabled , ok := value . ( bool ) if ! ok { return fmt . Errorf ( " " , value ) } if ! asEnabled { return nil } newP := util . PathFromString ( inPath ) newPS := newP [ : len ( newP ) - 1 ] . String ( ) valMap := map [ string ] string { " " : " " , " " : " " , } for key , newVal := range valMap { valPath := newPS + key asVal , found , err := tpath . GetFromTreePath ( valueTree , util . ToYAMLPath ( valPath ) ) if found && err == nil { if err := setOutputAndClean ( valPath , outPath + newVal , asVal , valueTree , cpSpecTree , true ) ; err != nil { return err } } } valPath := newPS + " " asVal , found , err := tpath . GetFromTreePath ( valueTree , util . ToYAMLPath ( valPath ) ) if found && err == nil { rs := make ( [ ] interface { } , 1 ) rsVal := `
- type: Resource
  resource:
    name: cpu
    targetAverageUtilization: %f` rsString := fmt . Sprintf ( rsVal , asVal ) if err = yaml . Unmarshal ( [ ] byte ( rsString ) , & rs ) ; err != nil { return err } if err := setOutputAndClean ( valPath , outPath + " " , rs , valueTree , cpSpecTree , true ) ; err != nil { return err } } st := make ( map [ string ] interface { } ) stVal := `
apiVersion: apps/v1
kind: Deployment
name: istio-%s` if specialComponentPath [ newPS ] && len ( newP ) > 2 { newPS = newP [ 1 : len ( newP ) - 1 ] . String ( ) } stString := fmt . Sprintf ( stVal , newPS ) if err := yaml . Unmarshal ( [ ] byte ( stString ) , & st ) ; err != nil { return err } if err := setOutputAndClean ( valPath , outPath + " " , st , valueTree , cpSpecTree , false ) ; err != nil { return err } return nil }
translateHPASpec translates HPA related configurations from helm values.yaml tree.
translateHPASpec translates HPA related configurations from helm values . yaml tree .
// last path element is k8s setting name // There is no direct source from value.yaml for scaleTargetRef value, we need to construct from component name // need to do special handling for gateways and mixer // ex. because deployment name should be istio-telemetry instead of istio-mixer.telemetry, we need to get rid of the prefix mixer part.