Skip to content

Commit

Permalink
Merge pull request #8 from kaplan-michael/more-config-options
Browse files Browse the repository at this point in the history
More config options
  • Loading branch information
james-nesbitt authored Jan 24, 2024
2 parents 00325af + c64a123 commit cbb6eb4
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 14 deletions.
18 changes: 18 additions & 0 deletions docs/resources/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ Required:
Optional:

- `hooks` (Block List) Hook configuration for the host (see [below for nested schema](#nestedblock--spec--host--hooks))
- `hostname` (String) Hostname override for the host
- `install_flags` (List of String) String install flags passed to k0s (e.g. '--taints=mytaint')
- `no_taints` (Boolean) Do not apply taints to the host, used in conjunction with the controller+worker role
- `private_address` (String) Private address override for the host
- `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 Expand Up @@ -96,8 +99,23 @@ Required:

Optional:

- `bastion` (Block List) SSH bastion configuration for the host (see [below for nested schema](#nestedblock--spec--host--ssh--bastion))
- `port` (Number) SSH Port

<a id="nestedblock--spec--host--ssh--bastion"></a>
### Nested Schema for `spec.host.ssh.bastion`

Required:

- `address` (String) bastion endpoint
- `key_path` (String) bastion endpoint
- `user` (String) bastion endpoint

Optional:

- `port` (Number) bastion Port



<a id="nestedblock--spec--host--winrm"></a>
### Nested Schema for `spec.host.winrm`
Expand Down
106 changes: 92 additions & 14 deletions internal/provider/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ func k0sctl_v1beta1_schema() schema.Schema {
Optional: true,
ElementType: types.StringType,
},
"hostname": schema.StringAttribute{
MarkdownDescription: "Hostname override for the host",
Optional: true,
},
"private_address": schema.StringAttribute{
MarkdownDescription: "Private address override for the host",
Optional: true,
},
"no_taints": schema.BoolAttribute{
MarkdownDescription: "Do not apply taints to the host, used in conjunction with the controller+worker role",
Optional: true,
},
},

Blocks: map[string]schema.Block{
Expand Down Expand Up @@ -245,6 +257,39 @@ func k0sctl_v1beta1_schema() schema.Schema {
Default: int64default.StaticInt64(22),
},
},

Blocks: map[string]schema.Block{
"bastion": schema.ListNestedBlock{
MarkdownDescription: "SSH bastion configuration for the host",

Validators: []validator.List{
listvalidator.SizeAtMost(1),
},

NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"address": schema.StringAttribute{
MarkdownDescription: "bastion endpoint",
Required: true,
},
"key_path": schema.StringAttribute{
MarkdownDescription: "bastion endpoint",
Required: true,
},
"user": schema.StringAttribute{
MarkdownDescription: "bastion endpoint",
Required: true,
},
"port": schema.Int64Attribute{
MarkdownDescription: "bastion Port",
Optional: true,
Computed: true,
Default: int64default.StaticInt64(22),
},
},
},
},
},
},
},
"winrm": schema.ListNestedBlock{
Expand Down Expand Up @@ -365,8 +410,11 @@ func (ksm *k0sctlSchemaModel) Cluster(ctx context.Context) (k0sctl_v1beta1.Clust

for _, sh := range ksm.Spec.Hosts {
h := k0sctl_v1beta1_cluster.Host{
Role: sh.Role.ValueString(),
Hooks: k0sctl_v1beta1_cluster.Hooks{},
Role: sh.Role.ValueString(),
Hooks: k0sctl_v1beta1_cluster.Hooks{},
PrivateAddress: sh.PrivateAddress.ValueString(),
HostnameOverride: sh.Hostname.ValueString(),
NoTaints: sh.NoTaints.ValueBool(),
}

if len(sh.InstallFlags) > 0 {
Expand All @@ -378,15 +426,33 @@ func (ksm *k0sctlSchemaModel) Cluster(ctx context.Context) (k0sctl_v1beta1.Clust
}
if len(sh.SSH) > 0 {
shssh := sh.SSH[0]
if len(shssh.Bastion) > 0 {
h.Connection = k0s_rig.Connection{
SSH: &k0s_rig.SSH{
Address: shssh.Address.ValueString(),
KeyPath: shssh.KeyPath.ValueStringPointer(),
User: shssh.User.ValueString(),
Port: int(shssh.Port.ValueInt64()),
Bastion: &k0s_rig.SSH{
Address: shssh.Bastion[0].Address.ValueString(),
KeyPath: shssh.Bastion[0].KeyPath.ValueStringPointer(),
User: shssh.Bastion[0].User.ValueString(),
Port: int(shssh.Bastion[0].Port.ValueInt64()),
},
},
}
} else {
h.Connection = k0s_rig.Connection{
SSH: &k0s_rig.SSH{
Address: shssh.Address.ValueString(),
KeyPath: shssh.KeyPath.ValueStringPointer(),
User: shssh.User.ValueString(),
Port: int(shssh.Port.ValueInt64()),
},
}

h.Connection = k0s_rig.Connection{
SSH: &k0s_rig.SSH{
Address: shssh.Address.ValueString(),
KeyPath: shssh.KeyPath.ValueStringPointer(),
User: shssh.User.ValueString(),
Port: int(shssh.Port.ValueInt64()),
},
}

} else if len(sh.WinRM) > 0 {
shwinrm := sh.WinRM[0]

Expand Down Expand Up @@ -526,11 +592,14 @@ type k0sctlSchemaModelSpecK0s struct {
}

type k0sctlSchemaModelSpecHost struct {
Role types.String `tfsdk:"role"`
InstallFlags []types.String `tfsdk:"install_flags"`
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"`
PrivateAddress types.String `tfsdk:"private_address"`
Hostname types.String `tfsdk:"hostname"`
NoTaints types.Bool `tfsdk:"no_taints"`
}
type k0sctlSchemaModelSpecHostHooks struct {
Apply []k0sctlSchemaModelSpecHostHookAction `tfsdk:"apply"`
Expand All @@ -540,11 +609,20 @@ type k0sctlSchemaModelSpecHostHookAction struct {
After types.List `tfsdk:"after"`
}
type k0sctlSchemaModelSpecHostSSH struct {
Address types.String `tfsdk:"address"`
KeyPath types.String `tfsdk:"key_path"`
User types.String `tfsdk:"user"`
Port types.Int64 `tfsdk:"port"`
Bastion []k0sctlSchemaModelSpecHostSSHBastion `tfsdk:"bastion"`
}

type k0sctlSchemaModelSpecHostSSHBastion struct {
Address types.String `tfsdk:"address"`
KeyPath types.String `tfsdk:"key_path"`
User types.String `tfsdk:"user"`
Port types.Int64 `tfsdk:"port"`
}

type k0sctlSchemaModelSpecHostWinrm struct {
Address types.String `tfsdk:"address"`
User types.String `tfsdk:"user"`
Expand Down

0 comments on commit cbb6eb4

Please sign in to comment.