Fix: install Terraform and apply the support for a provider in one jump (#2778)

* Fix: install Terraform and apply the support for a provider in one jump

- Fix issue: addon name should not include forward-slash "/" cloud-resource fix addon name should not include forward-slash "/" #2588
- Install terraform and the provider in one jump. Instead of installing terraform
and terraform-xxx in two steps
This commit is contained in:
Zheng Xi Zhou
2021-11-26 23:01:11 +08:00
committed by GitHub
parent 334ef864da
commit 7bdf4c176b
23 changed files with 156 additions and 108 deletions

View File

@@ -165,7 +165,7 @@ e2e-setup:
helm upgrade --install --create-namespace --namespace vela-system --set image.pullPolicy=IfNotPresent --set image.repository=vela-core-test --set applicationRevisionLimit=5 --set dependCheckWait=10s --set image.tag=$(GIT_COMMIT) --wait kubevela ./charts/vela-core
helm upgrade --install --create-namespace --namespace oam-runtime-system --set image.pullPolicy=IfNotPresent --set image.repository=vela-core-test --set dependCheckWait=10s --set image.tag=$(GIT_COMMIT) --wait oam-runtime ./charts/oam-runtime
bin/vela addon enable fluxcd
bin/vela addon enable terraform
bin/vela addon enable terraform-alibaba ALICLOUD_ACCESS_KEY=xxx ALICLOUD_SECRET_KEY=yyy ALICLOUD_REGION=cn-beijing
ginkgo version
ginkgo -v -r e2e/setup

View File

@@ -6,8 +6,8 @@ data:
metadata:
annotations:
addons.oam.dev/description: Kubernetes Terraform Controller for Alibaba Cloud
addons.oam.dev/name: terraform/provider-alibaba
name: terraform-provider-alibaba
addons.oam.dev/name: terraform-alibaba
name: terraform-alibaba
namespace: vela-system
spec:
components:
@@ -42,17 +42,26 @@ data:
provider: alibaba
region: '[[ index .Args "ALICLOUD_REGION" ]]'
type: raw
workflow:
steps:
- name: ""
properties:
name: terraform
namespace: vela-system
type: depends-on-app
- name: ""
type: apply-application
status: {}
detail: |-
# terraform/provider-alibaba
detail: |
# terraform-alibaba
This addon contains terraform provider for Alibaba Cloud.
kind: ConfigMap
metadata:
annotations:
addons.oam.dev/description: Kubernetes Terraform Controller for Alibaba Cloud
addons.oam.dev/name: terraform/provider-alibaba
addons.oam.dev/name: terraform-alibaba
labels:
addons.oam.dev/type: terraform-provider-alibaba
name: terraform-provider-alibaba
addons.oam.dev/type: terraform-alibaba
name: terraform-alibaba
namespace: {{.Values.systemDefinitionNamespace}}

View File

@@ -6,8 +6,8 @@ data:
metadata:
annotations:
addons.oam.dev/description: Kubernetes Terraform Controller for AWS
addons.oam.dev/name: terraform/provider-aws
name: terraform-provider-aws
addons.oam.dev/name: terraform-aws
name: terraform-aws
namespace: vela-system
spec:
components:
@@ -42,17 +42,26 @@ data:
provider: aws
region: '[[ index .Args "AWS_DEFAULT_REGION" ]]'
type: raw
workflow:
steps:
- name: ""
properties:
name: terraform
namespace: vela-system
type: depends-on-app
- name: ""
type: apply-application
status: {}
detail: |-
# terraform/provider-aws
detail: |
# terraform-aws
This addon contains terraform provider for AWS
This addon contains terraform provider for AWS.
kind: ConfigMap
metadata:
annotations:
addons.oam.dev/description: Kubernetes Terraform Controller for AWS
addons.oam.dev/name: terraform/provider-aws
addons.oam.dev/name: terraform-aws
labels:
addons.oam.dev/type: terraform-provider-aws
name: terraform-provider-aws
addons.oam.dev/type: terraform-aws
name: terraform-aws
namespace: {{.Values.systemDefinitionNamespace}}

View File

@@ -6,8 +6,8 @@ data:
metadata:
annotations:
addons.oam.dev/description: Kubernetes Terraform Controller for Azure
addons.oam.dev/name: terraform/provider-azure
name: terraform-provider-azure
addons.oam.dev/name: terraform-azure
name: terraform-azure
namespace: vela-system
spec:
components:
@@ -42,17 +42,26 @@ data:
source: Secret
provider: azure
type: raw
workflow:
steps:
- name: ""
properties:
name: terraform
namespace: vela-system
type: depends-on-app
- name: ""
type: apply-application
status: {}
detail: |-
# terraform/provider-azure
detail: |
# terraform-azure
This addon contains terraform provider for Azure.
kind: ConfigMap
metadata:
annotations:
addons.oam.dev/description: Kubernetes Terraform Controller for Azure
addons.oam.dev/name: terraform/provider-azure
addons.oam.dev/name: terraform-azure
labels:
addons.oam.dev/type: terraform-provider-azure
name: terraform-provider-azure
addons.oam.dev/type: terraform-azure
name: terraform-azure
namespace: {{.Values.systemDefinitionNamespace}}

View File

@@ -11,19 +11,12 @@ data:
namespace: vela-system
spec:
components:
- name: ns-terraform-system
properties:
apiVersion: v1
kind: Namespace
metadata:
name: terraform-system
type: raw
- name: terraform-controller
properties:
chart: terraform-controller
repoType: helm
url: https://charts.kubevela.net/addons
version: 0.2.5
version: 0.2.8
type: helm
- name: alibaba-redis
properties:
@@ -572,20 +565,15 @@ data:
type: raw
workflow:
steps:
- name: checking-depends-on
- name: ""
properties:
name: fluxcd
namespace: vela-system
type: depends-on-app
- name: apply-ns
properties:
component: ns-terraform-system
type: apply-component
- name: apply-resources
type: apply-remaining
- name: ""
type: apply-application
status: {}
detail: "# Terraform\n\nThis addon contains terraform operation kit, which allows
you to arrange, \ngenerate and use cloud service from different cloud vendor."
detail: ""
kind: ConfigMap
metadata:
annotations:

View File

@@ -31,6 +31,7 @@ import (
"github.com/spf13/cobra"
v1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
types2 "k8s.io/apimachinery/pkg/types"
@@ -201,6 +202,10 @@ func listAddons() error {
table := uitable.New()
table.AddRow("NAME", "DESCRIPTION", "STATUS")
for _, addon := range addons {
// Addon terraform should be invisible to end-users. It will be installed by other addons like `terraform-alibaba`
if addon.name == "terraform" {
continue
}
table.AddRow(addon.name, addon.description, addon.getStatus())
}
fmt.Println(table.String())
@@ -217,7 +222,7 @@ func enableAddon(ctx context.Context, k8sClient client.Client, name string, args
if err != nil {
return err
}
if strings.HasPrefix(name, "terraform-provider") {
if strings.HasPrefix(name, "terraform-") {
args, _ = getTerraformProviderArgumentValue(name, args)
}
addon.setArgs(args)
@@ -378,9 +383,9 @@ func (a *Addon) enable(ctx context.Context, k8sClient client.Client, name string
return err
}
if strings.HasPrefix(name, "terraform/provider") {
if strings.HasPrefix(name, "terraform-") {
providerName, existed, err := checkWhetherTerraformProviderExist(ctx, k8sClient, name, args)
if err != nil {
if err != nil && !apimeta.IsNoMatchError(err) {
return err
}
if existed {
@@ -499,8 +504,8 @@ func getTerraformProviderNames(ctx context.Context, k8sClient client.Client) ([]
providerList := &terraformv1beta1.ProviderList{}
err := k8sClient.List(ctx, providerList, client.InNamespace(AddonTerraformProviderNamespace))
if err != nil {
if kerrors.IsNotFound(err) {
return nil, err
if apimeta.IsNoMatchError(err) || kerrors.IsNotFound(err) {
return nil, nil
}
return nil, err
}
@@ -515,11 +520,11 @@ func getTerraformProviderArgumentValue(addonName string, args map[string]string)
providerName, ok := args[AddonTerraformProviderNameArgument]
if !ok {
switch addonName {
case "terraform-provider-alibaba":
case "terraform-alibaba":
providerName = "default"
case "terraform-provider-aws":
case "terraform-aws":
providerName = "aws"
case "terraform-provider-azure":
case "terraform-azure":
providerName = "azure"
}
args[AddonTerraformProviderNameArgument] = providerName

View File

@@ -25,6 +25,7 @@ import (
"strconv"
"time"
terraformv1beta1 "github.com/oam-dev/terraform-controller/api/v1beta1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
@@ -87,7 +88,7 @@ var _ = Describe("Addon tests", func() {
It("Addons Terraform is successfully enables and Terraform application works", func() {
By("Install Addon Terraform")
output, err := exec.Command("bash", "-c", "/tmp/vela addon enable terraform").Output()
output, err := exec.Command("bash", "-c", "/tmp/vela addon enable terraform-alibaba providerName=alibaba-e2e ALICLOUD_ACCESS_KEY=xxx ALICLOUD_SECRET_KEY=yyy ALICLOUD_REGION=cn-beijing").Output()
var ee *exec.ExitError
if errors.As(err, &ee) {
fmt.Println("exit code error:", string(ee.Stderr))
@@ -95,6 +96,12 @@ var _ = Describe("Addon tests", func() {
Expect(err).Should(BeNil())
Expect(string(output)).Should(ContainSubstring("Successfully enable addon:"))
By("Checking Provider")
Eventually(func() error {
var provider terraformv1beta1.Provider
return k8sClient.Get(ctx, client.ObjectKey{Name: "alibaba-e2e", Namespace: "default"}, &provider)
}, time.Second*120, time.Millisecond*500).Should(BeNil())
By("Apply an application with Terraform Component")
var terraformApp v1beta1.Application
Expect(common.ReadYamlToObject("testdata/app/app_terraform_oss.yaml", &terraformApp)).Should(BeNil())

View File

@@ -21,11 +21,9 @@ import (
"testing"
"time"
"github.com/oam-dev/kubevela/apis/standard.oam.dev/v1alpha1"
terraformv1beta1 "github.com/oam-dev/terraform-controller/api/v1beta1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
crdv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
@@ -36,6 +34,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"
core "github.com/oam-dev/kubevela/apis/core.oam.dev"
"github.com/oam-dev/kubevela/apis/standard.oam.dev/v1alpha1"
// +kubebuilder:scaffold:imports
)
@@ -62,6 +61,8 @@ var _ = BeforeSuite(func(done Done) {
Expect(err).Should(BeNil())
err = v1alpha1.AddToScheme(scheme)
Expect(err).Should(BeNil())
err = terraformv1beta1.AddToScheme(scheme)
Expect(err).Should(BeNil())
By("Setting up kubernetes client")
k8sClient, err = client.New(config.GetConfigOrDie(), client.Options{Scheme: scheme})
if err != nil {

View File

@@ -3,8 +3,8 @@ kind: Application
metadata:
annotations:
addons.oam.dev/description: Kubernetes Terraform Controller for Alibaba Cloud
addons.oam.dev/name: terraform/provider-alibaba
name: terraform-provider-alibaba
addons.oam.dev/name: terraform-alibaba
name: terraform-alibaba
namespace: vela-system
spec:
components:
@@ -39,4 +39,13 @@ spec:
provider: alibaba
region: '[[ index .Args "ALICLOUD_REGION" ]]'
type: raw
workflow:
steps:
- name: ""
properties:
name: terraform
namespace: vela-system
type: depends-on-app
- name: ""
type: apply-application
status: {}

View File

@@ -3,8 +3,8 @@ kind: Application
metadata:
annotations:
addons.oam.dev/description: Kubernetes Terraform Controller for AWS
addons.oam.dev/name: terraform/provider-aws
name: terraform-provider-aws
addons.oam.dev/name: terraform-aws
name: terraform-aws
namespace: vela-system
spec:
components:
@@ -39,4 +39,13 @@ spec:
provider: aws
region: '[[ index .Args "AWS_DEFAULT_REGION" ]]'
type: raw
workflow:
steps:
- name: ""
properties:
name: terraform
namespace: vela-system
type: depends-on-app
- name: ""
type: apply-application
status: {}

View File

@@ -3,8 +3,8 @@ kind: Application
metadata:
annotations:
addons.oam.dev/description: Kubernetes Terraform Controller for Azure
addons.oam.dev/name: terraform/provider-azure
name: terraform-provider-azure
addons.oam.dev/name: terraform-azure
name: terraform-azure
namespace: vela-system
spec:
components:
@@ -39,4 +39,13 @@ spec:
source: Secret
provider: azure
type: raw
workflow:
steps:
- name: ""
properties:
name: terraform
namespace: vela-system
type: depends-on-app
- name: ""
type: apply-application
status: {}

View File

@@ -8,19 +8,12 @@ metadata:
namespace: vela-system
spec:
components:
- name: ns-terraform-system
properties:
apiVersion: v1
kind: Namespace
metadata:
name: terraform-system
type: raw
- name: terraform-controller
properties:
chart: terraform-controller
repoType: helm
url: https://charts.kubevela.net/addons
version: 0.2.5
version: 0.2.8
type: helm
- name: alibaba-redis
properties:
@@ -569,15 +562,11 @@ spec:
type: raw
workflow:
steps:
- name: checking-depends-on
- name: ""
properties:
name: fluxcd
namespace: vela-system
type: depends-on-app
- name: apply-ns
properties:
component: ns-terraform-system
type: apply-component
- name: apply-resources
type: apply-remaining
- name: ""
type: apply-application
status: {}

View File

@@ -0,0 +1,3 @@
# terraform-alibaba
This addon contains terraform provider for Alibaba Cloud.

View File

@@ -3,10 +3,17 @@ kind: Application
metadata:
annotations:
addons.oam.dev/description: Kubernetes Terraform Controller for Alibaba Cloud
addons.oam.dev/name: terraform/provider-alibaba
name: terraform-provider-alibaba
addons.oam.dev/name: terraform-alibaba
name: terraform-alibaba
namespace: vela-system
spec:
workflow:
steps:
- type: depends-on-app
properties:
name: terraform
namespace: vela-system
- type: apply-application
components:
- name: alibaba-account-creds-[[ index .Args "providerName" ]]
properties:

View File

@@ -0,0 +1,3 @@
# terraform-aws
This addon contains terraform provider for AWS.

View File

@@ -3,10 +3,17 @@ kind: Application
metadata:
annotations:
addons.oam.dev/description: Kubernetes Terraform Controller for AWS
addons.oam.dev/name: terraform/provider-aws
name: terraform-provider-aws
addons.oam.dev/name: terraform-aws
name: terraform-aws
namespace: vela-system
spec:
workflow:
steps:
- type: depends-on-app
properties:
name: terraform
namespace: vela-system
- type: apply-application
components:
- name: aws-account-creds
properties:

View File

@@ -0,0 +1,3 @@
# terraform-azure
This addon contains terraform provider for Azure.

View File

@@ -3,10 +3,17 @@ kind: Application
metadata:
annotations:
addons.oam.dev/description: Kubernetes Terraform Controller for Azure
addons.oam.dev/name: terraform/provider-azure
name: terraform-provider-azure
addons.oam.dev/name: terraform-azure
name: terraform-azure
namespace: vela-system
spec:
workflow:
steps:
- type: depends-on-app
properties:
name: terraform
namespace: vela-system
- type: apply-application
components:
- name: azure-account-creds
properties:

View File

@@ -1,3 +0,0 @@
# terraform/provider-alibaba
This addon contains terraform provider for Alibaba Cloud.

View File

@@ -1,3 +0,0 @@
# terraform/provider-aws
This addon contains terraform provider for AWS

View File

@@ -1,3 +0,0 @@
# terraform/provider-azure
This addon contains terraform provider for Azure.

View File

@@ -1,4 +0,0 @@
# Terraform
This addon contains terraform operation kit, which allows you to arrange,
generate and use cloud service from different cloud vendor.

View File

@@ -8,32 +8,19 @@ metadata:
spec:
workflow:
steps:
- name: checking-depends-on
type: depends-on-app
- type: depends-on-app
properties:
name: fluxcd
namespace: vela-system
- name: apply-ns
type: apply-component
properties:
component: ns-terraform-system
- name: apply-resources
type: apply-remaining
- type: apply-application
components:
- name: ns-terraform-system
type: raw
properties:
apiVersion: v1
kind: Namespace
metadata:
name: terraform-system
- name: terraform-controller
type: helm
properties:
repoType: helm
url: https://charts.kubevela.net/addons
chart: terraform-controller
version: 0.2.5
version: 0.2.8
{{ range .ResourceFiles }}
- name: {{ .Name }}
type: raw