mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-18 03:56:36 +00:00
Feat: alibaba provider addon (#2243)
bump up terraform version Signed-off-by: qiaozp <chivalry.pp@gmail.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
+10
-7
@@ -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, "/", "-")
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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:
|
||||
|
||||
@@ -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 }}
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user