From 6bc093f5b27f03610bab109657e0b2bab4c0079e Mon Sep 17 00:00:00 2001 From: Zheng Xi Zhou Date: Thu, 28 Apr 2022 10:46:40 +0800 Subject: [PATCH 1/3] Support inline credentials besides provider Fix https://github.com/oam-dev/terraform-controller/issues/290 Signed-off-by: Zheng Xi Zhou --- api/v1beta2/configuration_types.go | 9 +++ controllers/configuration/configuration.go | 4 ++ .../configuration/configuration_test.go | 61 +++++++++++++------ controllers/configuration_controller.go | 30 +++++---- controllers/configuration_controller_test.go | 14 ++--- 5 files changed, 78 insertions(+), 40 deletions(-) diff --git a/api/v1beta2/configuration_types.go b/api/v1beta2/configuration_types.go index 2700cd79..6e54c245 100644 --- a/api/v1beta2/configuration_types.go +++ b/api/v1beta2/configuration_types.go @@ -58,6 +58,15 @@ type BaseConfigurationSpec struct { // ProviderReference specifies the reference to Provider ProviderReference *types.Reference `json:"providerRef,omitempty"` + // InlineCredentials specifies the credentials in spec.HCl field as below. + // provider "aws" { + // region = "us-west-2" + // access_key = "my-access-key" + // secret_key = "my-secret-key" + // } + // +kubebuilder:default:=false + InlineCredentials bool `json:"inlineCredentials,omitempty"` + // DeleteResource will determine whether provisioned cloud resources will be deleted when CR is deleted // +kubebuilder:default:=true DeleteResource bool `json:"deleteResource,omitempty"` diff --git a/controllers/configuration/configuration.go b/controllers/configuration/configuration.go index 18000425..2b03d942 100644 --- a/controllers/configuration/configuration.go +++ b/controllers/configuration/configuration.go @@ -113,6 +113,10 @@ func Get(ctx context.Context, k8sClient client.Client, namespacedName apitypes.N // IsDeletable will check whether the Configuration can be deleted immediately // If deletable, it means no external cloud resources are provisioned func IsDeletable(ctx context.Context, k8sClient client.Client, configuration *v1beta2.Configuration) (bool, error) { + // If credentials is inline in spec.HCL of the configuration, which is a simple scenario, the Configuration is allowed to be deleted + if configuration.Spec.InlineCredentials { + return true, nil + } providerRef := GetProviderNamespacedName(*configuration) providerObj, err := provider.GetProviderFromConfiguration(ctx, k8sClient, providerRef.Namespace, providerRef.Name) if err != nil { diff --git a/controllers/configuration/configuration_test.go b/controllers/configuration/configuration_test.go index 350bbac5..112ff494 100644 --- a/controllers/configuration/configuration_test.go +++ b/controllers/configuration/configuration_test.go @@ -279,6 +279,31 @@ func TestIsDeletable(t *testing.T) { Name: "default", Namespace: "default", } + configuration.Spec.InlineCredentials = false + + defaultConfiguration := &v1beta2.Configuration{} + defaultConfiguration.Spec.InlineCredentials = false + + provisioningConfiguration := &v1beta2.Configuration{ + Status: v1beta2.ConfigurationStatus{ + Apply: v1beta2.ConfigurationApplyStatus{ + State: types.ConfigurationProvisioningAndChecking, + }, + }, + } + provisioningConfiguration.Spec.InlineCredentials = false + + readyConfiguration := &v1beta2.Configuration{ + Status: v1beta2.ConfigurationStatus{ + Apply: v1beta2.ConfigurationApplyStatus{ + State: types.Available, + }, + }, + } + readyConfiguration.Spec.InlineCredentials = false + + inlineConfiguration := &v1beta2.Configuration{} + inlineConfiguration.Spec.InlineCredentials = true type args struct { configuration *v1beta2.Configuration @@ -297,7 +322,7 @@ func TestIsDeletable(t *testing.T) { name: "provider is not found", args: args{ k8sClient: k8sClient1, - configuration: &v1beta2.Configuration{}, + configuration: defaultConfiguration, }, want: want{ deletable: true, @@ -307,7 +332,7 @@ func TestIsDeletable(t *testing.T) { name: "provider is not ready, use default providerRef", args: args{ k8sClient: k8sClient2, - configuration: &v1beta2.Configuration{}, + configuration: defaultConfiguration, }, want: want{ deletable: true, @@ -326,14 +351,8 @@ func TestIsDeletable(t *testing.T) { { name: "configuration is provisioning", args: args{ - k8sClient: k8sClient3, - configuration: &v1beta2.Configuration{ - Status: v1beta2.ConfigurationStatus{ - Apply: v1beta2.ConfigurationApplyStatus{ - State: types.ConfigurationProvisioningAndChecking, - }, - }, - }, + k8sClient: k8sClient3, + configuration: provisioningConfiguration, }, want: want{ errMsg: "Destroy could not complete and needs to wait for Provision to complete first", @@ -342,14 +361,8 @@ func TestIsDeletable(t *testing.T) { { name: "configuration is ready", args: args{ - k8sClient: k8sClient3, - configuration: &v1beta2.Configuration{ - Status: v1beta2.ConfigurationStatus{ - Apply: v1beta2.ConfigurationApplyStatus{ - State: types.Available, - }, - }, - }, + k8sClient: k8sClient3, + configuration: readyConfiguration, }, want: want{}, }, @@ -357,12 +370,22 @@ func TestIsDeletable(t *testing.T) { name: "failed to get provider", args: args{ k8sClient: k8sClient4, - configuration: &v1beta2.Configuration{}, + configuration: defaultConfiguration, }, want: want{ errMsg: "failed to get Provider object", }, }, + { + name: "no provider is needed", + args: args{ + k8sClient: k8sClient4, + configuration: inlineConfiguration, + }, + want: want{ + deletable: true, + }, + }, } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { diff --git a/controllers/configuration_controller.go b/controllers/configuration_controller.go index 5a087ec2..1d3613f5 100644 --- a/controllers/configuration_controller.go +++ b/controllers/configuration_controller.go @@ -267,7 +267,9 @@ func initTFConfigurationMeta(req ctrl.Request, configuration v1beta2.Configurati meta.RemoteGitPath = configuration.Spec.Path } - meta.ProviderReference = tfcfg.GetProviderNamespacedName(configuration) + if !configuration.Spec.InlineCredentials { + meta.ProviderReference = tfcfg.GetProviderNamespacedName(configuration) + } // Check the existence of Terraform state secret which is used to store TF state file. For detailed information, // please refer to https://www.terraform.io/docs/language/settings/backends/kubernetes.html#configuration-variables @@ -519,20 +521,22 @@ func (r *ConfigurationReconciler) preCheck(ctx context.Context, configuration *v } // Check provider - p, err := provider.GetProviderFromConfiguration(ctx, k8sClient, meta.ProviderReference.Namespace, meta.ProviderReference.Name) - if p == nil { - msg := types.ErrProviderNotFound - if err != nil { - msg = err.Error() - } - if updateStatusErr := meta.updateApplyStatus(ctx, k8sClient, types.Authorizing, msg); updateStatusErr != nil { - return errors.Wrap(updateStatusErr, msg) + if !configuration.Spec.InlineCredentials { + p, err := provider.GetProviderFromConfiguration(ctx, k8sClient, meta.ProviderReference.Namespace, meta.ProviderReference.Name) + if p == nil { + msg := types.ErrProviderNotFound + if err != nil { + msg = err.Error() + } + if updateStatusErr := meta.updateApplyStatus(ctx, k8sClient, types.Authorizing, msg); updateStatusErr != nil { + return errors.Wrap(updateStatusErr, msg) + } + return errors.New(msg) } - return errors.New(msg) - } - if err := meta.getCredentials(ctx, k8sClient, p); err != nil { - return err + if err := meta.getCredentials(ctx, k8sClient, p); err != nil { + return err + } } // Check whether env changes diff --git a/controllers/configuration_controller_test.go b/controllers/configuration_controller_test.go index 71b56109..9647f128 100644 --- a/controllers/configuration_controller_test.go +++ b/controllers/configuration_controller_test.go @@ -17,10 +17,8 @@ import ( batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" - kerrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -34,7 +32,6 @@ import ( "github.com/oam-dev/terraform-controller/api/types" crossplane "github.com/oam-dev/terraform-controller/api/types/crossplane-runtime" - runtimetypes "github.com/oam-dev/terraform-controller/api/types/crossplane-runtime" "github.com/oam-dev/terraform-controller/api/v1beta1" "github.com/oam-dev/terraform-controller/api/v1beta2" "github.com/oam-dev/terraform-controller/controllers/provider" @@ -60,6 +57,7 @@ func TestInitTFConfigurationMeta(t *testing.T) { Name: "xxx", Namespace: "default", } + completeConfiguration.Spec.InlineCredentials = false testcases := []struct { name string @@ -1388,7 +1386,7 @@ func TestGetTFOutputs(t *testing.T) { configuration4 := v1beta2.Configuration{ Spec: v1beta2.ConfigurationSpec{ BaseConfigurationSpec: v1beta2.BaseConfigurationSpec{ - WriteConnectionSecretToReference: &runtimetypes.SecretReference{ + WriteConnectionSecretToReference: &crossplane.SecretReference{ Name: "connection-secret-c", Namespace: "default", }, @@ -1431,7 +1429,7 @@ func TestGetTFOutputs(t *testing.T) { }, Spec: v1beta2.ConfigurationSpec{ BaseConfigurationSpec: v1beta2.BaseConfigurationSpec{ - WriteConnectionSecretToReference: &runtimetypes.SecretReference{ + WriteConnectionSecretToReference: &crossplane.SecretReference{ Name: "connection-secret-d", Namespace: "default", }, @@ -1476,7 +1474,7 @@ func TestGetTFOutputs(t *testing.T) { }, Spec: v1beta2.ConfigurationSpec{ BaseConfigurationSpec: v1beta2.BaseConfigurationSpec{ - WriteConnectionSecretToReference: &runtimetypes.SecretReference{ + WriteConnectionSecretToReference: &crossplane.SecretReference{ Name: "connection-secret-e", Namespace: "default", }, @@ -1523,7 +1521,7 @@ func TestGetTFOutputs(t *testing.T) { }, Spec: v1beta2.ConfigurationSpec{ BaseConfigurationSpec: v1beta2.BaseConfigurationSpec{ - WriteConnectionSecretToReference: &runtimetypes.SecretReference{ + WriteConnectionSecretToReference: &crossplane.SecretReference{ Name: "connection-secret-e", Namespace: "default", }, @@ -1565,7 +1563,7 @@ func TestGetTFOutputs(t *testing.T) { }, Spec: v1beta2.ConfigurationSpec{ BaseConfigurationSpec: v1beta2.BaseConfigurationSpec{ - WriteConnectionSecretToReference: &runtimetypes.SecretReference{ + WriteConnectionSecretToReference: &crossplane.SecretReference{ Name: "connection-secret-d", Namespace: "default", }, From 7635134cd8cc24be1d18b9f6f10d23a7a1c72e4f Mon Sep 17 00:00:00 2001 From: Zheng Xi Zhou Date: Mon, 9 May 2022 16:02:11 +0800 Subject: [PATCH 2/3] add e2e Signed-off-by: Zheng Xi Zhou --- CONTRIBUTING.md | 8 +++ api/v1beta2/configuration_types.go | 2 +- ...terraform.core.oam.dev_configurations.yaml | 7 ++ controllers/configuration/configuration.go | 24 ++++--- controllers/configuration_controller.go | 8 +-- e2e/configuration_test.go | 49 +++++++------- examples/alibaba/inline-credentials/eip.yaml | 65 +++++++++++++++++++ examples/random/configuration_random.yaml | 19 ++++++ examples/tf-native/random/main.tf | 7 ++ hack/e2e-test.yml | 62 ------------------ 10 files changed, 144 insertions(+), 107 deletions(-) create mode 100644 examples/alibaba/inline-credentials/eip.yaml create mode 100644 examples/random/configuration_random.yaml create mode 100644 examples/tf-native/random/main.tf delete mode 100644 hack/e2e-test.yml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f106e991..401f5b07 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -151,3 +151,11 @@ Bucket Number is: 0 0.030917(s) elapsed ``` + +## Generate CRDs + +```shell +$ make manifests +go: creating new go.mod: module tmp +/Users/zhouzhengxi/go/bin/controller-gen "crd:trivialVersions=true" webhook paths="./..." output:crd:artifacts:config=chart/crds +``` diff --git a/api/v1beta2/configuration_types.go b/api/v1beta2/configuration_types.go index 6e54c245..8fe41e4a 100644 --- a/api/v1beta2/configuration_types.go +++ b/api/v1beta2/configuration_types.go @@ -64,7 +64,7 @@ type BaseConfigurationSpec struct { // access_key = "my-access-key" // secret_key = "my-secret-key" // } - // +kubebuilder:default:=false + // Or indicates a Terraform module or configuration don't need credentials at all, like provider `random` InlineCredentials bool `json:"inlineCredentials,omitempty"` // DeleteResource will determine whether provisioned cloud resources will be deleted when CR is deleted diff --git a/chart/crds/terraform.core.oam.dev_configurations.yaml b/chart/crds/terraform.core.oam.dev_configurations.yaml index 8d4528e8..7074cc26 100644 --- a/chart/crds/terraform.core.oam.dev_configurations.yaml +++ b/chart/crds/terraform.core.oam.dev_configurations.yaml @@ -215,6 +215,13 @@ spec: hcl: description: HCL is the Terraform HCL type configuration type: string + inlineCredentials: + description: "InlineCredentials specifies the credentials in spec.HCl + field as below. \tprovider \"aws\" { \t\tregion = \"us-west-2\" + \t\taccess_key = \"my-access-key\" \t\tsecret_key = \"my-secret-key\" + \t} Or indicates a Terraform module or configuration don't need + credentials at all, like provider `random`" + type: boolean path: description: Path is the sub-directory of remote git repository. type: string diff --git a/controllers/configuration/configuration.go b/controllers/configuration/configuration.go index 2b03d942..74e775b8 100644 --- a/controllers/configuration/configuration.go +++ b/controllers/configuration/configuration.go @@ -113,19 +113,17 @@ func Get(ctx context.Context, k8sClient client.Client, namespacedName apitypes.N // IsDeletable will check whether the Configuration can be deleted immediately // If deletable, it means no external cloud resources are provisioned func IsDeletable(ctx context.Context, k8sClient client.Client, configuration *v1beta2.Configuration) (bool, error) { - // If credentials is inline in spec.HCL of the configuration, which is a simple scenario, the Configuration is allowed to be deleted - if configuration.Spec.InlineCredentials { - return true, nil - } - providerRef := GetProviderNamespacedName(*configuration) - providerObj, err := provider.GetProviderFromConfiguration(ctx, k8sClient, providerRef.Namespace, providerRef.Name) - if err != nil { - return false, err - } - // allow Configuration to delete when the Provider doesn't exist or is not ready, which means external cloud resources are - // not provisioned at all - if providerObj == nil || providerObj.Status.State == types.ProviderIsNotReady || configuration.Status.Apply.State == types.TerraformInitError { - return true, nil + if !configuration.Spec.InlineCredentials { + providerRef := GetProviderNamespacedName(*configuration) + providerObj, err := provider.GetProviderFromConfiguration(ctx, k8sClient, providerRef.Namespace, providerRef.Name) + if err != nil { + return false, err + } + // allow Configuration to delete when the Provider doesn't exist or is not ready, which means external cloud resources are + // not provisioned at all + if providerObj == nil || providerObj.Status.State == types.ProviderIsNotReady || configuration.Status.Apply.State == types.TerraformInitError { + return true, nil + } } if configuration.Status.Apply.State == types.ConfigurationProvisioningAndChecking { diff --git a/controllers/configuration_controller.go b/controllers/configuration_controller.go index 1d3613f5..9b2fecf0 100644 --- a/controllers/configuration_controller.go +++ b/controllers/configuration_controller.go @@ -957,7 +957,7 @@ func (meta *TFConfigurationMeta) prepareTFVariables(configuration *v1beta2.Confi if configuration == nil { return errors.New("configuration is nil") } - if meta.ProviderReference == nil { + if !configuration.Spec.InlineCredentials && meta.ProviderReference == nil { return errors.New("The referenced provider could not be retrieved") } @@ -976,7 +976,7 @@ func (meta *TFConfigurationMeta) prepareTFVariables(configuration *v1beta2.Confi envs = append(envs, v1.EnvVar{Name: k, ValueFrom: valueFrom}) } - if meta.Credentials == nil { + if !configuration.Spec.InlineCredentials && meta.Credentials == nil { return errors.New(provider.ErrCredentialNotRetrieved) } for k, v := range meta.Credentials { @@ -985,10 +985,6 @@ func (meta *TFConfigurationMeta) prepareTFVariables(configuration *v1beta2.Confi valueFrom.SecretKeyRef.Name = meta.VariableSecretName envs = append(envs, v1.EnvVar{Name: k, ValueFrom: valueFrom}) } - // make sure the env of the Job is set - if envs == nil { - return errors.New(provider.ErrCredentialNotRetrieved) - } meta.Envs = envs meta.VariableSecretData = data diff --git a/e2e/configuration_test.go b/e2e/configuration_test.go index 8d4d4b2a..11c3c667 100644 --- a/e2e/configuration_test.go +++ b/e2e/configuration_test.go @@ -23,24 +23,23 @@ const ( ) var ( - testConfigurationsBasic = "examples/alibaba/eip/configuration_eip.yaml" - testConfigurationsRegression = []string{ + testConfigurationsInlineCredentials = "examples/random/configuration_random.yaml" + testConfigurationsRegression = []string{ "examples/alibaba/eip/configuration_eip.yaml", "examples/alibaba/eip/configuration_eip_remote_in_another_namespace.yaml", "examples/alibaba/eip/configuration_eip_remote_subdirectory.yaml", - // "examples/alibaba/rds/configuration_hcl_rds.yaml", "examples/alibaba/oss/configuration_hcl_bucket.yaml", } ) -func TestBasicConfiguration(t *testing.T) { +func TestInlineCredentialsConfiguration(t *testing.T) { clientSet, err := client.Init() assert.NilError(t, err) ctx := context.Background() klog.Info("1. Applying Configuration") pwd, _ := os.Getwd() - configuration := filepath.Join(pwd, "..", testConfigurationsBasic) + configuration := filepath.Join(pwd, "..", testConfigurationsInlineCredentials) cmd := fmt.Sprintf("kubectl apply -f %s", configuration) err = exec.Command("bash", "-c", cmd).Start() assert.NilError(t, err) @@ -57,7 +56,7 @@ func TestBasicConfiguration(t *testing.T) { continue } fields = strings.Fields(line) - if len(fields) == 3 && fields[0] == "alibaba-eip" && fields[1] == Available { + if len(fields) == 3 && fields[0] == "random-e2e" && fields[1] == Available { goto continueCheck } } @@ -68,22 +67,22 @@ func TestBasicConfiguration(t *testing.T) { } continueCheck: - klog.Info("3. Checking Configuration status") + klog.Info("3. Checking the status of Configs and Secrets") klog.Info("- Checking ConfigMap which stores .tf") - _, err = clientSet.CoreV1().ConfigMaps("default").Get(ctx, "tf-alibaba-eip", v1.GetOptions{}) + _, err = clientSet.CoreV1().ConfigMaps("default").Get(ctx, "tf-random-e2e", v1.GetOptions{}) assert.NilError(t, err) klog.Info("- Checking Secret which stores Backend") - _, err = clientSet.CoreV1().Secrets(backendSecretNamespace).Get(ctx, "tfstate-default-alibaba-eip", v1.GetOptions{}) + _, err = clientSet.CoreV1().Secrets(backendSecretNamespace).Get(ctx, "tfstate-default-random-e2e", v1.GetOptions{}) assert.NilError(t, err) klog.Info("- Checking Secret which stores outputs") - _, err = clientSet.CoreV1().Secrets("default").Get(ctx, "eip-conn", v1.GetOptions{}) + _, err = clientSet.CoreV1().Secrets("default").Get(ctx, "random-conn", v1.GetOptions{}) assert.NilError(t, err) klog.Info("- Checking Secret which stores variables") - _, err = clientSet.CoreV1().Secrets("default").Get(ctx, "variable-alibaba-eip", v1.GetOptions{}) + _, err = clientSet.CoreV1().Secrets("default").Get(ctx, "variable-random-e2e", v1.GetOptions{}) assert.NilError(t, err) klog.Info("4. Deleting Configuration") @@ -107,7 +106,7 @@ continueCheck: continue } fields = strings.Fields(line) - if len(fields) == 3 && fields[0] == "alibaba-eip" { + if len(fields) == 3 && fields[0] == "random-e2e" { existed = true } } @@ -124,25 +123,25 @@ continueCheck: } klog.Info("6. Checking Secrets and ConfigMap which should all be deleted") - _, err = clientSet.CoreV1().Secrets("default").Get(ctx, "variable-alibaba-eip", v1.GetOptions{}) + _, err = clientSet.CoreV1().Secrets("default").Get(ctx, "variable-random-e2e", v1.GetOptions{}) assert.Equal(t, kerrors.IsNotFound(err), true) - _, err = clientSet.CoreV1().Secrets("default").Get(ctx, "eip-conn", v1.GetOptions{}) + _, err = clientSet.CoreV1().Secrets("default").Get(ctx, "random-conn", v1.GetOptions{}) assert.Equal(t, kerrors.IsNotFound(err), true) - _, err = clientSet.CoreV1().Secrets(backendSecretNamespace).Get(ctx, "tfstate-default-alibaba-eip", v1.GetOptions{}) + _, err = clientSet.CoreV1().Secrets(backendSecretNamespace).Get(ctx, "tfstate-default-random-e2e", v1.GetOptions{}) assert.Equal(t, kerrors.IsNotFound(err), true) - _, err = clientSet.CoreV1().ConfigMaps("default").Get(ctx, "tf-alibaba-eip", v1.GetOptions{}) + _, err = clientSet.CoreV1().ConfigMaps("default").Get(ctx, "tf-random-e2e", v1.GetOptions{}) assert.Equal(t, kerrors.IsNotFound(err), true) } -func TestBasicConfigurationRegression(t *testing.T) { - var retryTimes = 120 - - klog.Info("0. Create namespace") - err := exec.Command("bash", "-c", "kubectl create ns abc").Start() - assert.NilError(t, err) - - Regression(t, testConfigurationsRegression, retryTimes) -} +//func TestBasicConfigurationRegression(t *testing.T) { +// var retryTimes = 120 +// +// klog.Info("0. Create namespace") +// err := exec.Command("bash", "-c", "kubectl create ns abc").Start() +// assert.NilError(t, err) +// +// Regression(t, testConfigurationsRegression, retryTimes) +//} diff --git a/examples/alibaba/inline-credentials/eip.yaml b/examples/alibaba/inline-credentials/eip.yaml new file mode 100644 index 00000000..cf736902 --- /dev/null +++ b/examples/alibaba/inline-credentials/eip.yaml @@ -0,0 +1,65 @@ +apiVersion: terraform.core.oam.dev/v1beta2 +kind: Configuration +metadata: + name: alibaba-eip-inline +spec: + hcl: | + provider "alicloud" { + access_key = var.access_key + secret_key = var.secret_key + region = var.region + } + + resource "alicloud_eip" "this" { + bandwidth = var.bandwidth + address_name = var.address_name + } + + variable "address_name" { + description = "Name to be used on all resources as prefix. Default to 'TF-Module-EIP'." + default = "TF-Module-EIP" + type = string + } + + variable "bandwidth" { + description = "Maximum bandwidth to the elastic public network, measured in Mbps (Mega bit per second)." + type = number + default = 1 + } + + variable "access_key" { + description = "Access Key ID of the Alibaba Cloud account." + type = string + } + + variable "secret_key" { + description = "Access Key Secret of the Alibaba Cloud account." + type = string + } + + variable "region" { + description = "Region of the Alibaba Cloud account." + type = string + default = "cn-beijing" + } + + output "EIP_ADDRESS" { + description = "The elastic ip address." + value = alicloud_eip.this.ip_address + } + + output "NAME" { + value = var.address_name + } + + variable: + access_key: xxx + secret_key: yyy + + inlineCredentials: true + + writeConnectionSecretToRef: + name: eip-e2e-inline + namespace: default + + diff --git a/examples/random/configuration_random.yaml b/examples/random/configuration_random.yaml new file mode 100644 index 00000000..320f5b6a --- /dev/null +++ b/examples/random/configuration_random.yaml @@ -0,0 +1,19 @@ +apiVersion: terraform.core.oam.dev/v1beta2 +kind: Configuration +metadata: + name: random-e2e +spec: + hcl: | + resource "random_id" "server" { + byte_length = 8 + } + + output "random_id" { + value = random_id.server.hex + } + + inlineCredentials: true + + writeConnectionSecretToRef: + name: random-conn + namespace: default diff --git a/examples/tf-native/random/main.tf b/examples/tf-native/random/main.tf new file mode 100644 index 00000000..50bc047a --- /dev/null +++ b/examples/tf-native/random/main.tf @@ -0,0 +1,7 @@ +resource "random_id" "server" { + byte_length = 8 +} + +output "random_id" { + value = random_id.server.hex +} diff --git a/hack/e2e-test.yml b/hack/e2e-test.yml deleted file mode 100644 index 63e967cc..00000000 --- a/hack/e2e-test.yml +++ /dev/null @@ -1,62 +0,0 @@ -name: E2E Test - -on: - push: - branches: - - master - workflow_dispatch: {} - pull_request: - branches: - - master - -env: - GO_VERSION: '1.17.6' - GOLANGCI_VERSION: 'v1.38' - KUBECONFIG: /home/github/.kube/config - -jobs: - e2e-tests: - runs-on: self-hosted - - steps: - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Setup Go - uses: actions/setup-go@v2 - with: - go-version: ${{ env.GO_VERSION }} - - - name: Get dependencies - run: | - go get -v -t -d ./... - - - name: Build and push images - run: | - sed -i "s/0.2.8/latest/g" Makefile - make docker-build - make docker-push - - - name: Install chart - run: | - kubectl cluster-info - echo "current-context:" $(kubectl config current-context) - - helm delete terraform-controller -n terraform - - sed -i "s/0.2.8/latest/g" chart/values.yaml - helm lint ./chart --debug - helm upgrade --install --create-namespace --namespace terraform terraform-controller ./chart - helm test -n terraform terraform-controller --timeout 5m - kubectl get pod -n terraform -l "app=terraform-controller" - - - name: E2E tests - run: | - make configuration - - - name: Upload coverage report - uses: codecov/codecov-action@v2 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: ./e2e-coverage1.xml - flags: e2e From d40417a47861b57e1c1aabbc8a4047afc87b6d5a Mon Sep 17 00:00:00 2001 From: Zheng Xi Zhou Date: Mon, 9 May 2022 16:15:46 +0800 Subject: [PATCH 3/3] fix UT Signed-off-by: Zheng Xi Zhou --- controllers/configuration/configuration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/configuration/configuration_test.go b/controllers/configuration/configuration_test.go index 112ff494..c41c98ff 100644 --- a/controllers/configuration/configuration_test.go +++ b/controllers/configuration/configuration_test.go @@ -383,7 +383,7 @@ func TestIsDeletable(t *testing.T) { configuration: inlineConfiguration, }, want: want{ - deletable: true, + deletable: false, }, }, }