Skip to content

Commit

Permalink
k0s host install flags
Browse files Browse the repository at this point in the history
- schema now accepts install flags

Signed-off-by: James Nesbitt <[email protected]>
  • Loading branch information
james-nesbitt committed Dec 7, 2023
1 parent b1e3948 commit 45c7ee9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/resources/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
6 changes: 1 addition & 5 deletions internal/provider/k0s_config_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/k0s_config_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
Expand Down Expand Up @@ -51,6 +52,7 @@ resource "k0sctl_config" "test" {
host {
role = "worker"
install_flags = [ "--taints=mytaint" ]
ssh {
address = "worker1.example.org"
key_path = "./key.pem"
Expand Down
31 changes: 21 additions & 10 deletions internal/provider/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -284,7 +291,7 @@ func k0sctl_v1beta1_schema(ctx context.Context) (schema.Schema, diag.Diagnostics
},
},
},
}, nil
}
}

type k0sctlSchemaModel struct {
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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"`
Expand Down

0 comments on commit 45c7ee9

Please sign in to comment.