Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testcase on RKE1 cluster #995

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Spec is not designed as harvester_api, it would be a bit confusing.
I would suggest that if we are not let Spec as class attribute have more customization, we can simply use create_data instead. (then there would not need the ChartSpec)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment.
Already put it into refactoring workitem. Will fix in #960 (comment)

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
Loading