devantler / ksail

CLI tool for provisioning GitOps enabled K8s clusters in Docker.
https://devantler.github.io/ksail/
Apache License 2.0
46 stars 3 forks source link

Automatically discover clusterName #209

Open rvangsgaard opened 4 months ago

rvangsgaard commented 4 months ago

Description

Try to discover clusterName based on current folder name. Consider validating the discovered name by looking for a corresponding YAML-file.

Example:

  1. CWD=$(current work dir)
  2. Check for file with name $CWD-k3d-config.yaml
devantler commented 4 months ago

Hmm, really good idea! I thought about this once but I was not able to come up with a good solution, as one could potentially want to initialize multiple clusters in the same folder.

I do not want to enforce ways of working, so do you have a suggestion of how I could handle if there are multiple KSail clusters initialized in the same folder?

rvangsgaard commented 3 months ago

I do not want to enforce ways of working, so do you have a suggestion of how I could handle if there are multiple KSail clusters initialized in the same folder?

I think a good default behavior is a good thing, and allow the user to override it. In this case:

  1. If the user specifies a cluster name, user it.
  2. If not, look for a config file (cluster) with the same name as the folder.
devantler commented 3 months ago

If not, look for a config file (cluster) with the same name as the folder.

The problem with this is that there could be:

cluster1-ksail-k3d-config.yaml
cluster2-ksail-k3d-config.yaml
k8s/clusters/cluster1/**
k8s/clusters/cluster2/**

In the same folder, thus I would not know which cluster the user wants to use by default.

My current solution proposal is to await having implemented a ksail native config file with something like this:

ksail-config.yaml
---
clusterName: cluster1
otherOption: dsadsad
anotherOption: dsdsad

There would only be one of these in your current folder, and that file can then be used to control the behavior of the CLI. Flags and arguments would overwrite the config values, and thus it would still be possible to run ksail up cluster2 to setup the other cluster using the default values from the config file.

Would this solve it for you? :-)

rvangsgaard commented 3 weeks ago

I do not understand the proposed solution - will the ksail native config file only contain exactly one clusterName or multiple. If you can, please elaborate on the ksail native config file, especially the example.

devantler commented 3 weeks ago

It will contain one cluster name.

See it as a per-project configuration. One folder should not contain more than one ksail cluster. In rare cases where there could be more than one ksail cluster in a folder, the configuration will use the cluster name to infer which one to provision when running:

ksail up