diff --git a/charts/vela-core/templates/addons/fluxcd.yaml b/charts/vela-core/templates/addons/fluxcd.yaml index a2cae45aa..2768b66be 100644 --- a/charts/vela-core/templates/addons/fluxcd.yaml +++ b/charts/vela-core/templates/addons/fluxcd.yaml @@ -5933,7 +5933,8 @@ data: == \"helm\" {\n\t\t\t\t\t\tkind: \"HelmRepository\"\n\t\t\t\t\t}\n\t\t\t\t\tname: \ context.name\n\t\t\t\t\tnamespace: context.namespace\n\t\t\t\t}\n\t\t\t\tinterval: parameter.pullInterval\n\t\t\t}\n\t\t}\n\t\tif parameter.targetNamespace - != _|_ {\n\t\t\ttargetNamespace: parameter.targetNamespace\n\t\t}\n\t\tif + != _|_ {\n\t\t\ttargetNamespace: parameter.targetNamespace\n\t\t}\n + \ if parameter.releaseName != _|_ {\n\t\t\treleaseName: parameter.releaseName\n\t\t}\n\n\t\tif parameter.values != _|_ {\n\t\t\tvalues: parameter.values\n\t\t}\n\t}\n}\n\nparameter: {\n\trepoType: \"git\" | \"helm\"\n\t// +usage=The Git or Helm repository URL, accept HTTP/S or SSH address as git url.\n\trepoUrl: string\n\t// @@ -5946,7 +5947,8 @@ data: name of the secret containing authentication credentials for the Helm repository.\n\tsecretRef?: string\n\t// +usage=The namespace for helm chart\n\ttargetNamespace?: string\n\t// +usage=Chart version\n\tvalue?: - #nestedmap\n}\n\n#nestedmap: {\n\t...\n} \n" + #nestedmap\n // +usage=The release name\n releaseName?: string\n}\n\n#nestedmap: + {\n\t...\n} \n" workload: type: autodetects.core.oam.dev type: raw diff --git a/charts/vela-core/templates/addons/observability-asset.yaml b/charts/vela-core/templates/addons/observability-asset.yaml new file mode 100644 index 000000000..3e8bd7f17 --- /dev/null +++ b/charts/vela-core/templates/addons/observability-asset.yaml @@ -0,0 +1,127 @@ +apiVersion: v1 +data: + initializer: | + apiVersion: core.oam.dev/v1beta1 + kind: Initializer + metadata: + annotations: + addons.oam.dev/description: Preparations that observability need + name: observability-asset + namespace: vela-system + spec: + appTemplate: + spec: + components: + - name: observability + properties: + apiVersion: v1 + kind: Namespace + metadata: + name: observability + type: raw + - name: import-grafana-dashboard + properties: + apiVersion: core.oam.dev/v1beta1 + kind: TraitDefinition + metadata: + annotations: + definition.oam.dev/description: Add a datasource to Grafana + name: import-grafana-dashboard + namespace: vela-system + spec: + schematic: + cue: + template: "outputs: registerdatasource: {\n\tapiVersion: \"grafana.extension.oam.dev/v1alpha1\"\n\tkind: + \ \"ImportDashboard\"\n\tspec: {\n\t\tgrafana: {\n\t\t\tservice: + \ parameter.grafanaServiceName\n\t\t\tnamespace: + \ parameter.grafanaServiceNamespace\n\t\t\tcredentialSecret: + \ parameter.credentialSecret\n\t\t\tcredentialSecretNamespace: + parameter.credentialSecretNamespace\n\t\t}\n\t\turls: parameter.urls\n\t}\n}\nparameter: + {\n\tgrafanaServiceName: string\n\tgrafanaServiceNamespace: + \ *\"default\" | string\n\tcredentialSecret: string\n\tcredentialSecretNamespace: + *\"default\" | string\n\turls: [...string]\n} \n" + type: raw + - name: pure-ingress + properties: + apiVersion: core.oam.dev/v1beta1 + kind: TraitDefinition + metadata: + annotations: + definition.oam.dev/description: Enable public web traffic for the component + without creating a Service. + name: pure-ingress + namespace: vela-system + spec: + schematic: + cue: + template: "\noutputs: ingress: {\n\tapiVersion: \"networking.k8s.io/v1beta1\"\n\tkind: + \ \"Ingress\"\n\tmetadata:\n\t\tname: context.name\n\tspec: + {\n\t\trules: [{\n\t\t\thost: parameter.domain\n\t\t\thttp: {\n\t\t\t\tpaths: + [\n\t\t\t\t\tfor k, v in parameter.http {\n\t\t\t\t\t\tpath: k\n\t\t\t\t\t\tbackend: + {\n\t\t\t\t\t\t\tserviceName: context.name\n\t\t\t\t\t\t\tservicePort: + v\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t}\n\t\t}]\n\t}\n}\n\nparameter: + {\n\t// +usage=Specify the domain you want to expose\n\tdomain: + string\n\n\t// +usage=Specify the mapping relationship between the + http path and the workload port\n\thttp: [string]: int\n}\n" + status: + customStatus: |- + let igs = context.outputs.ingress.status.loadBalancer.ingress + if igs == _|_ { + message: "No loadBalancer found, visiting by using 'vela port-forward " + context.appName + " --route'\n" + } + if len(igs) > 0 { + if igs[0].ip != _|_ { + message: "Visiting URL: " + context.outputs.ingress.spec.rules[0].host + ", IP: " + igs[0].ip + } + if igs[0].ip == _|_ { + message: "Visiting URL: " + context.outputs.ingress.spec.rules[0].host + } + } + healthPolicy: | + isHealth: len(context.outputs.ingress.status.loadBalancer.ingress) > 0 + type: raw + - name: register-grafana-datasource + properties: + apiVersion: core.oam.dev/v1beta1 + kind: TraitDefinition + metadata: + annotations: + definition.oam.dev/description: Add a datasource to Grafana + name: register-grafana-datasource + namespace: vela-system + spec: + schematic: + cue: + template: "outputs: registerdatasource: {\n\tapiVersion: \"grafana.extension.oam.dev/v1alpha1\"\n\tkind: + \ \"DatasourceRegistration\"\n\tspec: {\n\t\tgrafana: {\n\t\t\tservice: + \ parameter.grafanaServiceName\n\t\t\tnamespace: + \ parameter.grafanaServiceNamespace\n\t\t\tcredentialSecret: + \ parameter.credentialSecret\n\t\t\tcredentialSecretNamespace: + parameter.credentialSecretNamespace\n\t\t}\n\t\tdatasource: {\n\t\t\tname: + \ parameter.name\n\t\t\ttype: parameter.type\n\t\t\taccess: + \ parameter.access\n\t\t\tservice: parameter.service\n\t\t\tnamespace: + parameter.namespace\n\t\t}\n\t}\n}\n\nparameter: {\n\tgrafanaServiceName: + \ string\n\tgrafanaServiceNamespace: *\"default\" | string\n\tcredentialSecret: + \ string\n\tcredentialSecretNamespace: string\n\tname: string\n\ttype: + \ string\n\taccess: *\"proxy\" + | string\n\tservice: string\n\tnamespace: *\"default\" + | string\n}\n" + type: raw + status: + rollout: + batchRollingState: "" + currentBatch: 0 + lastTargetAppRevision: "" + rollingState: "" + upgradedReadyReplicas: 0 + upgradedReplicas: 0 + status: + observedGeneration: 0 +kind: ConfigMap +metadata: + annotations: + addons.oam.dev/description: Preparations that observability need + labels: + addons.oam.dev/type: observability-asset + name: observability-asset + namespace: {{.Values.systemDefinitionNamespace}} diff --git a/charts/vela-core/templates/addons/observability.yaml b/charts/vela-core/templates/addons/observability.yaml new file mode 100644 index 000000000..9f90139e5 --- /dev/null +++ b/charts/vela-core/templates/addons/observability.yaml @@ -0,0 +1,139 @@ +apiVersion: v1 +data: + initializer: | + apiVersion: core.oam.dev/v1beta1 + kind: Initializer + metadata: + annotations: + addons.oam.dev/description: An out of the box solution for KubeVela observability + name: observability + namespace: observability + spec: + appTemplate: + spec: + components: + - name: grafana-registration + properties: + branch: master + chart: ./chart + repoType: git + repoUrl: https://github.com/oam-dev/grafana-registration + targetNamespace: observability + values: + replicaCount: 1 + type: helm + - name: grafana + properties: + chart: grafana + releaseName: grafana + repoType: helm + repoUrl: https://grafana.github.io/helm-charts + targetNamespace: observability + version: 6.14.1 + traits: + - properties: + domain: '[[ index .Args "grafana-domain" ]]' + http: + /: 80 + type: pure-ingress + - properties: + credentialSecret: grafana + credentialSecretNamespace: observability + grafanaServiceName: grafana + grafanaServiceNamespace: observability + urls: + - https://raw.githubusercontent.com/oam-dev/grafana-registration/master/dashboards/kubevela_core_logging.json + - https://raw.githubusercontent.com/oam-dev/grafana-registration/master/dashboards/kubevela_core_monitoring.json + type: import-grafana-dashboard + type: helm + - name: loki + properties: + chart: loki-stack + releaseName: loki + repoType: helm + repoUrl: https://grafana.github.io/helm-charts + targetNamespace: observability + version: 2.4.1 + traits: + - properties: + access: proxy + credentialSecret: grafana + credentialSecretNamespace: observability + grafanaServiceName: grafana + grafanaServiceNamespace: observability + name: loki + namespace: observability + service: loki + type: loki + type: register-grafana-datasource + type: helm + - name: prometheus-server + properties: + chart: prometheus + releaseName: prometheus + repoType: helm + repoUrl: https://prometheus-community.github.io/helm-charts + targetNamespace: observability + values: + alertmanager: + persistentVolume: + enabled: '[[ index .Args "alertmanager-pvc-enabled" | default "true" + ]]' + size: '[[ index .Args "alertmanager-pvc-size" | default "20Gi" ]]' + storageClass: '[[ index .Args "alertmanager-pvc-class" ]]' + server: + persistentVolume: + enabled: '[[ index .Args "server-pvc-enabled" | default "true" ]]' + size: '[[ index .Args "server-pvc-size" | default "20Gi" ]]' + storageClass: '[[ index .Args "server-pvc-class" ]]' + version: 14.4.1 + traits: + - properties: + access: proxy + credentialSecret: grafana + credentialSecretNamespace: observability + grafanaServiceName: grafana + grafanaServiceNamespace: observability + name: prometheus + namespace: observability + service: prometheus-server + type: prometheus + type: register-grafana-datasource + type: helm + - name: kube-state-metrics + properties: + chart: kube-state-metrics + repoType: helm + repoUrl: https://prometheus-community.github.io/helm-charts + targetNamespace: observability + version: 3.4.1 + type: helm + status: + rollout: + batchRollingState: "" + currentBatch: 0 + lastTargetAppRevision: "" + rollingState: "" + upgradedReadyReplicas: 0 + upgradedReplicas: 0 + dependsOn: + - ref: + apiVersion: core.oam.dev/v1beta1 + kind: Initializer + name: fluxcd + namespace: vela-system + - ref: + apiVersion: core.oam.dev/v1beta1 + kind: Initializer + name: observability-asset + namespace: vela-system + status: + observedGeneration: 0 +kind: ConfigMap +metadata: + annotations: + addons.oam.dev/description: An out of the box solution for KubeVela observability + labels: + addons.oam.dev/type: observability + name: observability + namespace: {{.Values.systemDefinitionNamespace}} diff --git a/e2e/addon/addon_test.go b/e2e/addon/addon_test.go index ae7cd8a37..21ea6843d 100644 --- a/e2e/addon/addon_test.go +++ b/e2e/addon/addon_test.go @@ -57,7 +57,7 @@ var _ = Describe("Addon Test", func() { }) }) Context("Enable addon", func() { - It("Enable addon fluxcd", func() { + It("Enable addon test-addon", func() { output, err := e2e.Exec("vela addon enable test-addon") Expect(err).NotTo(HaveOccurred()) Expect(output).To(ContainSubstring("Successfully enable addon")) @@ -80,7 +80,7 @@ var _ = Describe("Addon Test", func() { }) Context("Disable addon", func() { - It("Disable addon fluxcd", func() { + It("Disable addon test-addon", func() { output, err := e2e.LongTimeExec("vela addon disable test-input-addon", 600*time.Second) Expect(err).NotTo(HaveOccurred()) Expect(output).To(ContainSubstring("Successfully disable addon")) @@ -162,9 +162,9 @@ data: components: - name: test-chart properties: - chart: {{ index .Args "chart" }} + chart: [[ index .Args "chart" ]] repoType: helm - repoUrl: {{ index .Args "repoUrl" }} + repoUrl: [[ index .Args "repoUrl" ]] type: helm status: rollout: diff --git a/references/cli/addon.go b/references/cli/addon.go index 29d0dfce6..fa9400d39 100644 --- a/references/cli/addon.go +++ b/references/cli/addon.go @@ -24,6 +24,7 @@ import ( "text/template" "time" + "github.com/Masterminds/sprig" "github.com/gosuri/uitable" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -306,7 +307,7 @@ func (a *Addon) renderInitializer() (*unstructured.Unstructured, error) { if a.Args == nil { a.Args = map[string]string{} } - t, err := template.New("addon-template").Parse(a.initYaml) + t, err := template.New("addon-template").Delims("[[", "]]").Funcs(sprig.TxtFuncMap()).Parse(a.initYaml) if err != nil { return nil, errors.Wrap(err, "parsing addon initializer template error") } diff --git a/vela-templates/addons/auto-gen/fluxcd.yaml b/vela-templates/addons/auto-gen/fluxcd.yaml index e9566bab6..ed3ef021b 100644 --- a/vela-templates/addons/auto-gen/fluxcd.yaml +++ b/vela-templates/addons/auto-gen/fluxcd.yaml @@ -5930,7 +5930,8 @@ spec: == \"helm\" {\n\t\t\t\t\t\tkind: \"HelmRepository\"\n\t\t\t\t\t}\n\t\t\t\t\tname: \ context.name\n\t\t\t\t\tnamespace: context.namespace\n\t\t\t\t}\n\t\t\t\tinterval: parameter.pullInterval\n\t\t\t}\n\t\t}\n\t\tif parameter.targetNamespace - != _|_ {\n\t\t\ttargetNamespace: parameter.targetNamespace\n\t\t}\n\t\tif + != _|_ {\n\t\t\ttargetNamespace: parameter.targetNamespace\n\t\t}\n + \ if parameter.releaseName != _|_ {\n\t\t\treleaseName: parameter.releaseName\n\t\t}\n\n\t\tif parameter.values != _|_ {\n\t\t\tvalues: parameter.values\n\t\t}\n\t}\n}\n\nparameter: {\n\trepoType: \"git\" | \"helm\"\n\t// +usage=The Git or Helm repository URL, accept HTTP/S or SSH address as git url.\n\trepoUrl: string\n\t// @@ -5943,7 +5944,8 @@ spec: name of the secret containing authentication credentials for the Helm repository.\n\tsecretRef?: string\n\t// +usage=The namespace for helm chart\n\ttargetNamespace?: string\n\t// +usage=Chart version\n\tvalue?: - #nestedmap\n}\n\n#nestedmap: {\n\t...\n} \n" + #nestedmap\n // +usage=The release name\n releaseName?: string\n}\n\n#nestedmap: + {\n\t...\n} \n" workload: type: autodetects.core.oam.dev type: raw diff --git a/vela-templates/addons/auto-gen/observability-asset.yaml b/vela-templates/addons/auto-gen/observability-asset.yaml new file mode 100644 index 000000000..4383f6a17 --- /dev/null +++ b/vela-templates/addons/auto-gen/observability-asset.yaml @@ -0,0 +1,116 @@ +apiVersion: core.oam.dev/v1beta1 +kind: Initializer +metadata: + annotations: + addons.oam.dev/description: Preparations that observability need + name: observability-asset + namespace: vela-system +spec: + appTemplate: + spec: + components: + - name: observability + properties: + apiVersion: v1 + kind: Namespace + metadata: + name: observability + type: raw + - name: import-grafana-dashboard + properties: + apiVersion: core.oam.dev/v1beta1 + kind: TraitDefinition + metadata: + annotations: + definition.oam.dev/description: Add a datasource to Grafana + name: import-grafana-dashboard + namespace: vela-system + spec: + schematic: + cue: + template: "outputs: registerdatasource: {\n\tapiVersion: \"grafana.extension.oam.dev/v1alpha1\"\n\tkind: + \ \"ImportDashboard\"\n\tspec: {\n\t\tgrafana: {\n\t\t\tservice: + \ parameter.grafanaServiceName\n\t\t\tnamespace: + \ parameter.grafanaServiceNamespace\n\t\t\tcredentialSecret: + \ parameter.credentialSecret\n\t\t\tcredentialSecretNamespace: + parameter.credentialSecretNamespace\n\t\t}\n\t\turls: parameter.urls\n\t}\n}\nparameter: + {\n\tgrafanaServiceName: string\n\tgrafanaServiceNamespace: + \ *\"default\" | string\n\tcredentialSecret: string\n\tcredentialSecretNamespace: + *\"default\" | string\n\turls: [...string]\n} \n" + type: raw + - name: pure-ingress + properties: + apiVersion: core.oam.dev/v1beta1 + kind: TraitDefinition + metadata: + annotations: + definition.oam.dev/description: Enable public web traffic for the component + without creating a Service. + name: pure-ingress + namespace: vela-system + spec: + schematic: + cue: + template: "\noutputs: ingress: {\n\tapiVersion: \"networking.k8s.io/v1beta1\"\n\tkind: + \ \"Ingress\"\n\tmetadata:\n\t\tname: context.name\n\tspec: + {\n\t\trules: [{\n\t\t\thost: parameter.domain\n\t\t\thttp: {\n\t\t\t\tpaths: + [\n\t\t\t\t\tfor k, v in parameter.http {\n\t\t\t\t\t\tpath: k\n\t\t\t\t\t\tbackend: + {\n\t\t\t\t\t\t\tserviceName: context.name\n\t\t\t\t\t\t\tservicePort: + v\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t}\n\t\t}]\n\t}\n}\n\nparameter: + {\n\t// +usage=Specify the domain you want to expose\n\tdomain: + string\n\n\t// +usage=Specify the mapping relationship between the + http path and the workload port\n\thttp: [string]: int\n}\n" + status: + customStatus: |- + let igs = context.outputs.ingress.status.loadBalancer.ingress + if igs == _|_ { + message: "No loadBalancer found, visiting by using 'vela port-forward " + context.appName + " --route'\n" + } + if len(igs) > 0 { + if igs[0].ip != _|_ { + message: "Visiting URL: " + context.outputs.ingress.spec.rules[0].host + ", IP: " + igs[0].ip + } + if igs[0].ip == _|_ { + message: "Visiting URL: " + context.outputs.ingress.spec.rules[0].host + } + } + healthPolicy: | + isHealth: len(context.outputs.ingress.status.loadBalancer.ingress) > 0 + type: raw + - name: register-grafana-datasource + properties: + apiVersion: core.oam.dev/v1beta1 + kind: TraitDefinition + metadata: + annotations: + definition.oam.dev/description: Add a datasource to Grafana + name: register-grafana-datasource + namespace: vela-system + spec: + schematic: + cue: + template: "outputs: registerdatasource: {\n\tapiVersion: \"grafana.extension.oam.dev/v1alpha1\"\n\tkind: + \ \"DatasourceRegistration\"\n\tspec: {\n\t\tgrafana: {\n\t\t\tservice: + \ parameter.grafanaServiceName\n\t\t\tnamespace: + \ parameter.grafanaServiceNamespace\n\t\t\tcredentialSecret: + \ parameter.credentialSecret\n\t\t\tcredentialSecretNamespace: + parameter.credentialSecretNamespace\n\t\t}\n\t\tdatasource: {\n\t\t\tname: + \ parameter.name\n\t\t\ttype: parameter.type\n\t\t\taccess: + \ parameter.access\n\t\t\tservice: parameter.service\n\t\t\tnamespace: + parameter.namespace\n\t\t}\n\t}\n}\n\nparameter: {\n\tgrafanaServiceName: + \ string\n\tgrafanaServiceNamespace: *\"default\" | string\n\tcredentialSecret: + \ string\n\tcredentialSecretNamespace: string\n\tname: string\n\ttype: + \ string\n\taccess: *\"proxy\" + | string\n\tservice: string\n\tnamespace: *\"default\" + | string\n}\n" + type: raw + status: + rollout: + batchRollingState: "" + currentBatch: 0 + lastTargetAppRevision: "" + rollingState: "" + upgradedReadyReplicas: 0 + upgradedReplicas: 0 +status: + observedGeneration: 0 diff --git a/vela-templates/addons/auto-gen/observability.yaml b/vela-templates/addons/auto-gen/observability.yaml new file mode 100644 index 000000000..20731df9a --- /dev/null +++ b/vela-templates/addons/auto-gen/observability.yaml @@ -0,0 +1,128 @@ +apiVersion: core.oam.dev/v1beta1 +kind: Initializer +metadata: + annotations: + addons.oam.dev/description: An out of the box solution for KubeVela observability + name: observability + namespace: observability +spec: + appTemplate: + spec: + components: + - name: grafana-registration + properties: + branch: master + chart: ./chart + repoType: git + repoUrl: https://github.com/oam-dev/grafana-registration + targetNamespace: observability + values: + replicaCount: 1 + type: helm + - name: grafana + properties: + chart: grafana + releaseName: grafana + repoType: helm + repoUrl: https://grafana.github.io/helm-charts + targetNamespace: observability + version: 6.14.1 + traits: + - properties: + domain: '[[ index .Args "grafana-domain" ]]' + http: + /: 80 + type: pure-ingress + - properties: + credentialSecret: grafana + credentialSecretNamespace: observability + grafanaServiceName: grafana + grafanaServiceNamespace: observability + urls: + - https://raw.githubusercontent.com/oam-dev/grafana-registration/master/dashboards/kubevela_core_logging.json + - https://raw.githubusercontent.com/oam-dev/grafana-registration/master/dashboards/kubevela_core_monitoring.json + type: import-grafana-dashboard + type: helm + - name: loki + properties: + chart: loki-stack + releaseName: loki + repoType: helm + repoUrl: https://grafana.github.io/helm-charts + targetNamespace: observability + version: 2.4.1 + traits: + - properties: + access: proxy + credentialSecret: grafana + credentialSecretNamespace: observability + grafanaServiceName: grafana + grafanaServiceNamespace: observability + name: loki + namespace: observability + service: loki + type: loki + type: register-grafana-datasource + type: helm + - name: prometheus-server + properties: + chart: prometheus + releaseName: prometheus + repoType: helm + repoUrl: https://prometheus-community.github.io/helm-charts + targetNamespace: observability + values: + alertmanager: + persistentVolume: + enabled: '[[ index .Args "alertmanager-pvc-enabled" | default "true" + ]]' + size: '[[ index .Args "alertmanager-pvc-size" | default "20Gi" ]]' + storageClass: '[[ index .Args "alertmanager-pvc-class" ]]' + server: + persistentVolume: + enabled: '[[ index .Args "server-pvc-enabled" | default "true" ]]' + size: '[[ index .Args "server-pvc-size" | default "20Gi" ]]' + storageClass: '[[ index .Args "server-pvc-class" ]]' + version: 14.4.1 + traits: + - properties: + access: proxy + credentialSecret: grafana + credentialSecretNamespace: observability + grafanaServiceName: grafana + grafanaServiceNamespace: observability + name: prometheus + namespace: observability + service: prometheus-server + type: prometheus + type: register-grafana-datasource + type: helm + - name: kube-state-metrics + properties: + chart: kube-state-metrics + repoType: helm + repoUrl: https://prometheus-community.github.io/helm-charts + targetNamespace: observability + version: 3.4.1 + type: helm + status: + rollout: + batchRollingState: "" + currentBatch: 0 + lastTargetAppRevision: "" + rollingState: "" + upgradedReadyReplicas: 0 + upgradedReplicas: 0 + dependsOn: + - ref: + apiVersion: core.oam.dev/v1beta1 + kind: Initializer + name: fluxcd + namespace: vela-system + - ref: + apiVersion: core.oam.dev/v1beta1 + kind: Initializer + name: observability-asset + namespace: vela-system +status: + observedGeneration: 0 diff --git a/vela-templates/addons/fluxcd/definitions/helm-release.yaml b/vela-templates/addons/fluxcd/definitions/helm-release.yaml index b9c59beaa..fc63b82a5 100644 --- a/vela-templates/addons/fluxcd/definitions/helm-release.yaml +++ b/vela-templates/addons/fluxcd/definitions/helm-release.yaml @@ -67,6 +67,10 @@ spec: if parameter.targetNamespace != _|_ { targetNamespace: parameter.targetNamespace } + if parameter.releaseName != _|_ { + releaseName: parameter.releaseName + } + if parameter.values != _|_ { values: parameter.values } @@ -91,6 +95,8 @@ spec: targetNamespace?: string // +usage=Chart version value?: #nestedmap + // +usage=The release name + releaseName?: string } #nestedmap: { diff --git a/vela-templates/addons/fluxcd/template.yaml b/vela-templates/addons/fluxcd/template.yaml index 805efb815..f99942cbe 100644 --- a/vela-templates/addons/fluxcd/template.yaml +++ b/vela-templates/addons/fluxcd/template.yaml @@ -15,12 +15,12 @@ spec: appTemplate: spec: components: -{{ range .ResourceFiles }} +{{ range .ResourceFiles }} - name: {{ .Name }} type: raw properties: {{ .Content | indent 12 }} {{ end }} -{{ range .DefinitionFiles }} +{{ range .DefinitionFiles }} - name: {{ .Name }} type: raw properties: diff --git a/vela-templates/addons/keda/template.yaml b/vela-templates/addons/keda/template.yaml index b2ee2ca36..d9c4344f3 100644 --- a/vela-templates/addons/keda/template.yaml +++ b/vela-templates/addons/keda/template.yaml @@ -21,7 +21,12 @@ spec: repoType: helm repoUrl: https://kedacore.github.io/charts chart: keda -{{ range .DefinitionFiles }} +{{ range .ResourceFiles }} + - name: {{ .Name }} + type: raw + properties: +{{ .Content | indent 12 }} {{ end }} +{{ range .DefinitionFiles }} - name: {{ .Name }} type: raw properties: diff --git a/vela-templates/addons/kruise/template.yaml b/vela-templates/addons/kruise/template.yaml index ca176e105..279c3d5ca 100644 --- a/vela-templates/addons/kruise/template.yaml +++ b/vela-templates/addons/kruise/template.yaml @@ -22,9 +22,14 @@ spec: repoUrl: https://github.com/openkruise/kruise chart: ./charts/kruise/v0.9.0 branch: master - values: + values: featureGates: PreDownloadImageForInPlaceUpdate=true -{{ range .DefinitionFiles }} +{{ range .ResourceFiles }} + - name: {{ .Name }} + type: raw + properties: +{{ .Content | indent 12 }} {{ end }} +{{ range .DefinitionFiles }} - name: {{ .Name }} type: raw properties: diff --git a/vela-templates/addons/ns-flux-system/template.yaml b/vela-templates/addons/ns-flux-system/template.yaml index 98db65af1..f2a0e185d 100644 --- a/vela-templates/addons/ns-flux-system/template.yaml +++ b/vela-templates/addons/ns-flux-system/template.yaml @@ -9,12 +9,12 @@ spec: appTemplate: spec: components: -{{ range .ResourceFiles }} +{{ range .ResourceFiles }} - name: {{ .Name }} type: raw properties: {{ .Content | indent 12 }} {{ end }} -{{ range .DefinitionFiles }} +{{ range .DefinitionFiles }} - name: {{ .Name }} type: raw properties: diff --git a/vela-templates/addons/observability-asset/definitions/trait-import-grafana-dashboard.yaml b/vela-templates/addons/observability-asset/definitions/trait-import-grafana-dashboard.yaml new file mode 100644 index 000000000..9f38666a4 --- /dev/null +++ b/vela-templates/addons/observability-asset/definitions/trait-import-grafana-dashboard.yaml @@ -0,0 +1,31 @@ +apiVersion: core.oam.dev/v1beta1 +kind: TraitDefinition +metadata: + annotations: + definition.oam.dev/description: "Add a datasource to Grafana" + name: import-grafana-dashboard + namespace: vela-system +spec: + schematic: + cue: + template: | + outputs: registerdatasource: { + apiVersion: "grafana.extension.oam.dev/v1alpha1" + kind: "ImportDashboard" + spec: { + grafana: { + service: parameter.grafanaServiceName + namespace: parameter.grafanaServiceNamespace + credentialSecret: parameter.credentialSecret + credentialSecretNamespace: parameter.credentialSecretNamespace + } + urls: parameter.urls + } + } + parameter: { + grafanaServiceName: string + grafanaServiceNamespace: *"default" | string + credentialSecret: string + credentialSecretNamespace: *"default" | string + urls: [...string] + } \ No newline at end of file diff --git a/vela-templates/addons/observability-asset/definitions/trait-pure-ingress.yaml b/vela-templates/addons/observability-asset/definitions/trait-pure-ingress.yaml new file mode 100644 index 000000000..9fa412b91 --- /dev/null +++ b/vela-templates/addons/observability-asset/definitions/trait-pure-ingress.yaml @@ -0,0 +1,58 @@ +apiVersion: core.oam.dev/v1beta1 +kind: TraitDefinition +metadata: + annotations: + definition.oam.dev/description: "Enable public web traffic for the component without creating a Service." + name: pure-ingress + namespace: vela-system +spec: + status: + customStatus: |- + let igs = context.outputs.ingress.status.loadBalancer.ingress + if igs == _|_ { + message: "No loadBalancer found, visiting by using 'vela port-forward " + context.appName + " --route'\n" + } + if len(igs) > 0 { + if igs[0].ip != _|_ { + message: "Visiting URL: " + context.outputs.ingress.spec.rules[0].host + ", IP: " + igs[0].ip + } + if igs[0].ip == _|_ { + message: "Visiting URL: " + context.outputs.ingress.spec.rules[0].host + } + } + healthPolicy: | + isHealth: len(context.outputs.ingress.status.loadBalancer.ingress) > 0 + schematic: + cue: + template: | + + outputs: ingress: { + apiVersion: "networking.k8s.io/v1beta1" + kind: "Ingress" + metadata: + name: context.name + spec: { + rules: [{ + host: parameter.domain + http: { + paths: [ + for k, v in parameter.http { + path: k + backend: { + serviceName: context.name + servicePort: v + } + }, + ] + } + }] + } + } + + parameter: { + // +usage=Specify the domain you want to expose + domain: string + + // +usage=Specify the mapping relationship between the http path and the workload port + http: [string]: int + } diff --git a/vela-templates/addons/observability-asset/definitions/trait-register-grafana-datasource.yaml b/vela-templates/addons/observability-asset/definitions/trait-register-grafana-datasource.yaml new file mode 100644 index 000000000..486ed431d --- /dev/null +++ b/vela-templates/addons/observability-asset/definitions/trait-register-grafana-datasource.yaml @@ -0,0 +1,42 @@ +apiVersion: core.oam.dev/v1beta1 +kind: TraitDefinition +metadata: + annotations: + definition.oam.dev/description: "Add a datasource to Grafana" + name: register-grafana-datasource + namespace: vela-system +spec: + schematic: + cue: + template: | + outputs: registerdatasource: { + apiVersion: "grafana.extension.oam.dev/v1alpha1" + kind: "DatasourceRegistration" + spec: { + grafana: { + service: parameter.grafanaServiceName + namespace: parameter.grafanaServiceNamespace + credentialSecret: parameter.credentialSecret + credentialSecretNamespace: parameter.credentialSecretNamespace + } + datasource: { + name: parameter.name + type: parameter.type + access: parameter.access + service: parameter.service + namespace: parameter.namespace + } + } + } + + parameter: { + grafanaServiceName: string + grafanaServiceNamespace: *"default" | string + credentialSecret: string + credentialSecretNamespace: string + name: string + type: string + access: *"proxy" | string + service: string + namespace: *"default" | string + } diff --git a/vela-templates/addons/observability-asset/resource/namespace.yaml b/vela-templates/addons/observability-asset/resource/namespace.yaml new file mode 100644 index 000000000..4872021cb --- /dev/null +++ b/vela-templates/addons/observability-asset/resource/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: observability \ No newline at end of file diff --git a/vela-templates/addons/observability-asset/template.yaml b/vela-templates/addons/observability-asset/template.yaml new file mode 100644 index 000000000..f927dab06 --- /dev/null +++ b/vela-templates/addons/observability-asset/template.yaml @@ -0,0 +1,21 @@ +apiVersion: core.oam.dev/v1beta1 +kind: Initializer +metadata: + annotations: + addons.oam.dev/description: "Preparations that observability need" + name: observability-asset + namespace: vela-system +spec: + appTemplate: + spec: + components: +{{ range .ResourceFiles }} + - name: {{ .Name }} + type: raw + properties: +{{ .Content | indent 12 }} {{ end }} +{{ range .DefinitionFiles }} + - name: {{ .Name }} + type: raw + properties: +{{ .Content | indent 12 }} {{ end }} diff --git a/vela-templates/addons/observability/template.yaml b/vela-templates/addons/observability/template.yaml new file mode 100644 index 000000000..d1e21cdc0 --- /dev/null +++ b/vela-templates/addons/observability/template.yaml @@ -0,0 +1,128 @@ +apiVersion: core.oam.dev/v1beta1 +kind: Initializer +metadata: + annotations: + addons.oam.dev/description: "An out of the box solution for KubeVela observability" + name: observability + namespace: observability +spec: + dependsOn: + - ref: + apiVersion: core.oam.dev/v1beta1 + kind: Initializer + name: fluxcd + namespace: vela-system + - ref: + apiVersion: core.oam.dev/v1beta1 + kind: Initializer + name: observability-asset + namespace: vela-system + appTemplate: + spec: + components: + - name: grafana-registration + type: helm + properties: + repoType: git + repoUrl: https://github.com/oam-dev/grafana-registration + branch: master + chart: ./chart + targetNamespace: observability + values: + replicaCount: 1 + - name: grafana + properties: + chart: grafana + version: 6.14.1 + repoType: helm + repoUrl: https://grafana.github.io/helm-charts + targetNamespace: observability + releaseName: grafana + type: helm + traits: + - type: pure-ingress + properties: + domain: '[[ index .Args "grafana-domain" ]]' + http: + "/": 80 + - type: import-grafana-dashboard + properties: + grafanaServiceName: grafana + grafanaServiceNamespace: observability + credentialSecret: grafana + credentialSecretNamespace: observability + urls: + - https://raw.githubusercontent.com/oam-dev/grafana-registration/master/dashboards/kubevela_core_logging.json + - https://raw.githubusercontent.com/oam-dev/grafana-registration/master/dashboards/kubevela_core_monitoring.json + - name: loki + type: helm + properties: + chart: loki-stack + version: 2.4.1 + repoType: helm + repoUrl: https://grafana.github.io/helm-charts + targetNamespace: observability + releaseName: loki + traits: + - type: register-grafana-datasource # register loki datasource to Grafana + properties: + grafanaServiceName: grafana + grafanaServiceNamespace: observability + credentialSecret: grafana + credentialSecretNamespace: observability + name: loki + service: loki + namespace: observability + type: loki + access: proxy + - name: prometheus-server + type: helm + properties: + chart: prometheus + version: 14.4.1 + repoType: helm + repoUrl: https://prometheus-community.github.io/helm-charts + targetNamespace: observability + releaseName: prometheus + values: + alertmanager: + persistentVolume: + enabled: '[[ index .Args "alertmanager-pvc-enabled" | default "true" ]]' + storageClass: '[[ index .Args "alertmanager-pvc-class" ]]' + size: '[[ index .Args "alertmanager-pvc-size" | default "20Gi" ]]' + server: + persistentVolume: + enabled: '[[ index .Args "server-pvc-enabled" | default "true" ]]' + storageClass: '[[ index .Args "server-pvc-class" ]]' + size: '[[ index .Args "server-pvc-size" | default "20Gi" ]]' + traits: + - type: register-grafana-datasource # register Prometheus datasource to Grafana + properties: + grafanaServiceName: grafana + grafanaServiceNamespace: observability + credentialSecret: grafana + credentialSecretNamespace: observability + name: prometheus + service: prometheus-server + namespace: observability + type: prometheus + access: proxy + - name: kube-state-metrics + type: helm + properties: + chart: kube-state-metrics + version: 3.4.1 + repoType: helm + repoUrl: https://prometheus-community.github.io/helm-charts + targetNamespace: observability + +{{ range .ResourceFiles }} + - name: {{ .Name }} + type: raw + properties: +{{ .Content | indent 12 }} {{ end }} +{{ range .DefinitionFiles }} + - name: {{ .Name }} + type: raw + properties: +{{ .Content | indent 12 }} {{ end }} diff --git a/vela-templates/addons/ocm-cluster-manager/template.yaml b/vela-templates/addons/ocm-cluster-manager/template.yaml index a9a650b82..49407bab4 100644 --- a/vela-templates/addons/ocm-cluster-manager/template.yaml +++ b/vela-templates/addons/ocm-cluster-manager/template.yaml @@ -9,12 +9,12 @@ spec: appTemplate: spec: components: -{{ range .ResourceFiles }} +{{ range .ResourceFiles }} - name: {{ .Name }} type: raw properties: {{ .Content | indent 12 }} {{ end }} -{{ range .DefinitionFiles }} +{{ range .DefinitionFiles }} - name: {{ .Name }} type: raw properties: diff --git a/vela-templates/addons/prometheus/template.yaml b/vela-templates/addons/prometheus/template.yaml index 59bc9c0d9..6b6244ac1 100644 --- a/vela-templates/addons/prometheus/template.yaml +++ b/vela-templates/addons/prometheus/template.yaml @@ -21,7 +21,7 @@ spec: repoType: helm repoUrl: https://prometheus-community.github.io/helm-charts chart: premetheus -{{ range .DefinitionFiles }} +{{ range .DefinitionFiles }} - name: {{ .Name }} type: raw properties: diff --git a/vela-templates/addons/terraform/template.yaml b/vela-templates/addons/terraform/template.yaml index c8ee44642..706b2d094 100644 --- a/vela-templates/addons/terraform/template.yaml +++ b/vela-templates/addons/terraform/template.yaml @@ -21,12 +21,12 @@ spec: repoType: git repoUrl: https://github.com/oam-dev/terraform-controller chart: ./chart -{{ range .ResourceFiles }} +{{ range .ResourceFiles }} - name: {{ .Name }} type: raw properties: {{ .Content | indent 12 }} {{ end }} -{{ range .DefinitionFiles }} +{{ range .DefinitionFiles }} - name: {{ .Name }} type: raw properties: diff --git a/vela-templates/gen_addons.go b/vela-templates/gen_addons.go index e742f0209..e32598380 100644 --- a/vela-templates/gen_addons.go +++ b/vela-templates/gen_addons.go @@ -31,6 +31,7 @@ import ( "text/template" "github.com/Masterminds/sprig" + "github.com/pkg/errors" corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -181,7 +182,7 @@ func generateInitializer(addon *AddonInfo) (*v1beta1.Initializer, error) { var buf bytes.Buffer err = t.Execute(&buf, addon) if err != nil { - return nil, err + return nil, errors.Wrapf(err, "generate Initializer %s fail", addon.Name) } init := new(v1beta1.Initializer) @@ -266,9 +267,9 @@ func main() { flag.Parse() addons, err := walkAllAddons(addonsPath) - dealErr := func(err error) { + dealErr := func(addonName string, err error) { if err != nil { - fmt.Println(err) + fmt.Printf("%s gen_addon err:%e", addonName, err) os.Exit(1) } } @@ -278,12 +279,12 @@ func main() { } for _, addon := range addons { addInfo, err := getAddonInfo(addon, addonsPath) - dealErr(err) + dealErr(addon, err) init, err := generateInitializer(addInfo) - dealErr(err) + dealErr(addon, err) err = storeInitializer(init, addonsPath, addInfo.Name) - dealErr(err) + dealErr(addon, err) err = storeConfigMap(addInfo, init, storePath) - dealErr(err) + dealErr(addon, err) } }