mirror of https://github.com/k3d-io/k3d
parent
c8eca27bee
commit
08bf145e95
@ -1,6 +1,6 @@ |
|||||||
apiVersion: k3d.io/v1alpha3 |
apiVersion: k3d.io/v1alpha4 |
||||||
kind: Cluster |
kind: Cluster |
||||||
name: foo |
name: foo |
||||||
nodes: |
nodes: |
||||||
- name: foo-node-0 |
- name: foo-node-0 |
||||||
role: server |
role: server |
||||||
|
@ -1,4 +1,4 @@ |
|||||||
apiVersion: k3d.io/v1alpha3 |
apiVersion: k3d.io/v1alpha4 |
||||||
kind: Simple |
kind: Simple |
||||||
name: supertest |
name: supertest |
||||||
agents: 8 |
agents: 8 |
||||||
|
@ -1,3 +1,3 @@ |
|||||||
apiVersion: k3d.io/v1alpha3 |
apiVersion: k3d.io/v1alpha4 |
||||||
kind: Unknown |
kind: Unknown |
||||||
foo: bar |
foo: bar |
||||||
|
@ -0,0 +1,56 @@ |
|||||||
|
/* |
||||||
|
Copyright © 2020-2022 The k3d Author(s) |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||||
|
of this software and associated documentation files (the "Software"), to deal |
||||||
|
in the Software without restriction, including without limitation the rights |
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||||
|
copies of the Software, and to permit persons to whom the Software is |
||||||
|
furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in |
||||||
|
all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||||
|
THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
package v1alpha4 |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
|
||||||
|
configtypes "github.com/rancher/k3d/v5/pkg/config/types" |
||||||
|
"github.com/rancher/k3d/v5/pkg/config/v1alpha2" |
||||||
|
"github.com/rancher/k3d/v5/pkg/config/v1alpha3" |
||||||
|
l "github.com/rancher/k3d/v5/pkg/logger" |
||||||
|
) |
||||||
|
|
||||||
|
var Migrations = map[string]func(configtypes.Config) (configtypes.Config, error){ |
||||||
|
v1alpha2.ApiVersion: MigrateV1Alpha2, |
||||||
|
v1alpha3.ApiVersion: MigrateV1Alpha3, |
||||||
|
} |
||||||
|
|
||||||
|
func MigrateV1Alpha2(input configtypes.Config) (configtypes.Config, error) { |
||||||
|
l.Log().Debugln("Migrating v1alpha2 to v1alpha4") |
||||||
|
|
||||||
|
// first, migrate to v1alpha3
|
||||||
|
input, err := v1alpha3.MigrateV1Alpha2(input) |
||||||
|
if err != nil { |
||||||
|
return nil, fmt.Errorf("error migration v1alpha2 to v1alpha3: %w", err) |
||||||
|
} |
||||||
|
|
||||||
|
// then, migrate to v1alpha4
|
||||||
|
return MigrateV1Alpha3(input) |
||||||
|
} |
||||||
|
|
||||||
|
func MigrateV1Alpha3(input configtypes.Config) (configtypes.Config, error) { |
||||||
|
l.Log().Debugln("Migrating v1alpha3 to v1alpha4") |
||||||
|
|
||||||
|
return input, nil |
||||||
|
} |
@ -0,0 +1,347 @@ |
|||||||
|
{ |
||||||
|
"$schema": "http://json-schema.org/draft-07/schema#", |
||||||
|
"title": "SimpleConfig", |
||||||
|
"type": "object", |
||||||
|
"required": [ |
||||||
|
"apiVersion", |
||||||
|
"kind" |
||||||
|
], |
||||||
|
"properties": { |
||||||
|
"apiVersion": { |
||||||
|
"type": "string", |
||||||
|
"enum": [ |
||||||
|
"k3d.io/v1alpha4" |
||||||
|
], |
||||||
|
"default": "k3d.io/v1alpha4" |
||||||
|
}, |
||||||
|
"kind": { |
||||||
|
"type": "string", |
||||||
|
"enum": [ |
||||||
|
"Simple" |
||||||
|
], |
||||||
|
"default": "Simple" |
||||||
|
}, |
||||||
|
"name": { |
||||||
|
"description": "Name of the cluster (must be a valid hostname and will be prefixed with 'k3d-'). Example: 'mycluster'.", |
||||||
|
"type": "string", |
||||||
|
"format": "hostname" |
||||||
|
}, |
||||||
|
"servers": { |
||||||
|
"type": "number", |
||||||
|
"minimum": 1 |
||||||
|
}, |
||||||
|
"agents": { |
||||||
|
"type": "number", |
||||||
|
"minimum": 0 |
||||||
|
}, |
||||||
|
"kubeAPI": { |
||||||
|
"type": "object", |
||||||
|
"properties": { |
||||||
|
"host": { |
||||||
|
"type": "string", |
||||||
|
"format": "hostname" |
||||||
|
}, |
||||||
|
"hostIP": { |
||||||
|
"type": "string", |
||||||
|
"format": "ipv4", |
||||||
|
"examples": [ |
||||||
|
"0.0.0.0", |
||||||
|
"192.168.178.55" |
||||||
|
] |
||||||
|
}, |
||||||
|
"hostPort": { |
||||||
|
"type": "string", |
||||||
|
"examples": [ |
||||||
|
"6443" |
||||||
|
] |
||||||
|
} |
||||||
|
}, |
||||||
|
"additionalProperties": false |
||||||
|
}, |
||||||
|
"image": { |
||||||
|
"type": "string", |
||||||
|
"examples": [ |
||||||
|
"rancher/k3s:latest" |
||||||
|
] |
||||||
|
}, |
||||||
|
"network": { |
||||||
|
"type": "string" |
||||||
|
}, |
||||||
|
"subnet": { |
||||||
|
"type": "string", |
||||||
|
"default": "auto", |
||||||
|
"examples": [ |
||||||
|
"172.28.0.0/16", |
||||||
|
"192.162.0.0/16" |
||||||
|
] |
||||||
|
}, |
||||||
|
"token": { |
||||||
|
"type": "string" |
||||||
|
}, |
||||||
|
"volumes": { |
||||||
|
"type": "array", |
||||||
|
"items": { |
||||||
|
"type": "object", |
||||||
|
"properties": { |
||||||
|
"volume": { |
||||||
|
"type": "string" |
||||||
|
}, |
||||||
|
"nodeFilters": { |
||||||
|
"$ref": "#/definitions/nodeFilters" |
||||||
|
} |
||||||
|
}, |
||||||
|
"additionalProperties": false |
||||||
|
} |
||||||
|
}, |
||||||
|
"ports": { |
||||||
|
"type": "array", |
||||||
|
"items": { |
||||||
|
"type": "object", |
||||||
|
"properties": { |
||||||
|
"port": { |
||||||
|
"type": "string" |
||||||
|
}, |
||||||
|
"nodeFilters": { |
||||||
|
"$ref": "#/definitions/nodeFilters" |
||||||
|
} |
||||||
|
}, |
||||||
|
"additionalProperties": false |
||||||
|
} |
||||||
|
}, |
||||||
|
"options": { |
||||||
|
"type": "object", |
||||||
|
"properties": { |
||||||
|
"k3d": { |
||||||
|
"type": "object", |
||||||
|
"properties": { |
||||||
|
"wait": { |
||||||
|
"type": "boolean", |
||||||
|
"default": true |
||||||
|
}, |
||||||
|
"timeout": { |
||||||
|
"examples": [ |
||||||
|
"60s", |
||||||
|
"1m", |
||||||
|
"1m30s" |
||||||
|
] |
||||||
|
}, |
||||||
|
"disableLoadbalancer": { |
||||||
|
"type": "boolean", |
||||||
|
"default": false |
||||||
|
}, |
||||||
|
"disableImageVolume": { |
||||||
|
"type": "boolean", |
||||||
|
"default": false |
||||||
|
}, |
||||||
|
"disableRollback": { |
||||||
|
"type": "boolean", |
||||||
|
"default": false |
||||||
|
}, |
||||||
|
"loadbalancer": { |
||||||
|
"type": "object", |
||||||
|
"properties": { |
||||||
|
"configOverrides": { |
||||||
|
"type": "array", |
||||||
|
"examples": [ |
||||||
|
"settings.workerConnections=2048", |
||||||
|
"settings.defaultProxyTimeout=900" |
||||||
|
] |
||||||
|
} |
||||||
|
}, |
||||||
|
"additionalProperties": false |
||||||
|
} |
||||||
|
}, |
||||||
|
"additionalProperties": false |
||||||
|
}, |
||||||
|
"k3s": { |
||||||
|
"type": "object", |
||||||
|
"properties": { |
||||||
|
"extraArgs": { |
||||||
|
"type": "array", |
||||||
|
"items": { |
||||||
|
"type": "object", |
||||||
|
"properties": { |
||||||
|
"arg": { |
||||||
|
"type": "string", |
||||||
|
"examples": [ |
||||||
|
"--tls-san=127.0.0.1", |
||||||
|
"--disable=traefik" |
||||||
|
] |
||||||
|
}, |
||||||
|
"nodeFilters": { |
||||||
|
"$ref": "#/definitions/nodeFilters" |
||||||
|
} |
||||||
|
}, |
||||||
|
"additionalProperties": false |
||||||
|
} |
||||||
|
}, |
||||||
|
"nodeLabels": { |
||||||
|
"type": "array", |
||||||
|
"items": { |
||||||
|
"type": "object", |
||||||
|
"properties": { |
||||||
|
"label": { |
||||||
|
"type": "string" |
||||||
|
}, |
||||||
|
"nodeFilters": { |
||||||
|
"$ref": "#/definitions/nodeFilters" |
||||||
|
} |
||||||
|
}, |
||||||
|
"additionalProperties": false |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"additionalProperties": false |
||||||
|
}, |
||||||
|
"kubeconfig": { |
||||||
|
"type": "object", |
||||||
|
"properties": { |
||||||
|
"updateDefaultKubeconfig": { |
||||||
|
"type": "boolean", |
||||||
|
"default": true |
||||||
|
}, |
||||||
|
"switchCurrentContext": { |
||||||
|
"type": "boolean", |
||||||
|
"default": true |
||||||
|
} |
||||||
|
}, |
||||||
|
"additionalProperties": false |
||||||
|
}, |
||||||
|
"runtime": { |
||||||
|
"type": "object", |
||||||
|
"properties": { |
||||||
|
"gpuRequest": { |
||||||
|
"type": "string" |
||||||
|
}, |
||||||
|
"serversMemory": { |
||||||
|
"type": "string" |
||||||
|
}, |
||||||
|
"agentsMemory": { |
||||||
|
"type": "string" |
||||||
|
}, |
||||||
|
"hostPidMode": { |
||||||
|
"type":"boolean", |
||||||
|
"default": false |
||||||
|
}, |
||||||
|
"labels": { |
||||||
|
"type": "array", |
||||||
|
"items": { |
||||||
|
"type": "object", |
||||||
|
"properties": { |
||||||
|
"label": { |
||||||
|
"type": "string" |
||||||
|
}, |
||||||
|
"nodeFilters": { |
||||||
|
"$ref": "#/definitions/nodeFilters" |
||||||
|
} |
||||||
|
}, |
||||||
|
"additionalProperties": false |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"additionalProperties": false |
||||||
|
}, |
||||||
|
"env": { |
||||||
|
"type": "array", |
||||||
|
"items": { |
||||||
|
"type": "object", |
||||||
|
"properties": { |
||||||
|
"envVar": { |
||||||
|
"type": "string" |
||||||
|
}, |
||||||
|
"nodeFilters": { |
||||||
|
"$ref": "#/definitions/nodeFilters" |
||||||
|
} |
||||||
|
}, |
||||||
|
"additionalProperties": false |
||||||
|
} |
||||||
|
}, |
||||||
|
"registries": { |
||||||
|
"type": "object", |
||||||
|
"properties": { |
||||||
|
"create": { |
||||||
|
"type": "object", |
||||||
|
"description": "Create a new container image registry alongside the cluster.", |
||||||
|
"properties": { |
||||||
|
"name": { |
||||||
|
"type": "string", |
||||||
|
"examples": [ |
||||||
|
"myregistry", |
||||||
|
"registry.localhost" |
||||||
|
] |
||||||
|
}, |
||||||
|
"host": { |
||||||
|
"type": "string", |
||||||
|
"examples": [ |
||||||
|
"0.0.0.0", |
||||||
|
"localhost", |
||||||
|
"127.0.0.1" |
||||||
|
], |
||||||
|
"default": "0.0.0.0" |
||||||
|
}, |
||||||
|
"hostPort": { |
||||||
|
"type": "string", |
||||||
|
"examples": [ |
||||||
|
"5000", |
||||||
|
"2345" |
||||||
|
], |
||||||
|
"default": "random" |
||||||
|
} |
||||||
|
}, |
||||||
|
"additionalProperties": false |
||||||
|
}, |
||||||
|
"use": { |
||||||
|
"type": "array", |
||||||
|
"description": "Connect another container image registry to the cluster.", |
||||||
|
"items": { |
||||||
|
"type": "string" |
||||||
|
}, |
||||||
|
"examples": [ |
||||||
|
"otherregistry:5000" |
||||||
|
] |
||||||
|
}, |
||||||
|
"config": { |
||||||
|
"type": "string", |
||||||
|
"description": "Reference a K3s registry configuration file or at it's contents here." |
||||||
|
}, |
||||||
|
"additionalProperties": false |
||||||
|
} |
||||||
|
}, |
||||||
|
"hostAliases": { |
||||||
|
"type": "array", |
||||||
|
"description": "Additional IP to multiple hostnames mappings", |
||||||
|
"items": { |
||||||
|
"type": "object", |
||||||
|
"properties": { |
||||||
|
"ip": { |
||||||
|
"type": "string" |
||||||
|
}, |
||||||
|
"hostnames": { |
||||||
|
"type": "array", |
||||||
|
"items": { |
||||||
|
"type": "string" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"additionalProperties": false, |
||||||
|
"definitions": { |
||||||
|
"nodeFilters": { |
||||||
|
"type": "array", |
||||||
|
"items": { |
||||||
|
"type": "string" |
||||||
|
}, |
||||||
|
"examples": [ |
||||||
|
"loadbalancer", |
||||||
|
"server:*", |
||||||
|
"server:0", |
||||||
|
"agent:1", |
||||||
|
"all" |
||||||
|
] |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,218 @@ |
|||||||
|
/* |
||||||
|
Copyright © 2020-2022 The k3d Author(s) |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||||
|
of this software and associated documentation files (the "Software"), to deal |
||||||
|
in the Software without restriction, including without limitation the rights |
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||||
|
copies of the Software, and to permit persons to whom the Software is |
||||||
|
furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in |
||||||
|
all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||||
|
THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
package v1alpha4 |
||||||
|
|
||||||
|
import ( |
||||||
|
_ "embed" |
||||||
|
"fmt" |
||||||
|
"strings" |
||||||
|
"time" |
||||||
|
|
||||||
|
config "github.com/rancher/k3d/v5/pkg/config/types" |
||||||
|
k3d "github.com/rancher/k3d/v5/pkg/types" |
||||||
|
"github.com/rancher/k3d/v5/version" |
||||||
|
) |
||||||
|
|
||||||
|
const ApiVersion = "k3d.io/v1alpha4" |
||||||
|
|
||||||
|
// JSONSchema describes the schema used to validate config files
|
||||||
|
//go:embed schema.json
|
||||||
|
var JSONSchema string |
||||||
|
|
||||||
|
// DefaultConfigTpl for printing
|
||||||
|
const DefaultConfigTpl = `--- |
||||||
|
apiVersion: k3d.io/v1alpha4 |
||||||
|
kind: Simple |
||||||
|
name: %s |
||||||
|
servers: 1 |
||||||
|
agents: 0 |
||||||
|
image: %s |
||||||
|
` |
||||||
|
|
||||||
|
// DefaultConfig templated DefaultConfigTpl
|
||||||
|
var DefaultConfig = fmt.Sprintf( |
||||||
|
DefaultConfigTpl, |
||||||
|
k3d.DefaultClusterName, |
||||||
|
fmt.Sprintf("%s:%s", k3d.DefaultK3sImageRepo, version.K3sVersion), |
||||||
|
) |
||||||
|
|
||||||
|
type VolumeWithNodeFilters struct { |
||||||
|
Volume string `mapstructure:"volume" yaml:"volume,omitempty" json:"volume,omitempty"` |
||||||
|
NodeFilters []string `mapstructure:"nodeFilters" yaml:"nodeFilters,omitempty" json:"nodeFilters,omitempty"` |
||||||
|
} |
||||||
|
|
||||||
|
type PortWithNodeFilters struct { |
||||||
|
Port string `mapstructure:"port" yaml:"port,omitempty" json:"port,omitempty"` |
||||||
|
NodeFilters []string `mapstructure:"nodeFilters" yaml:"nodeFilters,omitempty" json:"nodeFilters,omitempty"` |
||||||
|
} |
||||||
|
|
||||||
|
type LabelWithNodeFilters struct { |
||||||
|
Label string `mapstructure:"label" yaml:"label,omitempty" json:"label,omitempty"` |
||||||
|
NodeFilters []string `mapstructure:"nodeFilters" yaml:"nodeFilters,omitempty" json:"nodeFilters,omitempty"` |
||||||
|
} |
||||||
|
|
||||||
|
type EnvVarWithNodeFilters struct { |
||||||
|
EnvVar string `mapstructure:"envVar" yaml:"envVar,omitempty" json:"envVar,omitempty"` |
||||||
|
NodeFilters []string `mapstructure:"nodeFilters" yaml:"nodeFilters,omitempty" json:"nodeFilters,omitempty"` |
||||||
|
} |
||||||
|
|
||||||
|
type K3sArgWithNodeFilters struct { |
||||||
|
Arg string `mapstructure:"arg" yaml:"arg,omitempty" json:"arg,omitempty"` |
||||||
|
NodeFilters []string `mapstructure:"nodeFilters" yaml:"nodeFilters,omitempty" json:"nodeFilters,omitempty"` |
||||||
|
} |
||||||
|
|
||||||
|
type SimpleConfigRegistryCreateConfig struct { |
||||||
|
Name string `mapstructure:"name" yaml:"name,omitempty" json:"name,omitempty"` |
||||||
|
Host string `mapstructure:"host" yaml:"host,omitempty" json:"host,omitempty"` |
||||||
|
HostPort string `mapstructure:"hostPort" yaml:"hostPort,omitempty" json:"hostPort,omitempty"` |
||||||
|
} |
||||||
|
|
||||||
|
// SimpleConfigOptionsKubeconfig describes the set of options referring to the kubeconfig during cluster creation.
|
||||||
|
type SimpleConfigOptionsKubeconfig struct { |
||||||
|
UpdateDefaultKubeconfig bool `mapstructure:"updateDefaultKubeconfig" yaml:"updateDefaultKubeconfig" json:"updateDefaultKubeconfig,omitempty"` // default: true
|
||||||
|
SwitchCurrentContext bool `mapstructure:"switchCurrentContext" yaml:"switchCurrentContext" json:"switchCurrentContext,omitempty"` //nolint:lll // default: true
|
||||||
|
} |
||||||
|
|
||||||
|
type SimpleConfigOptions struct { |
||||||
|
K3dOptions SimpleConfigOptionsK3d `mapstructure:"k3d" yaml:"k3d" json:"k3d"` |
||||||
|
K3sOptions SimpleConfigOptionsK3s `mapstructure:"k3s" yaml:"k3s" json:"k3s"` |
||||||
|
KubeconfigOptions SimpleConfigOptionsKubeconfig `mapstructure:"kubeconfig" yaml:"kubeconfig" json:"kubeconfig"` |
||||||
|
Runtime SimpleConfigOptionsRuntime `mapstructure:"runtime" yaml:"runtime" json:"runtime"` |
||||||
|
} |
||||||
|
|
||||||
|
type SimpleConfigOptionsRuntime struct { |
||||||
|
GPURequest string `mapstructure:"gpuRequest" yaml:"gpuRequest,omitempty" json:"gpuRequest,omitempty"` |
||||||
|
ServersMemory string `mapstructure:"serversMemory" yaml:"serversMemory,omitempty" json:"serversMemory,omitempty"` |
||||||
|
AgentsMemory string `mapstructure:"agentsMemory" yaml:"agentsMemory,omitempty" json:"agentsMemory,omitempty"` |
||||||
|
HostPidMode bool `mapstructure:"hostPidMode" yaml:"hostPidMode,omitempty" json:"hostPidMode,omitempty"` |
||||||
|
Labels []LabelWithNodeFilters `mapstructure:"labels" yaml:"labels,omitempty" json:"labels,omitempty"` |
||||||
|
} |
||||||
|
|
||||||
|
type SimpleConfigOptionsK3d struct { |
||||||
|
Wait bool `mapstructure:"wait" yaml:"wait" json:"wait"` |
||||||
|
Timeout time.Duration `mapstructure:"timeout" yaml:"timeout,omitempty" json:"timeout,omitempty"` |
||||||
|
DisableLoadbalancer bool `mapstructure:"disableLoadbalancer" yaml:"disableLoadbalancer" json:"disableLoadbalancer"` |
||||||
|
DisableImageVolume bool `mapstructure:"disableImageVolume" yaml:"disableImageVolume" json:"disableImageVolume"` |
||||||
|
NoRollback bool `mapstructure:"disableRollback" yaml:"disableRollback" json:"disableRollback"` |
||||||
|
NodeHookActions []k3d.NodeHookAction `mapstructure:"nodeHookActions" yaml:"nodeHookActions,omitempty" json:"nodeHookActions,omitempty"` |
||||||
|
Loadbalancer SimpleConfigOptionsK3dLoadbalancer `mapstructure:"loadbalancer" yaml:"loadbalancer,omitempty" json:"loadbalancer,omitempty"` |
||||||
|
} |
||||||
|
|
||||||
|
type SimpleConfigOptionsK3dLoadbalancer struct { |
||||||
|
ConfigOverrides []string `mapstructure:"configOverrides" yaml:"configOverrides,omitempty" json:"configOverrides,omitempty"` |
||||||
|
} |
||||||
|
|
||||||
|
type SimpleConfigOptionsK3s struct { |
||||||
|
ExtraArgs []K3sArgWithNodeFilters `mapstructure:"extraArgs" yaml:"extraArgs,omitempty" json:"extraArgs,omitempty"` |
||||||
|
NodeLabels []LabelWithNodeFilters `mapstructure:"nodeLabels" yaml:"nodeLabels,omitempty" json:"nodeLabels,omitempty"` |
||||||
|
} |
||||||
|
|
||||||
|
type SimpleConfigRegistries struct { |
||||||
|
Use []string `mapstructure:"use" yaml:"use,omitempty" json:"use,omitempty"` |
||||||
|
Create *SimpleConfigRegistryCreateConfig `mapstructure:"create" yaml:"create,omitempty" json:"create,omitempty"` |
||||||
|
Config string `mapstructure:"config" yaml:"config,omitempty" json:"config,omitempty"` // registries.yaml (k3s config for containerd registry override)
|
||||||
|
} |
||||||
|
|
||||||
|
// SimpleConfig describes the toplevel k3d configuration file.
|
||||||
|
type SimpleConfig struct { |
||||||
|
config.TypeMeta `mapstructure:",squash" yaml:",inline"` |
||||||
|
Name string `mapstructure:"name" yaml:"name,omitempty" json:"name,omitempty"` |
||||||
|
Servers int `mapstructure:"servers" yaml:"servers,omitempty" json:"servers,omitempty"` //nolint:lll // default 1
|
||||||
|
Agents int `mapstructure:"agents" yaml:"agents,omitempty" json:"agents,omitempty"` //nolint:lll // default 0
|
||||||
|
ExposeAPI SimpleExposureOpts `mapstructure:"kubeAPI" yaml:"kubeAPI,omitempty" json:"kubeAPI,omitempty"` |
||||||
|
Image string `mapstructure:"image" yaml:"image,omitempty" json:"image,omitempty"` |
||||||
|
Network string `mapstructure:"network" yaml:"network,omitempty" json:"network,omitempty"` |
||||||
|
Subnet string `mapstructure:"subnet" yaml:"subnet,omitempty" json:"subnet,omitempty"` |
||||||
|
ClusterToken string `mapstructure:"token" yaml:"clusterToken,omitempty" json:"clusterToken,omitempty"` // default: auto-generated
|
||||||
|
Volumes []VolumeWithNodeFilters `mapstructure:"volumes" yaml:"volumes,omitempty" json:"volumes,omitempty"` |
||||||
|
Ports []PortWithNodeFilters `mapstructure:"ports" yaml:"ports,omitempty" json:"ports,omitempty"` |
||||||
|
Options SimpleConfigOptions `mapstructure:"options" yaml:"options,omitempty" json:"options,omitempty"` |
||||||
|
Env []EnvVarWithNodeFilters `mapstructure:"env" yaml:"env,omitempty" json:"env,omitempty"` |
||||||
|
Registries SimpleConfigRegistries `mapstructure:"registries" yaml:"registries,omitempty" json:"registries,omitempty"` |
||||||
|
HostAliases []k3d.HostAlias `mapstructure:"hostAliases" yaml:"hostAliases,omitempty" json:"hostAliases,omitempty"` |
||||||
|
} |
||||||
|
|
||||||
|
// SimpleExposureOpts provides a simplified syntax compared to the original k3d.ExposureOpts
|
||||||
|
type SimpleExposureOpts struct { |
||||||
|
Host string `mapstructure:"host" yaml:"host,omitempty" json:"host,omitempty"` |
||||||
|
HostIP string `mapstructure:"hostIP" yaml:"hostIP,omitempty" json:"hostIP,omitempty"` |
||||||
|
HostPort string `mapstructure:"hostPort" yaml:"hostPort,omitempty" json:"hostPort,omitempty"` |
||||||
|
} |
||||||
|
|
||||||
|
// GetKind implements Config.GetKind
|
||||||
|
func (c SimpleConfig) GetKind() string { |
||||||
|
return "Simple" |
||||||
|
} |
||||||
|
|
||||||
|
func (c SimpleConfig) GetAPIVersion() string { |
||||||
|
return ApiVersion |
||||||
|
} |
||||||
|
|
||||||
|
// ClusterConfig describes a single cluster config
|
||||||
|
type ClusterConfig struct { |
||||||
|
config.TypeMeta `mapstructure:",squash" yaml:",inline"` |
||||||
|
Cluster k3d.Cluster `mapstructure:",squash" yaml:",inline"` |
||||||
|
ClusterCreateOpts k3d.ClusterCreateOpts `mapstructure:"options" yaml:"options"` |
||||||
|
KubeconfigOpts SimpleConfigOptionsKubeconfig `mapstructure:"kubeconfig" yaml:"kubeconfig"` |
||||||
|
} |
||||||
|
|
||||||
|
// GetKind implements Config.GetKind
|
||||||
|
func (c ClusterConfig) GetKind() string { |
||||||
|
return "Simple" |
||||||
|
} |
||||||
|
|
||||||
|
func (c ClusterConfig) GetAPIVersion() string { |
||||||
|
return ApiVersion |
||||||
|
} |
||||||
|
|
||||||
|
// ClusterListConfig describes a list of clusters
|
||||||
|
type ClusterListConfig struct { |
||||||
|
config.TypeMeta `mapstructure:",squash" yaml:",inline"` |
||||||
|
Clusters []k3d.Cluster `mapstructure:"clusters" yaml:"clusters"` |
||||||
|
} |
||||||
|
|
||||||
|
func (c ClusterListConfig) GetKind() string { |
||||||
|
return "Simple" |
||||||
|
} |
||||||
|
|
||||||
|
func (c ClusterListConfig) GetAPIVersion() string { |
||||||
|
return ApiVersion |
||||||
|
} |
||||||
|
|
||||||
|
func GetConfigByKind(kind string) (config.Config, error) { |
||||||
|
|
||||||
|
// determine config kind
|
||||||
|
switch strings.ToLower(kind) { |
||||||
|
case "simple": |
||||||
|
return SimpleConfig{}, nil |
||||||
|
case "cluster": |
||||||
|
return ClusterConfig{}, nil |
||||||
|
case "clusterlist": |
||||||
|
return ClusterListConfig{}, nil |
||||||
|
case "": |
||||||
|
return nil, fmt.Errorf("missing `kind` in config file") |
||||||
|
default: |
||||||
|
return nil, fmt.Errorf("unknown `kind` '%s' in config file", kind) |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,4 +1,4 @@ |
|||||||
apiVersion: k3d.io/v1alpha3 |
apiVersion: k3d.io/v1alpha4 |
||||||
kind: Simple |
kind: Simple |
||||||
name: testenvexpand |
name: testenvexpand |
||||||
servers: ${K3D_TEST_SERVERS} |
servers: ${K3D_TEST_SERVERS} |
||||||
|
Loading…
Reference in new issue