Skip to content

Commit

Permalink
add support for cilium cniplugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nrobert13 committed Dec 14, 2023
1 parent a637231 commit 73416cb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion metakube/resource_cluster_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
Expand Down
10 changes: 10 additions & 0 deletions metakube/resource_cluster_structure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
Expand Down
47 changes: 43 additions & 4 deletions metakube/resource_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -307,6 +344,7 @@ type clusterOpenstackBasicData struct {
DatacenterName string
ProjectID string
Version string
CNIPlugin string
}

var clusterOpenstackBasicTemplate = mustParseTemplate("clusterOpenstackBasic", `
Expand All @@ -318,10 +356,6 @@ terraform {
}
}
data "metakube_project" "something" {
name = "some"
}
provider "openstack" {
auth_url = "{{ .OpenstackAuthURL }}"
user_name = "{{ .OpenstackUser }}"
Expand Down Expand Up @@ -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}}
}
}
Expand Down

0 comments on commit 73416cb

Please sign in to comment.