diff --git a/Makefile b/Makefile index 255ad4a..e15d903 100644 --- a/Makefile +++ b/Makefile @@ -39,8 +39,6 @@ testacc: # METAKUBE_K8S_VERSION - the kubernetes version # METAKUBE_K8S_OLDER_VERSION - lower kubernetes version then METAKUBE_K8S_VERSION # METAKUBE_OPENSTACK_AUTH_URL -# METAKUBE_OPENSTACK_APPLICATION_CREDENTIALS_ID -# METAKUBE_OPENSTACK_APPLICATION_CREDENTIALS_SECRET # METAKUBE_OPENSTACK_IMAGE - an image available for openstack clusters # METAKUBE_OPENSTACK_IMAGE2 - another image available for openstack clusters # METAKUBE_OPENSTACK_FLAVOR - openstack flavor to use diff --git a/metakube/resource_cluster_schema.go b/metakube/resource_cluster_schema.go index 775301f..669c47c 100644 --- a/metakube/resource_cluster_schema.go +++ b/metakube/resource_cluster_schema.go @@ -156,7 +156,7 @@ func metakubeResourceClusterSpecFields() map[string]*schema.Schema { "type": { Type: schema.TypeString, Required: true, - ValidateFunc: validation.StringInSlice([]string{"canal", "none"}, false), + ValidateFunc: validation.StringInSlice([]string{"cilium", "canal", "none"}, false), Description: "Define the type of CNI plugin", }, }, diff --git a/metakube/resource_cluster_structure_test.go b/metakube/resource_cluster_structure_test.go index 562fc85..d1571a7 100644 --- a/metakube/resource_cluster_structure_test.go +++ b/metakube/resource_cluster_structure_test.go @@ -107,7 +107,17 @@ func TestFlattenCniPlugin(t *testing.T) { ExpectedOutput []interface{} }{ { + &models.CNIPluginSettings{ + Type: models.CNIPluginType("cilium"), + }, + []interface{}{ + map[string]interface{}{ + "type": "cilium", + }, + }, + }, + { &models.CNIPluginSettings{ Type: models.CNIPluginType("canal"), }, diff --git a/metakube/resource_cluster_test.go b/metakube/resource_cluster_test.go index 2a0c8b2..5ab62dc 100644 --- a/metakube/resource_cluster_test.go +++ b/metakube/resource_cluster_test.go @@ -71,6 +71,12 @@ func TestAccMetakubeCluster_Openstack_Basic(t *testing.T) { if err := clusterOpenstackBasicTemplate3.Execute(&config3, data); err != nil { t.Fatal(err) } + data.CNIPlugin = "cilium" + var config4 strings.Builder + if err := clusterOpenstackBasicTemplate.Execute(&config4, data); err != nil { + t.Fatal(err) + } + t.Log("Generated randomname: ", data.Name) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheckForOpenstack(t) @@ -184,6 +190,37 @@ func TestAccMetakubeCluster_Openstack_Basic(t *testing.T) { resource.TestCheckResourceAttrSet(resourceName, "deletion_timestamp"), ), }, + { + Config: config4.String(), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckMetaKubeClusterExists(&cluster), + testAccCheckMetaKubeClusterOpenstackAttributes(&cluster, data.Name, data.DatacenterName, data.Version, false), + resource.TestCheckResourceAttr(resourceName, "dc_name", data.DatacenterName), + resource.TestCheckResourceAttr(resourceName, "name", data.Name), + resource.TestCheckResourceAttr(resourceName, "labels.%", "2"), + resource.TestCheckResourceAttr(resourceName, "labels.a", "b"), + resource.TestCheckResourceAttr(resourceName, "labels.c", "d"), + resource.TestCheckResourceAttr(resourceName, "spec.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.version", data.Version), + resource.TestCheckResourceAttr(resourceName, "spec.0.update_window.0.start", "Tue 02:00"), + resource.TestCheckResourceAttr(resourceName, "spec.0.update_window.0.length", "2h"), + resource.TestCheckResourceAttr(resourceName, "spec.0.services_cidr", "10.240.16.0/18"), + resource.TestCheckResourceAttr(resourceName, "spec.0.pods_cidr", "172.25.0.0/18"), + resource.TestCheckResourceAttr(resourceName, "spec.0.cni_plugin.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.cni_plugin.0.type", "cilium"), + resource.TestCheckResourceAttr(resourceName, "spec.0.cloud.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.cloud.0.aws.#", "0"), + resource.TestCheckResourceAttr(resourceName, "spec.0.cloud.0.openstack.#", "1"), + resource.TestCheckResourceAttrSet(resourceName, "spec.0.cloud.0.openstack.0.security_group"), + resource.TestCheckResourceAttrSet(resourceName, "spec.0.cloud.0.openstack.0.network"), + resource.TestCheckResourceAttrSet(resourceName, "spec.0.cloud.0.openstack.0.subnet_id"), + resource.TestCheckResourceAttr(resourceName, "spec.0.cloud.0.openstack.0.subnet_cidr", "192.168.2.0/24"), + resource.TestCheckResourceAttrSet(resourceName, "kube_config"), + resource.TestCheckResourceAttr(resourceName, "spec.0.audit_logging", "false"), + resource.TestCheckResourceAttrSet(resourceName, "creation_timestamp"), + resource.TestCheckResourceAttrSet(resourceName, "deletion_timestamp"), + ), + }, { ResourceName: resourceName, ImportState: true, @@ -307,6 +344,7 @@ type clusterOpenstackBasicData struct { DatacenterName string ProjectID string Version string + CNIPlugin string } var clusterOpenstackBasicTemplate = mustParseTemplate("clusterOpenstackBasic", ` @@ -318,10 +356,6 @@ terraform { } } -data "metakube_project" "something" { - name = "some" -} - provider "openstack" { auth_url = "{{ .OpenstackAuthURL }}" user_name = "{{ .OpenstackUser }}" @@ -367,6 +401,11 @@ resource "metakube_cluster" "acctest_cluster" { } services_cidr = "10.240.16.0/18" pods_cidr = "172.25.0.0/18" + {{if .CNIPlugin}} + cni_plugin { + type = "{{ .CNIPlugin }}" + } + {{end}} } }