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

Introduce drenv providers #1534

Merged
merged 14 commits into from
Sep 18, 2024
Merged

Introduce drenv providers #1534

merged 14 commits into from
Sep 18, 2024

Conversation

nirs
Copy link
Member

@nirs nirs commented Aug 27, 2024

Preparing for running drenv on Apple silicon via lima, introduce the providers package. The first provider is minikube.

This is change mostly internal refactoring without changing the behavior, making it easy to add a lima provider in a clean and safe way.

Behavior changes:

  • drenv setup and cleanup commands requires an env file, since the provider is a profile property. This allows mixing different types of clusters in the same environment which may be useful.
  • Minor logging changes

Testing:

Part of #1513

@nirs nirs force-pushed the drenv-providers branch from fce36f2 to d314271 Compare August 27, 2024 22:14
@nirs nirs marked this pull request as ready for review August 28, 2024 10:57
@nirs nirs force-pushed the drenv-providers branch 3 times, most recently from c02db9f to 18e6076 Compare August 28, 2024 18:25
@nirs nirs force-pushed the drenv-providers branch from 18e6076 to d8e659f Compare August 29, 2024 20:30
@nirs
Copy link
Member Author

nirs commented Aug 29, 2024

New version improves the provider interface:

  • exists() accepts a profile dict
  • minikube functions grouped by type
  • external grouping fixed (exists in cluster scope)

https://github.com/RamenDR/ramen/compare/18e6076f67122976d4d108bd0b7b6be78aa93d42..d8e659f75919afcb7683f7c4a954ef49d4e31c30

@nirs nirs force-pushed the drenv-providers branch 2 times, most recently from 082be65 to ca352fb Compare September 1, 2024 22:00
@nirs
Copy link
Member Author

nirs commented Sep 1, 2024

New version fixes containerd to be configured only when creating a cluster (bad refactoring).

https://github.com/RamenDR/ramen/compare/082be65ca3a9286fbbd0121e47598e643ec81f71..ca352fbdb7beba198a2cea108692360f64aecdeb

@nirs nirs mentioned this pull request Sep 2, 2024
5 tasks
@nirs nirs requested a review from abhijeet219 September 3, 2024 12:51
@nirs
Copy link
Member Author

nirs commented Sep 5, 2024

Lasted push add few improvements based on experience with the lima provider.

  • Support watching command log that log to stderror (like drenv and limactl)
  • Log drenv log in drenv tests
  • Use /readyz endpoint when waiting cluster is ready
  • Fail fast if cluster does not have a kubeconfig when starting external cluster
  • Wait until external cluster is ready when starting external cluster

https://github.com/RamenDR/ramen/compare/ca352fbdb7beba198a2cea108692360f64aecdeb..3718ad52949fb494963ad4b07fd0c15249a9abbf

@nirs
Copy link
Member Author

nirs commented Sep 5, 2024

Lat push improve logs when waiting until external cluster is ready.

https://github.com/RamenDR/ramen/compare/3718ad52949fb494963ad4b07fd0c15249a9abbf..a8fcd6ed6d8d89294e521422c910f15804ff0c6d

@nirs nirs force-pushed the drenv-providers branch 6 times, most recently from f19e22a to 4a62057 Compare September 13, 2024 00:44
@nirs
Copy link
Member Author

nirs commented Sep 13, 2024

Changes in latest version:

  • Add debug logs in envfile to make debugging on remote machines easier

https://github.com/RamenDR/ramen/compare/f19e22a5accde3c1ef1140e0a4a9a61bbda267fa..4a62057290b457284e4bab0cbcda7da55d39c313

@nirs nirs force-pushed the drenv-providers branch 2 times, most recently from e43dfb7 to f57fc27 Compare September 17, 2024 13:13
To make it possible to debug platform and machine detection in github
and or in developer environment.

Signed-off-by: Nir Soffer <[email protected]>
All the public functions in the minikube module accept a profile, but
this is actually a profile name. We want to pass a profile dict to
start(). Use `name` for functions accepting a profile names.

Signed-off-by: Nir Soffer <[email protected]>
nirs added 12 commits September 17, 2024 16:55
The minikube module is mostly a thin wrapper for the minikube command,
and we have higher level helpers in __main__.py. Since we wan to have
multiple providers (e.g. lima, external), move all the helpers to the
minikube module.

Signed-off-by: Nir Soffer <[email protected]>
This step is not part of creating vnev, and will be more complicated to
do as part of creating the venv when adding providers. This must be run
manually as we do in the CI.

Signed-off-by: Nir Soffer <[email protected]>
The envfile can have now a "provider" property, defaults to "$provider",
which expands to the platform default provider. The first provider is
minikube.

The setup and cleanup commands requires now an env file, since they need
to get the provider to setup.

Signed-off-by: Nir Soffer <[email protected]>
We want to minimize the provider interface to make it easier to create
new providers.

Signed-off-by: Nir Soffer <[email protected]>
These commands are not very portable, they work only on Linux when using
minikube kvm2 driver.

Signed-off-by: Nir Soffer <[email protected]>
All functions used in drenv/__main__.py pass now the profile dict
instead of the name. This is required for some functions like suspend
and resume, since these operations are available only on certain profile
driver.

The load_files() function was renamed to configure(). The function also
accepts the profile so the provider can configure the cluster based on
the cluster configuration. This will be useful to configure containerd
later.

The setup_files() and cleanup_files() were renamed to setup() and
cleanup(). They do not accept a profile since they are called once per
provider.

Functions are grouped by type: provider scope, cluster scope, and
private helpers.

Signed-off-by: Nir Soffer <[email protected]>
This makes the start flow more generic, and allow every provider to do
the right thing for the profile and cluster status.

Signed-off-by: Nir Soffer <[email protected]>
This is a specific minikube workaround - when starting an existing
cluster, kubernetes reports stale state for a while. The wait is not
needed for external cluster which we never restart. If this will be
needed for other provider we can extract a common helper later.

Signed-off-by: Nir Soffer <[email protected]>
Some commands (like drenv) log to stderr without writing anything to
stdout. When we watch such commands we want to watch stderr instead of
stdout. Since the command do not write anything to stdout, we can
redirect the command stderr to stdout.

When a command fails, we cannot report the error message since it was
already yielded to the code watching the command. This is the issue with
logging everything to stderr, but we don't control the commands we run.

This change add an option to redirect stderr to commands.watch() and
and test the behavior.

Signed-off-by: Nir Soffer <[email protected]>
Like limactl, drenv logs only to stderr, so when running it in tests
with:

    commands.run("drenv", "start", ...)

we don't see anything in the test logs. If the test is blocking for long
time, we have no way to debug this. The helpful log lines are buffered
in the command error buffer.

Use the new stderr= argument to watch and log the command output, and
add helpers for drenv in a consistent way.

Signed-off-by: Nir Soffer <[email protected]>
We used `kubectl version` as a proxy for cluster readynes, checking for
server info in the response. Replace the check with lower level check if
API server /readyz endpoint.

Signed-off-by: Nir Soffer <[email protected]>
Before this change we had only one provider, so this was internal
implementation detail. This change adds the second provider, allowing
users to configure the provider in the environment file.

Replace the `external: true` option with `provider: external`. With this
we can remove the special handling or external cluster with calls to the
external provider which does the right thing.

The external provider basically does nothing, since we do not manage
this cluster. However in start() we ensure that the cluster exists and
then wait until the cluster is ready. This helps to debug issues with
external cluster and reduces log noise.

Signed-off-by: Nir Soffer <[email protected]>
@ShyamsundarR ShyamsundarR merged commit 19b296a into RamenDR:main Sep 18, 2024
18 of 20 checks passed
@nirs nirs deleted the drenv-providers branch November 20, 2024 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants