From e0c8cf022ad5ba9a5817b3ab565b8d29bb9e8563 Mon Sep 17 00:00:00 2001 From: Ales Stimec Date: Mon, 16 Dec 2024 08:15:51 +0100 Subject: [PATCH] fix: kubernetes cloud resource --- .github/workflows/test_integration.yml | 8 ++++---- .github/workflows/test_integration_jaas.yaml | 9 +++++++-- .../provider/resource_kubernetes_cloud.go | 12 +++++++---- .../resource_kubernetes_cloud_test.go | 20 +++++++++++-------- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test_integration.yml b/.github/workflows/test_integration.yml index f75fca2a..64b59767 100644 --- a/.github/workflows/test_integration.yml +++ b/.github/workflows/test_integration.yml @@ -102,8 +102,8 @@ jobs: - env: TF_ACC: "1" TEST_CLOUD: ${{ matrix.action-operator.cloud }} - run: go test -parallel 1 -timeout 60m -v -cover ./internal/provider/ - timeout-minutes: 40 + run: go test -parallel 5 -timeout 60m -v -cover ./internal/provider/ + timeout-minutes: 60 # Run acceptance tests in a matrix with Terraform CLI versions add-machine-test: @@ -189,5 +189,5 @@ jobs: echo "Running the test" cd ./internal/provider/ - go test ./... -timeout 30m -v -test.run TestAcc_ResourceMachine_AddMachine - timeout-minutes: 40 + go test ./... -timeout 60m -v -test.run TestAcc_ResourceMachine_AddMachine + timeout-minutes: 60 diff --git a/.github/workflows/test_integration_jaas.yaml b/.github/workflows/test_integration_jaas.yaml index 6473a4cb..a67e74c3 100644 --- a/.github/workflows/test_integration_jaas.yaml +++ b/.github/workflows/test_integration_jaas.yaml @@ -84,6 +84,10 @@ jobs: run: | sudo lxc network create management-br ipv4.address=10.150.40.1/24 ipv4.nat=true ipv6.address=none ipv6.nat=false sudo lxc network create public-br ipv4.address=10.170.80.1/24 ipv4.nat=true ipv6.address=none ipv6.nat=false + - name: Show debug info + run: | + juju clouds + juju show-cloud localhost - name: "Set environment to configure provider" # language=bash run: | @@ -103,5 +107,6 @@ jobs: - env: TF_ACC: "1" TEST_CLOUD: "lxd" - run: go test -parallel 1 -timeout 40m -v -cover ./internal/provider/ - timeout-minutes: 40 + run: go test -parallel 5 -timeout 60m -v -cover ./internal/provider/ + timeout-minutes: 60 + diff --git a/internal/provider/resource_kubernetes_cloud.go b/internal/provider/resource_kubernetes_cloud.go index d7a5858a..b02f8b7e 100644 --- a/internal/provider/resource_kubernetes_cloud.go +++ b/internal/provider/resource_kubernetes_cloud.go @@ -128,8 +128,10 @@ func (r *kubernetesCloudResource) Create(ctx context.Context, req resource.Creat // Create the kubernetes cloud. cloudCredentialName, err := r.client.Clouds.CreateKubernetesCloud( &juju.CreateKubernetesCloudInput{ - Name: plan.CloudName.ValueString(), - KubernetesConfig: plan.KubernetesConfig.ValueString(), + Name: plan.CloudName.ValueString(), + KubernetesConfig: plan.KubernetesConfig.ValueString(), + ParentCloudName: plan.ParentCloudName.ValueString(), + ParentCloudRegion: plan.ParentCloudRegion.ValueString(), }, ) if err != nil { @@ -201,8 +203,10 @@ func (r *kubernetesCloudResource) Update(ctx context.Context, req resource.Updat // Update the kubernetes cloud. err := r.client.Clouds.UpdateKubernetesCloud( juju.UpdateKubernetesCloudInput{ - Name: plan.CloudName.ValueString(), - KubernetesConfig: plan.KubernetesConfig.ValueString(), + Name: plan.CloudName.ValueString(), + KubernetesConfig: plan.KubernetesConfig.ValueString(), + ParentCloudName: plan.ParentCloudName.ValueString(), + ParentCloudRegion: plan.ParentCloudRegion.ValueString(), }, ) if err != nil { diff --git a/internal/provider/resource_kubernetes_cloud_test.go b/internal/provider/resource_kubernetes_cloud_test.go index 5a6aafc1..e92ea054 100644 --- a/internal/provider/resource_kubernetes_cloud_test.go +++ b/internal/provider/resource_kubernetes_cloud_test.go @@ -14,12 +14,6 @@ import ( ) func TestAcc_ResourceKubernetesCloud(t *testing.T) { - // Note (alesstimec): Skipping this test, because the default - // hosted cloud tf provider adds is "other", which cannot - // be parsed by JIMM - it needs a valid cloud/region to determine - // which controller to add the cloud to. - SkipJAAS(t) - // TODO: This test is not adding model as a resource, which is required. // The reason in the race that we (potentially) have in the Juju side. // Once the problem is fixed (https://bugs.launchpad.net/juju/+bug/2084448), @@ -30,12 +24,17 @@ func TestAcc_ResourceKubernetesCloud(t *testing.T) { cloudName := acctest.RandomWithPrefix("tf-test-k8scloud") cloudConfig := os.Getenv("MICROK8S_CONFIG") + jaasTest := false + if _, ok := os.LookupEnv("IS_JAAS"); ok { + jaasTest = true + } + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: frameworkProviderFactories, Steps: []resource.TestStep{ { - Config: testAccResourceKubernetesCloudWithoutModel(cloudName, cloudConfig), + Config: testAccResourceKubernetesCloudWithoutModel(cloudName, cloudConfig, jaasTest), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("juju_kubernetes_cloud."+cloudName, "name", cloudName), ), @@ -44,16 +43,21 @@ func TestAcc_ResourceKubernetesCloud(t *testing.T) { }) } -func testAccResourceKubernetesCloudWithoutModel(cloudName string, config string) string { +func testAccResourceKubernetesCloudWithoutModel(cloudName string, config string, jaasTest bool) string { return internaltesting.GetStringFromTemplateWithData( "testAccResourceSecret", ` resource "juju_kubernetes_cloud" "{{.CloudName}}" { name = "{{.CloudName}}" kubernetes_config = file("~/microk8s-config.yaml") + {{ if .JAASTest }} + parent_cloud_name = "lxd" + parent_cloud_region = "localhost" + {{ end }} } `, internaltesting.TemplateData{ "CloudName": cloudName, "Config": config, + "JAASTest": jaasTest, }) }