Skip to content

Commit

Permalink
RKE1 test caes about cloud-provider and csi-driver
Browse files Browse the repository at this point in the history
  • Loading branch information
albinsun committed Nov 29, 2023
1 parent fa44a0f commit c0b91e6
Show file tree
Hide file tree
Showing 4 changed files with 320 additions and 10 deletions.
3 changes: 2 additions & 1 deletion apiclient/rancher_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
CloudCredentialManager, ClusterRegistrationTokenManager, HarvesterConfigManager,
KubeConfigManager, MgmtClusterManager, SecretManager, SettingManager,
ClusterManager, NodeTemplateManager, NodePoolManager, UserManager,
ClusterDeploymentManager, ClusterServiceManager, PVCManager
ChartManager, ClusterDeploymentManager, ClusterServiceManager, PVCManager
)


Expand Down Expand Up @@ -45,6 +45,7 @@ def __init__(self, endpoint, token=None, session=None):
self.clusters = ClusterManager(self)
self.node_templates = NodeTemplateManager(self)
self.node_pools = NodePoolManager(self)
self.charts = ChartManager(self)
self.cluster_deployments = ClusterDeploymentManager(self)
self.cluster_services = ClusterServiceManager(self)
self.pvcs = PVCManager(self)
Expand Down
33 changes: 29 additions & 4 deletions apiclient/rancher_api/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from weakref import ref
from collections.abc import Mapping

from .models import UserSpec
from .models import UserSpec, ChartSpec


DEFAULT_NAMESPACE = "default"
Expand Down Expand Up @@ -346,6 +346,24 @@ def create(self, name, cluster_id, *, raw=False):
return self._create(self.PATH_fmt.format(cluster_id=cluster_id), json=data, raw=raw)


class ChartManager(BaseManager):
PATH_fmt = "k8s/clusters/{cluster_id}/v1/catalog.cattle.io.apps"
CREATE_fmt = "k8s/clusters/{cluster_id}/v1/catalog.cattle.io.clusterrepos/rancher-charts"

def get(self, cluster_id, namespace, name, raw=False):
url = self.PATH_fmt.format(cluster_id=cluster_id)
if namespace:
url = f"{url}/{namespace}"
if name:
url = f"{url}/{name}"
return self._get(url, raw=raw)

def create(self, cluster_id, namespace, name, raw=False):
url = self.CREATE_fmt.format(cluster_id=cluster_id) + "?action=install"
data = ChartSpec(cluster_id, namespace, name).to_dict()
return self._create(url, json=data, raw=raw)


class ClusterDeploymentManager(BaseManager):
PATH_fmt = "k8s/clusters/{cluster_id}/v1/apps.deployments"

Expand Down Expand Up @@ -657,7 +675,7 @@ def delete(self, name, *, raw=False):
class ClusterManager(BaseManager):
PATH_fmt = "v3/cluster/{uid}"

def create_data(self, name, k8s_version):
def create_data(self, name, k8s_version, kubeconfig):

return {
"dockerRootDir": "/var/lib/docker",
Expand Down Expand Up @@ -755,6 +773,13 @@ def create_data(self, name, k8s_version):
"type": "nodeDrainInput"
},
"maxUnavailableUnit": "percentage"
},
"cloudProvider": {
"type": "cloudProvider",
"name": "harvester",
"harvesterCloudProvider": {
"cloudConfig": kubeconfig
}
}
},
"localClusterAuthEndpoint": {
Expand All @@ -772,8 +797,8 @@ def create_data(self, name, k8s_version):
def get(self, name="", *, raw=False):
return self._get(self.PATH_fmt.format(uid=name), raw=raw)

def create(self, name, k8s_version, *, raw=False):
data = self.create_data(name, k8s_version)
def create(self, name, k8s_version, kubeconfig, *, raw=False):
data = self.create_data(name, k8s_version, kubeconfig)
return self._create(self.PATH_fmt.format(uid=""), json=data, raw=raw)

def delete(self, name, *, raw=False):
Expand Down
40 changes: 40 additions & 0 deletions apiclient/rancher_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,43 @@ def from_dict(cls, data):
))
obj._data = data
return obj


class ChartSpec:
def __init__(self, cluster_id, namespace, chart):
self.cluster_id = cluster_id
self.namespace = namespace
self.chart = chart

def to_dict(self):
data = {
"charts": [
{
"chartName": self.chart,
"releaseName": self.chart,
"annotations": {
"catalog.cattle.io/ui-source-repo-type": "cluster",
"catalog.cattle.io/ui-source-repo": "rancher-charts"
},
"values": {
"global": {
"cattle": {
"systemDefaultRegistry": "",
"clusterId": self.cluster_id,
"rkePathPrefix": "",
"rkeWindowsPathPrefix": ""
},
"systemDefaultRegistry": ""
}
}
}
],
"noHooks": False,
"timeout": "600s",
"wait": True,
"namespace": self.namespace,
"disableOpenAPIValidation": False,
"skipCRDs": False
}

return data
Loading

0 comments on commit c0b91e6

Please sign in to comment.