package helm import ( "embed" "fmt" "sigs.k8s.io/yaml" l5dvalues "edge-infra.dev/pkg/edge/linkerd/helm/values" ) //go:embed linkerd/charts/* //go:embed linkerd/charts/partials/templates/**.tpl // Templates contains the static chart templates for Linkerd2 var Templates embed.FS //go:embed .version var Version string const ( ControlPath = "linkerd/charts/linkerd-control-plane" CrdPath = "linkerd/charts/linkerd-crds" Policies = "templates/policy" PartialsChartPath = "linkerd/charts/partials" Registry = "ghcr.io/linkerd" // Image Names. Needed to override the container registry URLs, because the // Linkerd chart specifies images by repo + name (e.g., cr.l5d.io/linkerd/policy-controller) PolicyControllerImage = "policy-controller" ProxyImage = "proxy" ProxyInitImage = "proxy-init" ControllerImage = "controller" DebugImage = "debug" ) // DefaultValues reads the contents of the values.yaml shipped with the Linkerd // Helm Chart, unmarshals it into the linkerd2.Values{} struct, and then sets // some values which always need updating before returning the result. These are // the unopinionated defaults based on the upstream chart. Edge specific defaults // are defined in pkg/edge/linkerd. // // A general rule of thumb is that this function should only set values that are // constants that would typically be set by the L5d Helm Chart publishing process -- // everything else should go into pkg/edge/linkerd/render as a rendering option. func DefaultValues() (*l5dvalues.Values, error) { // read the bundled values.yaml for linkerd-control-plane and linkerd-crds charts and merges them together // linkerd-crds is required to render the HTTPRoutes CRD introduced into linkerd 2.14.5 // // We will need https://github.com/linkerd/linkerd2/issues/11869 resolved so linkerd deploys the HTTPRoutes CRD, // instead of us manually deploying it via the linkerdctl pallet. v, err := readDefaults(CrdPath + "/values.yaml") if err != nil { return nil, err } vCP, err := readDefaults(ControlPath + "/values.yaml") if err != nil { return nil, err } *v, err = v.Merge(*vCP) if err != nil { return nil, err } // set correct defaults v.CliVersion = Version v.LinkerdVersion = Version v.PolicyController.Image.Version = Version v.Proxy.Image.Version = Version // heartbeat prometheus URL is hardcoded to l5d's prometheus, which we dont use v.DisableHeartBeat = true return v, nil } func readDefaults(p string) (*l5dvalues.Values, error) { // read the bundled values.yaml raw, err := Templates.ReadFile(p) if err != nil { return nil, fmt.Errorf("failed to read %s: %w", p, err) } // unmarshal it into Values{} struct v := &l5dvalues.Values{} err = yaml.Unmarshal(raw, &v) if err != nil { return nil, fmt.Errorf("failed to unmarshal values data into values struct: %w", err) } return v, nil }