...

Source file src/github.com/linkerd/linkerd2/pkg/charts/cni/values.go

Documentation: github.com/linkerd/linkerd2/pkg/charts/cni

     1  package cni
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/linkerd/linkerd2/pkg/charts"
     7  	"github.com/linkerd/linkerd2/pkg/charts/static"
     8  	"github.com/linkerd/linkerd2/pkg/k8s"
     9  	"helm.sh/helm/v3/pkg/chart/loader"
    10  	"helm.sh/helm/v3/pkg/chartutil"
    11  	"sigs.k8s.io/yaml"
    12  )
    13  
    14  const (
    15  	helmDefaultCNIChartDir = "linkerd2-cni"
    16  )
    17  
    18  // Image contains details about the location of the container image
    19  type Image struct {
    20  	Name       string      `json:"name"`
    21  	Version    string      `json:"version"`
    22  	PullPolicy interface{} `json:"pullPolicy"`
    23  }
    24  
    25  // Constraints wraps the Limit and Request settings for computational resources
    26  type Constraints struct {
    27  	Limit   string `json:"limit"`
    28  	Request string `json:"request"`
    29  }
    30  
    31  // Resources represents the computational resources setup for a given container
    32  type Resources struct {
    33  	CPU              Constraints `json:"cpu"`
    34  	Memory           Constraints `json:"memory"`
    35  	EphemeralStorage Constraints `json:"ephemeral-storage"`
    36  }
    37  
    38  // RepairController contains the config for the repair-controller container
    39  type RepairController struct {
    40  	Image                 Image     `json:"image"`
    41  	LogLevel              string    `json:"logLevel"`
    42  	LogFormat             string    `json:"logFormat"`
    43  	EnableSecurityContext bool      `json:"enableSecurityContext"`
    44  	Resources             Resources `json:"resources"`
    45  }
    46  
    47  // Values contains the top-level elements in the cni Helm chart
    48  type Values struct {
    49  	InboundProxyPort     uint                `json:"inboundProxyPort"`
    50  	OutboundProxyPort    uint                `json:"outboundProxyPort"`
    51  	IgnoreInboundPorts   string              `json:"ignoreInboundPorts"`
    52  	IgnoreOutboundPorts  string              `json:"ignoreOutboundPorts"`
    53  	CliVersion           string              `json:"cliVersion"`
    54  	Image                Image               `json:"image"`
    55  	LogLevel             string              `json:"logLevel"`
    56  	PortsToRedirect      string              `json:"portsToRedirect"`
    57  	ProxyUID             int64               `json:"proxyUID"`
    58  	ProxyGID             int64               `json:"proxyGID"`
    59  	DestCNINetDir        string              `json:"destCNINetDir"`
    60  	DestCNIBinDir        string              `json:"destCNIBinDir"`
    61  	UseWaitFlag          bool                `json:"useWaitFlag"`
    62  	PriorityClassName    string              `json:"priorityClassName"`
    63  	ProxyAdminPort       string              `json:"proxyAdminPort"`
    64  	ProxyControlPort     string              `json:"proxyControlPort"`
    65  	Tolerations          []interface{}       `json:"tolerations"`
    66  	PodLabels            map[string]string   `json:"podLabels"`
    67  	CommonLabels         map[string]string   `json:"commonLabels"`
    68  	ImagePullSecrets     []map[string]string `json:"imagePullSecrets"`
    69  	ExtraInitContainers  []interface{}       `json:"extraInitContainers"`
    70  	IptablesMode         string              `json:"iptablesMode"`
    71  	DisableIPv6          bool                `json:"disableIPv6"`
    72  	EnablePSP            bool                `json:"enablePSP"`
    73  	Privileged           bool                `json:"privileged"`
    74  	Resources            Resources           `json:"resources"`
    75  	RepairController     RepairController    `json:"repairController"`
    76  	RevisionHistoryLimit uint                `json:"revisionHistoryLimit"`
    77  }
    78  
    79  // NewValues returns a new instance of the Values type.
    80  func NewValues() (*Values, error) {
    81  	chartDir := fmt.Sprintf("%s/", helmDefaultCNIChartDir)
    82  	v, err := readDefaults(chartDir)
    83  	if err != nil {
    84  		return nil, err
    85  	}
    86  
    87  	v.CliVersion = k8s.CreatedByAnnotationValue()
    88  	return v, nil
    89  }
    90  
    91  // ToMap converts Values into a map[string]interface{}
    92  func (v *Values) ToMap() (map[string]interface{}, error) {
    93  	var valuesMap map[string]interface{}
    94  	rawValues, err := yaml.Marshal(v)
    95  	if err != nil {
    96  		return nil, fmt.Errorf("failed to marshal the values struct: %w", err)
    97  	}
    98  
    99  	err = yaml.Unmarshal(rawValues, &valuesMap)
   100  	if err != nil {
   101  		return nil, fmt.Errorf("failed to Unmarshal Values into a map: %w", err)
   102  	}
   103  
   104  	return valuesMap, nil
   105  }
   106  
   107  // readDefaults reads all the default variables from the values.yaml file.
   108  // chartDir is the root directory of the Helm chart where values.yaml is.
   109  func readDefaults(chartDir string) (*Values, error) {
   110  	file := &loader.BufferedFile{
   111  		Name: chartutil.ValuesfileName,
   112  	}
   113  	if err := charts.ReadFile(static.Templates, chartDir, file); err != nil {
   114  		return nil, err
   115  	}
   116  	values := Values{}
   117  	if err := yaml.Unmarshal(charts.InsertVersion(file.Data), &values); err != nil {
   118  		return nil, err
   119  	}
   120  	return &values, nil
   121  }
   122  

View as plain text