From 45c7ee988b254251c0770335534474e5fa36dcb9 Mon Sep 17 00:00:00 2001 From: James Nesbitt Date: Fri, 1 Dec 2023 14:06:41 +0200 Subject: [PATCH] k0s host install flags - schema now accepts install flags Signed-off-by: James Nesbitt --- README.md | 3 ++ docs/resources/config.md | 1 + internal/provider/k0s_config_resource.go | 6 +--- internal/provider/k0s_config_resource_test.go | 2 ++ internal/provider/schema.go | 31 +++++++++++++------ 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 149d926..7585ddf 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,9 @@ A terraform provider which integrates the k0s project tooling to natively convert a set of hosts to a kubernetes cluster using terraform resources. +This provider is developed internally, and comes with no warranty. Use it +at your own risk. + ## Requirements - [Terraform](https://www.terraform.io/downloads.html) >= 1.4 diff --git a/docs/resources/config.md b/docs/resources/config.md index 98169a1..02054b5 100644 --- a/docs/resources/config.md +++ b/docs/resources/config.md @@ -64,6 +64,7 @@ Required: Optional: - `hooks` (Block List) Hook configuration for the host (see [below for nested schema](#nestedblock--spec--host--hooks)) +- `install_flags` (List of String) String install flags passed to k0s (e.g. '--taints=mytaint') - `ssh` (Block List) SSH configuration for the host (see [below for nested schema](#nestedblock--spec--host--ssh)) - `winrm` (Block List) WinRM configuration for the host (see [below for nested schema](#nestedblock--spec--host--winrm)) diff --git a/internal/provider/k0s_config_resource.go b/internal/provider/k0s_config_resource.go index 84b55c8..8f2e0bc 100644 --- a/internal/provider/k0s_config_resource.go +++ b/internal/provider/k0s_config_resource.go @@ -32,11 +32,7 @@ func (r *K0sctlConfigResource) Metadata(ctx context.Context, req resource.Metada } func (r *K0sctlConfigResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { - schema, diags := k0sctl_v1beta1_schema(ctx) - resp.Schema = schema - if diags != nil { - resp.Diagnostics.Append(diags...) - } + resp.Schema = k0sctl_v1beta1_schema() } func (r *K0sctlConfigResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { diff --git a/internal/provider/k0s_config_resource_test.go b/internal/provider/k0s_config_resource_test.go index 675d9f0..5fc1709 100644 --- a/internal/provider/k0s_config_resource_test.go +++ b/internal/provider/k0s_config_resource_test.go @@ -16,6 +16,7 @@ func TestAccK0sctlConfigResource(t *testing.T) { Config: testAccK0sctlConfigResourceConfig_minimal(), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("k0sctl_config.test", "spec.host.0.hooks.0.apply.0.before.0", "ls -la"), + resource.TestCheckResourceAttr("k0sctl_config.test", "spec.host.1.install_flags.0", "--taints=mytaint"), resource.TestCheckResourceAttr("k0sctl_config.test", "spec.k0s.version", "0.13"), ), }, @@ -51,6 +52,7 @@ resource "k0sctl_config" "test" { host { role = "worker" + install_flags = [ "--taints=mytaint" ] ssh { address = "worker1.example.org" key_path = "./key.pem" diff --git a/internal/provider/schema.go b/internal/provider/schema.go index af22eda..517cbb8 100644 --- a/internal/provider/schema.go +++ b/internal/provider/schema.go @@ -29,7 +29,7 @@ const ( k0sctl_schema_kind = "cluster" ) -func k0sctl_v1beta1_schema(ctx context.Context) (schema.Schema, diag.Diagnostics) { +func k0sctl_v1beta1_schema() schema.Schema { return schema.Schema{ // This description is used by the documentation generator and the language server. MarkdownDescription: "Mirantis installation using launchpad, parametrized", @@ -170,7 +170,14 @@ func k0sctl_v1beta1_schema(ctx context.Context) (schema.Schema, diag.Diagnostics MarkdownDescription: "Host machine role in the cluster", Required: true, }, + + "install_flags": schema.ListAttribute{ + MarkdownDescription: "String install flags passed to k0s (e.g. '--taints=mytaint')", + Optional: true, + ElementType: types.StringType, + }, }, + Blocks: map[string]schema.Block{ "hooks": schema.ListNestedBlock{ @@ -284,7 +291,7 @@ func k0sctl_v1beta1_schema(ctx context.Context) (schema.Schema, diag.Diagnostics }, }, }, - }, nil + } } type k0sctlSchemaModel struct { @@ -362,6 +369,13 @@ func (ksm *k0sctlSchemaModel) Cluster(ctx context.Context) (k0sctl_v1beta1.Clust Hooks: k0sctl_v1beta1_cluster.Hooks{}, } + if len(sh.InstallFlags) > 0 { + var shifs = make([]string, len(sh.InstallFlags)) + for i, shif := range sh.InstallFlags { + shifs[i] = shif.ValueString() + } + h.InstallFlags = k0sctl_v1beta1_cluster.Flags(shifs) + } if len(sh.SSH) > 0 { shssh := sh.SSH[0] @@ -512,18 +526,15 @@ type k0sctlSchemaModelSpecK0s struct { } type k0sctlSchemaModelSpecHost struct { - Role types.String `tfsdk:"role"` - Hooks []k0sctlSchemaModelSpecHostHooks `tfsdk:"hooks"` - SSH []k0sctlSchemaModelSpecHostSSH `tfsdk:"ssh"` - WinRM []k0sctlSchemaModelSpecHostWinrm `tfsdk:"winrm"` + Role types.String `tfsdk:"role"` + InstallFlags []types.String `tfsdk:"install_flags"` + Hooks []k0sctlSchemaModelSpecHostHooks `tfsdk:"hooks"` + SSH []k0sctlSchemaModelSpecHostSSH `tfsdk:"ssh"` + WinRM []k0sctlSchemaModelSpecHostWinrm `tfsdk:"winrm"` } type k0sctlSchemaModelSpecHostHooks struct { Apply []k0sctlSchemaModelSpecHostHookAction `tfsdk:"apply"` } -type k0sctlSchemaModelSpecHostMCRconfigDefaultAddressPools struct { - Base types.String `json:"base" tfsdk:"base"` - Size types.Int64 `json:"size" tfsdk:"size"` -} type k0sctlSchemaModelSpecHostHookAction struct { Before types.List `tfsdk:"before"` After types.List `tfsdk:"after"`