Compare commits
3 Commits
0c35993122
...
feat/bin
Author | SHA1 | Date | |
---|---|---|---|
009062c51a | |||
|
1b9b79c67f | ||
|
981ee7dce4 |
1
Makefile
1
Makefile
@@ -23,6 +23,7 @@ help:
|
||||
.PHONY: publish
|
||||
publish:
|
||||
@echo Publication de : ${OC_VERSION}
|
||||
@(cd src && make --quiet build VERSION=$(OC_VERSION))
|
||||
@(cd publish && \
|
||||
PUBLISH_REPO=${PUBLISH_REPO} \
|
||||
PUBLISH_TOKEN=${PUBLISH_TOKEN} \
|
||||
|
@@ -12,12 +12,12 @@ PLUGINS := $(wildcard ../plugins/*/*.go)
|
||||
OBJS := ${PLUGINS:.go=.so}
|
||||
|
||||
##################
|
||||
DATE := $(shell date)
|
||||
DATE := $(shell date --iso-8601)
|
||||
GOVERSION := $(shell go version)
|
||||
VERSION := $(shell git describe --tags --abbrev=8 --dirty --always --long)
|
||||
PREFIX := "oc-deploy/version"
|
||||
PREFIX := oc-deploy/occonst
|
||||
|
||||
LDFLAGS := -X '${PREFIX}.Version=${VERSION}'
|
||||
LDFLAGS := "-X '${PREFIX}.Version=${VERSION}' -X '${PREFIX}.Date=${DATE}' -X '${PREFIX}.GoVersion=${GOVERSION}'"
|
||||
|
||||
##################
|
||||
|
||||
@@ -49,7 +49,7 @@ help:
|
||||
@echo
|
||||
|
||||
${BIN_DIR}/${BIN_NAME}: ${SOURCES} $(OBJS)
|
||||
go build -o ${BIN_DIR}/${BIN_NAME} -ldflags "${LDFLAGS}"
|
||||
go build -o ${BIN_DIR}/${BIN_NAME} -ldflags ${LDFLAGS}
|
||||
|
||||
get-deps:
|
||||
@go mod tidy
|
||||
|
@@ -25,8 +25,13 @@ type repoData struct {
|
||||
Opts string `yaml:"opts"`
|
||||
}
|
||||
|
||||
type ociData struct {
|
||||
Url string `yaml:"url"`
|
||||
}
|
||||
|
||||
type ChartRepoData struct {
|
||||
Repository repoData `yaml:"repository"`
|
||||
Oci ociData `yaml:"oci"`
|
||||
Charts []ChartData `yaml:"charts"`
|
||||
}
|
||||
|
||||
|
@@ -39,7 +39,7 @@ func _TestReadConfChart(t *testing.T) {
|
||||
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")
|
||||
|
||||
assert.FileExists(t, src, "FromConfigFile error")
|
||||
@@ -48,3 +48,16 @@ func TestReadConfChartOverwrite(t *testing.T){
|
||||
// Nombre de lettres
|
||||
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")
|
||||
|
||||
}
|
||||
|
||||
|
@@ -39,7 +39,7 @@ func cobraUninstallCmd() *cobra.Command{
|
||||
Args: cobra.MaximumNArgs(0),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
log.Log().Info().Msg("oc-deploy :")
|
||||
return UninstallCmd(context)
|
||||
return UninstallCmd(context, modules)
|
||||
},
|
||||
Example: "oc-deploy uninstall --context ex1",
|
||||
}
|
||||
@@ -89,6 +89,7 @@ func Execute() {
|
||||
cmdInstall.Flags().StringArrayVarP(&modules, "modules", "m", []string{}, "modules, ...")
|
||||
|
||||
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(&version, "version", "v", "latest", "Version")
|
||||
|
@@ -2,19 +2,19 @@ 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 {
|
||||
func UninstallCmd(context string, modules []string) error {
|
||||
log.Log().Info().Msg("Uninstall >> ")
|
||||
|
||||
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}
|
||||
@@ -38,7 +38,7 @@ func UninstallCmd(context string) error {
|
||||
log.Log().Fatal().Msg(" >> " + err.Error())
|
||||
}
|
||||
|
||||
err = obj.UninstallCharts()
|
||||
err = obj.UninstallCharts(modules)
|
||||
if err != nil {
|
||||
log.Log().Fatal().Msg(" >> " + err.Error())
|
||||
}
|
||||
|
19
src/cmd/versionCmd.go
Normal file
19
src/cmd/versionCmd.go
Normal 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
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
log "oc-deploy/log_wrapper"
|
||||
)
|
||||
|
||||
func VersionCmd() error {
|
||||
|
||||
version := "0.1.0"
|
||||
log.Log().Debug().Msg(fmt.Sprintf("Version : %s", version))
|
||||
fmt.Println(version)
|
||||
|
||||
return nil
|
||||
}
|
@@ -102,7 +102,10 @@ func (this HelmCommand) ChartInstall(data HelmChart) (string, error) {
|
||||
|
||||
var objmap installOutput
|
||||
|
||||
err = json.Unmarshal(stdout, &objmap)
|
||||
i := strings.Index(string(stdout), "{")
|
||||
stdout2 := string(stdout)[i:]
|
||||
|
||||
err = json.Unmarshal([]byte(stdout2), &objmap)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -142,6 +145,7 @@ func (this HelmCommand) ChartUninstall(data HelmChart) (string, error) {
|
||||
|
||||
// ../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)
|
||||
|
@@ -8,10 +8,6 @@ import (
|
||||
log "oc-deploy/log_wrapper"
|
||||
)
|
||||
|
||||
// type HelmData struct {
|
||||
// Name string
|
||||
// }
|
||||
|
||||
func (this HelmCommand) Status(data HelmChart) (string, error) {
|
||||
|
||||
helm_bin := this.Bin
|
||||
|
@@ -60,7 +60,14 @@ func (this *InstallClass) InstallCharts(modules []string) (error) {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
for _, v := range this.charts {
|
||||
repoName := v.Repository.Name
|
||||
repoName := ""
|
||||
if v.Repository.Name != "" {
|
||||
repoName = v.Repository.Name
|
||||
} else {
|
||||
if v.Oci.Url != "" {
|
||||
repoName = v.Oci.Url
|
||||
}
|
||||
}
|
||||
|
||||
for _, v1 := range v.Charts {
|
||||
if len(modules) == 0 || utils.StringInSlice(v1.Name, modules) {
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"sync"
|
||||
|
||||
log "oc-deploy/log_wrapper"
|
||||
"oc-deploy/utils"
|
||||
"oc-deploy/versionOc"
|
||||
"oc-deploy/tool"
|
||||
"oc-deploy/chart"
|
||||
@@ -39,20 +40,23 @@ func (this *InstallClass) NewUninstall() (string, error) {
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
func (this *InstallClass) UninstallCharts() (error) {
|
||||
func (this *InstallClass) UninstallCharts(modules []string) (error) {
|
||||
helm_bin, _ := this.getToolBin("helm")
|
||||
kubectl_bin, _ := this.getToolBin("kubectl")
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
for _, v := range this.charts {
|
||||
for _, v1 := range v.Charts {
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
this.uninstallChart(helm_bin, kubectl_bin, v1)
|
||||
} ()
|
||||
for _, v1 := range v.Charts {
|
||||
if len(modules) == 0 || utils.StringInSlice(v1.Name, modules) {
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
this.uninstallChart(helm_bin, kubectl_bin, v1)
|
||||
} ()
|
||||
}
|
||||
}
|
||||
}
|
||||
wg.Wait()
|
||||
@@ -69,9 +73,6 @@ func (this *InstallClass) uninstallChart(helm_bin string, kubectl_bin string, ch
|
||||
|
||||
data := helm.HelmChart{Name: chart.Name}
|
||||
|
||||
// helmchart := helm.HelmChart{Bin: helm_bin,
|
||||
// Name: chart.Name}
|
||||
|
||||
res, err := helm_cmd.ChartUninstall(data)
|
||||
if err != nil {
|
||||
log.Log().Error().Msg(fmt.Sprintf(" >> %s %s (%s)", data.Name, "KO", err))
|
||||
|
@@ -34,7 +34,7 @@ func (this KubectlCommand) getDeployment(data KubectlObject) (map[string]any, er
|
||||
m["name"] = data.Name
|
||||
m["kind"] = kind
|
||||
m["replicas"] = status.Replicas
|
||||
m["UnavailableReplicas"] = status.UnavailableReplicas
|
||||
m["unavailableReplicas"] = status.UnavailableReplicas
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ type getOutput struct {
|
||||
type getStatusOutput struct {
|
||||
Replicas int `json:"replicas"`
|
||||
UnavailableReplicas int `json:"unavailableReplicas"`
|
||||
AvailableReplicas int `json:"availableReplicas"`
|
||||
}
|
||||
|
||||
func (this KubectlCommand) Get(data KubectlObject) (map[string]any, error) {
|
||||
@@ -43,7 +44,7 @@ func (this KubectlCommand) Wait(data KubectlObject) (error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ko := m["UnavailableReplicas"].(int)
|
||||
ko := m["unavailableReplicas"].(int)
|
||||
if ko == 0 {
|
||||
return nil
|
||||
}
|
||||
|
@@ -19,10 +19,26 @@ func TestKubectStatefulset(t *testing.T) {
|
||||
|
||||
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.Equal(t, "StatefulSet", res["kind"], "TestKubectDeployment error")
|
||||
assert.Equal(t, 1, res["replicas"], "TestKubectDeployment error")
|
||||
assert.Equal(t, "StatefulSet", res["kind"], "TestKubectStatefulset error")
|
||||
assert.Equal(t, 1, res["replicas"], "TestKubectStatefulset 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")
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package kubectl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"errors"
|
||||
"encoding/json"
|
||||
|
||||
log "oc-deploy/log_wrapper"
|
||||
@@ -11,32 +11,32 @@ import (
|
||||
|
||||
func (this KubectlCommand) getStatefulSet(data KubectlObject) (map[string]any, error) {
|
||||
|
||||
bin := this.Bin
|
||||
name := data.Name
|
||||
bin := this.Bin
|
||||
name := data.Name
|
||||
|
||||
msg := fmt.Sprintf("%s get statefulset %s -o json", bin, name)
|
||||
log.Log().Debug().Msg(msg)
|
||||
msg := fmt.Sprintf("%s get statefulset %s -o json", bin, name)
|
||||
log.Log().Debug().Msg(msg)
|
||||
|
||||
m := make(map[string]any)
|
||||
m := make(map[string]any)
|
||||
|
||||
cmd_args := strings.Split(msg, " ")
|
||||
cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return m, errors.New(string(stdout))
|
||||
}
|
||||
cmd_args := strings.Split(msg, " ")
|
||||
cmd := this.Exec(cmd_args[0], cmd_args[1:]...)
|
||||
stdout, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return m, errors.New(string(stdout))
|
||||
}
|
||||
|
||||
var objmap getOutput
|
||||
var objmap getOutput
|
||||
|
||||
json.Unmarshal(stdout, &objmap)
|
||||
json.Unmarshal(stdout, &objmap)
|
||||
|
||||
kind := objmap.Kind
|
||||
status := objmap.Status
|
||||
kind := objmap.Kind
|
||||
status := objmap.Status
|
||||
|
||||
m["name"] = name
|
||||
m["kind"] = kind
|
||||
m["replicas"] = status.Replicas
|
||||
m["UnavailableReplicas"] = status.UnavailableReplicas
|
||||
m["name"] = name
|
||||
m["kind"] = kind
|
||||
m["replicas"] = status.Replicas
|
||||
m["unavailableReplicas"] = status.Replicas - status.AvailableReplicas
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
@@ -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 Version = "dev"
|
||||
var Date = "now"
|
||||
var GoVersion = ""
|
||||
|
||||
func getenv(key string, defaut string) string {
|
||||
value := os.Getenv(key)
|
||||
if len(value) == 0 {
|
||||
|
9
test/chart/oc_oci.yml
Normal file
9
test/chart/oc_oci.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
|
||||
opencloud:
|
||||
- oci:
|
||||
url: oci://harbor.dtf/dev
|
||||
charts:
|
||||
- name: oc-catalog
|
||||
chart: oc-catalog
|
||||
version: 0.1.0
|
100
test/kubectl/mongo_pending.json
Normal file
100
test/kubectl/mongo_pending.json
Normal 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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user