Skip to content

Commit 187f26c

Browse files
authored
simple plugin for clusterstacks-provided kaas (#916)
Signed-off-by: Matthias Büchse <[email protected]>
1 parent d5a797b commit 187f26c

22 files changed

+617
-173
lines changed

.zuul.d/config.yaml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
merge-mode: "squash-merge"
66
periodic-daily:
77
jobs:
8-
- scs-check-all
8+
- scs-check-iaas
9+
- scs-check-kaas
910
periodic-hourly:
1011
jobs:
1112
- scs-check-scs2-main
@@ -30,16 +31,31 @@
3031
nodeset: pod-fedora-40
3132
vars:
3233
preset: default
34+
iaas: true
35+
kaas: false
36+
do_provision: false
37+
do_cleanup: true
3338
pre-run:
3439
- playbooks/pre.yaml
3540
- playbooks/pre_cloud.yaml
3641
run: playbooks/compliance_check.yaml
42+
post-run:
43+
- playbooks/post_cloud.yaml
3744
- job:
3845
name: scs-check-scs2-main
3946
parent: scs-check-scs2
4047
branches: main
4148
- job:
42-
name: scs-check-all
49+
name: scs-check-iaas
4350
parent: scs-check-scs2-main
4451
vars:
45-
preset: all
52+
preset: iaas
53+
- job:
54+
name: scs-check-kaas
55+
parent: scs-check-scs2-main
56+
vars:
57+
preset: kaas
58+
iaas: false
59+
kaas: true
60+
do_provision: true
61+
do_cleanup: false

.zuul.d/secure.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,24 @@
321321
PHOVS1umROCJJi/5T78EA4ukDdFN/zdEktGauSDqUVRPASodV8Q3qvN6PgskPh1dQgxwB
322322
Po9R1405It3aQtBiXnT+38eKAd1nTJkaRlC03VgbeV+XrjMI1YsMQDAt+YhMKSfys1ZhB
323323
n6Dw+nc3Qi21G/CnY45rFUMLGTzevukKuHeiApf+eX4PdNQ1LPkUGrHdNnqkj8=
324+
syself_token: !encrypted/pkcs1-oaep
325+
- OYvAtbkl4/Bno5I21On7w7JkTlDhWZWKKOlHbVGcg4jBS4BW/HkPDsijnEjKsCg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CjZBOtsXw6ChbaagwzBxUk5zUIR3s56JKyjH
341+
WePIXTxyfpQVxP/PhLc7U659ooI/TflUyEUKyy0RlKVEvNINQcUSeoQHwWMCQPlWLbYPE
342+
uUgvW2Lghmg0+upQ1OfAV24lRryyUcpSYZ6yfohTgJsIMdy7r/Hn5GDnpZn2Um8rHkWxC
343+
rk7h2aWsD5IifYyt43ZHZdEdBX99NW+TMawXNZRevlmjoqgR4RGjo0Hxi4zSaqkNPHm/T
344+
YJcPPaJvKONZzrL3d+AWnhp6x/wi2uOBTFkrg8VmnZDiFf5YCZu/XMHYT5cjd0=

Tests/config.toml

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ subjects = [
1212
]
1313

1414

15-
[presets.all]
15+
[presets.iaas]
1616
scopes = [
1717
"scs-compatible-iaas",
1818
]
@@ -34,14 +34,26 @@ subjects = [
3434
workers = 4
3535

3636

37+
[presets.kaas]
38+
scopes = [
39+
"scs-compatible-kaas",
40+
]
41+
subjects = [
42+
"syself-1.32",
43+
"syself-1.31",
44+
"syself-1.30",
45+
]
46+
workers = 4
47+
48+
3749
[presets.kaas-dev]
3850
scopes = [
3951
"scs-compatible-kaas",
4052
]
4153
subjects = [
42-
"kind-current",
43-
"kind-current-1",
44-
"kind-current-2",
54+
"kind-1.32",
55+
"kind-1.31",
56+
"kind-1.30",
4557
]
4658
workers = 1 # better restrict this with clusters running on local machine
4759

@@ -58,29 +70,7 @@ spec = "./scs-compatible-kaas.yaml"
5870
# (this is the only mapping declaration that supports using Python string interpolation)
5971
[subjects._.mapping]
6072
os_cloud = "{subject}"
73+
# NOTE: this subject_root cannot be deviated from when using scs-test-runner.py
6174
subject_root = "{subject}"
6275
# NOTE: this kubeconfig cannot be deviated from when using scs-test-runner.py
6376
kubeconfig = "{subject}/kubeconfig.yaml"
64-
65-
66-
[subjects._.kubernetes_setup]
67-
clusterspec = "kaas/clusterspec.yaml"
68-
69-
70-
[subjects.kind-current.kubernetes_setup]
71-
kube_plugin = "kind"
72-
kube_plugin_config = "kaas/kind_config.yaml"
73-
clusterspec_cluster = "current-k8s-release"
74-
75-
76-
[subjects.kind-current-1.kubernetes_setup]
77-
kube_plugin = "kind"
78-
kube_plugin_config = "kaas/kind_config.yaml"
79-
clusterspec_cluster = "current-k8s-release-1"
80-
81-
82-
[subjects.kind-current-2.kubernetes_setup]
83-
kube_plugin = "kind"
84-
kube_plugin_config = "kaas/kind_config.yaml"
85-
clusterspec_cluster = "current-k8s-release-2"
86-

Tests/kaas/clusterspec.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

Tests/kaas/plugin/__init__.py

Whitespace-only changes.

Tests/kaas/plugin/cs_helper.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""helper functions for ClusterStacks plugin"""
2+
import base64
3+
import os
4+
5+
from kubernetes.client import Configuration, CoreV1Api, CustomObjectsApi
6+
7+
8+
def setup_client_config(client_config: Configuration, kubeconfig, cwd='.'):
9+
"""transfer authentication data from kubeconfig to client_config, creating file `ca.crt`s"""
10+
token = kubeconfig['users'][0]['user']['token']
11+
client_config.api_key['authorization'] = 'Bearer {}'.format(token)
12+
client_config.host = kubeconfig['clusters'][0]['cluster']['server']
13+
client_config.ssl_ca_cert = os.path.abspath(os.path.join(cwd, 'ca.crt'))
14+
with open(client_config.ssl_ca_cert, "wb") as fileobj:
15+
fileobj.write(base64.standard_b64decode(
16+
kubeconfig['clusters'][0]['cluster']['certificate-authority-data'].encode()
17+
))
18+
19+
20+
def create_cr(api_instance: CustomObjectsApi, namespace, resource_dict):
21+
"""mimic `kubectl apply` (rather create) with a custom resource"""
22+
group, ver = resource_dict['apiVersion'].split('/', 1)
23+
plural = resource_dict['kind'].lower() + 's'
24+
return api_instance.create_namespaced_custom_object(
25+
group, ver, namespace, plural, resource_dict, field_manager='plugin_clusterstacks',
26+
)
27+
28+
29+
def get_clusterstackreleases(api_instance: CustomObjectsApi, namespace):
30+
"""mimic `kubectl get clusterstackreleases`"""
31+
return api_instance.list_namespaced_custom_object(
32+
'clusterstack.x-k8s.io', 'v1alpha1', namespace, 'clusterstackreleases',
33+
)['items']
34+
35+
36+
def get_secret_data(api_instance: CoreV1Api, namespace, secret):
37+
"""mimic `kubectl get secrets NAME -o=jsonpath='{.data.value}' | base64 -d > kubeconfig.yaml`"""
38+
res = api_instance.read_namespaced_secret(secret, namespace)
39+
return base64.standard_b64decode(res.data['value'].encode())
40+
41+
42+
def get_cluster_status(api_instance: CustomObjectsApi, namespace, name):
43+
return api_instance.get_namespaced_custom_object_status(
44+
'cluster.x-k8s.io', 'v1beta1', namespace, 'clusters', name
45+
)
46+
47+
48+
def delete_cluster(api_instance: CustomObjectsApi, namespace, name):
49+
"""mimic `kubectl delete cluster`"""
50+
# beware: do not fiddle with propagation policy here, as this may lead to severe problems
51+
return api_instance.delete_namespaced_custom_object(
52+
'cluster.x-k8s.io', 'v1beta1', namespace, 'clusters', name,
53+
)

Tests/kaas/plugin/interface.py

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,36 @@
1-
2-
31
class KubernetesClusterPlugin():
42
"""
5-
An abstract base class for custom Kubernetes cluster provider plugins.
6-
It represents an interface class from which the api provider-specific
7-
plugins must be derived as child classes
8-
9-
To implement fill the methods `create_cluster` and `delete_cluster` with
10-
api provider-specific functionalities for creating and deleting clusters.
11-
The `create_cluster` method must ensure that the kubeconfigfile is provided
12-
at the position in the file system defined by the parameter
13-
`kubeconfig_filepath`
3+
An abstract base class for writing Kubernetes cluster provider plugins.
144
15-
- Implement `create_cluster` and `delete_cluster` methods
16-
- Create `__init__(self, config_file)` method to handle api specific
17-
configurations.
5+
- Implement the methods `create_cluster` and `delete_cluster`.
6+
- Create the method `__init__(self, config, basepath, cwd)` to
7+
handle API-specific configuration.
188
199
Example:
2010
.. code:: python
11+
import os.path
2112
2213
from interface import KubernetesClusterPlugin
2314
from apiX_library import cluster_api_class as ClusterAPI
2415
2516
class PluginX(KubernetesClusterPlugin):
2617
27-
def __init__(self, config_file):
28-
self.config = config_file
18+
def __init__(self, config, basepath, cwd):
19+
self.config = config
20+
self.basepath = basepath # find other config files here
21+
self.cwd = cwd # create new files here
2922
30-
def create_cluster(self, cluster_name, version, kubeconfig_filepath):
31-
self.cluster = ClusterAPI(name=cluster_name, image=cluster_image, kubeconfig_filepath)
32-
self.cluster.create(self.config)
23+
def create_cluster(self):
24+
kubeconfig_path = os.path.join(self.cwd, 'kubeconfig.yaml')
25+
ClusterAPI(name=self.config['name']).create(kubeconfig_path)
3326
3427
def delete_cluster(self, cluster_name):
35-
self.cluster = ClusterAPI(cluster_name)
36-
self.cluster.delete()
28+
ClusterAPI(name=self.config['name']).delete()
3729
..
3830
"""
3931

40-
def create_cluster(self, cluster_name, version, kubeconfig_filepath):
41-
"""
42-
This method is to be called to create a k8s cluster
43-
:param: cluster_name:
44-
:param: version:
45-
:param: kubeconfig_filepath:
46-
"""
32+
def create_cluster(self):
4733
raise NotImplementedError
4834

49-
def delete_cluster(self, cluster_name):
50-
"""
51-
This method is to be called in order to unprovision a cluster
52-
:param: cluster_name:
53-
"""
35+
def delete_cluster(self):
5436
raise NotImplementedError

0 commit comments

Comments
 (0)