...

Source file src/edge-infra.dev/third_party/k8s/linkerd/helm/charts.go

Documentation: edge-infra.dev/third_party/k8s/linkerd/helm

     1  package helm
     2  
     3  import (
     4  	"embed"
     5  	"fmt"
     6  
     7  	"sigs.k8s.io/yaml"
     8  
     9  	l5dvalues "edge-infra.dev/pkg/edge/linkerd/helm/values"
    10  )
    11  
    12  //go:embed linkerd/charts/*
    13  //go:embed linkerd/charts/partials/templates/**.tpl
    14  
    15  // Templates contains the static chart templates for Linkerd2
    16  var Templates embed.FS
    17  
    18  //go:embed .version
    19  var Version string
    20  
    21  const (
    22  	ControlPath       = "linkerd/charts/linkerd-control-plane"
    23  	CrdPath           = "linkerd/charts/linkerd-crds"
    24  	Policies          = "templates/policy"
    25  	PartialsChartPath = "linkerd/charts/partials"
    26  
    27  	Registry = "ghcr.io/linkerd"
    28  	// Image Names.  Needed to override the container registry URLs, because the
    29  	// Linkerd chart specifies images by repo + name (e.g., cr.l5d.io/linkerd/policy-controller)
    30  	PolicyControllerImage = "policy-controller"
    31  	ProxyImage            = "proxy"
    32  	ProxyInitImage        = "proxy-init"
    33  	ControllerImage       = "controller"
    34  	DebugImage            = "debug"
    35  )
    36  
    37  // DefaultValues reads the contents of the values.yaml shipped with the Linkerd
    38  // Helm Chart, unmarshals it into the linkerd2.Values{} struct, and then sets
    39  // some values which always need updating before returning the result. These are
    40  // the unopinionated defaults based on the upstream chart.  Edge specific defaults
    41  // are defined in pkg/edge/linkerd.
    42  //
    43  // A general rule of thumb is that this function should only set values that are
    44  // constants that would typically be set by the L5d Helm Chart publishing process --
    45  // everything else should go into pkg/edge/linkerd/render as a rendering option.
    46  func DefaultValues() (*l5dvalues.Values, error) {
    47  	// read the bundled values.yaml for linkerd-control-plane and linkerd-crds charts and merges them together
    48  	// linkerd-crds is required to render the HTTPRoutes CRD introduced into linkerd 2.14.5
    49  	//
    50  	// We will need https://github.com/linkerd/linkerd2/issues/11869 resolved so linkerd deploys the HTTPRoutes CRD,
    51  	// instead of us manually deploying it via the linkerdctl pallet.
    52  	v, err := readDefaults(CrdPath + "/values.yaml")
    53  	if err != nil {
    54  		return nil, err
    55  	}
    56  
    57  	vCP, err := readDefaults(ControlPath + "/values.yaml")
    58  	if err != nil {
    59  		return nil, err
    60  	}
    61  
    62  	*v, err = v.Merge(*vCP)
    63  	if err != nil {
    64  		return nil, err
    65  	}
    66  
    67  	// set correct defaults
    68  	v.CliVersion = Version
    69  	v.LinkerdVersion = Version
    70  	v.PolicyController.Image.Version = Version
    71  	v.Proxy.Image.Version = Version
    72  	// heartbeat prometheus URL is hardcoded to l5d's prometheus, which we dont use
    73  	v.DisableHeartBeat = true
    74  
    75  	return v, nil
    76  }
    77  
    78  func readDefaults(p string) (*l5dvalues.Values, error) {
    79  	// read the bundled values.yaml
    80  	raw, err := Templates.ReadFile(p)
    81  	if err != nil {
    82  		return nil, fmt.Errorf("failed to read %s: %w", p, err)
    83  	}
    84  
    85  	// unmarshal it into Values{} struct
    86  	v := &l5dvalues.Values{}
    87  	err = yaml.Unmarshal(raw, &v)
    88  	if err != nil {
    89  		return nil, fmt.Errorf("failed to unmarshal values data into values struct: %w", err)
    90  	}
    91  	return v, nil
    92  }
    93  

View as plain text