...
1 package values
2
3 import (
4 "fmt"
5
6 "github.com/linkerd/linkerd2/multicluster/static"
7 "github.com/linkerd/linkerd2/pkg/charts"
8 "github.com/linkerd/linkerd2/pkg/k8s"
9 "helm.sh/helm/v3/pkg/chart/loader"
10 "helm.sh/helm/v3/pkg/chartutil"
11 corev1 "k8s.io/api/core/v1"
12 "sigs.k8s.io/yaml"
13 )
14
15 const (
16 helmDefaultChartDir = "linkerd-multicluster"
17 helmDefaultLinkChartDir = "linkerd-multicluster-link"
18 )
19
20
21 type Values struct {
22 CliVersion string `json:"cliVersion"`
23 ControllerImage string `json:"controllerImage"`
24 ControllerImageVersion string `json:"controllerImageVersion"`
25 Gateway *Gateway `json:"gateway"`
26 IdentityTrustDomain string `json:"identityTrustDomain"`
27 LinkerdNamespace string `json:"linkerdNamespace"`
28 LinkerdVersion string `json:"linkerdVersion"`
29 ProxyOutboundPort uint32 `json:"proxyOutboundPort"`
30 ServiceMirror bool `json:"serviceMirror"`
31 LogLevel string `json:"logLevel"`
32 LogFormat string `json:"logFormat"`
33 ServiceMirrorRetryLimit uint32 `json:"serviceMirrorRetryLimit"`
34 ServiceMirrorUID int64 `json:"serviceMirrorUID"`
35 ServiceMirrorGID int64 `json:"serviceMirrorGID"`
36 Replicas uint32 `json:"replicas"`
37 RemoteMirrorServiceAccount bool `json:"remoteMirrorServiceAccount"`
38 RemoteMirrorServiceAccountName string `json:"remoteMirrorServiceAccountName"`
39 TargetClusterName string `json:"targetClusterName"`
40 EnablePodAntiAffinity bool `json:"enablePodAntiAffinity"`
41 RevisionHistoryLimit uint32 `json:"revisionHistoryLimit"`
42
43 ServiceMirrorAdditionalEnv []corev1.EnvVar `json:"serviceMirrorAdditionalEnv"`
44 ServiceMirrorExperimentalEnv []corev1.EnvVar `json:"serviceMirrorExperimentalEnv"`
45 }
46
47
48 type Gateway struct {
49 Enabled bool `json:"enabled"`
50 Replicas uint32 `json:"replicas"`
51 Name string `json:"name"`
52 Port uint32 `json:"port"`
53 NodePort uint32 `json:"nodePort"`
54 ServiceType string `json:"serviceType"`
55 Probe *Probe `json:"probe"`
56 ServiceAnnotations map[string]string `json:"serviceAnnotations"`
57 LoadBalancerIP string `json:"loadBalancerIP"`
58 PauseImage string `json:"pauseImage"`
59 UID int64 `json:"UID"`
60 GID int64 `json:"GID"`
61 }
62
63
64 type Probe struct {
65 Path string `json:"path"`
66 Port uint32 `json:"port"`
67 NodePort uint32 `json:"nodePort"`
68 Seconds uint32 `json:"seconds"`
69 }
70
71
72 func NewInstallValues() (*Values, error) {
73 chartDir := fmt.Sprintf("%s/", helmDefaultChartDir)
74 v, err := readDefaults(chartDir)
75 if err != nil {
76 return nil, err
77 }
78
79 v.CliVersion = k8s.CreatedByAnnotationValue()
80 return v, nil
81 }
82
83
84 func NewLinkValues() (*Values, error) {
85 chartDir := fmt.Sprintf("%s/", helmDefaultLinkChartDir)
86 v, err := readDefaults(chartDir)
87 if err != nil {
88 return nil, err
89 }
90
91 v.CliVersion = k8s.CreatedByAnnotationValue()
92 return v, nil
93 }
94
95
96
97 func readDefaults(chartDir string) (*Values, error) {
98 file := &loader.BufferedFile{
99 Name: chartutil.ValuesfileName,
100 }
101 if err := charts.ReadFile(static.Templates, chartDir, file); err != nil {
102 return nil, err
103 }
104 values := Values{}
105 if err := yaml.Unmarshal(charts.InsertVersion(file.Data), &values); err != nil {
106 return nil, err
107 }
108 return &values, nil
109 }
110
View as plain text