This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from kf5i/add_init_command
[feat:] Adding init command
- Loading branch information
Showing
17 changed files
with
719 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package cli | ||
|
||
import ( | ||
|
||
//"os" | ||
// "runtime" | ||
// "strings" | ||
// "time" | ||
|
||
// "github.com/enescakir/emoji" | ||
"github.com/kf5i/k3ai-core/internal/infra/cloud" | ||
"github.com/kf5i/k3ai-core/internal/infra/local" | ||
|
||
//"fmt" | ||
|
||
"github.com/kf5i/k3ai-core/internal/shared" | ||
// "github.com/manifoldco/promptui" | ||
//"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const absPath = "$HOME/.k3ai/config.yaml" | ||
|
||
var kubeconfig []byte | ||
|
||
/* First step is to check if inside .k3ai folder exist a copy of config.yaml if not pull one from github | ||
// the default one disabled locally with no plugins and will ask user what want to do. | ||
// based on user choices will enable the right configuration on the config | ||
// finally will instruct the user on how to change the config */ | ||
|
||
func newInitCommand() *cobra.Command { | ||
|
||
var initCmd = &cobra.Command{ | ||
Use: "init", | ||
Short: "Initialize K3ai Client", | ||
Long: `Initialize K3ai Client, allowing user to deploy a new K8's cluster, list plugins and groups`, | ||
Example: `k3ai-cli init #Will use config from $HOME/.k3ai/config.yaml and use interactive menus | ||
k3ai-cli init --config /myfolder/myconfig.yaml #Use a custom config.yaml in another location(local or remote) | ||
k3ai-cli init --local k3s #Use config target marked local and of type k3s | ||
k3ai-cli init --cloud civo #Use config target marked as cloud and of type civo`, | ||
SilenceUsage: true, | ||
} | ||
|
||
initCmd.Flags().String("local", "", "Options availabe k3s,k0s,kind") | ||
initCmd.Flags().String("cloud", "", "Options availabe for cloud providers") | ||
initCmd.Flags().String("config", "/.k3ai/config.yaml", "Custom config file [default is $HOME/.k3ai/config.yaml]") | ||
|
||
initCmd.RunE = func(cmd *cobra.Command, args []string) error { | ||
localConfig, _ := initCmd.Flags().GetString("config") | ||
//localClusterConfig, _ := initCmd.Flags().GetString("local") | ||
remoteClusterConfig, _ := initCmd.Flags().GetString("cloud") | ||
if remoteClusterConfig != "" { | ||
cloud.CivoCloudInit("windows", "civo") | ||
} | ||
|
||
//check if config.yaml exist otherwise grab a copy | ||
cfg, _ := shared.Init(localConfig) | ||
for i := range cfg.TargetCustomization { | ||
if cfg.TargetCustomization[i].Enabled { | ||
//check type call relative function: prepare the data we need and push to the relative function | ||
if cfg.TargetCustomization[i].ClusterDeployment == "cloud" { | ||
cloud.Init(cfg.TargetCustomization[i]) | ||
} else { | ||
local.Init(cfg.TargetCustomization[i]) | ||
} | ||
} | ||
// we assume everything is false (first time?) so we need a simple interactive menu | ||
} | ||
return nil | ||
} | ||
return initCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
kind: cluster | ||
targetCustomizations: | ||
- name: localK3s #name of the cluster instance not the name of the cluster | ||
enabled: false | ||
type: k3s | ||
config: "/etc/rancher/k3s/k3s.yaml" #default location of config file or your existing config file to copy | ||
clusterName: demo-wsl-k3s #name of the cluster (this need to be the same as in a config file) | ||
clusterDeployment: local | ||
clusterStart: "sudo bash -ic 'k3s server --write-kubeconfig-mode 644 > /dev/null 2>&1 &'" | ||
spec: | ||
# If the OS is not needed may be removed so the three below are mutually exclusive, if not needed set them to null or remove it | ||
wsl: "https://github.com/rancher/k3s/releases/download/v1.19.4%2Bk3s1/k3s" | ||
mac: | ||
linux: "https://get.k3s.io | K3S_KUBECONFIG_MODE=644 sh -s -" | ||
windows: | ||
# Everything from this repo will be ran in this cluster. You trust me right? | ||
plugins: | ||
- repo: | ||
name: | ||
- repo: | ||
name: | ||
|
||
- name: localK0s #name of the cluster instance not the name of the cluster | ||
enabled: false | ||
type: k0s | ||
config: "${HOME}/.k3ai/kubeconfig" #default location of config file or your existing config file to copy | ||
clusterName: demo-wsl-k0s #name of the cluster (this need to be the same as in a config file) | ||
clusterDeployment: local | ||
clusterStart: "k0s default-config | tee ${HOME}/.k3ai/k0s.yaml && sudo bash -ic 'k0s server -c ${HOME}/.k3ai/k0s.yaml --enable-worker > /dev/null 2>&1 &' && sudo cat /var/lib/k0s/pki/admin.conf > $HOME/.k3ai/k0s-config" | ||
spec: | ||
# If the OS is not needed may be removed so the three below are mutually exclusive, if not needed set them to null or remove it | ||
wsl: "https://github.com/k0sproject/k0s/releases/download/v0.8.1/k0s-v0.8.1-amd64" | ||
mac: | ||
linux: "https://github.com/k0sproject/k0s/releases/download/v0.8.1/k0s-v0.8.1-amd64" | ||
windows: | ||
# Everything from this repo will be ran in this cluster. You trust me right? | ||
plugins: | ||
- repo: | ||
name: | ||
- repo: | ||
name: | ||
|
||
- name: localKind #name of the cluster instance not the name of the cluster | ||
enabled: false | ||
type: kind | ||
config: #default location of config file or your existing config file to copy | ||
clusterName: demo-win-kind #name of the cluster (this need to be the same as in a config file) | ||
clusterDeployment: local | ||
clusterStart: "kind create cluster" | ||
spec: | ||
# If the OS is not needed may be removed so the three below are mutually exclusive, if not needed set them to null or remove it | ||
wsl: "https://kind.sigs.k8s.io/dl/v0.9.0/kind-linux-amd64" | ||
mac: "https://kind.sigs.k8s.io/dl/v0.9.0/kind-darwin-amd64" | ||
linux: "https://kind.sigs.k8s.io/dl/v0.9.0/kind-linux-amd64" | ||
windows: "https://kind.sigs.k8s.io/dl/v0.9.0/kind-windows-amd64" | ||
# Everything from this repo will be ran in this cluster. You trust me right? | ||
plugins: | ||
- repo: | ||
name: | ||
- repo: | ||
name: | ||
|
||
- name: localK3d #name of the cluster instance not the name of the cluster | ||
enabled: true | ||
type: k3d | ||
config: #default location of config file or your existing config file to copy | ||
clusterName: demo-win-k3d #name of the cluster (this need to be the same as in a config file) | ||
clusterDeployment: local | ||
clusterStart: "k3d cluster create" | ||
spec: | ||
# If the OS is not needed may be removed so the three below are mutually exclusive, if not needed set them to null or remove it | ||
wsl: "https://kind.sigs.k8s.io/dl/v0.9.0/kind-linux-amd64" | ||
mac: "https://kind.sigs.k8s.io/dl/v0.9.0/kind-darwin-amd64" | ||
linux: "https://kind.sigs.k8s.io/dl/v0.9.0/kind-linux-amd64" | ||
windows: "https://github.com/rancher/k3d/releases/download/v3.4.0-test.0/k3d-windows-amd64.exe" | ||
# Everything from this repo will be ran in this cluster. You trust me right? | ||
plugins: | ||
- repo: | ||
name: | ||
- repo: | ||
name: | ||
|
||
- name: remoteK3s #name of the cluster instance not the name of the cluster | ||
enabled: false | ||
type: k3s | ||
config: remote #default location of config file or your existing config file to copy if Remote will be copy from remote location | ||
clusterName: demo-cluster-remote #name of the cluster (this need to be the same as in a config file) | ||
clusterDeployment: cloud | ||
clusterStart: | ||
spec: | ||
# If the OS is not needed may be removed so the three below are mutually exclusive, if not needed set them to null or remove it | ||
wsl: | ||
mac: | ||
linux: | ||
windows: | ||
cloudType: civo | ||
cloudNodes: 1 | ||
cloudSecretPath: $HOME/.k3ai/secret.txt | ||
# Everything from this repo will be ran in this cluster. You trust me right? | ||
plugins: | ||
- repo: "https://github.com/alfsuse/demo-plugins" | ||
name: "demo" | ||
- repo: "https://github.com/alfsuse/demo-plugins-2" | ||
name: "demo2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cloud | ||
|
||
import ( | ||
"fmt" | ||
|
||
//Cloud providers GO packages | ||
|
||
"github.com/enescakir/emoji" | ||
) | ||
|
||
// const ( | ||
// apiKey = "7TEH9KPSunoBRxYwyUAMGrf1vpCaVtmF03IQ2068cDXk4sbOgi" | ||
// ) | ||
|
||
//AwsCloudInit run specific client configurations based on cloud providers selection | ||
func AwsCloudInit(osFlavor string, cloudProvider string) { | ||
fmt.Printf("%v Ouch sorry we still working on this but hey if it is important for you why not open an issue?\n", emoji.ConstructionWorker) | ||
fmt.Printf("%v https://github.com/kf5i/k3ai-core/issues/new/choose", emoji.RightArrow) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cloud | ||
|
||
import ( | ||
"fmt" | ||
|
||
//Cloud providers GO packages | ||
|
||
"github.com/enescakir/emoji" | ||
) | ||
|
||
// const ( | ||
// apiKey = "7TEH9KPSunoBRxYwyUAMGrf1vpCaVtmF03IQ2068cDXk4sbOgi" | ||
// ) | ||
|
||
//AzureCloudInit run specific client configurations based on cloud providers selection | ||
func AzureCloudInit(osFlavor string, cloudProvider string) { | ||
fmt.Printf("%v Ouch sorry we still working on this but hey if it is important for you why not open an issue?\n", emoji.ConstructionWorker) | ||
fmt.Printf("%v https://github.com/kf5i/k3ai-core/issues/new/choose", emoji.RightArrow) | ||
} |
Oops, something went wrong.