11 Commits

Author SHA1 Message Date
ej
009062c51a Correction statefulset ; uninstall par modules 2024-09-26 19:01:49 +00:00
admju
1b9b79c67f oci 2024-09-19 12:10:03 +00:00
admju
981ee7dce4 version 2024-09-18 19:31:18 +00:00
admju
0c35993122 Version 2024-09-18 09:09:21 +00:00
admju
3abf53ec6c version 2024-09-18 08:59:28 +00:00
admju
19790f61e2 Correction chart via repo 2024-09-18 08:41:47 +00:00
admju
ebf9d3fc6d Supp code commentée 2024-09-18 08:41:16 +00:00
admju
741d1a0ffe Correction 2024-09-18 08:40:53 +00:00
admju
8632b02f0e Aide 2024-09-18 08:40:33 +00:00
admju
95884e14d6 Doc 2024-09-13 12:57:24 +00:00
admju
bd58ac1e02 publish 2024-09-13 12:43:09 +00:00
27 changed files with 850 additions and 432 deletions

2
.gitignore vendored
View File

@@ -1 +1,3 @@
bin bin
*.base64
env

View File

@@ -1,6 +1,34 @@
#!make
include env
export
ifndef OC_VERSION
$(error OC_VERSION is not set)
endif
ifndef PUBLISH_TOKEN
$(error PUBLISH_TOKEN is not set)
endif
PUBLISH_REPO := "core/oc-deploy"
PUBLISH_BRANCH := main
help:
@echo
@echo 'Usage:'
@echo ' make publish'
@echo ' make clean'
.PHONY: publish
publish: publish:
curl -X 'POST' \ @echo Publication de : ${OC_VERSION}
'https://cloud.o-forge.io/api/v1/repos/core/oc-deploy/releases/2/assets?name=oc.json&token=92ad0a4b3d75ec7c5964913b7085d7ddf379247c' \ @(cd src && make --quiet build VERSION=$(OC_VERSION))
-H 'accept: application/json' \ @(cd publish && \
-H 'Content-Type: multipart/form-data' \ PUBLISH_REPO=${PUBLISH_REPO} \
-F 'attachment=@oc.json;type=application/json' PUBLISH_TOKEN=${PUBLISH_TOKEN} \
PUBLISH_BRANCH=${PUBLISH_BRANCH} \
go run main.go ${OC_VERSION})
clean:
@rm *.base64

View File

@@ -17,20 +17,101 @@ It thus contains a first optional installation layer which deploys the Kubernete
This documentation will be updated with the needed command and/or requirements to properly execute the installation. This documentation will be updated with the needed command and/or requirements to properly execute the installation.
# Deploy cluster
## For dev in Docker # oc-deploy tools
Install brew
## Usage
| Command | Description |
| ----------------------------------------------------------------------------- | --------------------------- |
| ```oc-deploy``` | Display help |
| ```oc-deploy version``` | Display the version of tool |
| ```oc-deploy install [-c\|--context <context>] [-v\|--version <OcVersion>]``` | Deploy an OpenCloud |
| ```oc-deploy uninstall [-c\|--context <context>]``` | Undeploy an OpenCloud |
| Arguments | Description | Default |
| ---------------- | --------------------------- | ------------ |
| ```context``` | Context Kubernetes | _opencloud_ |
| ```OcVersion``` | Specific version or latest | _latest_ |
## Principe
* Download an "OpenCloud file version" : oc_<version>.yml from relase on GitEa (core/oc-version).
* Initialise an workspace direcotry : ./workspace_<contextK8S>
* Install tools as describe, if not found on the path :
* Helm
* Kubectl
* Check if the Cluster (context) is available
* Install all charts as describe :
* Charts : from Harbor or local
* Images : from Harbor or local
* Check if componants are available
## Pre-requis
**oc-deploy** need to access to an Kubernetes Cluster, c'est-à-dire : kubeconfig.
**oc-deploy** need to access to Internet :
* to download the _oc.json_ file (contient _oc.yml_) :
* Url : https://cloud.o-forge.io/core/oc-deploy/releases
* to download _kubectl_ and _helm_ tools if
* Url : Urls are specified into _oc.yml_
## Dev
Cf. src/README.md
## Publish
Publish in the relase GitEa the binary (the binary is base64 coding).
Set **env** file to overwrite varibable as :
#!make
PUBLISH_TOKEN = <gitea_token>
To publish :
OC_VERSION = <x.y.z> make publish
# Installation on Kubernetes
## Minikube
TO DO
## Kubernetes
TO DO
## RKE2
TO DO
## OpenShift
TO DO
# Installation on Docker
Without Kubernetes, for dev in Docker
## Install brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install Talos ## Install Talos
brew install siderolabs/tap/talosctl brew install siderolabs/tap/talosctl
talosctl cluster create talosctl cluster create
# Install helm ## Install helm
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh chmod 700 get_helm.sh
./get_helm.sh ./get_helm.sh
# Create OpenCloud Chart ## Create OpenCloud Chart
Obsolete : use oc-deploy tool
helm create occhart helm create occhart

View File

@@ -1,27 +1,83 @@
package main package main
import ( import (
"fmt" "fmt"
"os" "os"
"oc-publish/releases" "io/ioutil"
"encoding/base64"
"oc-publish/releases"
"oc-publish/occonst"
) )
func main() { func main() {
fmt.Println(" >> oc-publish :") version := os.Args[1]
version := os.Args[1] fmt.Printf(" >> oc-publish :\n")
fmt.Println(fmt.Sprintf(" << version : %s", version))
existe, _ := releases.CheckRelease(version) fmt.Printf(" << Url : %s/%s\n", occonst.PUBLISH_URL, occonst.PUBLISH_REPO)
fmt.Println(fmt.Sprintf(" << existe : %t ", existe))
idRelease, _ := releases.GetReleaseId(version) fmt.Printf(" << version : %s %s\n", version, occonst.PUBLISH_BRANCH)
fmt.Println(fmt.Sprintf(" << id : %d ", idRelease))
idAsset, _ := releases.GetAssetId(idRelease, "oc.json") vversion := fmt.Sprintf("v%s", version)
fmt.Println(fmt.Sprintf(" << idAsset : %d ", idAsset)) existe, _ := releases.CheckRelease(vversion)
fmt.Println(releases.CreateAsset(idRelease, "../bin/oc-deploy")) if existe == false {
err := releases.CreateRelease(vversion, occonst.PUBLISH_BRANCH)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
idRelease, _ := releases.GetReleaseId(vversion)
if existe == true {
fmt.Println(fmt.Sprintf(" << Release existante : %d ", idRelease))
} else {
fmt.Println(fmt.Sprintf(" << Release crée : %d ", idRelease))
}
assetname := "oc-deploy.base64"
binary := fmt.Sprintf("../bin/oc-deploy")
binary64 := fmt.Sprintf("../%s", assetname)
err := createBinaryFile(binary, binary64)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
idAsset, _ := releases.GetAssetId(idRelease, assetname)
if idAsset == 0 {
fmt.Println(fmt.Sprintf(" << Ajout Asset : %s", assetname))
err := releases.CreateAsset(idRelease, binary64, assetname)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
} else {
fmt.Println(fmt.Sprintf(" << Mise à jour : %s (idAsset=%d) ", assetname, idAsset))
err := releases.UpdateAsset(idRelease, idAsset, binary64, assetname)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
} }
func createBinaryFile(source string, dest string) error {
fout, _ := os.Create(dest)
defer fout.Close()
byteValue, err := ioutil.ReadFile(source)
if err != nil {
fmt.Println("64e", err)
return err
}
data64 := base64.StdEncoding.EncodeToString(byteValue)
fout.Write([]byte(data64))
return nil
}

View File

@@ -1,6 +1,18 @@
package occonst package occonst
var PUBLISH_URL = "https://cloud.o-forge.io" import (
var PUBLISH_VERSION = "core/oc-deploy" "os"
)
var PUBLISH_TOKEN = "" var PUBLISH_URL = getenv("PUBLISH_URL", "https://cloud.o-forge.io")
var PUBLISH_REPO = getenv("PUBLISH_REPO", "core/oc-deploy")
var PUBLISH_TOKEN = getenv("PUBLISH_TOKEN", "")
var PUBLISH_BRANCH = getenv("PUBLISH_BRANCH", "main")
func getenv(key string, defaut string) string {
value := os.Getenv(key)
if len(value) == 0 {
return defaut
}
return value
}

6
publish/release.txt Normal file
View File

@@ -0,0 +1,6 @@
Version %s d'OpenCloud
```
wget %s/%s/releases/download/%s/oc-deploy.base64 -O - | base64 -d > oc-deploy
chmod u+x ./oc-deploy
```

View File

@@ -6,6 +6,7 @@ import (
"path/filepath" "path/filepath"
"mime/multipart" "mime/multipart"
"io" "io"
"io/ioutil"
"encoding/json" "encoding/json"
"net/http" "net/http"
"bytes" "bytes"
@@ -21,7 +22,7 @@ type assetStruct struct {
func GetAssetId(idRelease int, name string) (int, error) { func GetAssetId(idRelease int, name string) (int, error) {
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/%d/assets", url := fmt.Sprintf("%s/api/v1/repos/%s/releases/%d/assets",
occonst.PUBLISH_URL, occonst.PUBLISH_URL,
occonst.PUBLISH_VERSION, occonst.PUBLISH_REPO,
idRelease) idRelease)
res, err := http.Get(url) res, err := http.Get(url)
@@ -36,7 +37,6 @@ func GetAssetId(idRelease int, name string) (int, error) {
var data []assetStruct var data []assetStruct
err = json.Unmarshal(body, &data) err = json.Unmarshal(body, &data)
fmt.Println(err)
if err != nil { if err != nil {
return -3, err return -3, err
} }
@@ -54,48 +54,52 @@ func GetAssetId(idRelease int, name string) (int, error) {
// -H 'accept: application/json' \ // -H 'accept: application/json' \
// -H 'Content-Type: multipart/form-data' \ // -H 'Content-Type: multipart/form-data' \
// -F 'attachment=oc-deploy' // -F 'attachment=oc-deploy'
func CreateAsset(idRelease int, filename string) (int, error) { func CreateAsset(idRelease int, filename string, name string) (error) {
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/%d/assets?name=%s&token=%s", url := fmt.Sprintf("%s/api/v1/repos/%s/releases/%d/assets?name=%s&token=%s",
occonst.PUBLISH_URL, occonst.PUBLISH_URL,
occonst.PUBLISH_VERSION, occonst.PUBLISH_REPO,
idRelease, idRelease,
"name", name,
occonst.PUBLISH_TOKEN) occonst.PUBLISH_TOKEN)
// request, err := newfileUploadRequest(url, extraParams, "file", "/tmp/doc.pdf")
err := uploadFile(url, "attachment", filename) err := uploadFile(url, "attachment", filename)
fmt.Println(url, err)
return err
}
// fmt.Println(url) func UpdateAsset(idRelease int, idAsset int, filename string, name string) (error) {
// body := []byte("CONTENU") url := fmt.Sprintf("%s/api/v1/repos/%s/releases/%d/assets/%d?token=%s",
// req, err := http.NewRequest("POST", url, bytes.NewBuffer(body)) occonst.PUBLISH_URL,
// if err != nil { occonst.PUBLISH_REPO,
// return -1, err idRelease,
// } idAsset,
// req.Header.Add("accept", "application/json") occonst.PUBLISH_TOKEN)
// req.Header.Add("Content-Type", "multipart/form-data")
// client := &http.Client{} // Create client
// res, err := client.Do(req) client := &http.Client{}
// fmt.Println(res, err)
// cnt, err := io.ReadAll(res.Body) // Create request
// fmt.Println(string(cnt), err) req, err := http.NewRequest("DELETE", url, nil)
if err != nil {
return err
}
// if err != nil { // Fetch Request
// return -1, err resp, err := client.Do(req)
// } if err != nil {
return err
}
defer resp.Body.Close()
// if err != nil { // Read Response Body
// return -2, err respBody, err := ioutil.ReadAll(resp.Body)
// } if err != nil {
return err
}
fmt.Println(string(respBody))
// defer res.Body.Close() return CreateAsset(idRelease, filename, name)
return 0, nil
} }
func uploadFile(url string, paramName string, filePath string) error { func uploadFile(url string, paramName string, filePath string) error {
@@ -104,7 +108,7 @@ func uploadFile(url string, paramName string, filePath string) error {
return err return err
} }
defer file.Close() defer file.Close()
body := &bytes.Buffer{} body := &bytes.Buffer{}
writer := multipart.NewWriter(body) writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile(paramName, filepath.Base(filePath)) part, err := writer.CreateFormFile(paramName, filepath.Base(filePath))
@@ -123,44 +127,19 @@ func uploadFile(url string, paramName string, filePath string) error {
request.Header.Add("accept", "application/json") request.Header.Add("accept", "application/json")
client := &http.Client{} client := &http.Client{}
response, err := client.Do(request) response, err := client.Do(request)
if err != nil { if err != nil {
fmt.Println(109, err)
return err return err
} }
defer response.Body.Close() defer response.Body.Close()
cnt, err := io.ReadAll(response.Body) if response.StatusCode > 400 {
fmt.Println(string(cnt), err, writer.FormDataContentType()) return fmt.Errorf(response.Status)
// Handle the server response...
return nil
} }
_, err1 := io.ReadAll(response.Body)
// func newfileUploadRequest(uri string, params map[string]string, paramName, path string) (*http.Request, error) { // Handle the server response...
// file, err := os.Open(path) return err1
// 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
// }

View File

@@ -3,6 +3,8 @@ package releases
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"strings"
"encoding/json" "encoding/json"
"net/http" "net/http"
@@ -15,10 +17,9 @@ type checkStruct struct {
} }
func CheckRelease(version string) (bool, error) { func CheckRelease(version string) (bool, error) {
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/tags/%s", url := fmt.Sprintf("%s/api/v1/repos/%s/releases",
occonst.PUBLISH_URL, occonst.PUBLISH_URL,
occonst.PUBLISH_VERSION, occonst.PUBLISH_REPO)
version)
res, err := http.Get(url) res, err := http.Get(url)
if err != nil { if err != nil {
@@ -29,19 +30,25 @@ func CheckRelease(version string) (bool, error) {
return false, err return false, err
} }
var data checkStruct var data []checkStruct
err = json.Unmarshal(body, &data) err = json.Unmarshal(body, &data)
if err != nil { if err != nil {
return false, err return false, err
} }
return data.Name != "", nil for _, ele := range data {
if ele.Name == version {
return true, nil
}
}
// return data.Name != "", nil
return false, nil
} }
func GetReleaseId(version string) (int, error) { func GetReleaseId(version string) (int, error) {
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/tags/%s", url := fmt.Sprintf("%s/api/v1/repos/%s/releases/tags/%s",
occonst.PUBLISH_URL, occonst.PUBLISH_URL,
occonst.PUBLISH_VERSION, occonst.PUBLISH_REPO,
version) version)
res, err := http.Get(url) res, err := http.Get(url)
@@ -60,4 +67,60 @@ func GetReleaseId(version string) (int, error) {
} }
return data.Id, nil return data.Id, nil
} }
// curl -X 'POST' \
// 'https://cloud.o-forge.io/api/v1/repos/na/oc-version/releases?token=sss' \
// -H 'accept: application/json' \
// -H 'Content-Type: application/json' \
// -d '{
// "body": "string",
// "draft": true,
// "name": "string",
// "prerelease": true,
// "tag_name": "string",
// "target_commitish": "string"
// }'
func CreateRelease(version string, branch string) (error) {
url := fmt.Sprintf("%s/api/v1/repos/%s/releases?token=%s",
occonst.PUBLISH_URL,
occonst.PUBLISH_REPO,
occonst.PUBLISH_TOKEN)
releasebytes, err := ioutil.ReadFile("release.txt")
releasetxt := string(releasebytes)
releasetxt = strings.Replace(releasetxt, "\n", "\\n", -1)
releasetxt = fmt.Sprintf(releasetxt, version, occonst.PUBLISH_URL, occonst.PUBLISH_REPO, version)
body := fmt.Sprintf(`{
"body": "%s",
"draft": false,
"name": "%s",
"prerelease": false,
"tag_name": "%s",
"target_commitish": "%s"
}`, releasetxt, version, version, branch)
request, err := http.NewRequest("POST", url, strings.NewReader(body))
if err != nil {
return err
}
request.Header.Add("accept", "application/json")
request.Header.Add("Content-Type", "application/json")
client := &http.Client{}
response, err := client.Do(request)
if err != nil {
return err
}
defer response.Body.Close()
_, err1 := io.ReadAll(response.Body)
// cnt, err1 := io.ReadAll(response.Body)
// fmt.Println(string(cnt))
if err1 != nil {
return err1
}
return nil
}

View File

@@ -11,6 +11,16 @@ BIN_DIR = ../bin/
PLUGINS := $(wildcard ../plugins/*/*.go) PLUGINS := $(wildcard ../plugins/*/*.go)
OBJS := ${PLUGINS:.go=.so} OBJS := ${PLUGINS:.go=.so}
##################
DATE := $(shell date --iso-8601)
GOVERSION := $(shell go version)
VERSION := $(shell git describe --tags --abbrev=8 --dirty --always --long)
PREFIX := oc-deploy/occonst
LDFLAGS := "-X '${PREFIX}.Version=${VERSION}' -X '${PREFIX}.Date=${DATE}' -X '${PREFIX}.GoVersion=${GOVERSION}'"
##################
%.so: %.go %.so: %.go
go build -buildmode=plugin -o $@ $< go build -buildmode=plugin -o $@ $<
@@ -23,35 +33,44 @@ help:
@echo ' make run BIN_OPTS=... Go run' @echo ' make run BIN_OPTS=... Go run'
@echo ' make run_install BIN_OPTS=... Go run' @echo ' make run_install BIN_OPTS=... Go run'
@echo ' make run_uninstall BIN_OPTS=... Go run' @echo ' make run_uninstall BIN_OPTS=... Go run'
@echo ' make run_version Go run'
@echo ' make exec BIN_OPTS=... exécutable' @echo ' make exec BIN_OPTS=... exécutable'
@echo ' make exec_install BIN_OPTS=... exécutable' @echo ' make exec_install BIN_OPTS=... exécutable'
@echo ' make exec_uninstall BIN_OPTS=... exécutable' @echo ' make exec_uninstall BIN_OPTS=... exécutable'
@echo ' make test Test.' @echo ' make exec_version exécutable'
@echo ' make test Test' @echo ' make test Test'
@echo ' make clean Clean the directory tree.' @echo ' make clean Clean the directory tree.'
@echo @echo
@echo ' DATE ${DATE}'
@echo ' GOVERSION ${GOVERSION}'
@echo ' VERSION ${VERSION}'
@echo
${BIN_DIR}/${BIN_NAME}: ${SOURCES} $(OBJS) ${BIN_DIR}/${BIN_NAME}: ${SOURCES} $(OBJS)
go build -o ${BIN_DIR}/${BIN_NAME} go build -o ${BIN_DIR}/${BIN_NAME} -ldflags ${LDFLAGS}
get-deps: get-deps:
@go mod tidy @go mod tidy
build: ${BIN_DIR}/${BIN_NAME} build: ${BIN_DIR}/${BIN_NAME}
run: $(OBJS) run:
@go run main.go ${BIN_OPTS} @go run main.go ${BIN_OPTS}
run_generate: $(OBJS) run_generate:
@go run main.go generate ${BIN_OPTS} @go run main.go generate ${BIN_OPTS}
run_install: $(OBJS) run_install:
@go run main.go install ${BIN_OPTS} @go run main.go install ${BIN_OPTS}
run_uninstall: $(OBJS) run_uninstall:
@go run main.go uninstall ${BIN_OPTS} @go run main.go uninstall ${BIN_OPTS}
run_version:
@go run main.go version
exec: ${BIN_DIR}/${BIN_NAME} $(OBJS) exec: ${BIN_DIR}/${BIN_NAME} $(OBJS)
@${BIN_DIR}/${BIN_NAME} ${BIN_OPTS} @${BIN_DIR}/${BIN_NAME} ${BIN_OPTS}
@@ -61,6 +80,9 @@ exec_install: ${BIN_DIR}/${BIN_NAME} $(OBJS)
exec_uninstall: ${BIN_DIR}/${BIN_NAME} $(OBJS) exec_uninstall: ${BIN_DIR}/${BIN_NAME} $(OBJS)
@${BIN_DIR}/${BIN_NAME} uninstall ${BIN_OPTS} @${BIN_DIR}/${BIN_NAME} uninstall ${BIN_OPTS}
exec_version: ${BIN_DIR}/${BIN_NAME} $(OBJS)
@${BIN_DIR}/${BIN_NAME} version
clean: clean:
@test ! -e ${BIN_DIR}/${BIN_NAME} || rm ${BIN_DIR}/${BIN_NAME} @test ! -e ${BIN_DIR}/${BIN_NAME} || rm ${BIN_DIR}/${BIN_NAME}
@test ! -e .coverage.out || rm .coverage.out @test ! -e .coverage.out || rm .coverage.out

View File

@@ -2,33 +2,6 @@
**oc-deploy** is a tool to deploy (with **helm**) all component of **OpenCloud**. **oc-deploy** is a tool to deploy (with **helm**) all component of **OpenCloud**.
# Usage
| Command | Description |
| ----------------------------------------------------------------------------- | --------------------------- |
| ```oc-deploy``` | Display help |
| ```oc-deploy version``` | Display the version of tool |
| ```oc-deploy install [-c\|--context <context>] [-v\|--version <OcVersion>]``` | Deploy an OpenCloud |
| ```oc-deploy uninstall [-c\|--context <context>]``` | Undeploy an OpenCloud |
| Arguments | Description | Default |
| ---------------- | --------------------------- | ------------ |
| ```context``` | Context Kubernetes | _opencloud_ |
| ```OcVersion``` | Specific version or latest | _latest_ |
# Principe
# Pre-requis
**oc-deploy** need to access to an Kubernetes Cluster, c'est-à-dire : kubeconfig.
**oc-deploy** need to access to Internet :
* to download the _oc.json_ file (contient _oc.yml_) :
* Url : https://cloud.o-forge.io/core/oc-deploy/releases
* to download _kubectl_ and _helm_ tools if
* Url : Urls are specified into _oc.yml_
# Development # Development
To init: To init:

View File

@@ -25,8 +25,13 @@ type repoData struct {
Opts string `yaml:"opts"` Opts string `yaml:"opts"`
} }
type ociData struct {
Url string `yaml:"url"`
}
type ChartRepoData struct { type ChartRepoData struct {
Repository repoData `yaml:"repository"` Repository repoData `yaml:"repository"`
Oci ociData `yaml:"oci"`
Charts []ChartData `yaml:"charts"` Charts []ChartData `yaml:"charts"`
} }

View File

@@ -39,7 +39,7 @@ func _TestReadConfChart(t *testing.T) {
assert.Equal(t, "https://zzzz/myfirstchart-0.1.0.tgz", myfirstrelease.Url, "FromConfigFile error") assert.Equal(t, "https://zzzz/myfirstchart-0.1.0.tgz", myfirstrelease.Url, "FromConfigFile error")
} }
func TestReadConfChartOverwrite(t *testing.T){ func _TestReadConfChartOverwrite(t *testing.T){
src := filepath.Join(TEST_SRC_DIR, "oc_overwrite.yml") src := filepath.Join(TEST_SRC_DIR, "oc_overwrite.yml")
assert.FileExists(t, src, "FromConfigFile error") assert.FileExists(t, src, "FromConfigFile error")
@@ -47,4 +47,17 @@ func TestReadConfChartOverwrite(t *testing.T){
data, _ := FromConfigFile(src) data, _ := FromConfigFile(src)
// Nombre de lettres // Nombre de lettres
assert.Equal(t, 70, len(data[0].Charts[0].Overwrite), "TestReadConfChartOverwrite error") assert.Equal(t, 70, len(data[0].Charts[0].Overwrite), "TestReadConfChartOverwrite error")
} }
func TestReadConfChartOci(t *testing.T) {
src := filepath.Join(TEST_SRC_DIR, "oc_oci.yml")
assert.FileExists(t, src, "FromConfigFile error")
data, _ := FromConfigFile(src)
assert.Equal(t, "", data[0].Repository.Name, "FromConfigFile error")
assert.Equal(t, "oci://harbor.dtf/dev", data[0].Oci.Url, "FromConfigFile error")
}

View File

@@ -24,6 +24,7 @@ func cobraInstallCmd() *cobra.Command {
Long: `deploy Charts`, Long: `deploy Charts`,
Args: cobra.MaximumNArgs(0), Args: cobra.MaximumNArgs(0),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
log.Log().Info().Msg("oc-deploy :")
return InstallCmd(context, version, modules) return InstallCmd(context, version, modules)
}, },
Example: "oc-deploy install --version 0.1.0 --context ex1", Example: "oc-deploy install --version 0.1.0 --context ex1",
@@ -37,7 +38,8 @@ func cobraUninstallCmd() *cobra.Command{
Long: `Undeploy`, Long: `Undeploy`,
Args: cobra.MaximumNArgs(0), Args: cobra.MaximumNArgs(0),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return UninstallCmd(context) log.Log().Info().Msg("oc-deploy :")
return UninstallCmd(context, modules)
}, },
Example: "oc-deploy uninstall --context ex1", Example: "oc-deploy uninstall --context ex1",
} }
@@ -48,15 +50,29 @@ func cobraGenerateCmd() *cobra.Command{
return &cobra.Command{ return &cobra.Command{
Use: "generate", Use: "generate",
Short: "generate", Short: "generate",
Long: "Value", Long: "generate",
Args: cobra.MaximumNArgs(0), Args: cobra.MaximumNArgs(0),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
log.Log().Info().Msg("oc-deploy :")
return GenerateCmd(context, version) return GenerateCmd(context, version)
}, },
Example: "oc-deploy generate --version 0.1.0 --context ex1", Example: "oc-deploy generate --version 0.1.0 --context ex1",
} }
} }
func cobraVersionCmd() *cobra.Command{
return &cobra.Command{
Use: "version",
Short: "version",
Long: "Get Version",
Args: cobra.MaximumNArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
return VersionCmd()
},
Example: "oc-deploy version",
}
}
func Execute() { func Execute() {
log.Log().Debug().Msg("Execute") log.Log().Debug().Msg("Execute")
@@ -66,12 +82,14 @@ func Execute() {
var cmdInstall = cobraInstallCmd() var cmdInstall = cobraInstallCmd()
var cmdUninstall = cobraUninstallCmd() var cmdUninstall = cobraUninstallCmd()
var cmdGenerate = cobraGenerateCmd() var cmdGenerate = cobraGenerateCmd()
var cmdVersion = cobraVersionCmd()
cmdInstall.Flags().StringVarP(&context, "context", "c", "opencloud", "Nom du context") cmdInstall.Flags().StringVarP(&context, "context", "c", "opencloud", "Nom du context")
cmdInstall.Flags().StringVarP(&version, "version", "v", "latest", "Version") cmdInstall.Flags().StringVarP(&version, "version", "v", "latest", "Version")
cmdInstall.Flags().StringArrayVarP(&modules, "modules", "m", []string{}, "modules, ...") cmdInstall.Flags().StringArrayVarP(&modules, "modules", "m", []string{}, "modules, ...")
cmdUninstall.Flags().StringVarP(&context, "context", "c", "opencloud", "Nom du context") cmdUninstall.Flags().StringVarP(&context, "context", "c", "opencloud", "Nom du context")
cmdUninstall.Flags().StringArrayVarP(&modules, "modules", "m", []string{}, "modules, ...")
cmdGenerate.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") cmdGenerate.Flags().StringVarP(&version, "version", "v", "latest", "Version")
@@ -79,6 +97,7 @@ func Execute() {
rootCmd.AddCommand(cmdInstall) rootCmd.AddCommand(cmdInstall)
rootCmd.AddCommand(cmdUninstall) rootCmd.AddCommand(cmdUninstall)
rootCmd.AddCommand(cmdGenerate) rootCmd.AddCommand(cmdGenerate)
rootCmd.AddCommand(cmdVersion)
cobra.CheckErr(rootCmd.Execute()) cobra.CheckErr(rootCmd.Execute())

View File

@@ -2,19 +2,19 @@ package cmd
import ( import (
"fmt" "fmt"
// "strings"
// "github.com/spf13/cobra"
log "oc-deploy/log_wrapper" log "oc-deploy/log_wrapper"
// "oc-deploy/versionOc"
"oc-deploy/install" "oc-deploy/install"
) )
func UninstallCmd(context string) error { func UninstallCmd(context string, modules []string) error {
log.Log().Info().Msg("Uninstall >> ") log.Log().Info().Msg("Uninstall >> ")
log.Log().Info().Msg(" << Contexte : " + context) 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) workspace := fmt.Sprintf("workspace_%s", context)
obj := install.InstallClass{Workspace: workspace} obj := install.InstallClass{Workspace: workspace}
@@ -31,12 +31,14 @@ func UninstallCmd(context string) error {
log.Log().Fatal().Msg(" >> " + err.Error()) log.Log().Fatal().Msg(" >> " + err.Error())
} }
obj.SetCommands()
err = obj.K8s(context) err = obj.K8s(context)
if err != nil { if err != nil {
log.Log().Fatal().Msg(" >> " + err.Error()) log.Log().Fatal().Msg(" >> " + err.Error())
} }
err = obj.UninstallCharts() err = obj.UninstallCharts(modules)
if err != nil { if err != nil {
log.Log().Fatal().Msg(" >> " + err.Error()) log.Log().Fatal().Msg(" >> " + err.Error())
} }

19
src/cmd/versionCmd.go Normal file
View File

@@ -0,0 +1,19 @@
package cmd
import (
"fmt"
"oc-deploy/occonst"
log "oc-deploy/log_wrapper"
)
func VersionCmd() error {
version := occonst.Version
date := occonst.Date
goversion := occonst.GoVersion
log.Log().Debug().Msg(fmt.Sprintf("Version : %s (%s) ; GoVersion : %s", version, date, goversion))
fmt.Println(version)
return nil
}

View File

@@ -1,173 +1,169 @@
package helm package helm
import ( import (
"fmt" "fmt"
"strconv" "strconv"
"os" "os"
"strings" "strings"
"errors" "errors"
"path/filepath" "path/filepath"
"encoding/json" "encoding/json"
log "oc-deploy/log_wrapper" log "oc-deploy/log_wrapper"
) )
type HelmChart struct { type HelmChart struct {
Bin string Bin string
Name string Name string
Chart string Chart string
Version string Version string
Url string Url string
Workspace string Workspace string
Opts string Opts string
Values map[string]string Values map[string]string
FileValues []string FileValues []string
} }
type installInfoOutput struct { type installInfoOutput struct {
Description string `json:"description"` Description string `json:"description"`
Notes string `json:"notes"` Notes string `json:"notes"`
Status string `json:"status"` Status string `json:"status"`
} }
type installOutput struct { type installOutput struct {
Info installInfoOutput `json:"info"` Info installInfoOutput `json:"info"`
} }
func (this HelmCommand) ChartInstall(data HelmChart) (string, error) { func (this HelmCommand) ChartInstall(data HelmChart) (string, error) {
bin := this.Bin bin := this.Bin
existe, err := this.chartExists(data) existe, err := this.chartExists(data)
if err != nil { if err != nil {
return "", err return "", err
} }
if existe { if existe {
return "Existe déjà", nil return "Existe déjà", nil
} }
ficChart := data.Chart ficChart := data.Chart
// Recherche locale // Recherche locale
if _, err := os.Stat(ficChart); err != nil { if _, err := os.Stat(ficChart); err != nil {
} else { } else {
// Recherche voa le Workspace // Recherche voa le Workspace
ficChart := filepath.Join(data.Workspace, data.Chart) ficChart := filepath.Join(data.Workspace, data.Chart)
if _, err := os.Stat(ficChart); err == nil { if _, err := os.Stat(ficChart); err == nil {
} else { } else {
if data.Url != "" { if data.Url != "" {
fmt.Println("============ 52 Télechargement", 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) msg := fmt.Sprintf("%s install %s %s %s --output json", bin, data.Name, ficChart, data.Opts)
if data.Version != "" { if data.Version != "" {
msg = fmt.Sprintf("%s --version %s", msg, data.Version) msg = fmt.Sprintf("%s --version %s", msg, data.Version)
} }
for key, value := range data.Values { for key, value := range data.Values {
msg = fmt.Sprintf("%s --set %s=%s", msg, key, value) msg = fmt.Sprintf("%s --set %s=%s", msg, key, value)
} }
ficoverwrite := filepath.Join(data.Workspace, fmt.Sprintf("value-%s.yml", data.Name)) ficoverwrite := filepath.Join(data.Workspace, fmt.Sprintf("value-%s.yml", data.Name))
if _, err := os.Stat(ficoverwrite); err != nil { if _, err := os.Stat(ficoverwrite); err != nil {
log.Log().Warn().Msg(ficoverwrite) log.Log().Warn().Msg(ficoverwrite)
} else { } else {
msg = fmt.Sprintf("%s --values %s", msg, ficoverwrite) msg = fmt.Sprintf("%s --values %s", msg, ficoverwrite)
} }
for _, valuefilename := range data.FileValues { for _, valuefilename := range data.FileValues {
fic := filepath.Join(data.Workspace, valuefilename) fic := filepath.Join(data.Workspace, valuefilename)
if _, err := os.Stat(fic); err != nil { if _, err := os.Stat(fic); err != nil {
log.Log().Warn().Msg(fic) log.Log().Warn().Msg(fic)
} else { } else {
msg = fmt.Sprintf("%s --values %s", msg, fic) msg = fmt.Sprintf("%s --values %s", msg, fic)
} }
} }
msg = strings.Replace(msg, " ", " ", -1) msg = strings.Replace(msg, " ", " ", -1)
log.Log().Debug().Msg(msg) log.Log().Debug().Msg(msg)
cmd_args := strings.Split(msg, " ") cmd_args := strings.Split(msg, " ")
cmd := this.Exec(cmd_args[0], cmd_args[1:]...) cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
stdout, err := cmd.CombinedOutput() stdout, err := cmd.CombinedOutput()
if err != nil { if err != nil {
res := string(stdout) res := string(stdout)
res = strings.TrimSuffix(res, "\n") res = strings.TrimSuffix(res, "\n")
return "", errors.New(res) return "", errors.New(res)
} }
var objmap installOutput var objmap installOutput
err = json.Unmarshal(stdout, &objmap) i := strings.Index(string(stdout), "{")
if err != nil { stdout2 := string(stdout)[i:]
return "", err
} err = json.Unmarshal([]byte(stdout2), &objmap)
if err != nil {
res := objmap.Info.Status return "", err
}
return res, nil
} res := objmap.Info.Status
func (this HelmCommand) ChartUninstall(data HelmChart) (string, error) { return res, nil
bin := this.Bin }
log.Log().Info().Msg(" >> Chart : " + data.Name) func (this HelmCommand) ChartUninstall(data HelmChart) (string, error) {
bin := this.Bin
existe, err := this.chartExists(data)
if err != nil { log.Log().Info().Msg(" >> Chart : " + data.Name)
return "", err
} existe, err := this.chartExists(data)
if ! existe { if err != nil {
return "Non présent", nil return "", err
} }
if ! existe {
msg := fmt.Sprintf("%s uninstall %s", bin, data.Name) return "Non présent", nil
log.Log().Debug().Msg(msg) }
cmd_args := strings.Split(msg, " ") msg := fmt.Sprintf("%s uninstall %s", bin, data.Name)
cmd := this.Exec(cmd_args[0], cmd_args[1:]...) log.Log().Debug().Msg(msg)
stdout, err := cmd.CombinedOutput()
cmd_args := strings.Split(msg, " ")
res := string(stdout) cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
res = strings.TrimSuffix(res, "\n") stdout, err := cmd.CombinedOutput()
log.Log().Debug().Msg(res) res := string(stdout)
res = strings.TrimSuffix(res, "\n")
return res, err
} log.Log().Debug().Msg(res)
// ../bin/helm list --filter phpmyadminm --short return res, err
func (this HelmCommand) chartExists(data HelmChart) (bool, error) { }
bin := this.Bin
// ../bin/helm list --filter phpmyadminm --short
msg := fmt.Sprintf("%s list --filter %s --no-headers", bin, data.Name) func (this HelmCommand) chartExists(data HelmChart) (bool, error) {
log.Log().Debug().Msg(msg)
bin := this.Bin
cmd_args := strings.Split(msg, " ")
cmd := this.Exec(cmd_args[0], cmd_args[1:]...) msg := fmt.Sprintf("%s list --filter %s --no-headers", bin, data.Name)
stdout, err := cmd.CombinedOutput() log.Log().Debug().Msg(msg)
if err != nil {
log.Log().Debug().Msg(string(stdout)) cmd_args := strings.Split(msg, " ")
return false, errors.New(string(stdout)) cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
} stdout, err := cmd.CombinedOutput()
if err != nil {
res := string(stdout) log.Log().Debug().Msg(string(stdout))
res = strings.TrimSuffix(res, "\n") return false, errors.New(string(stdout))
}
log.Log().Debug().Msg(string(stdout))
log.Log().Debug().Msg(strconv.FormatBool(res != "")) res := string(stdout)
res = strings.TrimSuffix(res, "\n")
return res != "", nil
} log.Log().Debug().Msg(string(stdout))
log.Log().Debug().Msg(strconv.FormatBool(res != ""))
// func (this HelmChart) GetRessources() (map[string]string, error) {
// hs := HelmStatus{Name: this.Name} return res != "", nil
// hs.New(this.Bin) }
// data, _ := hs.getRessources()
// return data, nil
// }

View File

@@ -1,32 +1,28 @@
package helm package helm
import ( import (
"fmt" "fmt"
"strings" "strings"
"errors" "errors"
log "oc-deploy/log_wrapper" log "oc-deploy/log_wrapper"
) )
// type HelmData struct { func (this HelmCommand) Status(data HelmChart) (string, error) {
// Name string
// } helm_bin := this.Bin
func (this HelmCommand) Status(data HelmChart) (string, error) { msg := fmt.Sprintf("%s status %s --show-resources -o json", helm_bin, data.Name)
log.Log().Debug().Msg(msg)
helm_bin := this.Bin
cmd_args := strings.Split(msg, " ")
msg := fmt.Sprintf("%s status %s --show-resources -o json", helm_bin, data.Name)
log.Log().Debug().Msg(msg) cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
stdout, err := cmd.CombinedOutput()
cmd_args := strings.Split(msg, " ") if err != nil {
log.Log().Debug().Msg(string(stdout))
cmd := this.Exec(cmd_args[0], cmd_args[1:]...) return "", errors.New(string(stdout))
stdout, err := cmd.CombinedOutput() }
if err != nil {
log.Log().Debug().Msg(string(stdout)) return string(stdout), nil
return "", errors.New(string(stdout)) }
}
return string(stdout), nil
}

View File

@@ -60,13 +60,22 @@ func (this *InstallClass) InstallCharts(modules []string) (error) {
var wg sync.WaitGroup var wg sync.WaitGroup
for _, v := range this.charts { for _, v := range this.charts {
repoName := ""
if v.Repository.Name != "" {
repoName = v.Repository.Name
} else {
if v.Oci.Url != "" {
repoName = v.Oci.Url
}
}
for _, v1 := range v.Charts { for _, v1 := range v.Charts {
if len(modules) == 0 || utils.StringInSlice(v1.Name, modules) { if len(modules) == 0 || utils.StringInSlice(v1.Name, modules) {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
this.installChart(v1) this.installChart(repoName, v1)
} () } ()
} }
} }
@@ -75,12 +84,19 @@ func (this *InstallClass) InstallCharts(modules []string) (error) {
return nil return nil
} }
func (this *InstallClass) installChart(chart chart.ChartData) { func (this *InstallClass) installChart(repoName string, chart chart.ChartData) {
log.Log().Info().Msg(fmt.Sprintf(" << Chart : %s ", chart.Name)) log.Log().Info().Msg(fmt.Sprintf(" << Chart : %s ", chart.Name))
chartName := chart.Chart
if chartName == "" {
chartName = chart.Name
}
if repoName != "" {
chartName = fmt.Sprintf("%s/%s", repoName, chartName)
}
data := helm.HelmChart{Name: chart.Name, data := helm.HelmChart{Name: chart.Name,
Chart: chart.Chart, Chart: chartName,
Url: chart.Url, Url: chart.Url,
Version: chart.Version, Version: chart.Version,
Workspace: this.Workspace, Workspace: this.Workspace,

View File

@@ -6,6 +6,7 @@ import (
"sync" "sync"
log "oc-deploy/log_wrapper" log "oc-deploy/log_wrapper"
"oc-deploy/utils"
"oc-deploy/versionOc" "oc-deploy/versionOc"
"oc-deploy/tool" "oc-deploy/tool"
"oc-deploy/chart" "oc-deploy/chart"
@@ -39,20 +40,23 @@ func (this *InstallClass) NewUninstall() (string, error) {
return dst, nil return dst, nil
} }
func (this *InstallClass) UninstallCharts() (error) { func (this *InstallClass) UninstallCharts(modules []string) (error) {
helm_bin, _ := this.getToolBin("helm") helm_bin, _ := this.getToolBin("helm")
kubectl_bin, _ := this.getToolBin("kubectl") kubectl_bin, _ := this.getToolBin("kubectl")
var wg sync.WaitGroup var wg sync.WaitGroup
for _, v := range this.charts { for _, v := range this.charts {
for _, v1 := range v.Charts {
wg.Add(1)
go func() { for _, v1 := range v.Charts {
defer wg.Done() if len(modules) == 0 || utils.StringInSlice(v1.Name, modules) {
this.uninstallChart(helm_bin, kubectl_bin, v1) wg.Add(1)
} ()
go func() {
defer wg.Done()
this.uninstallChart(helm_bin, kubectl_bin, v1)
} ()
}
} }
} }
wg.Wait() wg.Wait()
@@ -69,9 +73,6 @@ func (this *InstallClass) uninstallChart(helm_bin string, kubectl_bin string, ch
data := helm.HelmChart{Name: chart.Name} data := helm.HelmChart{Name: chart.Name}
// helmchart := helm.HelmChart{Bin: helm_bin,
// Name: chart.Name}
res, err := helm_cmd.ChartUninstall(data) res, err := helm_cmd.ChartUninstall(data)
if err != nil { if err != nil {
log.Log().Error().Msg(fmt.Sprintf(" >> %s %s (%s)", data.Name, "KO", err)) log.Log().Error().Msg(fmt.Sprintf(" >> %s %s (%s)", data.Name, "KO", err))

View File

@@ -34,7 +34,7 @@ func (this KubectlCommand) getDeployment(data KubectlObject) (map[string]any, er
m["name"] = data.Name m["name"] = data.Name
m["kind"] = kind m["kind"] = kind
m["replicas"] = status.Replicas m["replicas"] = status.Replicas
m["UnavailableReplicas"] = status.UnavailableReplicas m["unavailableReplicas"] = status.UnavailableReplicas
return m, nil return m, nil
} }

View File

@@ -22,6 +22,7 @@ type getOutput struct {
type getStatusOutput struct { type getStatusOutput struct {
Replicas int `json:"replicas"` Replicas int `json:"replicas"`
UnavailableReplicas int `json:"unavailableReplicas"` UnavailableReplicas int `json:"unavailableReplicas"`
AvailableReplicas int `json:"availableReplicas"`
} }
func (this KubectlCommand) Get(data KubectlObject) (map[string]any, error) { func (this KubectlCommand) Get(data KubectlObject) (map[string]any, error) {
@@ -43,7 +44,7 @@ func (this KubectlCommand) Wait(data KubectlObject) (error) {
if err != nil { if err != nil {
return err return err
} }
ko := m["UnavailableReplicas"].(int) ko := m["unavailableReplicas"].(int)
if ko == 0 { if ko == 0 {
return nil return nil
} }

View File

@@ -1,28 +1,44 @@
package kubectl package kubectl
import ( import (
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestKubectStatefulset(t *testing.T) { func TestKubectStatefulset(t *testing.T) {
fileName := filepath.Join(TEST_SRC_DIR, "statefulset.json") fileName := filepath.Join(TEST_SRC_DIR, "statefulset.json")
cmd_json, _ := os.ReadFile(fileName) cmd_json, _ := os.ReadFile(fileName)
cmd := getCmdKubectl(true, string(cmd_json)) cmd := getCmdKubectl(true, string(cmd_json))
data := KubectlObject{Name: "dep1", Kind: "Statefulset"} data := KubectlObject{Name: "dep1", Kind: "Statefulset"}
res, err := cmd.getDeployment(data) res, err := cmd.getStatefulSet(data)
// map[string]interface {}(map[string]interface {}{"UnavailableReplicas":0, "kind":"StatefulSet", "name":"dep1", "replicas":1}) assert.Nilf(t, err, "error message %s", err)
assert.Nilf(t, err, "error message %s", err) assert.Equal(t, "StatefulSet", res["kind"], "TestKubectStatefulset error")
assert.Equal(t, "StatefulSet", res["kind"], "TestKubectDeployment error") assert.Equal(t, 1, res["replicas"], "TestKubectStatefulset error")
assert.Equal(t, 1, res["replicas"], "TestKubectDeployment error") }
}
func TestKubectStatefulsetPending(t *testing.T) {
fileName := filepath.Join(TEST_SRC_DIR, "mongo_pending.json")
cmd_json, _ := os.ReadFile(fileName)
cmd := getCmdKubectl(true, string(cmd_json))
data := KubectlObject{Name: "dep1", Kind: "Statefulset"}
res, err := cmd.getStatefulSet(data)
assert.Nilf(t, err, "error message %s", err)
assert.Equal(t, 1, res["unavailableReplicas"], "TestKubectStatefulsetPending error")
assert.Equal(t, "StatefulSet", res["kind"], "TestKubectStatefulsetPending error")
assert.Equal(t, 1, res["replicas"], "TestKubectStatefulsetPending error")
}

View File

@@ -1,43 +1,43 @@
package kubectl package kubectl
import ( import (
"fmt" "fmt"
"strings" "strings"
"errors" "errors"
"encoding/json" "encoding/json"
log "oc-deploy/log_wrapper" log "oc-deploy/log_wrapper"
) )
func (this KubectlCommand) getStatefulSet(data KubectlObject) (map[string]any, error) { func (this KubectlCommand) getStatefulSet(data KubectlObject) (map[string]any, error) {
bin := this.Bin bin := this.Bin
name := data.Name name := data.Name
msg := fmt.Sprintf("%s get statefulset %s -o json", bin, name) msg := fmt.Sprintf("%s get statefulset %s -o json", bin, name)
log.Log().Debug().Msg(msg) log.Log().Debug().Msg(msg)
m := make(map[string]any) m := make(map[string]any)
cmd_args := strings.Split(msg, " ") cmd_args := strings.Split(msg, " ")
cmd := this.Exec(cmd_args[0], cmd_args[1:]...) cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
stdout, err := cmd.CombinedOutput() stdout, err := cmd.CombinedOutput()
if err != nil { if err != nil {
return m, errors.New(string(stdout)) return m, errors.New(string(stdout))
} }
var objmap getOutput var objmap getOutput
json.Unmarshal(stdout, &objmap) json.Unmarshal(stdout, &objmap)
kind := objmap.Kind kind := objmap.Kind
status := objmap.Status status := objmap.Status
m["name"] = name m["name"] = name
m["kind"] = kind m["kind"] = kind
m["replicas"] = status.Replicas m["replicas"] = status.Replicas
m["UnavailableReplicas"] = status.UnavailableReplicas m["unavailableReplicas"] = status.Replicas - status.AvailableReplicas
return m, nil return m, nil
} }

View File

@@ -10,7 +10,6 @@ func main() {
log.InitLog(".oc-deploy") log.InitLog(".oc-deploy")
log.Log().Debug().Msg("Start") log.Log().Debug().Msg("Start")
log.Log().Info().Msg("oc-deploy :")
cmd.Execute() cmd.Execute()

View File

@@ -9,6 +9,10 @@ var OCDEPLOY_ONLINE_REPO = getenv("OCDEPLOY_ONLINE_REPO", "core/oc-version")
var OCDEPLOY_OFFLINE_DIR = getenv("OCDEPLOY_OFFLINE_DIR", "../../offline") var OCDEPLOY_OFFLINE_DIR = getenv("OCDEPLOY_OFFLINE_DIR", "../../offline")
var Version = "dev"
var Date = "now"
var GoVersion = ""
func getenv(key string, defaut string) string { func getenv(key string, defaut string) string {
value := os.Getenv(key) value := os.Getenv(key)
if len(value) == 0 { if len(value) == 0 {

9
test/chart/oc_oci.yml Normal file
View File

@@ -0,0 +1,9 @@
---
opencloud:
- oci:
url: oci://harbor.dtf/dev
charts:
- name: oc-catalog
chart: oc-catalog
version: 0.1.0

View File

@@ -0,0 +1,100 @@
{
"apiVersion": "apps/v1",
"kind": "StatefulSet",
"metadata": {
"annotations": {
"meta.helm.sh/release-name": "oc-mongo",
"meta.helm.sh/release-namespace": "default"
},
"creationTimestamp": "2024-09-26T07:48:00Z",
"generation": 1,
"labels": {
"app": "mongo",
"app.kubernetes.io/managed-by": "Helm"
},
"name": "mongo",
"namespace": "default",
"resourceVersion": "13762492",
"uid": "9a354ea1-f91f-4b4e-9a8c-622dde93e448"
},
"spec": {
"persistentVolumeClaimRetentionPolicy": {
"whenDeleted": "Retain",
"whenScaled": "Retain"
},
"podManagementPolicy": "OrderedReady",
"replicas": 1,
"revisionHistoryLimit": 10,
"selector": {
"matchLabels": {
"app": "mongo"
}
},
"serviceName": "mongo",
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"app": "mongo"
}
},
"spec": {
"containers": [
{
"image": "harbor.dtf/mongo:v0.1.0",
"imagePullPolicy": "IfNotPresent",
"name": "mongo",
"ports": [
{
"containerPort": 27017,
"protocol": "TCP"
}
],
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"volumeMounts": [
{
"mountPath": "/data/db",
"name": "mongo-persistent-storage"
},
{
"mountPath": "/data/configdb",
"name": "mongo-persistent-storage"
}
]
}
],
"dnsPolicy": "ClusterFirst",
"restartPolicy": "Always",
"schedulerName": "default-scheduler",
"securityContext": {},
"terminationGracePeriodSeconds": 30,
"volumes": [
{
"name": "mongo-persistent-storage",
"persistentVolumeClaim": {
"claimName": "mongo-pvc-helm"
}
}
]
}
},
"updateStrategy": {
"rollingUpdate": {
"partition": 0
},
"type": "RollingUpdate"
}
},
"status": {
"availableReplicas": 0,
"collisionCount": 0,
"currentReplicas": 1,
"currentRevision": "mongo-7989cd65cb",
"observedGeneration": 1,
"replicas": 1,
"updateRevision": "mongo-7989cd65cb",
"updatedReplicas": 1
}
}