diff --git a/charts/vela-core/templates/addons-default/terraform.yaml b/charts/vela-core/templates/addons-default/terraform.yaml index fef38272f..20ff17546 100644 --- a/charts/vela-core/templates/addons-default/terraform.yaml +++ b/charts/vela-core/templates/addons-default/terraform.yaml @@ -16,7 +16,7 @@ spec: chart: terraform-controller repoType: helm url: https://charts.kubevela.net/addons - version: 0.1.17 + version: 0.1.19 type: helm - name: terraform-system properties: diff --git a/charts/vela-core/templates/addons/fluxcd.yaml b/charts/vela-core/templates/addons/fluxcd.yaml index 1a04ff0f2..282e0767d 100644 --- a/charts/vela-core/templates/addons/fluxcd.yaml +++ b/charts/vela-core/templates/addons/fluxcd.yaml @@ -6163,6 +6163,7 @@ metadata: annotations: addons.oam.dev/description: Flux is a set of continuous and progressive delivery solutions for Kubernetes + addons.oam.dev/name: fluxcd labels: addons.oam.dev/type: fluxcd name: fluxcd diff --git a/charts/vela-core/templates/addons/istio.yaml b/charts/vela-core/templates/addons/istio.yaml index cbb9a2a36..d3720e9fb 100644 --- a/charts/vela-core/templates/addons/istio.yaml +++ b/charts/vela-core/templates/addons/istio.yaml @@ -182,6 +182,7 @@ metadata: annotations: addons.oam.dev/description: istio Controller is a Kubernetes Controller for manage traffic. + addons.oam.dev/name: istio labels: addons.oam.dev/type: istio name: istio diff --git a/charts/vela-core/templates/addons/keda.yaml b/charts/vela-core/templates/addons/keda.yaml index ee51728c1..d34f7a244 100644 --- a/charts/vela-core/templates/addons/keda.yaml +++ b/charts/vela-core/templates/addons/keda.yaml @@ -38,6 +38,7 @@ kind: ConfigMap metadata: annotations: addons.oam.dev/description: KEDA is a Kubernetes-based Event Driven Autoscaler. + addons.oam.dev/name: keda labels: addons.oam.dev/type: keda name: keda diff --git a/charts/vela-core/templates/addons/kruise.yaml b/charts/vela-core/templates/addons/kruise.yaml index 91a062ae5..04b3c5ec2 100644 --- a/charts/vela-core/templates/addons/kruise.yaml +++ b/charts/vela-core/templates/addons/kruise.yaml @@ -191,6 +191,7 @@ metadata: annotations: addons.oam.dev/description: Kruise is a Kubernetes extended suite for application automations + addons.oam.dev/name: kruise labels: addons.oam.dev/type: kruise name: kruise diff --git a/charts/vela-core/templates/addons/ns-flux-system.yaml b/charts/vela-core/templates/addons/ns-flux-system.yaml index 5eba926de..cc3b740e5 100644 --- a/charts/vela-core/templates/addons/ns-flux-system.yaml +++ b/charts/vela-core/templates/addons/ns-flux-system.yaml @@ -33,6 +33,7 @@ kind: ConfigMap metadata: annotations: addons.oam.dev/description: Create namespace for flux-system + addons.oam.dev/name: ns-flux-system labels: addons.oam.dev/type: ns-flux-system name: ns-flux-system diff --git a/charts/vela-core/templates/addons/ns-istio-system.yaml b/charts/vela-core/templates/addons/ns-istio-system.yaml index 092ae7c8c..6a791a6e1 100644 --- a/charts/vela-core/templates/addons/ns-istio-system.yaml +++ b/charts/vela-core/templates/addons/ns-istio-system.yaml @@ -33,6 +33,7 @@ kind: ConfigMap metadata: annotations: addons.oam.dev/description: Create namespace for istio-system + addons.oam.dev/name: ns-istio-system labels: addons.oam.dev/type: ns-istio-system name: ns-istio-system diff --git a/charts/vela-core/templates/addons/observability-asset.yaml b/charts/vela-core/templates/addons/observability-asset.yaml index 3e8bd7f17..732dd3dea 100644 --- a/charts/vela-core/templates/addons/observability-asset.yaml +++ b/charts/vela-core/templates/addons/observability-asset.yaml @@ -121,6 +121,7 @@ kind: ConfigMap metadata: annotations: addons.oam.dev/description: Preparations that observability need + addons.oam.dev/name: observability-asset labels: addons.oam.dev/type: observability-asset name: observability-asset diff --git a/charts/vela-core/templates/addons/observability.yaml b/charts/vela-core/templates/addons/observability.yaml index 8a1a46144..b11d75448 100644 --- a/charts/vela-core/templates/addons/observability.yaml +++ b/charts/vela-core/templates/addons/observability.yaml @@ -147,6 +147,7 @@ kind: ConfigMap metadata: annotations: addons.oam.dev/description: An out of the box solution for KubeVela observability + addons.oam.dev/name: observability labels: addons.oam.dev/type: observability name: observability diff --git a/charts/vela-core/templates/addons/ocm-cluster-manager.yaml b/charts/vela-core/templates/addons/ocm-cluster-manager.yaml index 691867e74..76ae1c72f 100644 --- a/charts/vela-core/templates/addons/ocm-cluster-manager.yaml +++ b/charts/vela-core/templates/addons/ocm-cluster-manager.yaml @@ -517,6 +517,7 @@ metadata: annotations: addons.oam.dev/description: ocm-cluster-manager can deploy an OCM hub cluster environment. + addons.oam.dev/name: ocm-cluster-manager labels: addons.oam.dev/type: ocm-cluster-manager name: ocm-cluster-manager diff --git a/charts/vela-core/templates/addons/prometheus.yaml b/charts/vela-core/templates/addons/prometheus.yaml index 5aa8466fd..b4a1bbd6b 100644 --- a/charts/vela-core/templates/addons/prometheus.yaml +++ b/charts/vela-core/templates/addons/prometheus.yaml @@ -40,6 +40,7 @@ metadata: annotations: addons.oam.dev/description: Prometheus is an open-source systems monitoring and alerting toolkit + addons.oam.dev/name: prometheus labels: addons.oam.dev/type: prometheus name: prometheus diff --git a/charts/vela-core/templates/addons/terraform-provider-alibaba.yaml b/charts/vela-core/templates/addons/terraform-provider-alibaba.yaml new file mode 100644 index 000000000..95080c5b7 --- /dev/null +++ b/charts/vela-core/templates/addons/terraform-provider-alibaba.yaml @@ -0,0 +1,65 @@ +apiVersion: v1 +data: + initializer: | + apiVersion: core.oam.dev/v1beta1 + kind: Initializer + metadata: + annotations: + addons.oam.dev/description: terraform provider (alibaba) + addons.oam.dev/name: terraform/provider-alibaba + name: terraform-provider-alibaba + namespace: default + spec: + appTemplate: + spec: + components: + - name: alibaba-account-creds + properties: + apiVersion: v1 + kind: Secret + metadata: + name: alibaba-provider-secret + namespace: vela-system + stringData: + credentials: | + accessKeyID: [[ index .Args "ALICLOUD_ACCESS_KEY" ]] + accessKeySecret: [[ index .Args "ALICLOUD_SECRET_KEY" ]] + securityToken: [[ index .Args "ALICLOUD_SECURITY_TOKEN" ]] + type: Opaque + type: raw + - name: default + properties: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Provider + metadata: + name: default + namespace: default + spec: + credentials: + secretRef: + key: credentials + name: alibaba-account-creds + namespace: vela-system + source: Secret + provider: alibaba + region: cn-beijing + type: raw + status: + rollout: + batchRollingState: "" + currentBatch: 0 + lastTargetAppRevision: "" + rollingState: "" + upgradedReadyReplicas: 0 + upgradedReplicas: 0 + status: + observedGeneration: 0 +kind: ConfigMap +metadata: + annotations: + addons.oam.dev/description: terraform provider (alibaba) + addons.oam.dev/name: terraform/provider-alibaba + labels: + addons.oam.dev/type: terraform-provider-alibaba + name: terraform-provider-alibaba + namespace: {{.Values.systemDefinitionNamespace}} diff --git a/charts/vela-core/templates/addons/terraform.yaml b/charts/vela-core/templates/addons/terraform.yaml index 27a749a1a..5846d7b47 100644 --- a/charts/vela-core/templates/addons/terraform.yaml +++ b/charts/vela-core/templates/addons/terraform.yaml @@ -18,7 +18,7 @@ data: chart: terraform-controller repoType: helm url: https://charts.kubevela.net/addons - version: 0.1.17 + version: 0.1.19 type: helm - name: terraform-system properties: @@ -48,6 +48,7 @@ metadata: annotations: addons.oam.dev/description: Terraform Controller is a Kubernetes Controller for Terraform. + addons.oam.dev/name: terraform labels: addons.oam.dev/type: terraform name: terraform diff --git a/e2e/addon/addon_test.go b/e2e/addon/addon_test.go index 08e97f6d3..74aa6d4b7 100644 --- a/e2e/addon/addon_test.go +++ b/e2e/addon/addon_test.go @@ -64,7 +64,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-addon", 600*time.Second) Expect(err).NotTo(HaveOccurred()) Expect(output).To(ContainSubstring("Successfully disable addon")) @@ -106,6 +106,7 @@ kind: ConfigMap metadata: annotations: addons.oam.dev/description: This is a addon for e2e test + addons.oam.dev/name: test-addon labels: addons.oam.dev/type: test-addon name: test-addon @@ -142,6 +143,7 @@ kind: ConfigMap metadata: annotations: addons.oam.dev/description: This is a test addon for test addon input + addons.oam.dev/name: test-input-addon labels: addons.oam.dev/type: test name: test-input-addon diff --git a/pkg/oam/labels.go b/pkg/oam/labels.go index 5539c9dce..e3e1b0404 100644 --- a/pkg/oam/labels.go +++ b/pkg/oam/labels.go @@ -116,4 +116,7 @@ const ( // AnnotationDefinitionRevisionName is used to specify the name of DefinitionRevision in component/trait definition AnnotationDefinitionRevisionName = "definitionrevision.oam.dev/name" + + // AnnotationAddonsName records the name of initializer stored in configMap + AnnotationAddonsName = "addons.oam.dev/name" ) diff --git a/references/cli/addon.go b/references/cli/addon.go index 00166e33c..e5c534fc6 100644 --- a/references/cli/addon.go +++ b/references/cli/addon.go @@ -42,6 +42,7 @@ import ( "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1" "github.com/oam-dev/kubevela/apis/types" + "github.com/oam-dev/kubevela/pkg/oam" "github.com/oam-dev/kubevela/pkg/oam/discoverymapper" "github.com/oam-dev/kubevela/pkg/utils/apply" "github.com/oam-dev/kubevela/pkg/utils/common" @@ -51,9 +52,6 @@ import ( const ( // DescAnnotation records the description of addon DescAnnotation = "addons.oam.dev/description" - - // MarkLabel is annotation key marks configMap as an addon - MarkLabel = "addons.oam.dev/type" ) var statusUninstalled = "uninstalled" @@ -217,7 +215,7 @@ func disableAddon(name string) error { } func newAddon(data *v1.ConfigMap) *Addon { description := data.ObjectMeta.Annotations[DescAnnotation] - a := Addon{name: data.Name, description: description, initYaml: data.Data["initializer"]} + a := Addon{name: data.Annotations[oam.AnnotationAddonsName], description: description, initYaml: data.Data["initializer"]} init, _ := a.renderInitializer() a.addonNamespace = init.GetNamespace() return &a @@ -234,7 +232,7 @@ func NewAddonRepo() (AddonRepo, error) { list := v1.ConfigMapList{} matchLabels := metav1.LabelSelector{ MatchExpressions: []metav1.LabelSelectorRequirement{{ - Key: MarkLabel, + Key: oam.LabelAddonsName, Operator: metav1.LabelSelectorOpExists, }}, } @@ -255,7 +253,7 @@ type configMapAddonRepo struct { func (c configMapAddonRepo) getAddon(name string) (Addon, error) { for i := range c.maps { - if c.maps[i].Name == name { + if addonName, ok := c.maps[i].Annotations[oam.AnnotationAddonsName]; ok && name == addonName { return *newAddon(&c.maps[i]), nil } } @@ -415,7 +413,7 @@ func (a *Addon) getStatus() string { var initializer v1beta1.Initializer err := clt.Get(context.Background(), client.ObjectKey{ Namespace: a.addonNamespace, - Name: a.name, + Name: TransAddonName(a.name), }, &initializer) if err != nil { return statusUninstalled @@ -426,3 +424,8 @@ func (a *Addon) getStatus() string { func (a *Addon) setArgs(args map[string]string) { a.Args = args } + +// TransAddonName will turn addon's name from xxx/yyy to xxx-yyy +func TransAddonName(name string) string { + return strings.ReplaceAll(name, "/", "-") +} diff --git a/vela-templates/addons/auto-gen/terraform-provider-alibaba.yaml b/vela-templates/addons/auto-gen/terraform-provider-alibaba.yaml new file mode 100644 index 000000000..81ec37488 --- /dev/null +++ b/vela-templates/addons/auto-gen/terraform-provider-alibaba.yaml @@ -0,0 +1,53 @@ +apiVersion: core.oam.dev/v1beta1 +kind: Initializer +metadata: + annotations: + addons.oam.dev/description: terraform provider (alibaba) + addons.oam.dev/name: terraform/provider-alibaba + name: terraform-provider-alibaba + namespace: default +spec: + appTemplate: + spec: + components: + - name: alibaba-account-creds + properties: + apiVersion: v1 + kind: Secret + metadata: + name: alibaba-provider-secret + namespace: vela-system + stringData: + credentials: | + accessKeyID: [[ index .Args "ALICLOUD_ACCESS_KEY" ]] + accessKeySecret: [[ index .Args "ALICLOUD_SECRET_KEY" ]] + securityToken: [[ index .Args "ALICLOUD_SECURITY_TOKEN" ]] + type: Opaque + type: raw + - name: default + properties: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Provider + metadata: + name: default + namespace: default + spec: + credentials: + secretRef: + key: credentials + name: alibaba-account-creds + namespace: vela-system + source: Secret + provider: alibaba + region: cn-beijing + type: raw + status: + rollout: + batchRollingState: "" + currentBatch: 0 + lastTargetAppRevision: "" + rollingState: "" + upgradedReadyReplicas: 0 + upgradedReplicas: 0 +status: + observedGeneration: 0 diff --git a/vela-templates/addons/auto-gen/terraform.yaml b/vela-templates/addons/auto-gen/terraform.yaml index f33b46dc8..a82a6fdbf 100644 --- a/vela-templates/addons/auto-gen/terraform.yaml +++ b/vela-templates/addons/auto-gen/terraform.yaml @@ -15,7 +15,7 @@ spec: chart: terraform-controller repoType: helm url: https://charts.kubevela.net/addons - version: 0.1.17 + version: 0.1.19 type: helm - name: terraform-system properties: diff --git a/vela-templates/addons/terraform-provider-alibaba/template.yaml b/vela-templates/addons/terraform-provider-alibaba/template.yaml new file mode 100644 index 000000000..a8089d315 --- /dev/null +++ b/vela-templates/addons/terraform-provider-alibaba/template.yaml @@ -0,0 +1,53 @@ +apiVersion: core.oam.dev/v1beta1 +kind: Initializer +metadata: + annotations: + addons.oam.dev/description: terraform provider (alibaba) + addons.oam.dev/name: terraform/provider-alibaba + name: terraform-provider-alibaba + namespace: default +spec: + appTemplate: + spec: + components: + - name: alibaba-account-creds + properties: + apiVersion: v1 + kind: Secret + metadata: + name: alibaba-provider-secret + namespace: vela-system + type: Opaque + stringData: + credentials: | + accessKeyID: [[ index .Args "ALICLOUD_ACCESS_KEY" ]] + accessKeySecret: [[ index .Args "ALICLOUD_SECRET_KEY" ]] + securityToken: [[ index .Args "ALICLOUD_SECURITY_TOKEN" ]] + type: raw + - name: default + type: raw + properties: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Provider + metadata: + name: default + namespace: default + spec: + provider: alibaba + region: cn-beijing + credentials: + source: Secret + secretRef: + namespace: vela-system + name: alibaba-account-creds + key: credentials +{{ 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/terraform/template.yaml b/vela-templates/addons/terraform/template.yaml index a9173852a..d9ae6c15a 100644 --- a/vela-templates/addons/terraform/template.yaml +++ b/vela-templates/addons/terraform/template.yaml @@ -21,7 +21,7 @@ spec: repoType: helm url: https://charts.kubevela.net/addons chart: terraform-controller - version: 0.1.17 + version: 0.1.19 {{ range .ResourceFiles }} - name: {{ .Name }} type: raw diff --git a/vela-templates/gen_addons.go b/vela-templates/gen_addons.go index fa3a46a9a..51dc509a5 100644 --- a/vela-templates/gen_addons.go +++ b/vela-templates/gen_addons.go @@ -39,6 +39,7 @@ import ( "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1" "github.com/oam-dev/kubevela/pkg/oam/util" + "github.com/oam-dev/kubevela/references/cli" ) const ( @@ -62,6 +63,9 @@ const ( // ChartTemplateNamespace is placeholder for helm chart ChartTemplateNamespace = "{{.Values.systemDefinitionNamespace}}" + + // NameAnnotation marked the addon's name if exist, or initializer's name + NameAnnotation = "addons.oam.dev/name" ) // DefaultEnableAddons is default enabled addons @@ -79,6 +83,7 @@ type AddonInfo struct { DefinitionFiles []velaFile HasDefs bool Name string + StoreName string Description string TemplatePath string } @@ -136,7 +141,6 @@ func getAddonInfo(addon string, addonsPath string) (*AddonInfo, error) { resourcesFiles := make([]velaFile, 0) defFiles := make([]velaFile, 0) addInfo := &AddonInfo{ - Name: addon, TemplatePath: filepath.Join(addonRoot, InitializerTemplateName), } // raw resources directory @@ -186,7 +190,7 @@ func generateInitializer(addon *AddonInfo) (*v1beta1.Initializer, error) { var buf bytes.Buffer err = t.Execute(&buf, addon) if err != nil { - return nil, errors.Wrapf(err, "generate Initializer %s fail", addon.Name) + return nil, errors.Wrapf(err, "generate Initializer %s fail", addon.TemplatePath) } init := new(v1beta1.Initializer) @@ -199,11 +203,12 @@ func generateInitializer(addon *AddonInfo) (*v1beta1.Initializer, error) { func setConfigMapLabels(addonInfo *AddonInfo) map[string]string { return map[string]string{ - MarkLabel: addonInfo.Name, + MarkLabel: addonInfo.StoreName, } } func setConfigMapAnnotations(addonInfo *AddonInfo) map[string]string { return map[string]string{ + NameAnnotation: addonInfo.Name, DescAnnotation: addonInfo.Description, } } @@ -226,7 +231,7 @@ func storeConfigMap(addonInfo *AddonInfo, initializer *v1beta1.Initializer, stor }, } addonInfo.Description = initializer.GetAnnotations()[DescAnnotation] - configMap.SetName(addonInfo.Name) + configMap.SetName(addonInfo.StoreName) configMap.SetNamespace(ChartTemplateNamespace) configMap.SetAnnotations(setConfigMapAnnotations(addonInfo)) configMap.SetLabels(setConfigMapLabels(addonInfo)) @@ -245,7 +250,7 @@ func storeConfigMap(addonInfo *AddonInfo, initializer *v1beta1.Initializer, stor raw := string(content) removeTimestampInplace(&raw) raw = strings.ReplaceAll(raw, fmt.Sprintf("'%s'", ChartTemplateNamespace), ChartTemplateNamespace) - filename := storePath + "/" + addonInfo.Name + ".yaml" + filename := storePath + "/" + addonInfo.StoreName + ".yaml" return WriteToFile(filename, raw) } @@ -305,7 +310,8 @@ func main() { dealErr(addon, err) init, err := generateInitializer(addInfo) dealErr(addon, err) - err = storeInitializer(init, addonsPath, addInfo.Name) + setAddonName(addInfo, init) + err = storeInitializer(init, addonsPath, addInfo.StoreName) dealErr(addon, err) err = storeConfigMap(addInfo, init, configMapStorePath) dealErr(addon, err) @@ -315,3 +321,14 @@ func main() { } } } + +func setAddonName(addInfo *AddonInfo, init *v1beta1.Initializer) { + var name string + if val, ok := init.Annotations[NameAnnotation]; ok { + name = val + } else { + name = init.Name + } + addInfo.Name = name + addInfo.StoreName = cli.TransAddonName(name) +}