Skip to content

Commit

Permalink
fix: kubernetes cloud resource
Browse files Browse the repository at this point in the history
  • Loading branch information
alesstimec committed Dec 16, 2024
1 parent 54f8588 commit c2ced71
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test_integration_jaas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
12 changes: 8 additions & 4 deletions internal/provider/resource_kubernetes_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 12 additions & 8 deletions internal/provider/resource_kubernetes_cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
),
Expand All @@ -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 = "localhost"
parent_cloud_region = "localhost"
{{ end }}
}
`, internaltesting.TemplateData{
"CloudName": cloudName,
"Config": config,
"JAASTest": jaasTest,
})
}

0 comments on commit c2ced71

Please sign in to comment.