Skip to content

Commit 7e1f9af

Browse files
committed
first sketches regards #882
Signed-off-by: Matthias Büchse <[email protected]>
1 parent 0764e98 commit 7e1f9af

File tree

3 files changed

+69
-25
lines changed

3 files changed

+69
-25
lines changed

Tests/kaas/plugin/plugin_kind.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ def create_cluster(self, cluster_name, version, kubeconfig):
2828
:return: kubeconfig_filepath
2929
"""
3030
cluster_version = version
31+
# latest versions to be found under https://hub.docker.com/r/kindest/node/tags
3132
if cluster_version == '1.29':
32-
cluster_version = 'v1.29.8'
33+
cluster_version = 'v1.29.14'
3334
elif cluster_version == '1.30':
34-
cluster_version = 'v1.30.4'
35+
cluster_version = 'v1.30.10'
3536
elif cluster_version == '1.31' or cluster_version == 'default':
36-
cluster_version = 'v1.31.1'
37+
cluster_version = 'v1.31.6'
38+
elif cluster_version == '1.32':
39+
cluster_version = 'v1.32.3'
3740
cluster_image = f"kindest/node:{cluster_version}"
3841
kubeconfig_filepath = Path(kubeconfig)
3942
if kubeconfig_filepath is None:

Tests/kaas/plugin/run_plugin.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,33 @@
88
from plugin_kind import PluginKind
99
from plugin_static import PluginStatic
1010

11+
1112
PLUGIN_LOOKUP = {
1213
"kind": PluginKind,
1314
"static": PluginStatic,
1415
}
1516

1617

17-
def init_plugin(plugin_kind, config_path):
18+
def load_config(path=None):
19+
if path:
20+
with open(path, "rb") as fileobj:
21+
cfg = yaml.load(fileobj, Loader=yaml.SafeLoader)
22+
if not isinstance(cfg, dict):
23+
raise RuntimeError('clusters.yaml must be a YAML dict')
24+
if 'clusters' not in cfg or not isinstance(cfg['clusters'], dict):
25+
raise RuntimeError('clusters.yaml must be a YAML dict, and so must be .clusters')
26+
return cfg
27+
path = os.path.join(os.path.expanduser('~'), '.config', 'scs', 'clusters.yaml')
28+
if os.path.exists(path):
29+
return load_config(path)
30+
raise FileNotFoundError('config')
31+
32+
33+
def init_plugin(plugin_kind, config):
1834
plugin_maker = PLUGIN_LOOKUP.get(plugin_kind)
1935
if plugin_maker is None:
2036
raise ValueError(f"unknown plugin '{plugin_kind}'")
21-
return plugin_maker(config_path)
22-
23-
24-
def load_spec(clusterspec_path):
25-
with open(clusterspec_path, "rb") as fileobj:
26-
return yaml.load(fileobj, Loader=yaml.SafeLoader)
37+
return plugin_maker(config)
2738

2839

2940
@click.group()
@@ -32,27 +43,25 @@ def cli():
3243

3344

3445
@cli.command()
35-
@click.argument('plugin_kind', type=click.Choice(list(PLUGIN_LOOKUP), case_sensitive=False))
36-
@click.argument('plugin_config', type=click.Path(exists=True, dir_okay=False))
37-
@click.argument('clusterspec_path', type=click.Path(exists=True, dir_okay=False))
3846
@click.argument('cluster_id', type=str, default="default")
39-
def create(plugin_kind, plugin_config, clusterspec_path, cluster_id):
40-
clusterspec = load_spec(clusterspec_path)['clusters']
41-
plugin = init_plugin(plugin_kind, plugin_config)
42-
clusterinfo = clusterspec[cluster_id]
43-
plugin.create_cluster(cluster_id, clusterinfo['branch'], os.path.abspath(clusterinfo['kubeconfig']))
47+
@cli.pass_obj
48+
def create(cfg, cluster_id):
49+
spec = cfg[cluster_id]
50+
config = spec['config']
51+
config['name'] = cluster_id
52+
init_plugin(spec['kind'], config).create_cluster()
4453

4554

4655
@cli.command()
47-
@click.argument('plugin_kind', type=click.Choice(list(PLUGIN_LOOKUP), case_sensitive=False))
48-
@click.argument('plugin_config', type=click.Path(exists=True, dir_okay=False))
49-
@click.argument('clusterspec_path', type=click.Path(exists=True, dir_okay=False))
5056
@click.argument('cluster_id', type=str, default="default")
51-
def delete(plugin_kind, plugin_config, clusterspec_path, cluster_id):
52-
plugin = init_plugin(plugin_kind, plugin_config)
53-
plugin.delete_cluster(cluster_id)
57+
@cli.pass_obj
58+
def delete(cfg, cluster_id):
59+
spec = cfg[cluster_id]
60+
config = spec['config']
61+
config['name'] = cluster_id
62+
init_plugin(spec['kind'], config).delete_cluster()
5463

5564

5665
if __name__ == '__main__':
5766
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
58-
cli()
67+
cli(obj=load_config())

playbooks/clusters.yaml.j2

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
clusters:
3+
syself-1.32:
4+
kind: clusterstacks
5+
config:
6+
token: "{{ clouds_conf.syself_token }}"
7+
kubernetesVersion: '1.32'
8+
autoVars: syself # will determine class and version automatically using kubernetesVersion
9+
cluster: syself-cluster.yaml
10+
clusterstack: syself-clusterstack.yaml
11+
vars:
12+
cs-name: hetzner-apalla-1-32
13+
syself-1.31:
14+
kind: clusterstacks
15+
config:
16+
token: "{{ clouds_conf.syself_token }}"
17+
kubernetesVersion: '1.31'
18+
autoVars: syself # will determine class and version automatically using kubernetesVersion
19+
cluster: syself-cluster.yaml
20+
clusterstack: syself-clusterstack.yaml
21+
vars:
22+
cs-name: hetzner-apalla-1-31
23+
syself-1.30:
24+
kind: clusterstacks
25+
config:
26+
token: "{{ clouds_conf.syself_token }}"
27+
kubernetesVersion: '1.30'
28+
autoVars: syself # will determine class and version automatically using kubernetesVersion
29+
cluster: syself-cluster.yaml
30+
clusterstack: syself-clusterstack.yaml
31+
vars:
32+
cs-name: hetzner-apalla-1-30

0 commit comments

Comments
 (0)