Skip to content

Commit f0b0641

Browse files
committed
continue sketch
Signed-off-by: Matthias Büchse <[email protected]>
1 parent 7e1f9af commit f0b0641

File tree

7 files changed

+158
-68
lines changed

7 files changed

+158
-68
lines changed

Tests/kaas/plugin/plugin_kind.py

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,20 @@ class PluginKind(KubernetesClusterPlugin):
1414
Plugin to handle the provisioning of kubernetes cluster for
1515
conformance testing purpose with the use of Kind
1616
"""
17-
def __init__(self, config_path):
18-
logger.info("Init PluginKind")
19-
self.config = config_path
17+
def __init__(self, config, basepath='.'):
18+
self.basepath = basepath
19+
self.config = config
2020
logger.debug(self.config)
21-
self.working_directory = os.getcwd()
22-
logger.debug(f"Working from {self.working_directory}")
2321

24-
def create_cluster(self, cluster_name, version, kubeconfig):
25-
"""
26-
This method is to be called to create a k8s cluster
27-
:param: kubernetes_version:
28-
:return: kubeconfig_filepath
29-
"""
30-
cluster_version = version
31-
# latest versions to be found under https://hub.docker.com/r/kindest/node/tags
32-
if cluster_version == '1.29':
33-
cluster_version = 'v1.29.14'
34-
elif cluster_version == '1.30':
35-
cluster_version = 'v1.30.10'
36-
elif cluster_version == '1.31' or cluster_version == 'default':
37-
cluster_version = 'v1.31.6'
38-
elif cluster_version == '1.32':
39-
cluster_version = 'v1.32.3'
40-
cluster_image = f"kindest/node:{cluster_version}"
41-
kubeconfig_filepath = Path(kubeconfig)
42-
if kubeconfig_filepath is None:
43-
raise ValueError("kubeconfig_filepath is missing")
44-
else:
45-
self.cluster = KindCluster(name=cluster_name, image=cluster_image, kubeconfig=kubeconfig_filepath)
46-
if self.config is None:
47-
self.cluster.create()
48-
else:
49-
self.cluster.create(self.config)
22+
def create_cluster(self, kubeconfig_path):
23+
cluster_name = self.config['name']
24+
cluster_image = self.config['image']
25+
cluster_yaml = self.config.get('cluster')
26+
if cluster_yaml and not os.path.isabs(cluster_yaml):
27+
cluster_yaml = os.path.normpath(os.path.join(self.basepath, cluster_yaml))
28+
cluster = KindCluster(name=cluster_name, image=cluster_image, kubeconfig=Path(kubeconfig_path))
29+
cluster.create(cluster_yaml)
5030

51-
def delete_cluster(self, cluster_name):
52-
self.cluster = KindCluster(cluster_name)
53-
self.cluster.delete()
31+
def delete_cluster(self):
32+
cluster_name = self.config['name']
33+
KindCluster(cluster_name).delete()

Tests/kaas/plugin/run_plugin.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@
1313
"kind": PluginKind,
1414
"static": PluginStatic,
1515
}
16+
BASEPATH = os.path.join(os.path.expanduser('~'), '.config', 'scs')
1617

1718

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')
19+
def load_config(path='clusters.yaml'):
20+
if not os.path.isabs(path):
21+
return load_config(os.path.normpath(os.path.join(BASEPATH, path)))
22+
if not os.path.exists(path):
23+
raise FileNotFoundError()
24+
with open(path, "rb") as fileobj:
25+
cfg = yaml.load(fileobj, Loader=yaml.SafeLoader)
26+
if not isinstance(cfg, dict):
27+
raise RuntimeError('clusters.yaml must be a YAML dict')
28+
if 'clusters' not in cfg or not isinstance(cfg['clusters'], dict):
29+
raise RuntimeError('clusters.yaml must be a YAML dict, and so must be .clusters')
30+
return cfg
3131

3232

3333
def init_plugin(plugin_kind, config):
3434
plugin_maker = PLUGIN_LOOKUP.get(plugin_kind)
3535
if plugin_maker is None:
3636
raise ValueError(f"unknown plugin '{plugin_kind}'")
37-
return plugin_maker(config)
37+
return plugin_maker(config, basepath=BASEPATH)
3838

3939

4040
@click.group()
@@ -44,19 +44,20 @@ def cli():
4444

4545
@cli.command()
4646
@click.argument('cluster_id', type=str, default="default")
47-
@cli.pass_obj
47+
@click.pass_obj
4848
def create(cfg, cluster_id):
49-
spec = cfg[cluster_id]
49+
spec = cfg['clusters'][cluster_id]
5050
config = spec['config']
5151
config['name'] = cluster_id
52-
init_plugin(spec['kind'], config).create_cluster()
52+
kubeconfig_path = os.path.abspath(os.path.join(cluster_id, 'kubeconfig.yaml'))
53+
init_plugin(spec['kind'], config).create_cluster(kubeconfig_path)
5354

5455

5556
@cli.command()
5657
@click.argument('cluster_id', type=str, default="default")
57-
@cli.pass_obj
58+
@click.pass_obj
5859
def delete(cfg, cluster_id):
59-
spec = cfg[cluster_id]
60+
spec = cfg['clusters'][cluster_id]
6061
config = spec['config']
6162
config['name'] = cluster_id
6263
init_plugin(spec['kind'], config).delete_cluster()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apiVersion: cluster.x-k8s.io/v1beta1
2+
kind: Cluster
3+
metadata:
4+
name: '{{ name }}'
5+
spec:
6+
clusterNetwork:
7+
services:
8+
cidrBlocks: ['10.128.0.0/12']
9+
pods:
10+
cidrBlocks: ['192.168.0.0/16']
11+
serviceDomain: 'cluster.local'
12+
topology:
13+
# the following variables can be determined automatically using autoVars: syself
14+
# for this detection, we list all clusterstackrelease objects and select the latest one that fits the
15+
# requested kubernetesVersion
16+
class: '{{ cs_class_name }}'
17+
version: '{{ cs_version }}'
18+
controlPlane:
19+
replicas: 3
20+
workers:
21+
machineDeployments:
22+
- class: workeramd64hcloud
23+
name: md-0
24+
replicas: 1
25+
failureDomain: nbg1
26+
variables:
27+
overrides:
28+
- name: workerMachineTypeHcloud
29+
value: cpx31
30+
variables:
31+
- name: region
32+
value: nbg1
33+
- name: controlPlaneMachineTypeHcloud
34+
value: cpx31
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: clusterstack.x-k8s.io/v1alpha1
2+
kind: ClusterStack
3+
metadata:
4+
name: '{{ cs_name }}'
5+
spec:
6+
provider: hetzner
7+
name: apalla
8+
kubernetesVersion: '{{ kubernetesVersion }}'
9+
channel: stable
10+
autoSubscribe: true
11+
providerRef:
12+
name: '{{ cs_name }}'
13+
kind: HetznerClusterStackReleaseTemplate
14+
apiVersion: infrastructure.clusterstack.x-k8s.io/v1alpha1
15+
---
16+
apiVersion: infrastructure.clusterstack.x-k8s.io/v1alpha1
17+
kind: HetznerClusterStackReleaseTemplate
18+
metadata:
19+
name: '{{ cs_name }}'
20+
spec:
21+
template:
22+
spec:
23+
nodeImages:
24+
- controlplaneamd64hcloud
25+
- workeramd64hcloud
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
clusters:
3+
- cluster:
4+
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM2akNDQWRLZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJek1Ea3hNREEyTXpnek1sb1hEVE16TURrd056QTJORE16TWxvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTWE3CjJYYWRieFVKSHdQSGQxMTNHNHdnSGZmL0RTMEhYVitaQjRyRDEvVllDSnFEemRTN2NkeC8yY245a3Z0VHA3UjgKakFVWUdkbndaTkdiWlZSY2xVZEMraWhTTFlMdU1kallWcWFyU3VmbVZlQ3lHcTFLQnNkTFpOcmpMU2RTL2o3awo1ZEZBL0Y2WmYzSzBlV3RZeDhJWTliQjQ0ZXgyY29ZOU1HTjV6WEUyZCs3Wm8wSVVCWXcxWHB1ODdYZFdlSzJJCjhpR0xxdVZFcGRac0lvZEJNZk4yWTVLK3JXVmJyQUhpWXB5U0llNkVyLzlpYU5nS2hndjlQanlBRFBHNEtFc2YKTjg3UDNWK2d4eG1VNzVVRUQwTjFXdXB3YkRLekVYY0JwajJ1QXF2MzA4SVM5ZzNwRE1oUVFKUDc5NjBFMUpqVwpOKzJWQzREZkY4K2FsUEF1S1VNQ0F3RUFBYU5GTUVNd0RnWURWUjBQQVFIL0JBUURBZ0trTUJJR0ExVWRFd0VCCi93UUlNQVlCQWY4Q0FRQXdIUVlEVlIwT0JCWUVGTVdxem03TjNxUDhIL2JsMHJvaUlkK1hVdkRSTUEwR0NTcUcKU0liM0RRRUJDd1VBQTRJQkFRQi9CSlNtVnB3aGhFTCtCNExicDBDVFdwYmFhL0xlTDVkdEZZL01wMnVpbXdPMQpKeWVuV0U5QWpJaTRMU1puV00yYzh2QTRkbmlMdXcwdjZrUGFjeHlIQVQ0Zk5WcFRpcURPNyt1L1hXaTZmYUMxCkNYanJjNjJxbXBWd0MwckhsU1U4eHpQckk3MHltNmVSZUJNUE5VV1k4OTc2K2pTQ1o0ZEdxc0g4aU1SMzNpT2UKd1BNQWltUTFabktXL0RpRkZoYXc3MHUrdEFOcGw4VXFuSjR4SGJIY2hpMkJ4b0M1Mzk4ZS82QVNsOVlKbG5MRwpCRFZCeFZISnpmTTZoM0lBQS9hVEtPM3JZSFlrWURVWFlkNXh0RTkvNForaXJKV1BBNzA5aFRXbHF3VWk5U25iCnhQMHppMFZteDRONjUvN1IxS3Z3UTJlS3N1d3ZqQ3ZMdnZ5Y3RUNTgKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
5+
server: https://autopilot-1.autopilot-prod.k8s.syself.net:443
6+
name: autopilot-1
7+
contexts:
8+
- context:
9+
cluster: autopilot-1
10+
namespace: org-scs
11+
user: gitops
12+
name: default
13+
current-context: default
14+
kind: Config
15+
preferences: {}
16+
users:
17+
- name: gitops
18+
user:
19+
token: '{{ token }}'

playbooks/clusters.yaml.j2

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,61 @@ clusters:
33
syself-1.32:
44
kind: clusterstacks
55
config:
6-
token: "{{ clouds_conf.syself_token }}"
76
kubernetesVersion: '1.32'
8-
autoVars: syself # will determine class and version automatically using kubernetesVersion
9-
cluster: syself-cluster.yaml
10-
clusterstack: syself-clusterstack.yaml
7+
autoVars: syself # determine cs_class_name and cs_version automatically using kubernetesVersion
8+
templates:
9+
cluster: syself-cluster.yaml
10+
clusterstack: syself-clusterstack.yaml
11+
kubeconfig: syself-kubeconfig.yaml
1112
vars:
12-
cs-name: hetzner-apalla-1-32
13+
cs_name: hetzner-apalla-1-32
14+
secrets:
15+
token: "{{ clouds_conf.syself_token }}"
1316
syself-1.31:
1417
kind: clusterstacks
1518
config:
16-
token: "{{ clouds_conf.syself_token }}"
1719
kubernetesVersion: '1.31'
18-
autoVars: syself # will determine class and version automatically using kubernetesVersion
19-
cluster: syself-cluster.yaml
20-
clusterstack: syself-clusterstack.yaml
20+
autoVars: syself # determine cs_class_name and cs_version automatically using kubernetesVersion
21+
templates:
22+
cluster: syself-cluster.yaml
23+
clusterstack: syself-clusterstack.yaml
24+
kubeconfig: syself-kubeconfig.yaml
2125
vars:
22-
cs-name: hetzner-apalla-1-31
26+
cs_name: hetzner-apalla-1-31
27+
secrets:
28+
token: "{{ clouds_conf.syself_token }}"
2329
syself-1.30:
2430
kind: clusterstacks
2531
config:
26-
token: "{{ clouds_conf.syself_token }}"
2732
kubernetesVersion: '1.30'
28-
autoVars: syself # will determine class and version automatically using kubernetesVersion
29-
cluster: syself-cluster.yaml
30-
clusterstack: syself-clusterstack.yaml
33+
autoVars: syself # determine cs_class_name and cs_version automatically using kubernetesVersion
34+
templates:
35+
cluster: syself-cluster.yaml
36+
clusterstack: syself-clusterstack.yaml
37+
kubeconfig: syself-kubeconfig.yaml
3138
vars:
32-
cs-name: hetzner-apalla-1-30
39+
cs_name: hetzner-apalla-1-30
40+
secrets:
41+
token: "{{ clouds_conf.syself_token }}"
42+
# dev clusters using kind
43+
# latest versions to be found under https://hub.docker.com/r/kindest/node/tags
44+
kind-1.32:
45+
kind: kind
46+
config:
47+
cluster: kind-cluster.yaml
48+
image: 'kindest/node:v1.32.3'
49+
kind-1.31:
50+
kind: kind
51+
config:
52+
cluster: kind-cluster.yaml
53+
image: 'kindest/node:v1.31.6'
54+
kind-1.30:
55+
kind: kind
56+
config:
57+
cluster: kind-cluster.yaml
58+
image: 'kindest/node:v1.30.10'
59+
kind-1.29:
60+
kind: kind
61+
config:
62+
cluster: kind-cluster.yaml
63+
image: 'kindest/node:v1.29.14'

0 commit comments

Comments
 (0)