Fully working oc-k8s
This commit is contained in:
@@ -30,14 +30,12 @@ func Delete_Cluster(folder string, release string) error {
|
||||
if b, err := os.ReadFile(folder + "/" + release + "-values.yaml"); err == nil {
|
||||
clusterName, _ = utils.Extract(string(b), "clusterName")
|
||||
}
|
||||
utils.Exec("kind delete cluster --name " + clusterName)
|
||||
utils.Exec("yes | sudo cp -rf /etc/rancher/k3s/k3s.yaml ~/.kube/config")
|
||||
return utils.Exec("chmod 600 ~/.kube/config")
|
||||
utils.Exec("export KUBECONFIG=~/.kube/config")
|
||||
return utils.Exec("kind delete cluster --name " + clusterName)
|
||||
}
|
||||
|
||||
func Install_Cluster() error {
|
||||
utils.Exec("yes | sudo cp -rf /etc/rancher/k3s/k3s.yaml ~/.kube/config")
|
||||
utils.Exec("chmod 700 /home/mr/.kube")
|
||||
utils.Exec("sudo cp -rf /etc/rancher/k3s/k3s.yaml ~/.kube/config")
|
||||
return utils.Exec("chmod 600 ~/.kube/config")
|
||||
}
|
||||
|
||||
@@ -51,8 +49,6 @@ func Create_Cluster(folder string, release string) error {
|
||||
port, _ = utils.Extract(string(b), "hostPort")
|
||||
}
|
||||
utils.Exec("sudo fuser -k -TERM " + port + "/tcp")
|
||||
utils.Exec("yes | sudo cp -rf /etc/rancher/k3s/k3s.yaml ~/.kube/config")
|
||||
|
||||
containerPort := "30950"
|
||||
if scheme == "https" {
|
||||
containerPort = "30951"
|
||||
@@ -73,12 +69,7 @@ nodes:
|
||||
- containerPort: ` + containerPort + `
|
||||
hostPort: ` + port + `
|
||||
protocol: TCP
|
||||
`
|
||||
utils.Exec(`docker exec -it oc-control-plane bash -c 'mkdir -p /etc/containerd && cat <<EOF >/etc/containerd/config.toml
|
||||
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5000"]
|
||||
endpoint = ["http://dev-docker-registry-ui-registry-server.opencloud.svc.cluster.local:5000"]
|
||||
EOF
|
||||
containerd config restart'`)
|
||||
`
|
||||
cmd := exec.Command("kind", "create", "cluster", "--name", clusterName, "--wait", "0", "--config=-")
|
||||
cmd.Stdin = bytes.NewBufferString(kindConfig)
|
||||
cmd.Stdout = os.Stdout
|
||||
@@ -88,17 +79,25 @@ containerd config restart'`)
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
utils.Exec(`docker exec -it oc-control-plane bash -c 'mkdir -p /etc/containerd && cat <<EOF >/etc/containerd/config.toml
|
||||
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5000"]
|
||||
endpoint = ["http://dev-docker-registry-ui-registry-server.opencloud.svc.cluster.local:5000"]
|
||||
EOF
|
||||
containerd config restart'`)
|
||||
|
||||
fmt.Println("[WARNING] New cluster should be merged into your current config !")
|
||||
|
||||
if err := utils.Exec("KUBECONFIG=~/.kube/config:/tmp/kind-" + clusterName + ".kubeconfig kubectl config view --flatten --merge --minify > /tmp/merged-kubeconfig.yaml"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := utils.Exec("cp -f /tmp/merged-kubeconfig.yaml ~/.kube/config"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := utils.Exec("export KUBECONFIG=~/.kube/config"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := utils.Exec("kubectl config get-contexts"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -71,11 +71,9 @@ func Create_DB(filePath *string, release string, namespace string, dbName string
|
||||
}
|
||||
for _, fileName := range getFileNames(*filePath) {
|
||||
fmt.Println("ADD file " + fileName + " in collection")
|
||||
fmt.Println("kubectl cp -n " + namespace + " " + *filePath + "/" + fileName + " \"" + podName + ":/tmp/" + fileName + "\"")
|
||||
if err := utils.Exec("kubectl cp -n " + namespace + " " + *filePath + "/" + fileName + " \"" + podName + ":/tmp/" + fileName + "\""); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("kubectl exec -n " + namespace + " " + podName + " -- mongoimport --db " + dbName + " --collection " + strings.ReplaceAll(fileName, ".json", "") + " --file /tmp/" + fileName + " --jsonArray -u " + adminUsr + " -p " + adminPsw +" --authenticationDatabase admin")
|
||||
if err := utils.Exec("kubectl exec -n " + namespace + " " + podName + " -- mongoimport --db " + dbName + " --collection " + strings.ReplaceAll(fileName, ".json", "") + " --file /tmp/" + fileName + " --jsonArray -u " + adminUsr + " -p " + adminPsw +" --authenticationDatabase admin"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -21,12 +21,13 @@ Usage:
|
||||
oc-k8s install -a [arch] -v [version]
|
||||
arch - Arch of OS (required)
|
||||
kind_version - version of kind (required)
|
||||
oc-k8s start -n [namespace] -r [release] -f [folder] -b [branch] -t [target] -p [port] -P [portTLS]
|
||||
oc-k8s start -n [namespace] -r [release] -f [folder] -b [branch] -t [target] -p [port] -P [portTLS] -build [true|false]
|
||||
folder - Helm config folder (required, default: .)
|
||||
release - environnement selected (default: dev)
|
||||
namespace - namespace selected (default: dev)
|
||||
branch - Git branch to build (default: main)
|
||||
target - make target (default: all)
|
||||
build - build mode (default: true)
|
||||
oc-k8s stop -n [namespace] -r [release] -f [folder]
|
||||
folder - Helm config folder (required, default: .)
|
||||
release - environnement selected (default: dev)
|
||||
@@ -40,7 +41,7 @@ Usage:
|
||||
Help_DB()
|
||||
}
|
||||
|
||||
func Start(folder string, release string, namespace string, branch string, target string) error {
|
||||
func Start(folder string, release string, namespace string, branch string, target string, build bool) error {
|
||||
Stop(folder, release, namespace)
|
||||
if err := Create_K3S(); err != nil {
|
||||
return err
|
||||
@@ -48,7 +49,7 @@ func Start(folder string, release string, namespace string, branch string, targe
|
||||
if err := Create_Cluster(folder, release); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := Create_Service(folder, release, branch, target); err != nil {
|
||||
if err := Create_Service(folder, release, branch, target, build); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := Create_Helm(folder, release, namespace); err != nil {
|
||||
|
||||
@@ -51,6 +51,7 @@ func Create_Helm(folder string, release string, namespace string) error {
|
||||
return err
|
||||
}
|
||||
ExtractTrees("assets", tmp)
|
||||
defer os.RemoveAll(tmp)
|
||||
|
||||
host := "beta.opencloud.com"
|
||||
if b, err := os.ReadFile(folder + "/" + release + "-values.yaml"); err == nil {
|
||||
@@ -68,25 +69,21 @@ func Create_Helm(folder string, release string, namespace string) error {
|
||||
if err := utils.Exec("helm dependency build " + tmp); err != nil {
|
||||
return err
|
||||
}
|
||||
utils.Exec("sudo ulimit -n 1000000")
|
||||
|
||||
utils.Exec("helm repo add jetstack https://charts.jetstack.io")
|
||||
utils.Exec("helm repo update")
|
||||
|
||||
utils.Exec("kubectl apply -f https://github.com/cert-manager/cert-manager/releases/latest/download/cert-manager.crds.yaml")
|
||||
utils.Exec("helm repo add jetstack https://charts.jetstack.io")
|
||||
utils.Exec("helm repo update")
|
||||
utils.Exec("helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --version v1.14.0")
|
||||
|
||||
utils.Exec("helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --version v1.14.0")
|
||||
utils.Exec("helm install admiralty oci://public.ecr.aws/admiralty/admiralty --namespace admiralty --create-namespace --version 0.17.0 --wait")
|
||||
utils.Exec("helm repo add argo https://argoproj.github.io/argo-helm")
|
||||
utils.Exec("helm repo update")
|
||||
utils.Exec("helm install argo-workflows argo/argo-workflows --namespace argo --create-namespace")
|
||||
|
||||
utils.Exec("helm repo add jetstack https://charts.jetstack.io")
|
||||
utils.Exec("helm repo add argo https://argoproj.github.io/argo-helm")
|
||||
|
||||
utils.Exec("helm repo update")
|
||||
|
||||
if err := utils.Exec("helm upgrade --install " + release + " " + tmp + " -n " + namespace + " --create-namespace -f " + folder + "/" + release + "-values.yaml --debug"); err != nil {
|
||||
return err
|
||||
}
|
||||
utils.Exec("sudo rm -rf " + tmp)
|
||||
utils.Exec("sudo sed -i.bak \"\n/[[:space:]]" + host + "$/d\" /etc/hosts")
|
||||
utils.Exec("echo \"\n127.0.0.1 " + host + "\" | sudo tee -a /etc/hosts > /dev/null")
|
||||
|
||||
@@ -99,8 +96,8 @@ func Upgrade_Helm(folder string, release string, namespace string) error {
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(tmp)
|
||||
ExtractTrees("assets", tmp)
|
||||
defer os.RemoveAll(tmp)
|
||||
|
||||
Delete_Cluster(folder, release)
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ func Install_K3S() error {
|
||||
}
|
||||
|
||||
func Create_K3S() error {
|
||||
utils.Exec("yes | sudo cp -rf /etc/rancher/k3s/k3s.yaml ~/.kube/config")
|
||||
utils.Exec("sudo cp -rf /etc/rancher/k3s/k3s.yaml ~/.kube/config")
|
||||
utils.Exec("chmod 700 /home/mr/.kube")
|
||||
return utils.Exec("chmod 600 ~/.kube/config")
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ var REPOS = []string{
|
||||
"oc-workspace",
|
||||
}
|
||||
|
||||
var officialRegistry = "opencloudregistry"
|
||||
|
||||
func Help_Service() {
|
||||
fmt.Println(`
|
||||
Service commands: oc-k8s <action> services
|
||||
@@ -27,15 +29,25 @@ Service commands: oc-k8s <action> services
|
||||
help - Show this help message
|
||||
|
||||
Usage:
|
||||
oc-k8s create services -f [env_folder] -r [release] -b [branch] -t [target]
|
||||
oc-k8s create services -f [env_folder] -r [release] -b [branch] -t [target] -build [true|false]
|
||||
env_folder - Helm config folder (required, default: .)
|
||||
release - Release values name (required, default: dev)
|
||||
branch - Git branch to build (default: main)
|
||||
target - make target (default: all)
|
||||
build - build mode (default: true)
|
||||
oc-k8s help services `)
|
||||
}
|
||||
|
||||
func Create_Service(folder string, release string, branch string, target string) error {
|
||||
func Create_Service(folder string, release string, branch string, target string, build bool) error {
|
||||
if build {
|
||||
return buildService(folder, release, branch, target)
|
||||
}
|
||||
utils.Exec("sed -i -e 's/: oc/: " + officialRegistry + "/g' " + folder + "/" + release + "-values.yaml")
|
||||
return nil
|
||||
}
|
||||
|
||||
func buildService(folder string, release string, branch string, target string) error {
|
||||
utils.Exec("sed -i -e 's/" + officialRegistry + "/oc/g' " + folder + "/" + release + "-values.yaml")
|
||||
scheme := "http"
|
||||
hostname := "beta.opencloud.com"
|
||||
clusterName := "opencloud"
|
||||
@@ -62,7 +74,7 @@ func Create_Service(folder string, release string, branch string, target string)
|
||||
}
|
||||
}
|
||||
fmt.Println("Repository '" + repo + "' now exists. Pulling latest changes...")
|
||||
utils.Exec("cd " + repo + " && git checkout " + branch + " && git pull")
|
||||
utils.Exec("cd " + repo + " && git pull") // " && git checkout " + branch +
|
||||
fmt.Println("Build '" + repo + "'...")
|
||||
if err := utils.Exec("cd " + repo + " && export CLUSTER_NAME=" + clusterName + " && export HOST=" + scheme + "://" + hostname + ":" + pport + " && export KUBERNETES_SERVICE_HOST=" + host + " && export KUBERNETES_SERVICE_PORT=" + port + " && export KUBE_CA=" + ca + " && export KUBE_CERT=" + cert + " && export KUBE_DATA=" + key + " && make " + target); err != nil {
|
||||
fmt.Println("ERR", err)
|
||||
@@ -72,3 +84,5 @@ func Create_Service(folder string, release string, branch string, target string)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// opencloudregistry.hub.docker.com
|
||||
|
||||
Reference in New Issue
Block a user