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

Wip/fix get harvester kubeconfig #1628

Merged
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
16 changes: 12 additions & 4 deletions apiclient/rancher_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,27 @@ def __repr__(self):

def _get(self, path, **kwargs):
url = urljoin(self.endpoint, path)
return self.session.get(url, **kwargs)
resp = self.session.get(url, **kwargs)
print(f"{resp.request.method} {resp.request.url}")
Copy link
Member

Choose a reason for hiding this comment

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

please remove the test output.

return resp

def _post(self, path, **kwargs):
url = urljoin(self.endpoint, path)
return self.session.post(url, **kwargs)
resp = self.session.post(url, **kwargs)
print(f"{resp.request.method} {resp.request.url}")
return resp

def _put(self, path, **kwargs):
url = urljoin(self.endpoint, path)
return self.session.put(url, **kwargs)
resp = self.session.put(url, **kwargs)
print(f"{resp.request.method} {resp.request.url}")
return resp

def _delete(self, path, **kwargs):
url = urljoin(self.endpoint, path)
return self.session.delete(url, **kwargs)
resp = self.session.delete(url, **kwargs)
print(f"{resp.request.method} {resp.request.url}")
return resp

def authenticate(self, user, passwd, **kwargs):
path = "v3-public/localProviders/local?action=login"
Expand Down
5 changes: 5 additions & 0 deletions apiclient/rancher_api/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ def delete(self, name, *, raw=False):

class ClusterManager(BaseManager):
PATH_fmt = "v3/cluster/{uid}"
PATH1_fmt = "v3/clusters/{uid}"
Copy link
Member

Choose a reason for hiding this comment

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

it looks we didn't use this, is there any reason to add it?


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

Expand Down Expand Up @@ -808,6 +809,10 @@ def create(self, name, k8s_version, kubeconfig, *, raw=False):
def delete(self, name, *, raw=False):
return self._delete(self.PATH_fmt.format(uid=name), raw=raw)

def generate_kubeconfig(self, name, *, raw=False):
params = {'action': 'generateKubeconfig'}
return self._create(f"v3/clusters/{name}", raw=raw, params=params)

def explore(self, name):
from .cluster_api import ClusterExploreAPI # circular dependency
return ClusterExploreAPI(self.api.endpoint, self.api.session, name)
Expand Down
4 changes: 3 additions & 1 deletion harvester_e2e_tests/fixtures/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def __init__(self):

def _storage_net_configured(self):
code, data = self.settings.get('storage-network')
if (cs := data.get('status', {}).get('conditions')):
Copy link
Member

Choose a reason for hiding this comment

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

The assignment expressions (:=) is introduced in python 3.8, which is the version we targeting to support, is there any reason to replace it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not supported in Python 3.6. We maintain a Python 3.6 environment in our tox config. Either we drop that as well, or we stick to Python 3.6 compatibility.


cs = data.get('status', {}).get('conditions')
if cs:
if 'True' == cs[-1].get('status') and 'Completed' == cs[-1].get('reason'):
return True, (code, data)
return False, (code, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,14 @@ def harvester_mgmt_cluster(api_client, rancher_api_client, unique_name, polling_
@pytest.fixture(scope='module')
def harvester_cloud_credential(api_client, rancher_api_client,
harvester_mgmt_cluster, unique_name):
harvester_kubeconfig = api_client.generate_kubeconfig()
code, data = rancher_api_client.clusters.generate_kubeconfig(
Copy link
Member

Choose a reason for hiding this comment

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

I think the two configurations are same, could you check with @albinsun about the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are not the same. One uses Rancher's API endpoint and authenticates with a Rancher token and the other one uses Harvester's API endpoint directly.
For these tests we need to use Rancher's API endpoint.
Please read the issue linked up top.

harvester_mgmt_cluster['id']
)
assert 200 == code, (
f"Failed to create kubconfig with error: {code}, {data}"
)
harvester_kubeconfig = data['config']

code, data = rancher_api_client.cloud_credentials.create(
unique_name,
harvester_kubeconfig,
Expand Down
3 changes: 2 additions & 1 deletion harvester_e2e_tests/integrations/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ def test_degraded_volume(self, api_client, wait_timeout, vm_shell_from_host,
# https://github.com/harvester/harvester/issues/6425
code, data = api_client.hosts.get()
assert 200 == code, (code, data)
if (cluster_size := len(data['data'])) < 3:
cluster_size = len(data['data'])
if cluster_size < 3:
pytest.skip(
f"Degraded volumes only checked on 3+ nodes cluster, skip on {cluster_size}."
)
Expand Down