Skip to content

Commit

Permalink
Add external provider
Browse files Browse the repository at this point in the history
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 mostly do nothing.

The external provider may be improved later, for example we may want to
configure containerd for kubevirt. Since we don't have yet environment
using this configuration I'm leaving as is now.

Signed-off-by: Nir Soffer <[email protected]>
  • Loading branch information
nirs committed Aug 29, 2024
1 parent b04b6cd commit d8e659f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 23 deletions.
8 changes: 5 additions & 3 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,11 @@ $ drenv delete envs/example.yaml

- `templates`: templates for creating new profiles.
- `name`: profile name.
- `external`: true if this is existing external cluster. In this
case the tool will not start a minikube cluster and all other
options are ignored.
- `provider`: cluster provider. The default provider is "minikube",
creating cluster using VM or containers. Use "external" to use
exsiting clusters not managed by `drenv`. Use the special value
"$provider" to select the best provider for the host. (default
"$provider")
- `driver`: The minikube driver. On Linux, the default drivers are kvm2 and
docker for VMs and containers. On MacOS, the defaults are hyperkit and
podman. Use "$vm" and "$container" values to use the recommended VM and
Expand Down
26 changes: 10 additions & 16 deletions test/drenv/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,13 @@ def collect_addons(env):

def start_cluster(profile, hooks=(), args=None, **options):
provider = providers.get(profile["provider"])
if profile["external"]:
logging.debug("[%s] Skipping external cluster", profile["name"])
else:
existing = provider.exists(profile)
provider.start(profile, verbose=args.verbose)
provider.configure(profile, existing=existing)
if existing:
restart_failed_deployments(profile)
existing = provider.exists(profile)

provider.start(profile, verbose=args.verbose)
provider.configure(profile, existing=existing)

if existing:
restart_failed_deployments(profile)

if hooks:
execute(
Expand All @@ -391,19 +390,14 @@ def stop_cluster(profile, hooks=(), **options):
allow_failure=True,
)

provider = providers.get(profile["provider"])
if profile["external"]:
logging.debug("[%s] Skipping external cluster", profile["name"])
elif cluster_status != cluster.UNKNOWN:
if cluster_status != cluster.UNKNOWN:
provider = providers.get(profile["provider"])
provider.stop(profile)


def delete_cluster(profile, **options):
provider = providers.get(profile["provider"])
if profile["external"]:
logging.debug("[%s] Skipping external cluster", profile["name"])
else:
provider.delete(profile)
provider.delete(profile)

profile_config = drenv.config_dir(profile["name"])
if os.path.exists(profile_config):
Expand Down
53 changes: 53 additions & 0 deletions test/drenv/providers/external.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# SPDX-FileCopyrightText: The RamenDR authors
# SPDX-License-Identifier: Apache-2.0

import logging

# Provider scope


def setup():
logging.info("[external] Skipping setup for external provider")


def cleanup():
logging.info("[external] Skipping cleanup for external provider")


# Cluster scope


def exists(profile):
return True


def start(profile, verbose=False):
logging.info("[%s] Skipping start for external cluster", profile["name"])


def configure(profile, existing=False):
logging.info("[%s] Skipping configure for external cluster", profile["name"])


def stop(profile):
logging.info("[%s] Skipping stop for external cluster", profile["name"])


def delete(profile):
logging.info("[%s] Skipping delete for external cluster", profile["name"])


def suspend(profile):
logging.info("[%s] Skipping suspend for external cluster", profile["name"])


def resume(profile):
logging.info("[%s] Skipping resume for external cluster", profile["name"])


def cp(name, src, dst):
logging.warning("[%s] cp not implemented yet for external cluster", name)


def ssh(name, command):
logging.warning("[%s] ssh not implemented yet for external cluster", name)
8 changes: 4 additions & 4 deletions test/envs/external.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# SPDX-FileCopyrightText: The RamenDR authors
# SPDX-License-Identifier: Apache-2.0

# Example environment using external clusters. The cluster `test` must exist
# when this environment is started.
# Example environment using external clusters. The cluster must exist when this
# environment is started.
#
# To try this example, create the cluster with:
#
# drenv start envs/test.yaml
# drenv start envs/vm.yaml
#
# Now you can start this environment with:
#
Expand All @@ -20,7 +20,7 @@
name: external
profiles:
- name: cluster
external: true
provider: external
workers:
- addons:
- name: example

0 comments on commit d8e659f

Please sign in to comment.