diff --git a/Dockerfile-proxy b/Dockerfile-proxy index bfdfda8f7f343..034e359ee1f0d 100644 --- a/Dockerfile-proxy +++ b/Dockerfile-proxy @@ -9,7 +9,7 @@ RUN (proxy=$(bin/fetch-proxy $(cat proxy-version)) && \ mv "$proxy" linkerd2-proxy) ## compile proxy-identity agent -FROM gcr.io/linkerd-io/go-deps:f6fda337 as golang +FROM gcr.io/linkerd-io/go-deps:bfb89c7f as golang WORKDIR /linkerd-build COPY pkg/flags pkg/flags COPY pkg/tls pkg/tls diff --git a/charts/linkerd2/add-ons/grafana/.helmignore b/charts/linkerd2/add-ons/grafana/.helmignore new file mode 100644 index 0000000000000..50af031725419 --- /dev/null +++ b/charts/linkerd2/add-ons/grafana/.helmignore @@ -0,0 +1,22 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/linkerd2/add-ons/grafana/Chart.yaml b/charts/linkerd2/add-ons/grafana/Chart.yaml new file mode 100644 index 0000000000000..6eb75b3981a13 --- /dev/null +++ b/charts/linkerd2/add-ons/grafana/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: grafana +version: 0.1.0 diff --git a/charts/linkerd2/add-ons/grafana/charts/partials-0.1.0.tgz b/charts/linkerd2/add-ons/grafana/charts/partials-0.1.0.tgz new file mode 100644 index 0000000000000..affabd045759c Binary files /dev/null and b/charts/linkerd2/add-ons/grafana/charts/partials-0.1.0.tgz differ diff --git a/charts/linkerd2/add-ons/grafana/requirements.lock b/charts/linkerd2/add-ons/grafana/requirements.lock new file mode 100644 index 0000000000000..ee146a7e0d9c2 --- /dev/null +++ b/charts/linkerd2/add-ons/grafana/requirements.lock @@ -0,0 +1,6 @@ +dependencies: +- name: partials + repository: file://../../../partials + version: 0.1.0 +digest: sha256:5eedd268cf82aa72641060432d2edfd9b350a27e022d243e9b71ac34e1cd6f8d +generated: "2019-12-26T12:38:35.839386551+05:30" diff --git a/charts/linkerd2/add-ons/grafana/requirements.yaml b/charts/linkerd2/add-ons/grafana/requirements.yaml new file mode 100644 index 0000000000000..529f5878210e7 --- /dev/null +++ b/charts/linkerd2/add-ons/grafana/requirements.yaml @@ -0,0 +1,4 @@ +dependencies: + - name: partials + version: 0.1.0 + repository: file://../../../partials diff --git a/charts/linkerd2/templates/grafana-rbac.yaml b/charts/linkerd2/add-ons/grafana/templates/grafana-rbac.yaml similarity index 100% rename from charts/linkerd2/templates/grafana-rbac.yaml rename to charts/linkerd2/add-ons/grafana/templates/grafana-rbac.yaml diff --git a/charts/linkerd2/templates/grafana.yaml b/charts/linkerd2/add-ons/grafana/templates/grafana.yaml similarity index 92% rename from charts/linkerd2/templates/grafana.yaml rename to charts/linkerd2/add-ons/grafana/templates/grafana.yaml index e00ce96949405..dc25a32778d7a 100644 --- a/charts/linkerd2/templates/grafana.yaml +++ b/charts/linkerd2/add-ons/grafana/templates/grafana.yaml @@ -84,7 +84,6 @@ spec: --- {{ $_ := set .Values.global.proxy "workloadKind" "deployment" -}} {{ $_ := set .Values.global.proxy "component" "linkerd-grafana" -}} -{{ include "linkerd.proxy.validation" .Values.global.proxy -}} apiVersion: apps/v1 kind: Deployment metadata: @@ -115,12 +114,11 @@ spec: {{.Values.global.controllerNamespaceLabel}}: {{.Values.global.namespace}} {{- include "partials.proxy.labels" .Values.global.proxy | nindent 8}} spec: - {{- include "linkerd.node-selector" . | nindent 6 }} containers: - env: - name: GF_PATHS_DATA value: /data - image: {{.Values.grafanaImage}}:{{default .Values.global.linkerdVersion .Values.controllerImageVersion}} + image: {{.Values.image}}:{{default .Values.global.linkerdVersion .Values.controllerImageVersion}} imagePullPolicy: {{.Values.global.imagePullPolicy}} livenessProbe: httpGet: @@ -135,8 +133,8 @@ spec: httpGet: path: /api/health port: 3000 - {{- if .Values.grafanaResources -}} - {{- include "partials.resources" .Values.grafanaResources | nindent 8 }} + {{- if .Values.resources -}} + {{- include "partials.resources" .Values.resources | nindent 8 }} {{- end }} securityContext: runAsUser: 472 @@ -147,7 +145,7 @@ spec: name: grafana-config readOnly: true - {{- include "partials.proxy" . | indent 8 | trimPrefix (repeat 7 " ") }} - {{ if not .Values.noInitContainer -}} + {{ if not .Values.global.noInitContainer -}} initContainers: - {{- include "partials.proxy-init" . | indent 8 | trimPrefix (repeat 7 " ") }} {{ end -}} diff --git a/charts/linkerd2/add-ons/grafana/values.yaml b/charts/linkerd2/add-ons/grafana/values.yaml new file mode 100644 index 0000000000000..7ea3c6f57b1b2 --- /dev/null +++ b/charts/linkerd2/add-ons/grafana/values.yaml @@ -0,0 +1,3 @@ +# Config for grafana add-on +enabled: true +image: gcr.io/linkerd-io/grafana \ No newline at end of file diff --git a/charts/linkerd2/add-ons/prometheus/.helmignore b/charts/linkerd2/add-ons/prometheus/.helmignore new file mode 100644 index 0000000000000..50af031725419 --- /dev/null +++ b/charts/linkerd2/add-ons/prometheus/.helmignore @@ -0,0 +1,22 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/linkerd2/add-ons/prometheus/Chart.yaml b/charts/linkerd2/add-ons/prometheus/Chart.yaml new file mode 100644 index 0000000000000..bc9abb6fe2ae9 --- /dev/null +++ b/charts/linkerd2/add-ons/prometheus/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: prometheus +version: 0.1.0 diff --git a/charts/linkerd2/add-ons/prometheus/charts/partials-0.1.0.tgz b/charts/linkerd2/add-ons/prometheus/charts/partials-0.1.0.tgz new file mode 100644 index 0000000000000..c1aa658103f87 Binary files /dev/null and b/charts/linkerd2/add-ons/prometheus/charts/partials-0.1.0.tgz differ diff --git a/charts/linkerd2/add-ons/prometheus/requirements.lock b/charts/linkerd2/add-ons/prometheus/requirements.lock new file mode 100644 index 0000000000000..d40fd91f67694 --- /dev/null +++ b/charts/linkerd2/add-ons/prometheus/requirements.lock @@ -0,0 +1,6 @@ +dependencies: +- name: partials + repository: file://../../../partials + version: 0.1.0 +digest: sha256:5eedd268cf82aa72641060432d2edfd9b350a27e022d243e9b71ac34e1cd6f8d +generated: "2020-01-02T21:27:59.919462049+05:30" diff --git a/charts/linkerd2/add-ons/prometheus/requirements.yaml b/charts/linkerd2/add-ons/prometheus/requirements.yaml new file mode 100644 index 0000000000000..06d25a721a3fa --- /dev/null +++ b/charts/linkerd2/add-ons/prometheus/requirements.yaml @@ -0,0 +1,4 @@ +dependencies: + - name: partials + version: 0.1.0 + repository: file://../../../partials diff --git a/charts/linkerd2/templates/prometheus-rbac.yaml b/charts/linkerd2/add-ons/prometheus/templates/prometheus-rbac.yaml similarity index 100% rename from charts/linkerd2/templates/prometheus-rbac.yaml rename to charts/linkerd2/add-ons/prometheus/templates/prometheus-rbac.yaml diff --git a/charts/linkerd2/templates/prometheus.yaml b/charts/linkerd2/add-ons/prometheus/templates/prometheus.yaml similarity index 95% rename from charts/linkerd2/templates/prometheus.yaml rename to charts/linkerd2/add-ons/prometheus/templates/prometheus.yaml index a1c0290c56ddd..2ca26bdad24fe 100644 --- a/charts/linkerd2/templates/prometheus.yaml +++ b/charts/linkerd2/add-ons/prometheus/templates/prometheus.yaml @@ -143,7 +143,6 @@ spec: {{ end -}} {{ $_ := set .Values.global.proxy "workloadKind" "deployment" -}} {{ $_ := set .Values.global.proxy "component" "linkerd-prometheus" -}} -{{ include "linkerd.proxy.validation" .Values.global.proxy -}} apiVersion: apps/v1 kind: Deployment metadata: @@ -174,14 +173,13 @@ spec: {{.Values.global.controllerNamespaceLabel}}: {{.Values.global.namespace}} {{- include "partials.proxy.labels" .Values.global.proxy | nindent 8}} spec: - {{- include "linkerd.node-selector" . | nindent 6 }} containers: - args: - --storage.tsdb.path=/data - --storage.tsdb.retention.time=6h - --config.file=/etc/prometheus/prometheus.yml - - --log.level={{lower .Values.prometheusLogLevel}} - image: {{.Values.prometheusImage}} + - --log.level={{lower .Values.logLevel}} + image: {{.Values.image}} imagePullPolicy: {{.Values.global.imagePullPolicy}} livenessProbe: httpGet: @@ -199,8 +197,8 @@ spec: port: 9090 initialDelaySeconds: 30 timeoutSeconds: 30 - {{- if .Values.prometheusResources -}} - {{- include "partials.resources" .Values.prometheusResources | nindent 8 }} + {{- if .Values.resources -}} + {{- include "partials.resources" .Values.resources | nindent 8 }} {{- end }} securityContext: runAsUser: 65534 @@ -211,7 +209,7 @@ spec: name: prometheus-config readOnly: true - {{- include "partials.proxy" . | indent 8 | trimPrefix (repeat 7 " ") }} - {{ if not .Values.noInitContainer -}} + {{ if not .Values.global.noInitContainer -}} initContainers: - {{- include "partials.proxy-init" . | indent 8 | trimPrefix (repeat 7 " ") }} {{ end -}} diff --git a/charts/linkerd2/add-ons/prometheus/values.yaml b/charts/linkerd2/add-ons/prometheus/values.yaml new file mode 100644 index 0000000000000..0ecf61f90bc01 --- /dev/null +++ b/charts/linkerd2/add-ons/prometheus/values.yaml @@ -0,0 +1,4 @@ +# Config for add-ons +enabled: true +image: prometheus/prom:v1.15.0 +logLevel: info \ No newline at end of file diff --git a/charts/linkerd2/requirements.lock b/charts/linkerd2/requirements.lock index b82d2145b2849..3db32ff9e7817 100644 --- a/charts/linkerd2/requirements.lock +++ b/charts/linkerd2/requirements.lock @@ -2,5 +2,11 @@ dependencies: - name: partials repository: file://../partials version: 0.1.0 -digest: sha256:3a86b96a2966f03ba04518723838b49719a3277dfb9bea0b3f067e83d370e0b3 -generated: 2019-07-24T19:51:15.04322926-07:00 +- name: grafana + repository: file://../linkerd2/add-ons/grafana + version: 0.1.0 +- name: prometheus + repository: file://../linkerd2/add-ons/prometheus + version: 0.1.0 +digest: sha256:92e328557dbf69c48fa71be1f68d98c2a5702c64e01553048b6062a15df66ebe +generated: "2020-01-06T22:34:19.253434901+05:30" diff --git a/charts/linkerd2/requirements.yaml b/charts/linkerd2/requirements.yaml index a17d782a8b996..260a1c85b666c 100644 --- a/charts/linkerd2/requirements.yaml +++ b/charts/linkerd2/requirements.yaml @@ -2,3 +2,11 @@ dependencies: - name: partials version: 0.1.0 repository: file://../partials +- name: grafana + version: 0.1.0 + repository: file://../linkerd2/add-ons/grafana + condition: grafana.enabled +- name: prometheus + version: 0.1.0 + repository: file://../linkerd2/add-ons/prometheus + condition: prometheus.enabled diff --git a/charts/linkerd2/templates/controller.yaml b/charts/linkerd2/templates/controller.yaml index a763d7c2f1eaf..612c2992258b5 100644 --- a/charts/linkerd2/templates/controller.yaml +++ b/charts/linkerd2/templates/controller.yaml @@ -63,7 +63,9 @@ spec: containers: - args: - public-api + {{ if .Values.prometheus.enabled -}} - -prometheus-url=http://linkerd-prometheus.{{.Values.global.namespace}}.svc.{{.Values.global.clusterDomain}}:9090 + {{ end -}} - -destination-addr=linkerd-dst.{{.Values.global.namespace}}.svc.{{.Values.global.clusterDomain}}:8086 - -controller-namespace={{.Values.global.namespace}} - -log-level={{.Values.controllerLogLevel}} diff --git a/charts/linkerd2/templates/heartbeat.yaml b/charts/linkerd2/templates/heartbeat.yaml index 295e52f6e7325..e052ec3497f67 100644 --- a/charts/linkerd2/templates/heartbeat.yaml +++ b/charts/linkerd2/templates/heartbeat.yaml @@ -38,8 +38,9 @@ spec: imagePullPolicy: {{.Values.global.imagePullPolicy}} args: - "heartbeat" + {{ if .Values.prometheus.enabled -}} - "-prometheus-url=http://linkerd-prometheus.{{.Values.global.namespace}}.svc.{{.Values.global.clusterDomain}}:9090" - - "-controller-namespace={{.Values.global.namespace}}" + {{ end -}} - "-controller-namespace={{.Values.global.namespace}}" - "-log-level={{.Values.controllerLogLevel}}" {{- if .Values.heartbeatResources -}} {{- include "partials.resources" .Values.heartbeatResources | nindent 12 }} diff --git a/charts/linkerd2/templates/linkerd-values.yaml b/charts/linkerd2/templates/linkerd-values.yaml new file mode 100644 index 0000000000000..7a66d403bcfd4 --- /dev/null +++ b/charts/linkerd2/templates/linkerd-values.yaml @@ -0,0 +1,24 @@ +--- +### +### linkerd values +### +--- +kind: ConfigMap +apiVersion: v1 +metadata: + name: linkerd-values + namespace: {{.Values.global.namespace}} + labels: + {{.Values.global.controllerComponentLabel}}: controller + {{.Values.global.controllerNamespaceLabel}}: {{.Values.global.namespace}} + annotations: + {{.Values.global.createdByAnnotation}}: {{default (printf "linkerd/helm %s" .Values.global.linkerdVersion) .Values.global.cliVersion}} +data: + values: |- + global: + {{- toYaml .Values.global | trim | nindent 6}} + grafana: + {{- toYaml .Values.grafana | trim | nindent 6}} + prometheus: + {{- toYaml .Values.prometheus | trim | nindent 6}} + diff --git a/charts/linkerd2/templates/psp.yaml b/charts/linkerd2/templates/psp.yaml index e4a8a04c3fd2b..cc8b9fa1497d2 100644 --- a/charts/linkerd2/templates/psp.yaml +++ b/charts/linkerd2/templates/psp.yaml @@ -90,9 +90,11 @@ subjects: - kind: ServiceAccount name: linkerd-destination namespace: {{.Values.global.namespace}} +{{ if .Values.grafana.enabled -}} - kind: ServiceAccount name: linkerd-grafana namespace: {{.Values.global.namespace}} +{{end -}} {{ if not .Values.disableHeartBeat -}} - kind: ServiceAccount name: linkerd-heartbeat @@ -101,9 +103,11 @@ subjects: - kind: ServiceAccount name: linkerd-identity namespace: {{.Values.global.namespace}} +{{ if .Values.prometheus.enabled -}} - kind: ServiceAccount name: linkerd-prometheus namespace: {{.Values.global.namespace}} +{{ end -}} - kind: ServiceAccount name: linkerd-proxy-injector namespace: {{.Values.global.namespace}} diff --git a/charts/linkerd2/templates/web.yaml b/charts/linkerd2/templates/web.yaml index f4bceb9c53521..f9ba35faafb0d 100644 --- a/charts/linkerd2/templates/web.yaml +++ b/charts/linkerd2/templates/web.yaml @@ -62,7 +62,9 @@ spec: containers: - args: - -api-addr=linkerd-controller-api.{{.Values.global.namespace}}.svc.{{.Values.global.clusterDomain}}:8085 + {{ if .Values.grafana.enabled -}} - -grafana-addr=linkerd-grafana.{{.Values.global.namespace}}.svc.{{.Values.global.clusterDomain}}:3000 + {{ end -}} - -controller-namespace={{.Values.global.namespace}} - -log-level={{.Values.controllerLogLevel}} {{- $hostFull := replace "." "\\." (printf "linkerd-web.%s.svc.%s" .Values.global.namespace .Values.global.clusterDomain) }} diff --git a/charts/linkerd2/values.yaml b/charts/linkerd2/values.yaml index 070ca3859f880..2e20d04d3b446 100644 --- a/charts/linkerd2/values.yaml +++ b/charts/linkerd2/values.yaml @@ -110,9 +110,6 @@ identity: # PEM-encoded ECDSA private key keyPEM: | -# grafana configuration -grafanaImage: gcr.io/linkerd-io/grafana - # heartbeat configuration disableHeartBeat: false heartbeatSchedule: "0 0 * * *" @@ -159,3 +156,13 @@ installNamespace: true # https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector. nodeSelector: beta.kubernetes.io/os: linux + +# Config for add-ons +grafana: + enabled: true + image: gcr.io/linkerd-io/grafana + +prometheus: + enabled: true + logLevel: debug + image: prom/prometheus:v2.11.1 diff --git a/cli/Dockerfile-bin b/cli/Dockerfile-bin index 0dfd983c20e1a..55edc161b5d42 100644 --- a/cli/Dockerfile-bin +++ b/cli/Dockerfile-bin @@ -1,5 +1,5 @@ ## compile binaries -FROM gcr.io/linkerd-io/go-deps:f6fda337 as golang +FROM gcr.io/linkerd-io/go-deps:bfb89c7f as golang WORKDIR /linkerd-build COPY cli cli COPY charts charts diff --git a/cli/cmd/install-cni-plugin.go b/cli/cmd/install-cni-plugin.go index 06a7aaa9d1603..5b4ccf8426284 100644 --- a/cli/cmd/install-cni-plugin.go +++ b/cli/cmd/install-cni-plugin.go @@ -197,7 +197,7 @@ func renderCNIPlugin(w io.Writer, config *cniPluginOptions) error { RawValues: rawValues, Files: files, } - buf, err := chart.RenderCNI() + buf, err := chart.RenderWithoutPartials() if err != nil { return err } diff --git a/cli/cmd/install.go b/cli/cmd/install.go index 33cc7bc40c6cc..0be7a7294eac4 100644 --- a/cli/cmd/install.go +++ b/cli/cmd/install.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "io" + "io/ioutil" "os" "strings" "time" @@ -19,6 +20,7 @@ import ( consts "github.com/linkerd/linkerd2/pkg/k8s" "github.com/linkerd/linkerd2/pkg/tls" "github.com/linkerd/linkerd2/pkg/version" + "github.com/pothulapati/mergo" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -38,6 +40,7 @@ type ( // install. installOptions struct { clusterDomain string + config string controlPlaneVersion string controllerReplicas uint controllerLogLevel string @@ -119,12 +122,11 @@ var ( "templates/web-rbac.yaml", "templates/serviceprofile-crd.yaml", "templates/trafficsplit-crd.yaml", - "templates/prometheus-rbac.yaml", - "templates/grafana-rbac.yaml", "templates/proxy-injector-rbac.yaml", "templates/sp-validator-rbac.yaml", "templates/tap-rbac.yaml", "templates/psp.yaml", + "templates/linkerd-values.yaml", } templatesControlPlaneStage = []string{ @@ -139,8 +141,6 @@ var ( "templates/destination.yaml", "templates/heartbeat.yaml", "templates/web.yaml", - "templates/prometheus.yaml", - "templates/grafana.yaml", "templates/proxy-injector.yaml", "templates/sp-validator.yaml", "templates/tap.yaml", @@ -418,6 +418,24 @@ func (options *installOptions) validateAndBuild(stage string, flags *pflag.FlagS values.Global.IdentityTrustDomain = identityValues.TrustDomain values.Stage = stage + // Update add-on fields in values + if options.config != "" { + config, err := ioutil.ReadFile(options.config) + if err != nil { + return nil, nil, err + } + + var addonValues *l5dcharts.Values + if err = yaml.Unmarshal(config, &addonValues); err != nil { + return nil, nil, err + } + + // Merge Add-On Values with Values + if err = mergeAddonValues(values, addonValues); err != nil { + return nil, nil, err + } + } + return values, configs, nil } @@ -483,6 +501,10 @@ func (options *installOptions) recordableFlagSet() *pflag.FlagSet { &options.identityOptions.trustPEMFile, "identity-trust-anchors-file", options.identityOptions.trustPEMFile, "A path to a PEM-encoded file containing Linkerd Identity trust anchors (generated by default)", ) + flags.StringVar( + &options.config, "config", options.config, + "A path to a config file for add-ons", + ) flags.StringVarP(&options.controlPlaneVersion, "control-plane-version", "", options.controlPlaneVersion, "(Development) Tag to be used for the control plane component images") flags.MarkHidden("control-plane-version") flags.MarkHidden("control-plane-tracing") @@ -714,6 +736,18 @@ func toPromLogLevel(level string) string { } } +func checkAddons(values *l5dcharts.Values) []l5dcharts.AddOn { + var addons []l5dcharts.AddOn + if values.Grafana.Enabled { + addons = append(addons, values.Grafana) + } + + if values.Prometheus.Enabled { + addons = append(addons, values.Prometheus) + } + return addons +} + func render(w io.Writer, values *l5dcharts.Values) error { // Render raw values and create chart config rawValues, err := yaml.Marshal(values) @@ -753,6 +787,31 @@ func render(w io.Writer, values *l5dcharts.Values) error { return err } + addons := checkAddons(values) + + // Render for each add-on separately and attach + // Pass only global values to add-ons + for _, addon := range addons { + + addonValues, err := yaml.Marshal(addon.GetValues()) + if err != nil { + return err + } + + subchart := &charts.Chart{ + Name: addon.GetChartName(), + Dir: l5dcharts.AddonChartsPath + addon.GetChartName(), + Namespace: controlPlaneNamespace, + RawValues: append(rawValues, addonValues...), + Files: addon.GetFiles(), + } + addonBuf, err := subchart.Render() + if err != nil { + return err + } + + buf.Write(addonBuf.Bytes()) + } _, err = w.Write(buf.Bytes()) return err } @@ -1096,3 +1155,18 @@ func toIdentityContext(idvals *identityWithAnchorsAndTrustDomain) *pb.IdentityCo Scheme: idvals.Identity.Issuer.Scheme, } } + +func mergeAddonValues(values, addonValues *l5dcharts.Values) error { + + if err := mergo.Merge(addonValues.Grafana, values.Grafana); err != nil { + return err + } + if err := mergo.Merge(addonValues.Prometheus, values.Prometheus); err != nil { + return err + } + + values.Grafana = addonValues.Grafana + values.Prometheus = addonValues.Prometheus + + return nil +} diff --git a/cli/cmd/upgrade.go b/cli/cmd/upgrade.go index d5e346c91ece7..554e184de86c8 100644 --- a/cli/cmd/upgrade.go +++ b/cli/cmd/upgrade.go @@ -8,6 +8,8 @@ import ( "os" "strings" + "sigs.k8s.io/yaml" + "github.com/linkerd/linkerd2/pkg/config" "github.com/linkerd/linkerd2/pkg/issuercerts" @@ -208,6 +210,16 @@ func upgradeRunE(options *upgradeOptions, stage string, flags *pflag.FlagSet) er return nil } +// GetReplicaSets returns all replicasets in a given namespace +func GetConfigMap(kubeAPI kubernetes.Interface, name string, namespace string) (map[string]string, error) { + cm, err := kubeAPI.CoreV1().ConfigMaps(namespace).Get(name, metav1.GetOptions{}) + if err != nil { + return nil, err + } + + return cm.Data, nil +} + func (options *upgradeOptions) validateAndBuild(stage string, k kubernetes.Interface, flags *pflag.FlagSet) (*charts.Values, *pb.All, error) { if err := options.validate(); err != nil { return nil, nil, err @@ -297,6 +309,7 @@ func (options *upgradeOptions) validateAndBuild(stage string, k kubernetes.Inter if err != nil { return nil, nil, fmt.Errorf("could not build install configuration: %s", err) } + values.Identity = identity.Identity values.Global.IdentityTrustAnchorsPEM = identity.TrustAnchorsPEM values.Global.IdentityTrustDomain = identity.TrustDomain @@ -340,6 +353,25 @@ func (options *upgradeOptions) validateAndBuild(stage string, k kubernetes.Inter values.Stage = stage + // Update Add-Ons values + // Get values from the linkerd-values ConfigMap + cmRawValues, _ := GetConfigMap(k, "linkerd-values", controlPlaneNamespace) + if cmRawValues != nil { + //Cm is present now get the data + cmData := cmRawValues["values"] + var cmValues *charts.Values + err := yaml.Unmarshal([]byte(cmData), cmValues) + if err != nil { + return nil, nil, err + } + + // over-write add-on values with cmValues + // Merge Add-On Values with Values + if err = mergeAddonValues(cmValues, values); err != nil { + return nil, nil, err + } + } + return values, configs, nil } diff --git a/cni-plugin/Dockerfile b/cni-plugin/Dockerfile index 2af622dc32a82..6ed1c4839d823 100644 --- a/cni-plugin/Dockerfile +++ b/cni-plugin/Dockerfile @@ -1,5 +1,5 @@ ## compile cni-plugin utility -FROM gcr.io/linkerd-io/go-deps:f6fda337 as golang +FROM gcr.io/linkerd-io/go-deps:bfb89c7f as golang WORKDIR /linkerd-build COPY pkg pkg COPY controller controller diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000000000..17cd7ae7b5884 --- /dev/null +++ b/config.yaml @@ -0,0 +1,8 @@ +grafana: + enabled: true + image: override-grafan + +prometheus: + enabled: true + image: override-broo + logLevel: debug \ No newline at end of file diff --git a/controller/Dockerfile b/controller/Dockerfile index d1fe4e01b9258..16f424779eb65 100644 --- a/controller/Dockerfile +++ b/controller/Dockerfile @@ -1,5 +1,5 @@ ## compile controller service -FROM gcr.io/linkerd-io/go-deps:f6fda337 as golang +FROM gcr.io/linkerd-io/go-deps:bfb89c7f as golang WORKDIR /linkerd-build COPY controller/gen controller/gen COPY pkg pkg diff --git a/go.mod b/go.mod index 1ebc7eccbc2eb..c0acf945c15f8 100644 --- a/go.mod +++ b/go.mod @@ -37,6 +37,7 @@ require ( github.com/nsf/termbox-go v0.0.0-20180613055208-5c94acc5e6eb github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pkg/browser v0.0.0-20170505125900-c90ca0c84f15 + github.com/pothulapati/mergo v0.3.9-0.20200119140448-5a1b1cee7b3f github.com/prometheus/client_golang v1.2.1 github.com/prometheus/common v0.7.0 github.com/sergi/go-diff v1.0.0 diff --git a/go.sum b/go.sum index 17aeb1159ced7..f0f7d387594ca 100644 --- a/go.sum +++ b/go.sum @@ -209,6 +209,7 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/linkerd/linkerd2-proxy-api v0.1.10 h1:zGwz2Fek7fdfCxyZW7jq8IE6sexeVFW5UFBQFL6MrP4= github.com/linkerd/linkerd2-proxy-api v0.1.10/go.mod h1:2WJHEYXoww5ALM6c1QspRFiROGZg08tGxCO1js0tTVA= +github.com/linkerd/linkerd2-proxy-api v0.1.11 h1:Y3coQyi2XjrJvXc6y9QWBvkoRqw6e9lDhfSrwNzcxDQ= github.com/linkerd/linkerd2-proxy-init v1.2.0 h1:cTuiVw2udZbcnuYgj9B/3Lqy2ZtiiXPf2w2QIzhsfOQ= github.com/linkerd/linkerd2-proxy-init v1.2.0/go.mod h1:lK/sORPZDP6aFhPZps+AHMKphX5v9bKVDNESllz18C0= github.com/linkerd/linkerd2-proxy-init v1.3.0 h1:kyrMpaNKGPfd7FA8O/6VGxsYXx++TxxZVgRL6knWSa8= @@ -267,6 +268,8 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pothulapati/mergo v0.3.9-0.20200119140448-5a1b1cee7b3f h1:A0EmZvodfElhpeY0FZwbN8tqp5Zb8UiCCJtKw+OsVFE= +github.com/pothulapati/mergo v0.3.9-0.20200119140448-5a1b1cee7b3f/go.mod h1:ZHOBBBkz9S/P9Sp2H2jkl+8upCXvQ9zENaeP/etJeGk= github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.2 h1:awm861/B8OKDd2I/6o1dy3ra4BamzKhYOiGItCeZ740= diff --git a/pkg/charts/charts.go b/pkg/charts/charts.go index 64e2b9eec696d..6fa973474af0d 100644 --- a/pkg/charts/charts.go +++ b/pkg/charts/charts.go @@ -83,8 +83,8 @@ func (chart *Chart) Render() (bytes.Buffer, error) { return chart.render(l5dPartials) } -// RenderCNI returns a bytes buffer with the result of rendering a Helm chart -func (chart *Chart) RenderCNI() (bytes.Buffer, error) { +// Render returns a bytes buffer with the result of rendering a Helm chart +func (chart *Chart) RenderWithoutPartials() (bytes.Buffer, error) { return chart.render([]*chartutil.BufferedFile{}) } diff --git a/pkg/charts/linkerd2/add-on.go b/pkg/charts/linkerd2/add-on.go new file mode 100644 index 0000000000000..cc0543ad52b8f --- /dev/null +++ b/pkg/charts/linkerd2/add-on.go @@ -0,0 +1,18 @@ +package linkerd2 + +import "k8s.io/helm/pkg/chartutil" + +var ( + AddonBufferedFiles = []*chartutil.BufferedFile{ + {Name: chartutil.ChartfileName}, + {Name: "templates/addon-cm.yaml"}, + } + AddonChartsPath = "linkerd2/add-ons/" +) + +type AddOn interface { + GetChartName() string + IsEnabled() bool + GetValues() interface{} + GetFiles() []*chartutil.BufferedFile +} diff --git a/pkg/charts/linkerd2/grafana.go b/pkg/charts/linkerd2/grafana.go new file mode 100644 index 0000000000000..502421ee6d127 --- /dev/null +++ b/pkg/charts/linkerd2/grafana.go @@ -0,0 +1,56 @@ +package linkerd2 + +import ( + "k8s.io/helm/pkg/chartutil" +) + +type ( + Grafana struct { + Enabled bool `json:"enabled"` + Image string `json:"image"` + Resources *Resources `json:"resources"` + } +) + +var ( + grafanaChartName = "grafana" + grafanaConfigStage = []string{ + "templates/grafana-rbac.yaml", + } + + grafanaControlPlaneStage = []string{ + "templates/grafana.yaml", + } +) + +func (*Grafana) GetChartName() string { + return grafanaChartName +} + +func (*Grafana) GetFiles() []*chartutil.BufferedFile { + files := []*chartutil.BufferedFile{ + {Name: chartutil.ChartfileName}, + } + + for _, template := range grafanaConfigStage { + files = append(files, &chartutil.BufferedFile{ + Name: template, + }) + } + + for _, template := range grafanaControlPlaneStage { + files = append(files, &chartutil.BufferedFile{ + Name: template, + }) + } + + return files +} + +func (g *Grafana) GetValues() interface{} { + return g +} + +func (g *Grafana) IsEnabled() bool { + return g.Enabled +} diff --git a/pkg/charts/linkerd2/prometheus.go b/pkg/charts/linkerd2/prometheus.go new file mode 100644 index 0000000000000..42b3514025874 --- /dev/null +++ b/pkg/charts/linkerd2/prometheus.go @@ -0,0 +1,57 @@ +package linkerd2 + +import ( + "k8s.io/helm/pkg/chartutil" +) + +type ( + Prometheus struct { + Enabled bool `json:"enabled"` + LogLevel string `json:"logLevel"` + Image string `json:"image"` + Resources *Resources `json:"resources"` + } +) + +var ( + prometheusChartName = "prometheus" + prometheusConfigStage = []string{ + "templates/prometheus-rbac.yaml", + } + + prometheusControlPlaneStage = []string{ + "templates/prometheus.yaml", + } +) + +func (*Prometheus) GetChartName() string { + return prometheusChartName +} + +func (*Prometheus) GetFiles() []*chartutil.BufferedFile { + files := []*chartutil.BufferedFile{ + {Name: chartutil.ChartfileName}, + } + + for _, template := range prometheusConfigStage { + files = append(files, &chartutil.BufferedFile{ + Name: template, + }) + } + + for _, template := range prometheusControlPlaneStage { + files = append(files, &chartutil.BufferedFile{ + Name: template, + }) + } + + return files +} + +func (g *Prometheus) GetValues() interface{} { + return g +} + +func (g *Prometheus) IsEnabled() bool { + return g.Enabled +} diff --git a/pkg/charts/linkerd2/values.go b/pkg/charts/linkerd2/values.go index 8e8fcf0e4fcdd..806698afc581f 100644 --- a/pkg/charts/linkerd2/values.go +++ b/pkg/charts/linkerd2/values.go @@ -60,6 +60,10 @@ type ( SPValidatorResources *Resources `json:"spValidatorResources"` TapResources *Resources `json:"tapResources"` WebResources *Resources `json:"webResources"` + + // Add-Ons for Linkerd + Grafana *Grafana `json:"grafana"` + Prometheus *Prometheus `json:"prometheus"` } // Global values common across all charts diff --git a/web/Dockerfile b/web/Dockerfile index b41c606a324fc..78da2a9cc6c3a 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -21,7 +21,7 @@ COPY web/app ./web/app RUN ./bin/web build ## compile go server -FROM gcr.io/linkerd-io/go-deps:f6fda337 as golang +FROM gcr.io/linkerd-io/go-deps:bfb89c7f as golang WORKDIR /linkerd-build RUN mkdir -p web COPY web/main.go web