Documentation

Overview

    Package translate defines translations from installer proto to values.yaml.

    Index

    Constants

    View Source
    const (
    	// HelmValuesEnabledSubpath is the subpath from the component root to the enabled parameter.
    	HelmValuesEnabledSubpath = "enabled"
    	// HelmValuesNamespaceSubpath is the subpath from the component root to the namespace parameter.
    	HelmValuesNamespaceSubpath = "namespace"
    	// HelmValuesHubSubpath is the subpath from the component root to the hub parameter.
    	HelmValuesHubSubpath = "hub"
    	// HelmValuesTagSubpath is the subpath from the component root to the tag parameter.
    	HelmValuesTagSubpath = "tag"
    )

    Variables

    This section is empty.

    Functions

    func IOPStoIOP

    func IOPStoIOP(iops proto.Message, name, namespace string) (*iopv1alpha1.IstioOperator, error)

      IOPStoIOP takes an IstioOperatorSpec and returns a corresponding IstioOperator with the given name and namespace.

      func IOPStoIOPstr

      func IOPStoIOPstr(iops proto.Message, name, namespace string) (string, error)

        IOPStoIOPstr takes an IstioOperatorSpec and returns a corresponding IstioOperator string with the given name and namespace.

        func IsComponentEnabledFromValue

        func IsComponentEnabledFromValue(cn name.ComponentName, valueSpec map[string]interface{}) (enabled bool, pathExist bool, err error)

          IsComponentEnabledFromValue get whether component is enabled in helm value.yaml tree. valuePath points to component path in the values tree.

          func IsComponentEnabledInSpec

          func IsComponentEnabledInSpec(componentName name.ComponentName, controlPlaneSpec *v1alpha1.IstioOperatorSpec) (bool, error)

            IsComponentEnabledInSpec reports whether the given component is enabled in the given spec. IsComponentEnabledInSpec assumes that controlPlaneSpec has been validated. TODO: remove extra validations when comfort level is high enough.

            func MergeK8sObject

            func MergeK8sObject(base *object.K8sObject, overlayNode interface{}, path util.Path) (*object.K8sObject, error)

              MergeK8sObject does strategic merge for overlayNode on the base object.

              func OverlayValuesEnablement

              func OverlayValuesEnablement(baseYAML, fileOverlayYAML, setOverlayYAML string) (string, error)

                OverlayValuesEnablement overlays any enablement in values path from the user file overlay or set flag overlay. The overlay is translated from values to the corresponding addonComponents enablement paths.

                func YAMLTree

                func YAMLTree(inTreeStr, outTreeStr string, translations map[string]string) (string, error)

                  YAMLTree takes an input tree inTreeStr, a partially constructed output tree outTreeStr, and a map of translations of source-path:dest-path in pkg/tpath format. It returns an output tree with paths from the input tree, translated and overlaid on the output tree.

                  Types

                  type ComponentMaps

                  type ComponentMaps struct {
                  	// ResourceType maps a ComponentName to the type of the rendered k8s resource.
                  	ResourceType string
                  	// ResourceName maps a ComponentName to the name of the rendered k8s resource.
                  	ResourceName string
                  	// ContainerName maps a ComponentName to the name of the container in a Deployment.
                  	ContainerName string
                  	// HelmSubdir is a mapping between a component name and the subdirectory of the component Chart.
                  	HelmSubdir string
                  	// ToHelmValuesTreeRoot is the tree root in values YAML files for the component.
                  	ToHelmValuesTreeRoot string
                  	// SkipReverseTranslate defines whether reverse translate of this component need to be skipped.
                  	SkipReverseTranslate bool
                  }

                    ComponentMaps is a set of mappings for an Istio component.

                    type ReverseTranslator

                    type ReverseTranslator struct {
                    	Version version.MinorVersion
                    	// APIMapping is Values.yaml path to API path mapping using longest prefix match. If the path is a non-leaf node,
                    	// the output path is the matching portion of the path, plus any remaining output path.
                    	APIMapping map[string]*Translation `yaml:"apiMapping,omitempty"`
                    	// KubernetesPatternMapping defines mapping patterns from k8s resource paths to IstioOperator API paths.
                    	KubernetesPatternMapping map[string]string `yaml:"kubernetesPatternMapping,omitempty"`
                    	// KubernetesMapping defines actual k8s mappings generated from KubernetesPatternMapping before each translation.
                    	KubernetesMapping map[string]*Translation `yaml:"kubernetesMapping,omitempty"`
                    	// GatewayKubernetesMapping defines actual k8s mappings for gateway components generated from KubernetesPatternMapping before each translation.
                    	GatewayKubernetesMapping gatewayKubernetesMapping `yaml:"GatewayKubernetesMapping,omitempty"`
                    	// ValuesToComponentName defines mapping from value path to component name in API paths.
                    	ValuesToComponentName map[string]name.ComponentName `yaml:"valuesToComponentName,omitempty"`
                    }

                      ReverseTranslator is a set of mappings to translate between values.yaml and API paths, charts, k8s paths.

                      func NewReverseTranslator

                      func NewReverseTranslator() *ReverseTranslator

                        NewReverseTranslator creates a new ReverseTranslator for minorVersion and returns a ptr to it.

                        func (*ReverseTranslator) TranslateFromValueToSpec

                        func (t *ReverseTranslator) TranslateFromValueToSpec(values []byte, force bool) (controlPlaneSpec *v1alpha1.IstioOperatorSpec, err error)

                          TranslateFromValueToSpec translates from values.yaml value to IstioOperatorSpec.

                          func (*ReverseTranslator) TranslateK8S

                          func (t *ReverseTranslator) TranslateK8S(valueTree map[string]interface{}, cpSpecTree map[string]interface{}) error

                            TranslateK8S is a helper function to translate k8s settings from values.yaml to IstioOperator, except for gateways.

                            func (*ReverseTranslator) TranslateK8SfromValueToIOP

                            func (t *ReverseTranslator) TranslateK8SfromValueToIOP(userOverlayYaml string) (string, error)

                              TranslateK8SfromValueToIOP use reverse translation to convert k8s settings defined in values API to IOP API. this ensures that user overlays that set k8s through spec.values are not overridden by spec.components.X.k8s settings in the base profiles

                              func (*ReverseTranslator) TranslateTree

                              func (t *ReverseTranslator) TranslateTree(valueTree map[string]interface{}, cpSpecTree map[string]interface{}, path util.Path) error

                                TranslateTree translates input value.yaml Tree to ControlPlaneSpec Tree.

                                func (*ReverseTranslator) WarningForGatewayK8SSettings

                                func (t *ReverseTranslator) WarningForGatewayK8SSettings(valuesOverlay string) (string, error)

                                  WarningForGatewayK8SSettings creates deprecated warning messages when user try to set kubernetes settings for gateways via values api.

                                  type Translation

                                  type Translation struct {
                                  	// OutPath defines the position in the yaml file
                                  	OutPath string `yaml:"outPath"`
                                  	// contains filtered or unexported fields
                                  }

                                    Translation is a mapping to an output path using a translation function.

                                    type TranslationFunc

                                    type TranslationFunc func(t *Translation, root map[string]interface{}, valuesPath string, value interface{}) error

                                      TranslationFunc maps a yamlStr API path into a YAML values tree.

                                      type Translator

                                      type Translator struct {
                                      	// Translations remain the same within a minor version.
                                      	Version version.MinorVersion
                                      	// APIMapping is a mapping between an API path and the corresponding values.yaml path using longest prefix
                                      	// match. If the path is a non-leaf node, the output path is the matching portion of the path, plus any remaining
                                      	// output path.
                                      	APIMapping map[string]*Translation `yaml:"apiMapping"`
                                      	// KubernetesMapping defines mappings from an IstioOperator API paths to k8s resource paths.
                                      	KubernetesMapping map[string]*Translation `yaml:"kubernetesMapping"`
                                      	// GlobalNamespaces maps feature namespaces to Helm global namespace definitions.
                                      	GlobalNamespaces map[name.ComponentName]string `yaml:"globalNamespaces"`
                                      	// ComponentMaps is a set of mappings for each Istio component.
                                      	ComponentMaps map[name.ComponentName]*ComponentMaps `yaml:"componentMaps"`
                                      }

                                        Translator is a set of mappings to translate between API paths, charts, values.yaml and k8s paths.

                                        func NewTranslator

                                        func NewTranslator() *Translator

                                          NewTranslator creates a new translator for minorVersion and returns a ptr to it.

                                          func (*Translator) ComponentMap

                                          func (t *Translator) ComponentMap(cns string) *ComponentMaps

                                            ComponentMap returns a ComponentMaps struct ptr for the given component name if one exists. If the name of the component is lower case, the function will use the capitalized version of the name.

                                            func (*Translator) IsComponentEnabled

                                            func (t *Translator) IsComponentEnabled(cn name.ComponentName, iop *v1alpha1.IstioOperatorSpec) (bool, error)

                                              IsComponentEnabled reports whether the component with name cn is enabled, according to the translations in t, and the contents of ocp.

                                              func (*Translator) OverlayK8sSettings

                                              func (t *Translator) OverlayK8sSettings(yml string, iop *v1alpha1.IstioOperatorSpec, componentName name.ComponentName,
                                              	resourceName string, index int) (string, error)

                                                OverlayK8sSettings overlays k8s settings from iop over the manifest objects, based on t's translation mappings.

                                                func (*Translator) ProtoToHelmValues

                                                func (t *Translator) ProtoToHelmValues(node interface{}, root map[string]interface{}, path util.Path) (errs util.Errors)

                                                  ProtoToHelmValues takes an interface which must be a struct ptr and recursively iterates through all its fields. For each leaf, if looks for a mapping from the struct data path to the corresponding YAML path and if one is found, it calls the associated mapping function if one is defined to populate the values YAML path. If no mapping function is defined, it uses the default mapping function.

                                                  func (*Translator) ProtoToValues

                                                  func (t *Translator) ProtoToValues(ii *v1alpha1.IstioOperatorSpec) (string, error)

                                                    ProtoToValues traverses the supplied IstioOperatorSpec and returns a values.yaml translation from it.

                                                    func (*Translator) TranslateHelmValues

                                                    func (t *Translator) TranslateHelmValues(iop *v1alpha1.IstioOperatorSpec, componentsSpec interface{}, componentName name.ComponentName) (string, error)

                                                      TranslateHelmValues creates a Helm values.yaml config data tree from iop using the given translator.