Skip to content

Commit

Permalink
Merge pull request #34 from tehcyx/feature/featureGates
Browse files Browse the repository at this point in the history
Feature/feature gates
  • Loading branch information
tehcyx authored May 14, 2023
2 parents f9ae1c6 + 6dd5de9 commit b9f7604
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ Perform the following steps to build the providers:

In order to test the provider you can run `go test ./...` for the unit tests as well as `make testacc` for the Acceptance Tests. If you prefer to only run tests and skip linting and formatting when running Acceptance Tests start them by running `TF_ACC=1 go test ./kind -v -count 1 -parallel 20 -timeout 120m`.

*Note:* Acceptance tests create real resources, and will consume significant resources on the machine they run on.
*Note:* Acceptance tests create real resources, and will consume significant resources on the machine they run on.

## Release

In order to be able to release a new version this repository needs signed git commits when pushing a tag in order to pick that up and start a new goreleaser run.

To set this up on Windows, follow [this tutorial](https://tau.gr/posts/2018-06-29-how-to-set-up-signing-commits-with-git/).
32 changes: 32 additions & 0 deletions kind/resource_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@ func TestAccClusterConfigBase(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "kind_config.0.runtime_config.0.api/all", "false"),
),
},
{
Config: testAccClusterConfigAndFeatureGates(clusterName),
Check: resource.ComposeTestCheckFunc(
testAccCheckClusterCreate(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", clusterName),
resource.TestCheckNoResourceAttr(resourceName, "node_image"),
resource.TestCheckResourceAttr(resourceName, "wait_for_ready", "false"),
resource.TestCheckResourceAttr(resourceName, "kind_config.#", "1"),
resource.TestCheckResourceAttr(resourceName, "kind_config.0.kind", "Cluster"),
resource.TestCheckResourceAttr(resourceName, "kind_config.0.api_version", "kind.x-k8s.io/v1alpha4"),
resource.TestCheckResourceAttr(resourceName, "kind_config.0.feature_gates.#", "1"),
resource.TestCheckResourceAttr(resourceName, "kind_config.0.feature_gates.0", "CSIMigration"),
resource.TestCheckResourceAttr(resourceName, "kind_config.0.feature_gates.0.CSIMigration", "true"),
),
},
},
})
}
Expand Down Expand Up @@ -725,3 +740,20 @@ resource "kind_cluster" "test" {
}
`, name)
}

func testAccClusterConfigAndFeatureGates(name string) string {
return fmt.Sprintf(`
resource "kind_cluster" "test" {
name = "%s"
wait_for_ready = false
kind_config {
kind = "Cluster"
api_version = "kind.x-k8s.io/v1alpha4"
feature_gates {
"CSIMigration": "true"
}
}
}
`, name)
}
7 changes: 7 additions & 0 deletions kind/schema_kind_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ func kindConfigFields() map[string]*schema.Schema {
Type: schema.TypeString,
},
},
"feature_gates": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
}
return forceNewAll(s)
}
Expand Down
20 changes: 20 additions & 0 deletions kind/structure_kind_config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package kind

import (
"strings"

"sigs.k8s.io/kind/pkg/apis/config/v1alpha4"
)

Expand Down Expand Up @@ -38,6 +40,24 @@ func flattenKindConfig(d map[string]interface{}) *v1alpha4.Cluster {
}
}

runtimeConfig := mapKeyIfExists(d, "runtime_config")
if runtimeConfig != nil {
for k, v := range runtimeConfig.(map[string]string) {
obj.RuntimeConfig[k] = v
}
}

featureGates := mapKeyIfExists(d, "features_gates")
if featureGates != nil {
for k, v := range featureGates.(map[string]string) {
if strings.ToLower(v) == "true" {
obj.FeatureGates[k] = true
} else {
obj.FeatureGates[k] = false
}
}
}

return obj
}

Expand Down

0 comments on commit b9f7604

Please sign in to comment.