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

Feat/add cluster stacks remote api plugin #831

Draft
wants to merge 5 commits into
base: feat/add-cluster-stacks-plugin
Choose a base branch
from

Conversation

tonifinger
Copy link
Contributor

This PR implement plugin for cluster-stacks-remote-api.

It provides a PoC for the basic functionality afor the usage of the moin cluster.
Currently supports only one cluster.yaml.

@tonifinger
Copy link
Contributor Author

tonifinger commented Nov 19, 2024

To test it against the scs-test-runner.py use the following command to provision a cluster:

./scs-test-runner.py --config ./config.toml --debug provision --preset="kaas-dev"

And the following command to unprovision a cluster:

./scs-test-runner.py --config ./config.toml --debug unprovision --preset="kaas-dev"

@michal-gubricky michal-gubricky force-pushed the feat/add-cluster-stacks-plugin branch from 3b32e32 to a967d90 Compare November 20, 2024 07:40
PoC for the basic functionality and use of the moin cluster.
Currently only supports one cluster.yaml.

Signed-off-by: Toni Finger <toni.finger@cloudandheat.com>
@tonifinger tonifinger force-pushed the feat/add-cluster-stacks-remote-api branch from 500b3c8 to 267d88c Compare November 20, 2024 08:25
@michal-gubricky michal-gubricky force-pushed the feat/add-cluster-stacks-plugin branch 3 times, most recently from a72080e to 70f580c Compare November 21, 2024 10:11
Signed-off-by: michal.gubricky <michal.gubricky@dnation.cloud>
Signed-off-by: michal.gubricky <michal.gubricky@dnation.cloud>
Signed-off-by: michal.gubricky <michal.gubricky@dnation.cloud>
@michal-gubricky
Copy link
Contributor

I've updated the implementation of the cluster stacks remote API plugin. The deletion and creation of workload clusters should work when the management cluster already has the necessary CAPI/CAPO resources, and the given namespace contains the required secret and ClusterResourceSet resource.

@anjastrunk anjastrunk added the SCS-VP10 Related to tender lot SCS-VP10 label Nov 25, 2024
@tonifinger
Copy link
Contributor Author

tonifinger commented Nov 25, 2024

DRAFT:

I've updated the implementation of the cluster stacks remote API plugin. The deletion and creation of workload clusters should work when the management cluster already has the necessary CAPI/CAPO resources, and the given namespace contains the required secret and ClusterResourceSet resource.

I did not get the provisioning process working it crashes with the following error:

(venv) tf@tf-ThinkPad:~/repos/ci/scs/01_ISSUES/standards/Tests$ ./scs-test-runner.py --config ./config.toml --debug provision --preset="kaas-dev"
DEBUG: running provision for subject(s) moin-cluster-current-2, num_workers: 1
/bin/sh: 1: /tmp/envsubst: not found
error: unknown command "oidc-login" for "kubectl"
Unable to connect to the server: getting credentials: exec: executable kubectl failed with exit code 1
ERROR: Error applying clusterstack.yaml: Command '/tmp/envsubst < /home/tf/repos/ci/scs/01_ISSUES/standards/Tests/../playbooks/k8s_configs/moin_cluster_clusterstack.yaml | kubectl apply -f -' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/home/tf/repos/ci/scs/01_ISSUES/standards/Tests/kaas/plugin/plugin_cluster_stacks_remote_api.py", line 203, in _apply_yaml
    self._run_subprocess(command, error_msg, shell=True, kubeconfig=kubeconfig)
  File "/home/tf/repos/ci/scs/01_ISSUES/standards/Tests/kaas/plugin/plugin_cluster_stacks_remote_api.py", line 312, in _run_subprocess
    result = subprocess.run(command, shell=shell, capture_output=capture_output, text=text, check=True, env=env)
  File "/usr/lib/python3.8/subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '/tmp/envsubst < /home/tf/repos/ci/scs/01_ISSUES/standards/Tests/../playbooks/k8s_configs/moin_cluster_clusterstack.yaml | kubectl apply -f -' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tf/repos/ci/scs/01_ISSUES/standards/Tests/kaas/plugin/run_plugin.py", line 65, in <module>
    cli()
  File "/home/tf/.local/lib/python3.8/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/home/tf/.local/lib/python3.8/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/home/tf/.local/lib/python3.8/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/tf/.local/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/tf/.local/lib/python3.8/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/home/tf/repos/ci/scs/01_ISSUES/standards/Tests/kaas/plugin/run_plugin.py", line 48, in create
    plugin.create_cluster(cluster_id, clusterinfo['branch'], os.path.abspath(clusterinfo['kubeconfig']))
  File "/home/tf/repos/ci/scs/01_ISSUES/standards/Tests/kaas/plugin/plugin_cluster_stacks_remote_api.py", line 140, in create_cluster
    self._apply_yaml(self.clusterstack, "Error applying clusterstack.yaml", kubeconfig=self.kubeconfig_mgmnt)
  File "/home/tf/repos/ci/scs/01_ISSUES/standards/Tests/kaas/plugin/plugin_cluster_stacks_remote_api.py", line 206, in _apply_yaml
    raise RuntimeError(f"{error_msg}: {error}")
RuntimeError: Error applying clusterstack.yaml: Command '/tmp/envsubst < /home/tf/repos/ci/scs/01_ISSUES/standards/Tests/../playbooks/k8s_configs/moin_cluster_clusterstack.yaml | kubectl apply -f -' returned non-zero exit status 1.

In the config.yaml I enabled only one moin cluster tests subject:

[subjects.moin-cluster-current-2.kubernetes_setup]
kube_plugin         = "cluster-stacks-api"
kube_plugin_config  = "../playbooks/k8s_configs/moin_cluster_config.yaml"
clusterspec_cluster = "current-k8s-release-2"

@michal-gubricky
Copy link
Contributor

DRAFT:

I've updated the implementation of the cluster stacks remote API plugin. The deletion and creation of workload clusters should work when the management cluster already has the necessary CAPI/CAPO resources, and the given namespace contains the required secret and ClusterResourceSet resource.

I did not get the provisioning process working it crashes with the following error:

(venv) tf@tf-ThinkPad:~/repos/ci/scs/01_ISSUES/standards/Tests$ ./scs-test-runner.py --config ./config.toml --debug provision --preset="kaas-dev"
DEBUG: running provision for subject(s) moin-cluster-current-2, num_workers: 1
/bin/sh: 1: /tmp/envsubst: not found
error: unknown command "oidc-login" for "kubectl"
Unable to connect to the server: getting credentials: exec: executable kubectl failed with exit code 1
ERROR: Error applying clusterstack.yaml: Command '/tmp/envsubst < /home/tf/repos/ci/scs/01_ISSUES/standards/Tests/../playbooks/k8s_configs/moin_cluster_clusterstack.yaml | kubectl apply -f -' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/home/tf/repos/ci/scs/01_ISSUES/standards/Tests/kaas/plugin/plugin_cluster_stacks_remote_api.py", line 203, in _apply_yaml
    self._run_subprocess(command, error_msg, shell=True, kubeconfig=kubeconfig)
  File "/home/tf/repos/ci/scs/01_ISSUES/standards/Tests/kaas/plugin/plugin_cluster_stacks_remote_api.py", line 312, in _run_subprocess
    result = subprocess.run(command, shell=shell, capture_output=capture_output, text=text, check=True, env=env)
  File "/usr/lib/python3.8/subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '/tmp/envsubst < /home/tf/repos/ci/scs/01_ISSUES/standards/Tests/../playbooks/k8s_configs/moin_cluster_clusterstack.yaml | kubectl apply -f -' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tf/repos/ci/scs/01_ISSUES/standards/Tests/kaas/plugin/run_plugin.py", line 65, in <module>
    cli()
  File "/home/tf/.local/lib/python3.8/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/home/tf/.local/lib/python3.8/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/home/tf/.local/lib/python3.8/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/tf/.local/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/tf/.local/lib/python3.8/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/home/tf/repos/ci/scs/01_ISSUES/standards/Tests/kaas/plugin/run_plugin.py", line 48, in create
    plugin.create_cluster(cluster_id, clusterinfo['branch'], os.path.abspath(clusterinfo['kubeconfig']))
  File "/home/tf/repos/ci/scs/01_ISSUES/standards/Tests/kaas/plugin/plugin_cluster_stacks_remote_api.py", line 140, in create_cluster
    self._apply_yaml(self.clusterstack, "Error applying clusterstack.yaml", kubeconfig=self.kubeconfig_mgmnt)
  File "/home/tf/repos/ci/scs/01_ISSUES/standards/Tests/kaas/plugin/plugin_cluster_stacks_remote_api.py", line 206, in _apply_yaml
    raise RuntimeError(f"{error_msg}: {error}")
RuntimeError: Error applying clusterstack.yaml: Command '/tmp/envsubst < /home/tf/repos/ci/scs/01_ISSUES/standards/Tests/../playbooks/k8s_configs/moin_cluster_clusterstack.yaml | kubectl apply -f -' returned non-zero exit status 1.

In the config.yaml I enabled only one moin cluster tests subject:

[subjects.moin-cluster-current-2.kubernetes_setup]
kube_plugin         = "cluster-stacks-api"
kube_plugin_config  = "../playbooks/k8s_configs/moin_cluster_config.yaml"
clusterspec_cluster = "current-k8s-release-2"

You must install envsubst. This step is described in README under the core requirements for now.

Signed-off-by: Toni Finger <toni.finger@cloudandheat.com>
@garloff
Copy link
Member

garloff commented Nov 26, 2024

If envsubst becomes to much of a hurdle, we could replace it with a few lines of python ...
How can we get this finalized?

@tonifinger
Copy link
Contributor Author

tonifinger commented Nov 29, 2024

If envsubst becomes to much of a hurdle, we could replace it with a few lines of python ... How can we get this finalized?

The envsubst part Is working I added the package to the python requirements.in.
So the generation of the clusterstack and cluster resource itself is working.

What needs to be changed, however, is the process of waiting for the k8s cluster to be ready. This is currently handled by waiting for resources that are not accessible to user accounts with minimal RBAC setup.

To resolve this problem, I suggest that we only use information provided by the “Cluster” resource.

@mbuechse mbuechse self-requested a review January 8, 2025 09:56
@mbuechse mbuechse self-assigned this Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SCS-VP10 Related to tender lot SCS-VP10
Projects
Status: Doing
Development

Successfully merging this pull request may close these issues.

5 participants