// translateK8sTree is internal method for translating K8s configurations from value.yaml tree.
translateK8sTree is internal method for translating K8s configurations from value.yaml tree.
// translateK8sTree is internal method for translating K8s configurations from value . yaml tree .
func (t *ReverseTranslator) translateK8sTree(valueTree map[string]interface{},
	cpSpecTree map[string]interface{}) error {
	for inPath, v := range t.KubernetesMapping {
		log.Infof("Checking for k8s path %s in helm Value.yaml tree", inPath)
		m, found, err := tpath.GetFromTreePath(valueTree, util.ToYAMLPath(inPath))
		if err != nil {
			return err
		}
		if !found {
			log.Infof("path %s not found in helm Value.yaml tree, skip mapping.", inPath)
			continue
		}
		if mstr, ok := m.(string); ok && mstr == "" {
			log.Infof("path %s is empty string, skip mapping.", inPath)
			continue
		}
		if mint, ok := util.ToIntValue(m); ok && mint == 0 {
			log.Infof("path %s is int 0, skip mapping.", inPath)
			continue
		}
		path := util.PathFromString(inPath)
		k8sSettingName := ""
		if len(path) != 0 {
			k8sSettingName = path[len(path)-1]
		}
		switch k8sSettingName {
		case "autoscaleEnabled":
			err := translateHPASpec(inPath, v.OutPath, m, valueTree, cpSpecTree)
			if err != nil {
				return fmt.Errorf("error in translating K8s HPA spec: %s", err)
			}
		case "env":
			err := translateEnv(v.OutPath, m, cpSpecTree)
			if err != nil {
				return fmt.Errorf("error in translating k8s Env: %s", err)
			}
		case "rollingMaxSurge", "rollingMaxUnavailable":
			err := translateStrategy(k8sSettingName, v.OutPath, m, cpSpecTree)
			if err != nil {
				return fmt.Errorf("error in translating k8s Strategy: %s", err)
			}
		default:
			output := util.ToYAMLPath(v.OutPath)
			log.Infof("path has value in helm Value.yaml tree, mapping to output path %s", output)
			if err := tpath.WriteNode(cpSpecTree, output, m); err != nil {
				return err
			}
		}
		if _, err := tpath.DeleteFromTree(valueTree, util.ToYAMLPath(inPath), util.ToYAMLPath(inPath)); err != nil {
			return err
		}
	}
	return nil
}
func ( t * ReverseTranslator ) translateK8sTree ( valueTree map [ string ] interface { } , cpSpecTree map [ string ] interface { } ) error { for inPath , v := range t . KubernetesMapping { log . Infof ( " " , inPath ) m , found , err := tpath . GetFromTreePath ( valueTree , util . ToYAMLPath ( inPath ) ) if err != nil { return err } if ! found { log . Infof ( " " , inPath ) continue } if mstr , ok := m . ( string ) ; ok && mstr == " " { log . Infof ( " " , inPath ) continue } if mint , ok := util . ToIntValue ( m ) ; ok && mint == 0 { log . Infof ( " " , inPath ) continue } path := util . PathFromString ( inPath ) k8sSettingName := " " if len ( path ) != 0 { k8sSettingName = path [ len ( path ) - 1 ] } switch k8sSettingName { case " " : err := translateHPASpec ( inPath , v . OutPath , m , valueTree , cpSpecTree ) if err != nil { return fmt . Errorf ( " " , err ) } case " " : err := translateEnv ( v . OutPath , m , cpSpecTree ) if err != nil { return fmt . Errorf ( " " , err ) } case " " , " " : err := translateStrategy ( k8sSettingName , v . OutPath , m , cpSpecTree ) if err != nil { return fmt . Errorf ( " " , err ) } default : output := util . ToYAMLPath ( v . OutPath ) log . Infof ( " " , output ) if err := tpath . WriteNode ( cpSpecTree , output , m ) ; err != nil { return err } } if _ , err := tpath . DeleteFromTree ( valueTree , util . ToYAMLPath ( inPath ) , util . ToYAMLPath ( inPath ) ) ; err != nil { return err } } return nil }
translateK8sTree is internal method for translating K8s configurations from value.yaml tree.
translateK8sTree is internal method for translating K8s configurations from value . yaml tree .
// Zero int values are due to proto3 compiling to scalars rather than ptrs. Skip these because values of 0 are // the default in destination fields and need not be set explicitly.