Compare commits
26 Commits
v0.1.0
...
6fef803ae9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6fef803ae9 | ||
|
|
3271246e74 | ||
|
|
80ef56bbc4 | ||
|
|
c1134f7403 | ||
|
|
9561dc5493 | ||
|
|
279f93224f | ||
|
|
c7f8503fb6 | ||
|
|
4bce096e1f | ||
|
|
75b7b94a50 | ||
|
|
13025746e6 | ||
|
|
550675a4aa | ||
|
|
a1af83689d | ||
|
|
53a614bd7e | ||
|
|
da9aab90eb | ||
|
|
052e6f1368 | ||
|
|
dddd5d1831 | ||
|
|
a7a5465a22 | ||
|
|
48301bf82e | ||
|
|
d12d3e31bf | ||
|
|
9e267becca | ||
|
|
756638fe21 | ||
|
|
11a4d5cc90 | ||
|
|
26404e5892 | ||
|
|
9cf954776f | ||
|
|
11f56722f7 | ||
|
|
4ae5926b01 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
bin
|
||||||
6
Makefile
Normal file
6
Makefile
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
publish:
|
||||||
|
curl -X 'POST' \
|
||||||
|
'https://cloud.o-forge.io/api/v1/repos/core/oc-deploy/releases/2/assets?name=oc.json&token=92ad0a4b3d75ec7c5964913b7085d7ddf379247c' \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Content-Type: multipart/form-data' \
|
||||||
|
-F 'attachment=@oc.json;type=application/json'
|
||||||
66
README.md
66
README.md
@@ -35,69 +35,5 @@ Install Talos
|
|||||||
chmod 700 get_helm.sh
|
chmod 700 get_helm.sh
|
||||||
./get_helm.sh
|
./get_helm.sh
|
||||||
|
|
||||||
--------------------------
|
|
||||||
# Create OpenCloud Chart
|
# Create OpenCloud Chart
|
||||||
|
helm create occhart
|
||||||
# `oc-deploy` Component
|
|
||||||
|
|
||||||
The `oc-deploy` component aims to simplify and automate the deployment of OpenCloud components on a Kubernetes cluster through the creation of Helm Charts.
|
|
||||||
|
|
||||||
## Prerequisites:
|
|
||||||
- Access to the OpenCloud forge and the associated Harbor registry: [https://registry.o-forge.io/](https://registry.o-forge.io/), which will allow pulling OpenCloud release images from the "stable" project.
|
|
||||||
- To test the connection to this registry from the Docker client:
|
|
||||||
```bash
|
|
||||||
docker login registry.o-forge.io
|
|
||||||
```
|
|
||||||
- A Kubernetes cluster: Minikube, K3s, RKE2, etc. See `KubernetesCluster`.
|
|
||||||
- Helm installed locally
|
|
||||||
|
|
||||||
## **To Be Defined:**
|
|
||||||
### Configuring a Docker Secret for Kubernetes
|
|
||||||
Kubernetes needs to know your credentials to pull images from the "registry.o-forge.io" registry. Create a Docker secret in Kubernetes:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl create secret docker-registry regcred \
|
|
||||||
--docker-server=registry.o-forge.io \
|
|
||||||
--docker-username=<your_username> \
|
|
||||||
--docker-password=<your_password> \
|
|
||||||
--docker-email=<your_email>
|
|
||||||
```
|
|
||||||
|
|
||||||
## Checking if Helm Recognizes Your Local Kubernetes Cluster:
|
|
||||||
|
|
||||||
### 1. Verify Connection to Kubernetes:
|
|
||||||
Before checking Helm, ensure that your `kubectl` is properly configured to connect to your local Kubernetes cluster.
|
|
||||||
Run the following command to see if you can communicate with the cluster:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl get nodes
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
If this command returns the list of nodes in your cluster, it means `kubectl` is properly connected.
|
|
||||||
|
|
||||||
### 2. Verify Helm Configuration:
|
|
||||||
Now, you can check if Helm can access the cluster by using the following command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
helm version
|
|
||||||
```
|
|
||||||
|
|
||||||
This command displays the Helm version and the Kubernetes version it is connected to.
|
|
||||||
|
|
||||||
## Deploying with Helm:
|
|
||||||
You can deploy the `oc-deploy` Chart with Helm:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
helm install oc-deploy path/to/your/Helm/oc-deploy
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Checking Helm Releases:
|
|
||||||
You can also list the existing releases to see if Helm is properly connected to the cluster:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
helm list
|
|
||||||
```
|
|
||||||
|
|
||||||
If all these commands execute without errors and give the expected results, your Helm installation is correctly configured to recognize and interact with your local Kubernetes cluster
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
@startuml Arch Diagram
|
@startuml
|
||||||
|
|
||||||
top to bottom direction
|
top to bottom direction
|
||||||
|
|
||||||
7
offline/default_value_1.0.yml
Normal file
7
offline/default_value_1.0.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
globals:
|
||||||
|
|
||||||
|
composant1:
|
||||||
|
|
||||||
|
composant2:
|
||||||
3
offline/latest.yml
Normal file
3
offline/latest.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
version: 1.0
|
||||||
41
offline/oc_1.0.yml
Normal file
41
offline/oc_1.0.yml
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
---
|
||||||
|
# Définition d'une version
|
||||||
|
|
||||||
|
version: 1.0
|
||||||
|
|
||||||
|
tools:
|
||||||
|
- name: kubectl
|
||||||
|
url: https://dl.k8s.io/release/%s/bin/linux/amd64/kubectl
|
||||||
|
version: v1.30.3
|
||||||
|
- name: helm
|
||||||
|
url: https://get.helm.sh/helm-%s-linux-amd64.tar.gz
|
||||||
|
version: v3.15.4
|
||||||
|
|
||||||
|
# helm install my-release <repo>/<chart>
|
||||||
|
opencloud:
|
||||||
|
- repository:
|
||||||
|
name: bitnami
|
||||||
|
url: https://charts.bitnami.com/bitnami # Repository des Charts
|
||||||
|
charts:
|
||||||
|
- name: wordpress
|
||||||
|
chart: bitnami/wordpress
|
||||||
|
version: 23.1.0
|
||||||
|
values: {}
|
||||||
|
helm_opts: --wait-for-jobs
|
||||||
|
helm_filevalues: values-init.yml
|
||||||
|
|
||||||
|
- name: phpmyadmin
|
||||||
|
chart: bitnami/phpmyadmin
|
||||||
|
version: 17.0.4
|
||||||
|
values: {}
|
||||||
|
|
||||||
|
- charts:
|
||||||
|
- name: mongo
|
||||||
|
chart: ../oc-mongo/mongo
|
||||||
|
|
||||||
|
- charts:
|
||||||
|
- name: myfirstrelease
|
||||||
|
chart: myfirstchart-0.1.0.tgz
|
||||||
|
url: https://zzzz/myfirstchart-0.1.0.tgz
|
||||||
|
|
||||||
|
# helm install myfirstrelease myfirstchart-0.1.0.tgz
|
||||||
3
publish/.gitignore
vendored
Normal file
3
publish/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
go.sum
|
||||||
|
*_
|
||||||
|
.coverage.*
|
||||||
3
publish/go.mod
Normal file
3
publish/go.mod
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module oc-publish
|
||||||
|
|
||||||
|
go 1.22.2
|
||||||
27
publish/main.go
Normal file
27
publish/main.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"oc-publish/releases"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
fmt.Println(" >> oc-publish :")
|
||||||
|
|
||||||
|
version := os.Args[1]
|
||||||
|
fmt.Println(fmt.Sprintf(" << version : %s", version))
|
||||||
|
|
||||||
|
existe, _ := releases.CheckRelease(version)
|
||||||
|
fmt.Println(fmt.Sprintf(" << existe : %t ", existe))
|
||||||
|
|
||||||
|
idRelease, _ := releases.GetReleaseId(version)
|
||||||
|
fmt.Println(fmt.Sprintf(" << id : %d ", idRelease))
|
||||||
|
|
||||||
|
idAsset, _ := releases.GetAssetId(idRelease, "oc.json")
|
||||||
|
fmt.Println(fmt.Sprintf(" << idAsset : %d ", idAsset))
|
||||||
|
|
||||||
|
fmt.Println(releases.CreateAsset(idRelease, "../bin/oc-deploy"))
|
||||||
|
|
||||||
|
}
|
||||||
6
publish/occonst/variables.go
Normal file
6
publish/occonst/variables.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package occonst
|
||||||
|
|
||||||
|
var PUBLISH_URL = "https://cloud.o-forge.io"
|
||||||
|
var PUBLISH_VERSION = "core/oc-deploy"
|
||||||
|
|
||||||
|
var PUBLISH_TOKEN = ""
|
||||||
166
publish/releases/assets.go
Normal file
166
publish/releases/assets.go
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
package releases
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"mime/multipart"
|
||||||
|
"io"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"bytes"
|
||||||
|
|
||||||
|
"oc-publish/occonst"
|
||||||
|
)
|
||||||
|
|
||||||
|
type assetStruct struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Id int `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAssetId(idRelease int, name string) (int, error) {
|
||||||
|
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/%d/assets",
|
||||||
|
occonst.PUBLISH_URL,
|
||||||
|
occonst.PUBLISH_VERSION,
|
||||||
|
idRelease)
|
||||||
|
|
||||||
|
res, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
body, err := io.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return -2, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var data []assetStruct
|
||||||
|
|
||||||
|
err = json.Unmarshal(body, &data)
|
||||||
|
fmt.Println(err)
|
||||||
|
if err != nil {
|
||||||
|
return -3, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ele := range data {
|
||||||
|
if ele.Name == name {
|
||||||
|
return ele.Id, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// curl -X 'POST' \
|
||||||
|
// 'https://cloud.o-forge.io/api/v1/repos/core/oc-deploy/releases/2/assets?name=zzzz' \
|
||||||
|
// -H 'accept: application/json' \
|
||||||
|
// -H 'Content-Type: multipart/form-data' \
|
||||||
|
// -F 'attachment=oc-deploy'
|
||||||
|
func CreateAsset(idRelease int, filename string) (int, error) {
|
||||||
|
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/%d/assets?name=%s&token=%s",
|
||||||
|
occonst.PUBLISH_URL,
|
||||||
|
occonst.PUBLISH_VERSION,
|
||||||
|
idRelease,
|
||||||
|
"name",
|
||||||
|
occonst.PUBLISH_TOKEN)
|
||||||
|
|
||||||
|
// request, err := newfileUploadRequest(url, extraParams, "file", "/tmp/doc.pdf")
|
||||||
|
|
||||||
|
err := uploadFile(url, "attachment", filename)
|
||||||
|
fmt.Println(url, err)
|
||||||
|
|
||||||
|
|
||||||
|
// fmt.Println(url)
|
||||||
|
|
||||||
|
// body := []byte("CONTENU")
|
||||||
|
// req, err := http.NewRequest("POST", url, bytes.NewBuffer(body))
|
||||||
|
// if err != nil {
|
||||||
|
// return -1, err
|
||||||
|
// }
|
||||||
|
// req.Header.Add("accept", "application/json")
|
||||||
|
// req.Header.Add("Content-Type", "multipart/form-data")
|
||||||
|
|
||||||
|
// client := &http.Client{}
|
||||||
|
// res, err := client.Do(req)
|
||||||
|
// fmt.Println(res, err)
|
||||||
|
|
||||||
|
// cnt, err := io.ReadAll(res.Body)
|
||||||
|
// fmt.Println(string(cnt), err)
|
||||||
|
|
||||||
|
// if err != nil {
|
||||||
|
// return -1, err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if err != nil {
|
||||||
|
// return -2, err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// defer res.Body.Close()
|
||||||
|
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func uploadFile(url string, paramName string, filePath string) error {
|
||||||
|
file, err := os.Open(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
body := &bytes.Buffer{}
|
||||||
|
writer := multipart.NewWriter(body)
|
||||||
|
part, err := writer.CreateFormFile(paramName, filepath.Base(filePath))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = io.Copy(part, file)
|
||||||
|
|
||||||
|
err = writer.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
request, err := http.NewRequest("POST", url, body)
|
||||||
|
request.Header.Add("Content-Type", writer.FormDataContentType())
|
||||||
|
request.Header.Add("accept", "application/json")
|
||||||
|
client := &http.Client{}
|
||||||
|
response, err := client.Do(request)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer response.Body.Close()
|
||||||
|
|
||||||
|
cnt, err := io.ReadAll(response.Body)
|
||||||
|
fmt.Println(string(cnt), err, writer.FormDataContentType())
|
||||||
|
|
||||||
|
// Handle the server response...
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// func newfileUploadRequest(uri string, params map[string]string, paramName, path string) (*http.Request, error) {
|
||||||
|
// file, err := os.Open(path)
|
||||||
|
// if err != nil {
|
||||||
|
// return nil, err
|
||||||
|
// }
|
||||||
|
// defer file.Close()
|
||||||
|
|
||||||
|
// body := &bytes.Buffer{}
|
||||||
|
// writer := multipart.NewWriter(body)
|
||||||
|
// part, err := writer.CreateFormFile(paramName, filepath.Base(path))
|
||||||
|
// if err != nil {
|
||||||
|
// return nil, err
|
||||||
|
// }
|
||||||
|
// _, err = io.Copy(part, file)
|
||||||
|
|
||||||
|
// // for key, val := range params {
|
||||||
|
// // _ = writer.WriteField(key, val)
|
||||||
|
// // }
|
||||||
|
// // err = writer.Close()
|
||||||
|
// // if err != nil {
|
||||||
|
// // return nil, err
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// req, err := http.NewRequest("POST", uri, body)
|
||||||
|
// req.Header.Set("Content-Type", writer.FormDataContentType())
|
||||||
|
// return req, err
|
||||||
|
// }
|
||||||
63
publish/releases/release.go
Normal file
63
publish/releases/release.go
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
package releases
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"oc-publish/occonst"
|
||||||
|
)
|
||||||
|
|
||||||
|
type checkStruct struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Id int `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func CheckRelease(version string) (bool, error) {
|
||||||
|
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/tags/%s",
|
||||||
|
occonst.PUBLISH_URL,
|
||||||
|
occonst.PUBLISH_VERSION,
|
||||||
|
version)
|
||||||
|
|
||||||
|
res, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
body, err := io.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var data checkStruct
|
||||||
|
err = json.Unmarshal(body, &data)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.Name != "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetReleaseId(version string) (int, error) {
|
||||||
|
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/tags/%s",
|
||||||
|
occonst.PUBLISH_URL,
|
||||||
|
occonst.PUBLISH_VERSION,
|
||||||
|
version)
|
||||||
|
|
||||||
|
res, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
body, err := io.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var data checkStruct
|
||||||
|
err = json.Unmarshal(body, &data)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.Id, nil
|
||||||
|
}
|
||||||
5
src/.gitignore
vendored
Normal file
5
src/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
go.sum
|
||||||
|
*_
|
||||||
|
.coverage.*
|
||||||
|
.*.log
|
||||||
|
workspace_*
|
||||||
79
src/Makefile
Normal file
79
src/Makefile
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
|
||||||
|
BIN_NAME := oc-deploy
|
||||||
|
|
||||||
|
BIN_OPTS :=
|
||||||
|
|
||||||
|
##################
|
||||||
|
|
||||||
|
SOURCES := $(wildcard *.go) $(wildcard */*.go)
|
||||||
|
BIN_DIR = ../bin/
|
||||||
|
|
||||||
|
PLUGINS := $(wildcard ../plugins/*/*.go)
|
||||||
|
OBJS := ${PLUGINS:.go=.so}
|
||||||
|
|
||||||
|
%.so: %.go
|
||||||
|
go build -buildmode=plugin -o $@ $<
|
||||||
|
|
||||||
|
help:
|
||||||
|
@echo
|
||||||
|
@echo 'Usage:'
|
||||||
|
@echo ' make build Génère les exécutables.'
|
||||||
|
@echo ' make get-deps Dependency download'
|
||||||
|
|
||||||
|
@echo ' make run BIN_OPTS=... Go run'
|
||||||
|
@echo ' make run_install BIN_OPTS=... Go run'
|
||||||
|
@echo ' make run_uninstall BIN_OPTS=... Go run'
|
||||||
|
@echo ' make exec BIN_OPTS=... exécutable'
|
||||||
|
@echo ' make exec_install BIN_OPTS=... exécutable'
|
||||||
|
@echo ' make exec_uninstall BIN_OPTS=... exécutable'
|
||||||
|
@echo ' make test Test.'
|
||||||
|
|
||||||
|
@echo ' make test Test'
|
||||||
|
@echo ' make clean Clean the directory tree.'
|
||||||
|
@echo
|
||||||
|
|
||||||
|
${BIN_DIR}/${BIN_NAME}: ${SOURCES} $(OBJS)
|
||||||
|
go build -o ${BIN_DIR}/${BIN_NAME}
|
||||||
|
|
||||||
|
get-deps:
|
||||||
|
@go mod tidy
|
||||||
|
|
||||||
|
build: ${BIN_DIR}/${BIN_NAME}
|
||||||
|
|
||||||
|
run: $(OBJS)
|
||||||
|
@go run main.go ${BIN_OPTS}
|
||||||
|
|
||||||
|
run_generate: $(OBJS)
|
||||||
|
@go run main.go generate ${BIN_OPTS}
|
||||||
|
|
||||||
|
run_install: $(OBJS)
|
||||||
|
@go run main.go install ${BIN_OPTS}
|
||||||
|
|
||||||
|
run_uninstall: $(OBJS)
|
||||||
|
@go run main.go uninstall ${BIN_OPTS}
|
||||||
|
|
||||||
|
exec: ${BIN_DIR}/${BIN_NAME} $(OBJS)
|
||||||
|
@${BIN_DIR}/${BIN_NAME} ${BIN_OPTS}
|
||||||
|
|
||||||
|
exec_install: ${BIN_DIR}/${BIN_NAME} $(OBJS)
|
||||||
|
@${BIN_DIR}/${BIN_NAME} install ${BIN_OPTS}
|
||||||
|
|
||||||
|
exec_uninstall: ${BIN_DIR}/${BIN_NAME} $(OBJS)
|
||||||
|
@${BIN_DIR}/${BIN_NAME} uninstall ${BIN_OPTS}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@test ! -e ${BIN_DIR}/${BIN_NAME} || rm ${BIN_DIR}/${BIN_NAME}
|
||||||
|
@test ! -e .coverage.out || rm .coverage.out
|
||||||
|
@test ! -e .coverage.html || rm .coverage.html
|
||||||
|
@test ! -e go.sum || rm go.sum
|
||||||
|
@test ! -e .oc-deploy.log || rm .oc-deploy.log
|
||||||
|
@rm -rf workspace_*
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test_%:
|
||||||
|
go test oc-deploy/$(subst test_,,$@) -coverprofile=.coverage.out -v
|
||||||
|
@go tool cover -html=.coverage.out -o .coverage.html
|
||||||
|
|
||||||
|
test:
|
||||||
|
@go test ./... -coverprofile=.coverage.out -v
|
||||||
|
go tool cover -html=.coverage.out -o .coverage.html
|
||||||
45
src/chart/conf.go
Normal file
45
src/chart/conf.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package chart
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ChartData struct {
|
||||||
|
Name string `yaml:"name"`
|
||||||
|
Chart string `yaml:"chart"`
|
||||||
|
Url string `yaml:"url"`
|
||||||
|
Version string `yaml:"version"`
|
||||||
|
|
||||||
|
Opts string `yaml:"helm_opts"`
|
||||||
|
Values map[string]string `yaml:"helm_values"`
|
||||||
|
FileValues []string `yaml:"helm_filevalues"`
|
||||||
|
|
||||||
|
Overwrite string `yaml:"helm_overwrite"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type repoData struct {
|
||||||
|
Name string `yaml:"name"`
|
||||||
|
Url string `yaml:"url"`
|
||||||
|
ForceUpdate bool `yaml:"forceupdate"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ChartRepoData struct {
|
||||||
|
Repository repoData `yaml:"repository"`
|
||||||
|
Charts []ChartData `yaml:"charts"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type chartsRepoData struct {
|
||||||
|
Charts []ChartRepoData `yaml:"opencloud"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func FromConfigFile(filename string) ([]ChartRepoData, error) {
|
||||||
|
yamlFile, _ := os.ReadFile(filename)
|
||||||
|
|
||||||
|
var data chartsRepoData
|
||||||
|
err := yaml.Unmarshal(yamlFile, &data)
|
||||||
|
if err != nil {
|
||||||
|
return data.Charts, err
|
||||||
|
}
|
||||||
|
return data.Charts, nil
|
||||||
|
}
|
||||||
50
src/chart/conf_test.go
Normal file
50
src/chart/conf_test.go
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package chart
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"path/filepath"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func _TestReadConfChart(t *testing.T) {
|
||||||
|
src := filepath.Join(TEST_SRC_DIR, "oc.yml")
|
||||||
|
|
||||||
|
assert.FileExists(t, src, "FromConfigFile error")
|
||||||
|
|
||||||
|
data, _ := FromConfigFile(src)
|
||||||
|
assert.Equal(t, "bitnami", data[0].Repository.Name, "FromConfigFile error")
|
||||||
|
assert.Equal(t, "https://charts.bitnami.com/bitnami", data[0].Repository.Url, "FromConfigFile error")
|
||||||
|
|
||||||
|
wordpress := data[0].Charts[0]
|
||||||
|
assert.Equal(t, "wordpress", wordpress.Name, "FromConfigFile error")
|
||||||
|
assert.Equal(t, "bitnami/wordpress", wordpress.Chart, "FromConfigFile error")
|
||||||
|
assert.Equal(t, "23.1.0", wordpress.Version, "FromConfigFile error")
|
||||||
|
assert.Equal(t, 0, len(wordpress.FileValues), "FromConfigFile error")
|
||||||
|
assert.Equal(t, 0, len(wordpress.Values), "FromConfigFile error")
|
||||||
|
|
||||||
|
phpmyadmin := data[0].Charts[1]
|
||||||
|
assert.Equal(t, "phpmyadmin", phpmyadmin.Name, "FromConfigFile error")
|
||||||
|
assert.Equal(t, "bitnami/phpmyadmin", phpmyadmin.Chart,"FromConfigFile error")
|
||||||
|
assert.Equal(t, "17.0.4", phpmyadmin.Version, "FromConfigFile error")
|
||||||
|
assert.Equal(t, 2, len(phpmyadmin.FileValues), "FromConfigFile error")
|
||||||
|
assert.Equal(t, 1, len(phpmyadmin.Values), "FromConfigFile error")
|
||||||
|
|
||||||
|
data1 := data[1]
|
||||||
|
assert.Equal(t, "", data1.Repository.Name, "FromConfigFile error")
|
||||||
|
assert.Equal(t, "", data1.Repository.Url, "FromConfigFile error")
|
||||||
|
|
||||||
|
myfirstrelease := data1.Charts[0]
|
||||||
|
assert.Equal(t, "myfirstrelease", myfirstrelease.Name, "FromConfigFile error")
|
||||||
|
assert.Equal(t, "https://zzzz/myfirstchart-0.1.0.tgz", myfirstrelease.Url, "FromConfigFile error")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReadConfChartOverwrite(t *testing.T){
|
||||||
|
src := filepath.Join(TEST_SRC_DIR, "oc_overwrite.yml")
|
||||||
|
|
||||||
|
assert.FileExists(t, src, "FromConfigFile error")
|
||||||
|
|
||||||
|
data, _ := FromConfigFile(src)
|
||||||
|
// Nombre de lettres
|
||||||
|
assert.Equal(t, 70, len(data[0].Charts[0].Overwrite), "TestReadConfChartOverwrite error")
|
||||||
|
}
|
||||||
23
src/chart/main_test.go
Normal file
23
src/chart/main_test.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package chart
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
var TEST_DEST_DIR = "../wrk_chart"
|
||||||
|
var TEST_SRC_DIR = filepath.Join("../../test", "chart")
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
folderPath := TEST_DEST_DIR
|
||||||
|
|
||||||
|
os.RemoveAll(folderPath)
|
||||||
|
os.MkdirAll(folderPath, os.ModePerm)
|
||||||
|
|
||||||
|
// call flag.Parse() here if TestMain uses flags
|
||||||
|
exitCode := m.Run()
|
||||||
|
|
||||||
|
os.RemoveAll(folderPath)
|
||||||
|
os.Exit(exitCode)
|
||||||
|
}
|
||||||
85
src/cmd/args.go
Normal file
85
src/cmd/args.go
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
// Package cmd : Parse les arguments
|
||||||
|
|
||||||
|
// Arguments : version ==> version d'OpenCloud
|
||||||
|
// Argument : projet ==> nom du projet
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
context string
|
||||||
|
version string
|
||||||
|
modules []string
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func cobraInstallCmd() *cobra.Command {
|
||||||
|
return &cobra.Command{
|
||||||
|
Use: "install",
|
||||||
|
Short: "install",
|
||||||
|
Long: `deploy Charts`,
|
||||||
|
Args: cobra.MaximumNArgs(0),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
return InstallCmd(context, version, modules)
|
||||||
|
},
|
||||||
|
Example: "oc-deploy install --version 1.0 --context ex1",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func cobraUninstallCmd() *cobra.Command{
|
||||||
|
return &cobra.Command{
|
||||||
|
Use: "uninstall",
|
||||||
|
Short: "undeploy",
|
||||||
|
Long: `Undeploy`,
|
||||||
|
Args: cobra.MaximumNArgs(0),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
return UninstallCmd(context)
|
||||||
|
},
|
||||||
|
Example: "oc-deploy uninstall --context ex1",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func cobraGenerateCmd() *cobra.Command{
|
||||||
|
return &cobra.Command{
|
||||||
|
Use: "generate",
|
||||||
|
Short: "generate",
|
||||||
|
Long: "Value",
|
||||||
|
Args: cobra.MaximumNArgs(0),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
return GenerateCmd(context, version)
|
||||||
|
},
|
||||||
|
Example: "oc-deploy generate --version 1.0 --context ex1",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Execute() {
|
||||||
|
|
||||||
|
log.Log().Debug().Msg("Execute")
|
||||||
|
|
||||||
|
var rootCmd = &cobra.Command{Use: "oc-deploy"}
|
||||||
|
|
||||||
|
var cmdInstall = cobraInstallCmd()
|
||||||
|
var cmdUninstall = cobraUninstallCmd()
|
||||||
|
var cmdGenerate = cobraGenerateCmd()
|
||||||
|
|
||||||
|
cmdInstall.Flags().StringVarP(&context, "context", "c", "opencloud", "Nom du context")
|
||||||
|
cmdInstall.Flags().StringVarP(&version, "version", "v", "latest", "Version")
|
||||||
|
cmdInstall.Flags().StringArrayVarP(&modules, "modules", "m", []string{}, "modules, ...")
|
||||||
|
|
||||||
|
cmdUninstall.Flags().StringVarP(&context, "context", "c", "opencloud", "Nom du context")
|
||||||
|
|
||||||
|
cmdGenerate.Flags().StringVarP(&context, "context", "c", "opencloud", "Nom du context")
|
||||||
|
cmdGenerate.Flags().StringVarP(&version, "version", "v", "latest", "Version")
|
||||||
|
|
||||||
|
rootCmd.AddCommand(cmdInstall)
|
||||||
|
rootCmd.AddCommand(cmdUninstall)
|
||||||
|
rootCmd.AddCommand(cmdGenerate)
|
||||||
|
|
||||||
|
cobra.CheckErr(rootCmd.Execute())
|
||||||
|
|
||||||
|
}
|
||||||
9
src/cmd/args_test.go
Normal file
9
src/cmd/args_test.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestExecute(t *testing.T) {
|
||||||
|
Execute()
|
||||||
|
}
|
||||||
23
src/cmd/generateCmd.go
Normal file
23
src/cmd/generateCmd.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
|
||||||
|
// "oc-deploy/versionOc"
|
||||||
|
"oc-deploy/install"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GenerateCmd(prcontextoject string, version string) error {
|
||||||
|
log.Log().Info().Msg("Generate >> ")
|
||||||
|
|
||||||
|
workspace := fmt.Sprintf("workspace_%s", context)
|
||||||
|
|
||||||
|
obj := install.InstallClass{Workspace: workspace, Version: version}
|
||||||
|
_, err := obj.NewGenerate()
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Fatal().Msg(" >> " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
51
src/cmd/installCmd.go
Normal file
51
src/cmd/installCmd.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
|
||||||
|
"oc-deploy/install"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InstallCmd(context string, version string, modules []string) error {
|
||||||
|
log.Log().Info().Msg("Install >> ")
|
||||||
|
|
||||||
|
log.Log().Info().Msg(" << Contexte : " + context)
|
||||||
|
if len(modules) > 0 {
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << Modules : %s", modules))
|
||||||
|
}
|
||||||
|
|
||||||
|
workspace := fmt.Sprintf("workspace_%s", context)
|
||||||
|
obj := install.InstallClass{Workspace: workspace, Version: version}
|
||||||
|
|
||||||
|
file, err := obj.NewInstall()
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Fatal().Msg(" >> " + err.Error())
|
||||||
|
}
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << Version : %s", obj.Version))
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" >> Config : %s", file))
|
||||||
|
|
||||||
|
err = obj.Tools()
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Fatal().Msg(" >> " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.SetCommands()
|
||||||
|
|
||||||
|
err = obj.ChartRepo()
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Fatal().Msg(" >> " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
err = obj.K8s(context)
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Fatal().Msg(" >> " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
err = obj.InstallCharts(modules)
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Fatal().Msg(" >> " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
41
src/cmd/installCmd_test.go
Normal file
41
src/cmd/installCmd_test.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestInstallCommand(t *testing.T) {
|
||||||
|
cmd := cobraInstallCmd()
|
||||||
|
|
||||||
|
inMock := false
|
||||||
|
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
||||||
|
inMock = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Execute()
|
||||||
|
assert.Truef(t, inMock, "TestInstallCommand")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInstallCommandErr(t *testing.T) {
|
||||||
|
cmd := cobraUninstallCmd()
|
||||||
|
|
||||||
|
inMock := false
|
||||||
|
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
||||||
|
inMock = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.SetArgs([]string{"bad"})
|
||||||
|
b := bytes.NewBufferString("")
|
||||||
|
cmd.SetOut(b)
|
||||||
|
|
||||||
|
err := cmd.Execute()
|
||||||
|
assert.Falsef(t, inMock, "TestInstallCommand args")
|
||||||
|
assert.NotNilf(t, err, "TestInstallCommand args")
|
||||||
|
}
|
||||||
45
src/cmd/uninstallCmd.go
Normal file
45
src/cmd/uninstallCmd.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
// "strings"
|
||||||
|
// "github.com/spf13/cobra"
|
||||||
|
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
|
||||||
|
// "oc-deploy/versionOc"
|
||||||
|
"oc-deploy/install"
|
||||||
|
)
|
||||||
|
|
||||||
|
func UninstallCmd(context string) error {
|
||||||
|
log.Log().Info().Msg("Uninstall >> ")
|
||||||
|
|
||||||
|
log.Log().Info().Msg(" << Contexte : " + context)
|
||||||
|
|
||||||
|
workspace := fmt.Sprintf("workspace_%s", context)
|
||||||
|
obj := install.InstallClass{Workspace: workspace}
|
||||||
|
|
||||||
|
file, err := obj.NewUninstall()
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Fatal().Msg(" >> " + err.Error())
|
||||||
|
}
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << Version : %s", obj.Version))
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" >> Config : %s", file))
|
||||||
|
|
||||||
|
err = obj.Tools()
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Fatal().Msg(" >> " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
err = obj.K8s(context)
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Fatal().Msg(" >> " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
err = obj.UninstallCharts()
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Fatal().Msg(" >> " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
41
src/cmd/uninstallCmd_test.go
Normal file
41
src/cmd/uninstallCmd_test.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUninstallCommand(t *testing.T) {
|
||||||
|
cmd := cobraUninstallCmd()
|
||||||
|
|
||||||
|
inMock := false
|
||||||
|
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
||||||
|
inMock = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Execute()
|
||||||
|
assert.Truef(t, inMock, "TestUninstallCommand")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUninstallCommandErr(t *testing.T) {
|
||||||
|
cmd := cobraUninstallCmd()
|
||||||
|
|
||||||
|
inMock := false
|
||||||
|
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
||||||
|
inMock = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.SetArgs([]string{"bad"})
|
||||||
|
b := bytes.NewBufferString("")
|
||||||
|
cmd.SetOut(b)
|
||||||
|
|
||||||
|
err := cmd.Execute()
|
||||||
|
assert.Falsef(t, inMock, "TestUninstallCommand args")
|
||||||
|
assert.NotNilf(t, err, "TestUninstallCommand args")
|
||||||
|
}
|
||||||
25
src/go.mod
Normal file
25
src/go.mod
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
module oc-deploy
|
||||||
|
|
||||||
|
go 1.22.0
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/jarcoal/httpmock v1.3.1
|
||||||
|
github.com/rs/zerolog v1.33.0
|
||||||
|
github.com/spf13/cobra v1.8.1
|
||||||
|
github.com/stretchr/testify v1.9.0
|
||||||
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
|
github.com/kr/pretty v0.3.1 // indirect
|
||||||
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/rogpeppe/go-internal v1.11.0 // indirect
|
||||||
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
|
golang.org/x/sys v0.22.0 // indirect
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
||||||
173
src/helm/chart.go
Normal file
173
src/helm/chart.go
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
package helm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"errors"
|
||||||
|
"path/filepath"
|
||||||
|
"encoding/json"
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HelmChart struct {
|
||||||
|
Bin string
|
||||||
|
Name string
|
||||||
|
Chart string
|
||||||
|
Version string
|
||||||
|
Url string
|
||||||
|
|
||||||
|
Workspace string
|
||||||
|
Opts string
|
||||||
|
Values map[string]string
|
||||||
|
FileValues []string
|
||||||
|
}
|
||||||
|
|
||||||
|
type installInfoOutput struct {
|
||||||
|
Description string `json:"description"`
|
||||||
|
Notes string `json:"notes"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type installOutput struct {
|
||||||
|
Info installInfoOutput `json:"info"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this HelmCommand) ChartInstall(data HelmChart) (string, error) {
|
||||||
|
bin := this.Bin
|
||||||
|
|
||||||
|
existe, err := this.chartExists(data)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if existe {
|
||||||
|
return "Existe déjà", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ficChart := data.Chart
|
||||||
|
// Recherche locale
|
||||||
|
if _, err := os.Stat(ficChart); err != nil {
|
||||||
|
} else {
|
||||||
|
// Recherche voa le Workspace
|
||||||
|
ficChart := filepath.Join(data.Workspace, data.Chart)
|
||||||
|
if _, err := os.Stat(ficChart); err == nil {
|
||||||
|
} else {
|
||||||
|
if data.Url != "" {
|
||||||
|
fmt.Println("============ 52 Télechargement", data.Url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := fmt.Sprintf("%s install %s %s %s --output json", bin, data.Name, ficChart, data.Opts)
|
||||||
|
|
||||||
|
if data.Version != "" {
|
||||||
|
msg = fmt.Sprintf("%s --version %s", msg, data.Version)
|
||||||
|
}
|
||||||
|
|
||||||
|
for key, value := range data.Values {
|
||||||
|
msg = fmt.Sprintf("%s --set %s=%s", msg, key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
ficoverwrite := filepath.Join(data.Workspace, fmt.Sprintf("value-%s.yml", data.Name))
|
||||||
|
if _, err := os.Stat(ficoverwrite); err != nil {
|
||||||
|
log.Log().Warn().Msg(ficoverwrite)
|
||||||
|
} else {
|
||||||
|
msg = fmt.Sprintf("%s --values %s", msg, ficoverwrite)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, valuefilename := range data.FileValues {
|
||||||
|
fic := filepath.Join(data.Workspace, valuefilename)
|
||||||
|
if _, err := os.Stat(fic); err != nil {
|
||||||
|
log.Log().Warn().Msg(fic)
|
||||||
|
} else {
|
||||||
|
msg = fmt.Sprintf("%s --values %s", msg, fic)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
msg = strings.Replace(msg, " ", " ", -1)
|
||||||
|
|
||||||
|
log.Log().Debug().Msg(msg)
|
||||||
|
|
||||||
|
cmd_args := strings.Split(msg, " ")
|
||||||
|
cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
|
||||||
|
stdout, err := cmd.CombinedOutput()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
res := string(stdout)
|
||||||
|
res = strings.TrimSuffix(res, "\n")
|
||||||
|
return "", errors.New(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
var objmap installOutput
|
||||||
|
|
||||||
|
err = json.Unmarshal(stdout, &objmap)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
res := objmap.Info.Status
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this HelmCommand) ChartUninstall(data HelmChart) (string, error) {
|
||||||
|
bin := this.Bin
|
||||||
|
|
||||||
|
log.Log().Info().Msg(" >> Chart : " + data.Name)
|
||||||
|
|
||||||
|
existe, err := this.chartExists(data)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if ! existe {
|
||||||
|
return "Non présent", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := fmt.Sprintf("%s uninstall %s", bin, data.Name)
|
||||||
|
log.Log().Debug().Msg(msg)
|
||||||
|
|
||||||
|
cmd_args := strings.Split(msg, " ")
|
||||||
|
cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
|
||||||
|
stdout, err := cmd.CombinedOutput()
|
||||||
|
|
||||||
|
res := string(stdout)
|
||||||
|
res = strings.TrimSuffix(res, "\n")
|
||||||
|
|
||||||
|
log.Log().Debug().Msg(res)
|
||||||
|
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ../bin/helm list --filter phpmyadminm --short
|
||||||
|
func (this HelmCommand) chartExists(data HelmChart) (bool, error) {
|
||||||
|
bin := this.Bin
|
||||||
|
|
||||||
|
msg := fmt.Sprintf("%s list --filter %s --no-headers", bin, data.Name)
|
||||||
|
log.Log().Debug().Msg(msg)
|
||||||
|
|
||||||
|
cmd_args := strings.Split(msg, " ")
|
||||||
|
cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
|
||||||
|
stdout, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Debug().Msg(string(stdout))
|
||||||
|
return false, errors.New(string(stdout))
|
||||||
|
}
|
||||||
|
|
||||||
|
res := string(stdout)
|
||||||
|
res = strings.TrimSuffix(res, "\n")
|
||||||
|
|
||||||
|
log.Log().Debug().Msg(string(stdout))
|
||||||
|
log.Log().Debug().Msg(strconv.FormatBool(res != ""))
|
||||||
|
|
||||||
|
return res != "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// func (this HelmChart) GetRessources() (map[string]string, error) {
|
||||||
|
// hs := HelmStatus{Name: this.Name}
|
||||||
|
// hs.New(this.Bin)
|
||||||
|
// data, _ := hs.getRessources()
|
||||||
|
|
||||||
|
// return data, nil
|
||||||
|
// }
|
||||||
30
src/helm/chart_test.go
Normal file
30
src/helm/chart_test.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package helm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHelmChartExists(t *testing.T){
|
||||||
|
|
||||||
|
cmd := getCmdHelm(true, `oc-catalog default 1 2024-09-06 16:01:49.17368605 +0200 CEST deployed oc-catalog-0.1.0 1.0`)
|
||||||
|
|
||||||
|
data := HelmChart{Name: "oc-catalog"}
|
||||||
|
res, err := cmd.chartExists(data)
|
||||||
|
|
||||||
|
assert.Nilf(t, err, "error message %s", err)
|
||||||
|
assert.Truef(t, res, "TestHelmVersion error")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func TestHelmChartNotExists(t *testing.T){
|
||||||
|
|
||||||
|
cmd := getCmdHelm(true, "\n")
|
||||||
|
|
||||||
|
data := HelmChart{Name: "phpmyadmin"}
|
||||||
|
res, err := cmd.chartExists(data)
|
||||||
|
|
||||||
|
assert.Nilf(t, err, "error message %s", err)
|
||||||
|
assert.Falsef(t, res, "TestHelmVersion error")
|
||||||
|
}
|
||||||
22
src/helm/helm.go
Normal file
22
src/helm/helm.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package helm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HelmCommand struct {
|
||||||
|
Bin string
|
||||||
|
Exec func(string,...string) commandExecutor
|
||||||
|
}
|
||||||
|
|
||||||
|
////
|
||||||
|
type commandExecutor interface {
|
||||||
|
Output() ([]byte, error)
|
||||||
|
CombinedOutput() ([]byte, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *HelmCommand) New() {
|
||||||
|
this.Exec = func(name string, arg ...string) commandExecutor {
|
||||||
|
return exec.Command(name, arg...)
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/helm/helm_test.go
Normal file
17
src/helm/helm_test.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package helm
|
||||||
|
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHelm(t *testing.T) {
|
||||||
|
cmd := HelmCommand{}
|
||||||
|
cmd.New()
|
||||||
|
|
||||||
|
assert.NotNilf(t, cmd.Exec, "TestHelm %s", "New")
|
||||||
|
|
||||||
|
cmd.Exec("pwd")
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user