Compare commits
14 Commits
ansible
...
53a614bd7e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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
|
||||||
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
|
||||||
5
src/.gitignore
vendored
Normal file
5
src/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
go.sum
|
||||||
|
*_
|
||||||
|
.coverage.*
|
||||||
|
.*.log
|
||||||
|
workspace_*
|
||||||
75
src/Makefile
Normal file
75
src/Makefile
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
|
||||||
|
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 ./... -coverprofile=.coverage.out -v
|
||||||
|
go tool cover -html=.coverage.out -o .coverage.html
|
||||||
75
src/README.md
Normal file
75
src/README.md
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
# Helm
|
||||||
|
|
||||||
|
[](https://github.com/helm/helm/actions?workflow=release)
|
||||||
|
[](https://goreportcard.com/report/github.com/helm/helm)
|
||||||
|
[](https://pkg.go.dev/helm.sh/helm/v3)
|
||||||
|
[](https://bestpractices.coreinfrastructure.org/projects/3131)
|
||||||
|
|
||||||
|
Helm is a tool for managing Charts. Charts are packages of pre-configured Kubernetes resources.
|
||||||
|
|
||||||
|
Use Helm to:
|
||||||
|
|
||||||
|
- Find and use [popular software packaged as Helm Charts](https://artifacthub.io/packages/search?kind=0) to run in Kubernetes
|
||||||
|
- Share your own applications as Helm Charts
|
||||||
|
- Create reproducible builds of your Kubernetes applications
|
||||||
|
- Intelligently manage your Kubernetes manifest files
|
||||||
|
- Manage releases of Helm packages
|
||||||
|
|
||||||
|
## Helm in a Handbasket
|
||||||
|
|
||||||
|
Helm is a tool that streamlines installing and managing Kubernetes applications.
|
||||||
|
Think of it like apt/yum/homebrew for Kubernetes.
|
||||||
|
|
||||||
|
- Helm renders your templates and communicates with the Kubernetes API
|
||||||
|
- Helm runs on your laptop, CI/CD, or wherever you want it to run.
|
||||||
|
- Charts are Helm packages that contain at least two things:
|
||||||
|
- A description of the package (`Chart.yaml`)
|
||||||
|
- One or more templates, which contain Kubernetes manifest files
|
||||||
|
- Charts can be stored on disk, or fetched from remote chart repositories
|
||||||
|
(like Debian or RedHat packages)
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
Binary downloads of the Helm client can be found on [the Releases page](https://github.com/helm/helm/releases/latest).
|
||||||
|
|
||||||
|
Unpack the `helm` binary and add it to your PATH and you are good to go!
|
||||||
|
|
||||||
|
If you want to use a package manager:
|
||||||
|
|
||||||
|
- [Homebrew](https://brew.sh/) users can use `brew install helm`.
|
||||||
|
- [Chocolatey](https://chocolatey.org/) users can use `choco install kubernetes-helm`.
|
||||||
|
- [Scoop](https://scoop.sh/) users can use `scoop install helm`.
|
||||||
|
- [Snapcraft](https://snapcraft.io/) users can use `snap install helm --classic`
|
||||||
|
|
||||||
|
To rapidly get Helm up and running, start with the [Quick Start Guide](https://helm.sh/docs/intro/quickstart/).
|
||||||
|
|
||||||
|
See the [installation guide](https://helm.sh/docs/intro/install/) for more options,
|
||||||
|
including installing pre-releases.
|
||||||
|
|
||||||
|
## Docs
|
||||||
|
|
||||||
|
Get started with the [Quick Start guide](https://helm.sh/docs/intro/quickstart/) or plunge into the [complete documentation](https://helm.sh/docs)
|
||||||
|
|
||||||
|
## Roadmap
|
||||||
|
|
||||||
|
The [Helm roadmap uses GitHub milestones](https://github.com/helm/helm/milestones) to track the progress of the project.
|
||||||
|
|
||||||
|
## Community, discussion, contribution, and support
|
||||||
|
|
||||||
|
You can reach the Helm community and developers via the following channels:
|
||||||
|
|
||||||
|
- [Kubernetes Slack](https://kubernetes.slack.com):
|
||||||
|
- [#helm-users](https://kubernetes.slack.com/messages/helm-users)
|
||||||
|
- [#helm-dev](https://kubernetes.slack.com/messages/helm-dev)
|
||||||
|
- [#charts](https://kubernetes.slack.com/messages/charts)
|
||||||
|
- Mailing List:
|
||||||
|
- [Helm Mailing List](https://lists.cncf.io/g/cncf-helm)
|
||||||
|
- Developer Call: Thursdays at 9:30-10:00 Pacific ([meeting details](https://github.com/helm/community/blob/master/communication.md#meetings))
|
||||||
|
|
||||||
|
### Contribution
|
||||||
|
|
||||||
|
If you're interested in contributing, please refer to the [Contributing Guide](CONTRIBUTING.md) **before submitting a pull request**.
|
||||||
|
|
||||||
|
### Code of conduct
|
||||||
|
|
||||||
|
Participation in the Helm community is governed by the [Code of Conduct](code-of-conduct.md).
|
||||||
42
src/chart/conf.go
Normal file
42
src/chart/conf.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
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 string `yaml:"helm_values"`
|
||||||
|
FileValues string `yaml:"helm_filevalues"`
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
39
src/chart/conf_test.go
Normal file
39
src/chart/conf_test.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package chart
|
||||||
|
|
||||||
|
// https://pkg.go.dev/github.com/stretchr/testify/assert
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
}
|
||||||
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)
|
||||||
|
}
|
||||||
73
src/cmd/args.go
Normal file
73
src/cmd/args.go
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
// 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 Execute() {
|
||||||
|
|
||||||
|
log.Log().Debug().Msg("Execute")
|
||||||
|
|
||||||
|
var rootCmd = &cobra.Command{Use: "oc-deploy"}
|
||||||
|
|
||||||
|
var cmdInstall = &cobra.Command{
|
||||||
|
Use: "install",
|
||||||
|
Short: "deploy",
|
||||||
|
Long: `deploy Charts`,
|
||||||
|
Args: cobra.MaximumNArgs(0),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
InstallCmd(context, version, modules)
|
||||||
|
},
|
||||||
|
Example: "oc-deploy install --version 1.0 --context ex1",
|
||||||
|
}
|
||||||
|
|
||||||
|
var cmdUninstall = &cobra.Command{
|
||||||
|
Use: "uninstall",
|
||||||
|
Short: "undeploy",
|
||||||
|
Long: `Undeploy`,
|
||||||
|
Args: cobra.MaximumNArgs(0),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
UninstallCmd(context)
|
||||||
|
},
|
||||||
|
Example: "oc-deploy uninstall --context ex1",
|
||||||
|
}
|
||||||
|
|
||||||
|
var cmdGenerate = &cobra.Command{
|
||||||
|
Use: "generate",
|
||||||
|
Short: "generate",
|
||||||
|
Long: "Value",
|
||||||
|
Args: cobra.MaximumNArgs(0),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
GenerateCmd(context, version)
|
||||||
|
},
|
||||||
|
Example: "oc-deploy generate --version 1.0 --context ex1",
|
||||||
|
}
|
||||||
|
|
||||||
|
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())
|
||||||
|
|
||||||
|
}
|
||||||
27
src/cmd/generateCmd.go
Normal file
27
src/cmd/generateCmd.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
|
||||||
|
"oc-deploy/versionOc"
|
||||||
|
"oc-deploy/generate"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GenerateCmd(project string, version string) {
|
||||||
|
log.Log().Info().Msg("Generate >> ")
|
||||||
|
|
||||||
|
version, err := versionOc.GetFromFile(version)
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Fatal().Msg("OpenCloud >> " + err.Error())
|
||||||
|
}
|
||||||
|
log.Log().Info().Msg(" >> Version : " + version)
|
||||||
|
|
||||||
|
obj := generate.GenerateClass{Workspace: "workspace_" + project, Version: version}
|
||||||
|
fic, err := obj.New()
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Fatal().Msg(" >> " + err.Error())
|
||||||
|
}
|
||||||
|
log.Log().Info().Msg(" >> Value : " + fic)
|
||||||
|
|
||||||
|
}
|
||||||
50
src/cmd/installCmd.go
Normal file
50
src/cmd/installCmd.go
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
|
||||||
|
"oc-deploy/install"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InstallCmd(context string, version string, modules []string) {
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
43
src/cmd/uninstallCmd.go
Normal file
43
src/cmd/uninstallCmd.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
// "strings"
|
||||||
|
// "github.com/spf13/cobra"
|
||||||
|
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
|
||||||
|
// "oc-deploy/versionOc"
|
||||||
|
"oc-deploy/install"
|
||||||
|
)
|
||||||
|
|
||||||
|
func UninstallCmd(context string) {
|
||||||
|
log.Log().Info().Msg("Unnstall >> ")
|
||||||
|
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/generate/generate.go
Normal file
22
src/generate/generate.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package generate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"oc-deploy/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GenerateClass struct {
|
||||||
|
Version string
|
||||||
|
Workspace string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this GenerateClass) New() (string, error) {
|
||||||
|
src := fmt.Sprintf("../offline/default_value_%s.yml", this.Version)
|
||||||
|
dst := fmt.Sprintf("%s/default_value.yml", this.Workspace)
|
||||||
|
|
||||||
|
err := utils.CopyFile(src, dst)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return src, nil
|
||||||
|
}
|
||||||
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
|
||||||
|
)
|
||||||
159
src/helm/chart.go
Normal file
159
src/helm/chart.go
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
package helm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"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 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 HelmChart) Install() (string, error) {
|
||||||
|
bin := this.Bin
|
||||||
|
|
||||||
|
existe, err := this.exists()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if existe {
|
||||||
|
return "Existe déjà", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ficChart := this.Chart
|
||||||
|
// Recherche locale
|
||||||
|
if _, err := os.Stat(ficChart); err != nil {
|
||||||
|
} else {
|
||||||
|
// Recherche voa le Workspace
|
||||||
|
ficChart := filepath.Join(this.Workspace, this.Chart)
|
||||||
|
if _, err := os.Stat(ficChart); err == nil {
|
||||||
|
} else {
|
||||||
|
if this.Url != "" {
|
||||||
|
fmt.Println("============ 52 Télechargement", this.Url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := fmt.Sprintf("%s install %s %s %s --output json", bin, this.Name, ficChart, this.Opts)
|
||||||
|
|
||||||
|
if this.Version != "" {
|
||||||
|
msg = fmt.Sprintf("%s --version %s", msg, this.Version)
|
||||||
|
}
|
||||||
|
|
||||||
|
if this.FileValues != "" {
|
||||||
|
fic := filepath.Join(this.Workspace, this.FileValues)
|
||||||
|
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 := exec.Command(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 HelmChart) Uninstall() (string, error) {
|
||||||
|
bin := this.Bin
|
||||||
|
|
||||||
|
log.Log().Info().Msg(" >> Chart : " + this.Name)
|
||||||
|
|
||||||
|
existe, err := this.exists()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if ! existe {
|
||||||
|
return "Non présent", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := fmt.Sprintf("%s uninstall %s", bin, this.Name)
|
||||||
|
log.Log().Debug().Msg(msg)
|
||||||
|
|
||||||
|
cmd := exec.Command(bin, "uninstall", this.Name)
|
||||||
|
stdout, err := cmd.CombinedOutput()
|
||||||
|
|
||||||
|
return string(stdout), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ../bin/helm list --filter phpmyadminm --short
|
||||||
|
func (this HelmChart) exists() (bool, error) {
|
||||||
|
bin := this.Bin
|
||||||
|
|
||||||
|
msg := fmt.Sprintf("%s list --filter %s --no-headers", bin, this.Name)
|
||||||
|
log.Log().Debug().Msg(msg)
|
||||||
|
|
||||||
|
cmd_args := strings.Split(msg, " ")
|
||||||
|
|
||||||
|
cmd := exec.Command(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
|
||||||
|
}
|
||||||
16
src/helm/command.go
Normal file
16
src/helm/command.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package helm
|
||||||
|
|
||||||
|
import (
|
||||||
|
)
|
||||||
|
|
||||||
|
type HelmCommandInterface interface {
|
||||||
|
Status(string) (string, error)
|
||||||
|
AddRepository(HelmRepo) (string, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type HelmCommandData struct {
|
||||||
|
Bin string
|
||||||
|
}
|
||||||
|
|
||||||
|
type RealHelmCommand HelmCommandData
|
||||||
|
|
||||||
24
src/helm/main_test.go
Normal file
24
src/helm/main_test.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package helm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
var TEST_DEST_DIR = "../wrk_helm"
|
||||||
|
var TEST_SRC_DIR = filepath.Join("../../test", "helm")
|
||||||
|
var TEST_BIN_DIR = filepath.Join("../../test", "bin")
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
96
src/helm/repo.go
Normal file
96
src/helm/repo.go
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
package helm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"os/exec"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
"oc-deploy/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HelmRepo struct {
|
||||||
|
Name string
|
||||||
|
Repository string // Url du dépôt
|
||||||
|
ForceUpdate bool
|
||||||
|
Opts string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this RealHelmCommand) AddRepository(repo HelmRepo) (string, error) {
|
||||||
|
|
||||||
|
helm_bin := this.Bin
|
||||||
|
|
||||||
|
force_update := "--force-update=false"
|
||||||
|
if repo.ForceUpdate {
|
||||||
|
force_update = "--force-update=true"
|
||||||
|
} else {
|
||||||
|
list, _ := this.ListRepository()
|
||||||
|
if utils.StringInSlice(repo.Name, list) {
|
||||||
|
return "Existe déjà", nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := fmt.Sprintf("%s repo add %s %s %s %s", helm_bin, repo.Name, repo.Repository, force_update, repo.Opts)
|
||||||
|
log.Log().Debug().Msg(msg)
|
||||||
|
|
||||||
|
cmd_args := strings.Split(msg, " ")
|
||||||
|
|
||||||
|
cmd := exec.Command(cmd_args[0], cmd_args[1:]...)
|
||||||
|
stdout, err := cmd.CombinedOutput()
|
||||||
|
|
||||||
|
res := string(stdout)
|
||||||
|
res = strings.TrimSuffix(res, "\n")
|
||||||
|
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
type parseList struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this RealHelmCommand) ListRepository() ([]string, error) {
|
||||||
|
|
||||||
|
helm_bin := this.Bin
|
||||||
|
res := make([]string, 0, 0)
|
||||||
|
|
||||||
|
msg := fmt.Sprintf("%s repo list -o json", helm_bin)
|
||||||
|
log.Log().Debug().Msg(msg)
|
||||||
|
|
||||||
|
cmd_args := strings.Split(msg, " ")
|
||||||
|
|
||||||
|
cmd := exec.Command(cmd_args[0], cmd_args[1:]...)
|
||||||
|
stdout, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var objmap []parseList
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(stdout), &objmap)
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ele := range objmap {
|
||||||
|
res = append(res, ele.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// helm repo remove [NAME]
|
||||||
|
func (this RealHelmCommand) RemoveRepository(repo HelmRepo) (string, error) {
|
||||||
|
helm_bin := this.Bin
|
||||||
|
|
||||||
|
msg := fmt.Sprintf("%s repo remove %s", helm_bin, repo.Name)
|
||||||
|
log.Log().Debug().Msg(msg)
|
||||||
|
|
||||||
|
cmd := exec.Command(helm_bin, "repo", "remove", repo.Name)
|
||||||
|
stdout, err := cmd.CombinedOutput()
|
||||||
|
|
||||||
|
res := string(stdout)
|
||||||
|
res = strings.TrimSuffix(res, "\n")
|
||||||
|
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
39
src/helm/repo_test.go
Normal file
39
src/helm/repo_test.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package helm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
// "os"
|
||||||
|
// "path/filepath"
|
||||||
|
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHelmRepoAdd(t *testing.T) {
|
||||||
|
|
||||||
|
repo := HelmRepo{
|
||||||
|
Bin: "./helm",
|
||||||
|
Name: "repooc",
|
||||||
|
Repository: "https://url",
|
||||||
|
ForceUpdate: true,
|
||||||
|
Opts: ""}
|
||||||
|
fmt.Println(" TestHelmRepoAdd ", repo)
|
||||||
|
|
||||||
|
res, err := repo.AddRepository()
|
||||||
|
fmt.Println("TestHelmRepoAdd.24", res, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// helm : not found
|
||||||
|
func TestHelmRepoAddErr(t *testing.T) {
|
||||||
|
|
||||||
|
repo := HelmRepo{
|
||||||
|
Bin: "./helm",
|
||||||
|
Name: "repooc",
|
||||||
|
Repository: "https://url",
|
||||||
|
ForceUpdate: true,
|
||||||
|
Opts: ""}
|
||||||
|
|
||||||
|
_, err := repo.AddRepository()
|
||||||
|
assert.NotNilf(t, err, "error message %s", "./helm")
|
||||||
|
}
|
||||||
84
src/helm/ressources.go
Normal file
84
src/helm/ressources.go
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
package helm
|
||||||
|
|
||||||
|
import (
|
||||||
|
// "fmt"
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HelmStatus struct {
|
||||||
|
Name string // Nom
|
||||||
|
command HelmCommandInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *HelmStatus) New(bin string) {
|
||||||
|
this.command = RealHelmCommand{Bin: bin}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *HelmStatus) NewMock(mock HelmCommandInterface) {
|
||||||
|
this.command = mock
|
||||||
|
}
|
||||||
|
|
||||||
|
////
|
||||||
|
|
||||||
|
type parseStatusInfoResourcesMetadata struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// type parseStatusInfoResourcesPod struct {
|
||||||
|
// Api string `json:"apiVersion"`
|
||||||
|
// }
|
||||||
|
|
||||||
|
type parseStatusInfoResourcesStatefulSet struct {
|
||||||
|
Api string `json:"apiVersion"`
|
||||||
|
Kind string `json:"kind"`
|
||||||
|
Metadata parseStatusInfoResourcesMetadata `json:"metadata"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type parseStatusInfoResourcesDeployment struct {
|
||||||
|
Api string `json:"apiVersion"`
|
||||||
|
Kind string `json:"kind"`
|
||||||
|
Metadata parseStatusInfoResourcesMetadata `json:"metadata"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type parseStatusInfoResources struct {
|
||||||
|
// Pod []parseStatusInfoResourcesPod `json:"v1/Pod(related)"`
|
||||||
|
StatefulSet []parseStatusInfoResourcesStatefulSet `json:"v1/StatefulSet"`
|
||||||
|
Deployment []parseStatusInfoResourcesDeployment `json:"v1/Deployment"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type parseStatusInfo struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Resources parseStatusInfoResources `json:"Resources"`
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type parseStatus struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Info parseStatusInfo `json:"info"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this HelmStatus) getRessources() (map[string]string, error) {
|
||||||
|
|
||||||
|
res := make(map[string]string)
|
||||||
|
|
||||||
|
status, err := this.command.Status(this.Name)
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var objmap parseStatus
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(status), &objmap)
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ele := range objmap.Info.Resources.StatefulSet {
|
||||||
|
res[ele.Metadata.Name] = ele.Kind
|
||||||
|
}
|
||||||
|
for _, ele := range objmap.Info.Resources.Deployment {
|
||||||
|
res[ele.Metadata.Name] = ele.Kind
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
28
src/helm/ressources_test.go
Normal file
28
src/helm/ressources_test.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package helm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MockCommandStatus HelmCommandData
|
||||||
|
|
||||||
|
func TestHelmStatus(t *testing.T){
|
||||||
|
|
||||||
|
hs := HelmStatus{Name: "oc-catalog"}
|
||||||
|
hs.NewMock(MockCommandStatus{})
|
||||||
|
|
||||||
|
data, _ := hs.getRessources()
|
||||||
|
assert.Equal(t, "StatefulSet", data["oc-catalog-oc-catalog"], "TestHelmStatus error")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mock
|
||||||
|
func (this MockCommandStatus) Status(name string) (string, error) {
|
||||||
|
fileName := filepath.Join(TEST_SRC_DIR, "helm_status.json")
|
||||||
|
data, _ := os.ReadFile(fileName)
|
||||||
|
return string(data), nil
|
||||||
|
}
|
||||||
30
src/helm/status.go
Normal file
30
src/helm/status.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package helm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"errors"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (this RealHelmCommand) Status(name string) (string, error) {
|
||||||
|
|
||||||
|
helm_bin := this.Bin
|
||||||
|
|
||||||
|
msg := fmt.Sprintf("%s status %s --show-resources -o json", helm_bin, name)
|
||||||
|
log.Log().Debug().Msg(msg)
|
||||||
|
|
||||||
|
cmd_args := strings.Split(msg, " ")
|
||||||
|
|
||||||
|
cmd := exec.Command(cmd_args[0], cmd_args[1:]...)
|
||||||
|
stdout, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Debug().Msg(string(stdout))
|
||||||
|
return "", errors.New(string(stdout))
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(stdout), nil
|
||||||
|
}
|
||||||
|
|
||||||
20
src/helm/version.go
Normal file
20
src/helm/version.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package helm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Version(path string) (string, error) {
|
||||||
|
|
||||||
|
cmd := exec.Command(path, "version", "--short")
|
||||||
|
stdout, err := cmd.CombinedOutput()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
res := string(stdout)
|
||||||
|
res = strings.TrimSuffix(res, "\n")
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
22
src/helm/version_test.go
Normal file
22
src/helm/version_test.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package helm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHelmVersion(t *testing.T){
|
||||||
|
|
||||||
|
bin := filepath.Join(TEST_BIN_DIR, "helm")
|
||||||
|
os.Chmod(bin, 0700)
|
||||||
|
assert.FileExists(t, bin, "TestHelmVersion error")
|
||||||
|
|
||||||
|
version, err := Version(bin)
|
||||||
|
|
||||||
|
assert.Nilf(t, err, "error message %s", bin)
|
||||||
|
assert.Equal(t, "v3.15.4+gfa9efb0", version, "TestHelmVersion error")
|
||||||
|
}
|
||||||
103
src/install/common.go
Normal file
103
src/install/common.go
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
package install
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
"oc-deploy/tool"
|
||||||
|
"oc-deploy/kubectl"
|
||||||
|
"oc-deploy/helm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (this *InstallClass) Tools() (error) {
|
||||||
|
|
||||||
|
var mem []tool.ToolClass
|
||||||
|
|
||||||
|
for _, v := range this.tools {
|
||||||
|
|
||||||
|
tool2 := tool.ToolClass{}
|
||||||
|
v.Bin = this.Workspace
|
||||||
|
err := tool2.New(v)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
mem = append(mem,tool2)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.toolsBin = make(map[string]string)
|
||||||
|
|
||||||
|
for _, p := range mem {
|
||||||
|
data := p.Obj.Get()
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" >> Outils : %s", data.Name))
|
||||||
|
err := p.Locate()
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << %s ", err))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << %s ", p.Path))
|
||||||
|
version, err1 := p.Version()
|
||||||
|
if err1 != nil {
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << %s ", err1))
|
||||||
|
return err1
|
||||||
|
}
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << %s ", version))
|
||||||
|
|
||||||
|
this.toolsBin[data.Name] = p.Path
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *InstallClass) SetCommands() {
|
||||||
|
helm_bin, _ := this.getToolBin("helm")
|
||||||
|
this.commandHelm = helm.RealHelmCommand{Bin: helm_bin}
|
||||||
|
|
||||||
|
// kubectl_bin, _ := this.getToolBin("kubectl")
|
||||||
|
// this.commandKubectl = helm.RealHelmCommand{Bin: kubectl_bin}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *InstallClass) SetCommandsMock(mock helm.HelmCommandInterface) {
|
||||||
|
this.commandHelm = mock
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *InstallClass) getToolBin(name string) (string, error) {
|
||||||
|
for key, value := range this.toolsBin {
|
||||||
|
if key == name {
|
||||||
|
return value, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", errors.New("Error")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *InstallClass) K8s(context string) (error) {
|
||||||
|
bin_path, _ := this.getToolBin("kubectl")
|
||||||
|
|
||||||
|
kube := kubectl.KubeContext{Bin: bin_path}
|
||||||
|
|
||||||
|
err := kube.UseContext(context)
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << Kube : %s ", err))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
currentcontext, namespace, server, err := kube.GetContext()
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << Kube : %s ", err))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << Kube : %s ", currentcontext))
|
||||||
|
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << : %s ", namespace))
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << : %s ", server))
|
||||||
|
|
||||||
|
err = kube.Check()
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << : %s ", err))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << : %s ", "OK"))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
162
src/install/install.go
Normal file
162
src/install/install.go
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
package install
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
"oc-deploy/utils"
|
||||||
|
"oc-deploy/tool"
|
||||||
|
"oc-deploy/chart"
|
||||||
|
"oc-deploy/helm"
|
||||||
|
"oc-deploy/kubectl"
|
||||||
|
"oc-deploy/versionOc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type InstallClass struct {
|
||||||
|
Version string
|
||||||
|
Workspace string
|
||||||
|
|
||||||
|
tools []tool.ToolData
|
||||||
|
toolsBin map[string]string
|
||||||
|
charts []chart.ChartRepoData
|
||||||
|
|
||||||
|
commandHelm helm.HelmCommandInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *InstallClass) NewInstall() (string, error) {
|
||||||
|
|
||||||
|
// Extraction du fichier de version
|
||||||
|
dst := fmt.Sprintf("%s/oc.yml", this.Workspace)
|
||||||
|
log.Log().Debug().Msg(fmt.Sprintf("Check du fichier de version : %s", dst))
|
||||||
|
if _, err := os.Stat(dst); err == nil {
|
||||||
|
log.Log().Debug().Msg("Existe déjà")
|
||||||
|
version, err := versionOc.GetFromFile(dst)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
this.Version = version
|
||||||
|
} else {
|
||||||
|
log.Log().Debug().Msg("Téléchargement du fichier de version")
|
||||||
|
// version, fileversion, err := versionOc.Get(this.Version)
|
||||||
|
version, fileversion, err := versionOc.GetFromOnline(this.Version)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
this.Version = version
|
||||||
|
|
||||||
|
err = utils.CopyContentFile(fileversion, dst)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lecture du fichier de conf
|
||||||
|
var err error
|
||||||
|
this.tools, err = tool.FromConfigFile(dst)
|
||||||
|
if err != nil {
|
||||||
|
return dst, err
|
||||||
|
}
|
||||||
|
this.charts, _ = chart.FromConfigFile(dst)
|
||||||
|
if err != nil {
|
||||||
|
return dst, err
|
||||||
|
}
|
||||||
|
|
||||||
|
bin_path, _ := this.getToolBin("helm")
|
||||||
|
fmt.Println("Install 67 bin_path", bin_path)
|
||||||
|
|
||||||
|
return dst, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (this *InstallClass) ChartRepo() (error) {
|
||||||
|
|
||||||
|
for _, v := range this.charts {
|
||||||
|
if v.Repository.Name != "" {
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" >> Helm Repo : %s", v.Repository.Name))
|
||||||
|
repo := helm.HelmRepo{Name: v.Repository.Name,
|
||||||
|
Repository: v.Repository.Url,
|
||||||
|
ForceUpdate: v.Repository.ForceUpdate}
|
||||||
|
res, err := this.commandHelm.AddRepository(repo)
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << %s ", err))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << %s ", res))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (this *InstallClass) InstallCharts(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 {
|
||||||
|
if len(modules) == 0 || stringInSlice(v1.Name, modules) {
|
||||||
|
wg.Add(1)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
this.installChart(helm_bin, kubectl_bin, v1)
|
||||||
|
} ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func stringInSlice(a string, list []string) bool {
|
||||||
|
for _, b := range list {
|
||||||
|
if b == a {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (this *InstallClass) installChart(helm_bin string, kubectl_bin string, chart chart.ChartData) {
|
||||||
|
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << Chart : %s ", chart.Name))
|
||||||
|
|
||||||
|
helmchart := helm.HelmChart{Bin: helm_bin,
|
||||||
|
Name: chart.Name,
|
||||||
|
Chart: chart.Chart,
|
||||||
|
Url: chart.Url,
|
||||||
|
Version: chart.Version,
|
||||||
|
Workspace: this.Workspace,
|
||||||
|
Opts: chart.Opts,
|
||||||
|
Values: chart.Values,
|
||||||
|
FileValues: chart.FileValues}
|
||||||
|
|
||||||
|
|
||||||
|
res, err := helmchart.Install()
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Error().Msg(fmt.Sprintf(" >> %s %s (%s)", helmchart.Name, "KO", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" >> %s (%s)", helmchart.Name, res))
|
||||||
|
|
||||||
|
ressources, _ := helmchart.GetRessources()
|
||||||
|
|
||||||
|
for key, value := range ressources {
|
||||||
|
obj := kubectl.KubeObject{Bin: kubectl_bin,
|
||||||
|
Kind: value,
|
||||||
|
Name: key}
|
||||||
|
err := obj.Wait()
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Error().Msg(fmt.Sprintf(" >> %s/%s KO (%s)", chart.Name, key, err))
|
||||||
|
} else {
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" >> %s/%s OK", chart.Name, key))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
75
src/install/uninstall.go
Normal file
75
src/install/uninstall.go
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
package install
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
"oc-deploy/versionOc"
|
||||||
|
"oc-deploy/tool"
|
||||||
|
"oc-deploy/chart"
|
||||||
|
"oc-deploy/helm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (this *InstallClass) NewUninstall() (string, error) {
|
||||||
|
dst := fmt.Sprintf("%s/oc.yml", this.Workspace)
|
||||||
|
|
||||||
|
if _, err := os.Stat(dst); err != nil {
|
||||||
|
return dst, err
|
||||||
|
}
|
||||||
|
|
||||||
|
version, err := versionOc.GetFromFile(dst)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Version = version
|
||||||
|
|
||||||
|
// Lecture du fichier de conf
|
||||||
|
this.tools, err = tool.FromConfigFile(dst)
|
||||||
|
if err != nil {
|
||||||
|
return dst, err
|
||||||
|
}
|
||||||
|
this.charts, _ = chart.FromConfigFile(dst)
|
||||||
|
if err != nil {
|
||||||
|
return dst, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return dst, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *InstallClass) UninstallCharts() (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)
|
||||||
|
} ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *InstallClass) uninstallChart(helm_bin string, kubectl_bin string, chart chart.ChartData) {
|
||||||
|
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" << Chart : %s ", chart.Name))
|
||||||
|
|
||||||
|
helmchart := helm.HelmChart{Bin: helm_bin,
|
||||||
|
Name: chart.Name}
|
||||||
|
|
||||||
|
res, err := helmchart.Uninstall()
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Error().Msg(fmt.Sprintf(" >> %s %s (%s)", helmchart.Name, "KO", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" >> %s (%s)", helmchart.Name, res))
|
||||||
|
}
|
||||||
29
src/kubectl/command.go
Normal file
29
src/kubectl/command.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package kubectl
|
||||||
|
|
||||||
|
// import (
|
||||||
|
// "fmt"
|
||||||
|
// )
|
||||||
|
|
||||||
|
// type KubectlCommandInterface interface {
|
||||||
|
// // GetDeployment() (string, error)
|
||||||
|
// GetDeployment() (string, error)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// type KubectlCommandData struct {
|
||||||
|
// bin string
|
||||||
|
// command string
|
||||||
|
// }
|
||||||
|
|
||||||
|
// type Real KubectlCommandStatus KubectlCommandData
|
||||||
|
|
||||||
|
// // func (this KubectlCommandStatus) Status() (string, error) {
|
||||||
|
// // fmt.Println("BIN ", this.bin)
|
||||||
|
// // fmt.Println("COMMAND status")
|
||||||
|
// // return "Res de KubectlCommandStatus", nil
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// func (this KubectlCommandStatus) GetDeployment() (string, error) {
|
||||||
|
// fmt.Println("BIN ", this.bin)
|
||||||
|
// fmt.Println("COMMAND status")
|
||||||
|
// return "Res de GetDeployment", nil
|
||||||
|
// }
|
||||||
111
src/kubectl/context.go
Normal file
111
src/kubectl/context.go
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
package kubectl
|
||||||
|
|
||||||
|
import (
|
||||||
|
// "fmt"
|
||||||
|
"strings"
|
||||||
|
"errors"
|
||||||
|
"os/exec"
|
||||||
|
"encoding/json"
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
)
|
||||||
|
|
||||||
|
type KubeContext struct {
|
||||||
|
Bin string // Chemin vers le binaire
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type kubeConfig struct {
|
||||||
|
CurrentContext string `json:"current-context"`
|
||||||
|
Contexts [] kubeConfigContexts `json:"contexts"`
|
||||||
|
Clusters [] kubeConfigClusters `json:"clusters"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type kubeConfigContexts struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Context kubeConfigContext `json:"context"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type kubeConfigContext struct {
|
||||||
|
Cluster string `json:"cluster"`
|
||||||
|
User string `json:"user"`
|
||||||
|
Namespace string `json:"namespace"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type kubeConfigCluster struct {
|
||||||
|
Server string `json:"server"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type kubeConfigClusters struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Cluster kubeConfigCluster `json:"cluster"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this KubeContext) GetCurrentContext() (string, error) {
|
||||||
|
|
||||||
|
cmd := exec.Command(this.Bin, "config", "current-context")
|
||||||
|
stdout, err := cmd.CombinedOutput()
|
||||||
|
|
||||||
|
res := string(stdout)
|
||||||
|
res = strings.TrimSuffix(res, "\n")
|
||||||
|
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Current Context
|
||||||
|
// namespace, server
|
||||||
|
func (this KubeContext) GetContext() (string, string, string, error) {
|
||||||
|
|
||||||
|
cmd := exec.Command(this.Bin, "config", "view", "-o", "json")
|
||||||
|
stdout, _ := cmd.CombinedOutput()
|
||||||
|
|
||||||
|
var objmap kubeConfig
|
||||||
|
|
||||||
|
err := json.Unmarshal(stdout, &objmap)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", "", err
|
||||||
|
}
|
||||||
|
currentContext := objmap.CurrentContext
|
||||||
|
|
||||||
|
currentCluster := ""
|
||||||
|
currentNamespace := ""
|
||||||
|
for _, v := range objmap.Contexts {
|
||||||
|
if v.Name == currentContext {
|
||||||
|
currentNamespace = v.Context.Namespace
|
||||||
|
currentCluster = v.Context.Cluster
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentServer := ""
|
||||||
|
for _, v := range objmap.Clusters {
|
||||||
|
if v.Name == currentCluster {
|
||||||
|
currentServer = v.Cluster.Server
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentContext, currentNamespace, currentServer, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this KubeContext) UseContext(newContext string) (error) {
|
||||||
|
|
||||||
|
cmd := exec.Command(this.Bin, "config", "use-context", newContext)
|
||||||
|
stdout, err := cmd.CombinedOutput()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Debug().Msg(string(stdout))
|
||||||
|
return errors.New(string(stdout))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this KubeContext) Check() (error) {
|
||||||
|
|
||||||
|
cmd := exec.Command(this.Bin, "cluster-info")
|
||||||
|
stdout, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Debug().Msg(string(stdout))
|
||||||
|
return errors.New("Kube non disponible")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
24
src/kubectl/main_test.go
Normal file
24
src/kubectl/main_test.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package kubectl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
var TEST_DEST_DIR = "../wrk_kubectl"
|
||||||
|
var TEST_SRC_DIR = filepath.Join("../../test", "kubectl")
|
||||||
|
var TEST_BIN_DIR = filepath.Join("../../test", "bin")
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
122
src/kubectl/object.go
Normal file
122
src/kubectl/object.go
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
package kubectl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"errors"
|
||||||
|
"time"
|
||||||
|
"os/exec"
|
||||||
|
"encoding/json"
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
)
|
||||||
|
|
||||||
|
type KubeObject struct {
|
||||||
|
Bin string // Chemin vers le binaire
|
||||||
|
Name string
|
||||||
|
Kind string
|
||||||
|
}
|
||||||
|
|
||||||
|
type getOutput struct {
|
||||||
|
Kind string `json:"kind"`
|
||||||
|
Status getStatusOutput `json:"status"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type getStatusOutput struct {
|
||||||
|
Replicas int `json:"replicas"`
|
||||||
|
UnavailableReplicas int `json:"unavailableReplicas"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this KubeObject) Get() (map[string]any, error) {
|
||||||
|
if this.Kind == "Deployment" {return this.getDeployment()}
|
||||||
|
if this.Kind == "StatefulSet" {return this.getStatefulSet()}
|
||||||
|
return make(map[string]any), fmt.Errorf("Kind %s inconnu", this.Kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this KubeObject) getDeployment() (map[string]any, error) {
|
||||||
|
bin := this.Bin
|
||||||
|
name := this.Name
|
||||||
|
|
||||||
|
msg := fmt.Sprintf("%s get deployment %s -o json", bin, name)
|
||||||
|
log.Log().Debug().Msg(msg)
|
||||||
|
|
||||||
|
m := make(map[string]any)
|
||||||
|
|
||||||
|
cmd_args := strings.Split(msg, " ")
|
||||||
|
|
||||||
|
cmd := exec.Command(cmd_args[0], cmd_args[1:]...)
|
||||||
|
stdout, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return m, errors.New(string(stdout))
|
||||||
|
}
|
||||||
|
|
||||||
|
var objmap getOutput
|
||||||
|
|
||||||
|
json.Unmarshal(stdout, &objmap)
|
||||||
|
|
||||||
|
kind := objmap.Kind
|
||||||
|
status := objmap.Status
|
||||||
|
|
||||||
|
m["name"] = name
|
||||||
|
m["kind"] = kind
|
||||||
|
m["replicas"] = status.Replicas
|
||||||
|
m["UnavailableReplicas"] = status.UnavailableReplicas
|
||||||
|
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this KubeObject) getStatefulSet() (map[string]any, error) {
|
||||||
|
bin := this.Bin
|
||||||
|
name := this.Name
|
||||||
|
|
||||||
|
msg := fmt.Sprintf("%s get statefulset %s -o json", bin, name)
|
||||||
|
log.Log().Debug().Msg(msg)
|
||||||
|
|
||||||
|
m := make(map[string]any)
|
||||||
|
|
||||||
|
cmd_args := strings.Split(msg, " ")
|
||||||
|
|
||||||
|
cmd := exec.Command(cmd_args[0], cmd_args[1:]...)
|
||||||
|
stdout, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return m, errors.New(string(stdout))
|
||||||
|
}
|
||||||
|
|
||||||
|
var objmap getOutput
|
||||||
|
|
||||||
|
json.Unmarshal(stdout, &objmap)
|
||||||
|
|
||||||
|
kind := objmap.Kind
|
||||||
|
status := objmap.Status
|
||||||
|
|
||||||
|
m["name"] = name
|
||||||
|
m["kind"] = kind
|
||||||
|
m["replicas"] = status.Replicas
|
||||||
|
m["UnavailableReplicas"] = status.UnavailableReplicas
|
||||||
|
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this KubeObject) Wait() (error) {
|
||||||
|
|
||||||
|
boucle := 10
|
||||||
|
sleep := 10000 * time.Millisecond
|
||||||
|
|
||||||
|
for _ = range boucle {
|
||||||
|
|
||||||
|
log.Log().Debug().Msg(fmt.Sprintf("Check Deployement %s", this.Name))
|
||||||
|
|
||||||
|
m, err := this.Get()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ko := m["UnavailableReplicas"].(int)
|
||||||
|
if ko == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Log().Info().Msg(fmt.Sprintf(" >> %s (Unavailable : %d)...", this.Name, ko))
|
||||||
|
time.Sleep(sleep)
|
||||||
|
|
||||||
|
}
|
||||||
|
return errors.New("Temps d'attente dépassé")
|
||||||
|
}
|
||||||
31
src/kubectl/version.go
Normal file
31
src/kubectl/version.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package kubectl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
type toolClientVersion struct {
|
||||||
|
GitVersion string `json:"gitVersion"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type toolVersion struct {
|
||||||
|
ClientVersion toolClientVersion `json:"clientVersion"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func Version(path string) (string, error) {
|
||||||
|
|
||||||
|
cmd := exec.Command(path, "version", "-o", "json", "--client=true")
|
||||||
|
stdout, err := cmd.CombinedOutput()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
var objmap toolVersion
|
||||||
|
|
||||||
|
json.Unmarshal(stdout, &objmap)
|
||||||
|
res := objmap.ClientVersion.GitVersion
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
22
src/kubectl/version_test.go
Normal file
22
src/kubectl/version_test.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package kubectl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestKubectlVersion(t *testing.T){
|
||||||
|
|
||||||
|
bin := filepath.Join(TEST_BIN_DIR, "kubectl")
|
||||||
|
os.Chmod(bin, 0700)
|
||||||
|
assert.FileExists(t, bin, "TestKubectlVersion error")
|
||||||
|
|
||||||
|
version, err := Version(bin)
|
||||||
|
|
||||||
|
assert.Nilf(t, err, "error message %s", bin)
|
||||||
|
assert.Equal(t, "v1.30.3", version, "TestKubectlVersion error")
|
||||||
|
}
|
||||||
48
src/log_wrapper/log_wrapper.go
Normal file
48
src/log_wrapper/log_wrapper.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package log_wrapper
|
||||||
|
|
||||||
|
// https://github.com/rs/zerolog/issues/150
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
)
|
||||||
|
|
||||||
|
var mainLogVar zerolog.Logger
|
||||||
|
|
||||||
|
type FilteredWriter struct {
|
||||||
|
w zerolog.LevelWriter
|
||||||
|
level zerolog.Level
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *FilteredWriter) Write(p []byte) (n int, err error) {
|
||||||
|
return w.w.Write(p)
|
||||||
|
}
|
||||||
|
func (w *FilteredWriter) WriteLevel(level zerolog.Level, p []byte) (n int, err error) {
|
||||||
|
if level == w.level {
|
||||||
|
return w.w.WriteLevel(level, p)
|
||||||
|
}
|
||||||
|
return len(p), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Log() *zerolog.Logger {
|
||||||
|
return &mainLogVar
|
||||||
|
}
|
||||||
|
|
||||||
|
func InitLog(serverName string) bool {
|
||||||
|
|
||||||
|
fAll, _ := os.OpenFile("./" + serverName + ".log", os.O_APPEND|os.O_CREATE|os.O_RDWR, 0644)
|
||||||
|
output := zerolog.ConsoleWriter{Out: os.Stdout}
|
||||||
|
|
||||||
|
writerInfo := zerolog.MultiLevelWriter(output)
|
||||||
|
writerError := zerolog.MultiLevelWriter(output)
|
||||||
|
writerFatal := zerolog.MultiLevelWriter(output)
|
||||||
|
filteredWriteInfo := &FilteredWriter{writerInfo, zerolog.InfoLevel}
|
||||||
|
filteredWriterError := &FilteredWriter{writerError, zerolog.ErrorLevel}
|
||||||
|
filteredWriterFatal := &FilteredWriter{writerFatal, zerolog.FatalLevel}
|
||||||
|
|
||||||
|
w := zerolog.MultiLevelWriter(fAll, filteredWriteInfo, filteredWriterError, filteredWriterFatal)
|
||||||
|
|
||||||
|
mainLogVar = zerolog.New(w).With().Timestamp().Logger()
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
19
src/main.go
Normal file
19
src/main.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"oc-deploy/cmd"
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
log.InitLog(".oc-deploy")
|
||||||
|
|
||||||
|
log.Log().Debug().Msg("Start")
|
||||||
|
log.Log().Info().Msg("oc-deploy :")
|
||||||
|
|
||||||
|
cmd.Execute()
|
||||||
|
|
||||||
|
log.Log().Debug().Msg("End")
|
||||||
|
|
||||||
|
}
|
||||||
6
src/occonst/variables.go
Normal file
6
src/occonst/variables.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package occonst
|
||||||
|
|
||||||
|
const ONLINE_URL = "https://cloud.o-forge.io"
|
||||||
|
const ONLINE_VERSION = "core/oc-deploy"
|
||||||
|
|
||||||
|
var OFFLINE_DIR = "../../offline"
|
||||||
21
src/tool/conf.go
Normal file
21
src/tool/conf.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package tool
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type toolsData struct {
|
||||||
|
Tools []ToolData `yaml:"tools"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lecture de la liste des outils
|
||||||
|
func FromConfigFile(filename string) ([]ToolData, error) {
|
||||||
|
yamlFile, _ := os.ReadFile(filename)
|
||||||
|
var data toolsData
|
||||||
|
err := yaml.Unmarshal(yamlFile, &data)
|
||||||
|
if err != nil {
|
||||||
|
return data.Tools, nil
|
||||||
|
}
|
||||||
|
return data.Tools, nil
|
||||||
|
}
|
||||||
21
src/tool/conf_test.go
Normal file
21
src/tool/conf_test.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package tool
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
// "os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestToolConf(t *testing.T) {
|
||||||
|
|
||||||
|
src := filepath.Join(TEST_SRC_DIR, "oc.yml")
|
||||||
|
|
||||||
|
data, err := FromConfigFile(src)
|
||||||
|
fmt.Println("data", src, data, err)
|
||||||
|
assert.Equal(t, "kubectl", data[0].Name, "TestToolConf error")
|
||||||
|
assert.Nilf(t, err, "error message %s", src)
|
||||||
|
}
|
||||||
53
src/tool/helm.go
Normal file
53
src/tool/helm.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package tool
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"oc-deploy/utils"
|
||||||
|
"oc-deploy/helm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HelmInstallData struct {
|
||||||
|
obj ToolData
|
||||||
|
tmp string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this HelmInstallData) Get() (ToolData) {
|
||||||
|
return this.obj
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this HelmInstallData) Download() (error) {
|
||||||
|
|
||||||
|
bin_dir := this.obj.Bin
|
||||||
|
err2 := os.MkdirAll(bin_dir, os.ModePerm)
|
||||||
|
if err2 != nil {
|
||||||
|
return err2
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp_file := fmt.Sprintf("%s/oc-deploy-%s", this.tmp, this.obj.Name)
|
||||||
|
url := fmt.Sprintf(this.obj.Url, this.obj.Version)
|
||||||
|
|
||||||
|
err := utils.DownloadFromUrl(tmp_file, url, 0777)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
r, _ := os.Open(tmp_file)
|
||||||
|
err1 := utils.ExtractTarGz(bin_dir, r)
|
||||||
|
if err1 != nil {return err1}
|
||||||
|
|
||||||
|
os.Remove(tmp_file)
|
||||||
|
|
||||||
|
bin_file := fmt.Sprintf("%s/%s", bin_dir, this.obj.Name)
|
||||||
|
|
||||||
|
errChmod := os.Chmod(bin_file, 0755)
|
||||||
|
if errChmod != nil {return errChmod}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////
|
||||||
|
func (this HelmInstallData) Version(path string) (string, error) {
|
||||||
|
return helm.Version(path)
|
||||||
|
}
|
||||||
1
src/tool/helm_test.go
Normal file
1
src/tool/helm_test.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package tool
|
||||||
41
src/tool/kubectl.go
Normal file
41
src/tool/kubectl.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package tool
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
"oc-deploy/utils"
|
||||||
|
"oc-deploy/kubectl"
|
||||||
|
)
|
||||||
|
|
||||||
|
type KubecltInstallData struct {
|
||||||
|
obj ToolData
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this KubecltInstallData) Get() (ToolData) {
|
||||||
|
return this.obj
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this KubecltInstallData) Download() (error) {
|
||||||
|
|
||||||
|
bin_dir := this.obj.Bin
|
||||||
|
bin := filepath.Join(bin_dir, this.obj.Name)
|
||||||
|
url := fmt.Sprintf(this.obj.Url, this.obj.Version)
|
||||||
|
|
||||||
|
log.Log().Debug().Msg(fmt.Sprintf("Téléchargement : %s, %s", bin, url))
|
||||||
|
os.MkdirAll(bin_dir, os.ModePerm)
|
||||||
|
|
||||||
|
err := utils.DownloadFromUrl(bin, url, 0777)
|
||||||
|
if err != nil {return err}
|
||||||
|
|
||||||
|
os.Chmod(bin, 0755)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////
|
||||||
|
func (this KubecltInstallData) Version(path string) (string, error) {
|
||||||
|
return kubectl.Version(path)
|
||||||
|
}
|
||||||
24
src/tool/main_test.go
Normal file
24
src/tool/main_test.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package tool
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
var TEST_DEST_DIR = "../wrk_tool"
|
||||||
|
var TEST_SRC_DIR = filepath.Join("../../test", "tool")
|
||||||
|
var TEST_BIN_DIR = filepath.Join("../../test", "bin")
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
79
src/tool/tool.go
Normal file
79
src/tool/tool.go
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
package tool
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ToolData struct {
|
||||||
|
Name string `yaml:"name"`
|
||||||
|
Url string `yaml:"url"`
|
||||||
|
Version string `yaml:"version"`
|
||||||
|
Bin string
|
||||||
|
}
|
||||||
|
|
||||||
|
type ToolClass struct {
|
||||||
|
Obj Forme
|
||||||
|
Path string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Forme interface {
|
||||||
|
Download() error
|
||||||
|
Version(string) (string, error)
|
||||||
|
Get() ToolData
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////
|
||||||
|
func (this *ToolClass) New(data ToolData) (error) {
|
||||||
|
f, err := factory(data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
this.Obj = f
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ToolClass) Locate() (error) {
|
||||||
|
|
||||||
|
obj := this.Obj
|
||||||
|
data := obj.Get()
|
||||||
|
path := filepath.Join(data.Bin, data.Name)
|
||||||
|
|
||||||
|
if _, err := os.Stat(path); err != nil {
|
||||||
|
path2, _ := exec.LookPath(data.Name)
|
||||||
|
if path2 != "" {
|
||||||
|
path = path2
|
||||||
|
} else {
|
||||||
|
err = obj.Download()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Path = path
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ToolClass) Version() (string, error) {
|
||||||
|
obj := (this.Obj)
|
||||||
|
return obj.Version(this.Path)
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////
|
||||||
|
func factory(data ToolData) (Forme, error) {
|
||||||
|
var f Forme
|
||||||
|
|
||||||
|
switch data.Name {
|
||||||
|
case "kubectl":
|
||||||
|
f = KubecltInstallData{obj: data}
|
||||||
|
case "helm":
|
||||||
|
f = HelmInstallData{obj: data, tmp: "/tmp"}
|
||||||
|
default:
|
||||||
|
return f, fmt.Errorf("Outil Inconnu : %s", data.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
return f, nil
|
||||||
|
}
|
||||||
53
src/utils/copyFile.go
Normal file
53
src/utils/copyFile.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"io"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CopyFile(src string, dst string) (error) {
|
||||||
|
|
||||||
|
if _, err := os.Stat(src); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fin, errOpen := os.Open(src)
|
||||||
|
if errOpen != nil {
|
||||||
|
return errOpen
|
||||||
|
}
|
||||||
|
defer fin.Close()
|
||||||
|
|
||||||
|
folderPath := filepath.Dir(dst)
|
||||||
|
os.MkdirAll(folderPath, os.ModePerm)
|
||||||
|
|
||||||
|
fout, errCreate := os.Create(dst)
|
||||||
|
if errCreate != nil {
|
||||||
|
return errCreate
|
||||||
|
}
|
||||||
|
defer fout.Close()
|
||||||
|
|
||||||
|
_, errCopy := io.Copy(fout, fin)
|
||||||
|
if errCopy != nil {
|
||||||
|
return errCopy
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CopyContentFile(content string, dst string) (error) {
|
||||||
|
|
||||||
|
folderPath := filepath.Dir(dst)
|
||||||
|
os.MkdirAll(folderPath, os.ModePerm)
|
||||||
|
|
||||||
|
fout, errCreate := os.Create(dst)
|
||||||
|
if errCreate != nil {
|
||||||
|
return errCreate
|
||||||
|
}
|
||||||
|
defer fout.Close()
|
||||||
|
|
||||||
|
_, errCopy := fout.WriteString(content)
|
||||||
|
if errCopy != nil {
|
||||||
|
return errCopy
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
57
src/utils/copyFile_test.go
Normal file
57
src/utils/copyFile_test.go
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
// https://pkg.go.dev/github.com/stretchr/testify/assert#Nilf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"path/filepath"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCopyFileExist(t *testing.T) {
|
||||||
|
src := filepath.Join(TEST_SRC_DIR, "fichier1")
|
||||||
|
dest := filepath.Join(TEST_DEST_DIR, "fichier1")
|
||||||
|
|
||||||
|
err := CopyFile(src, dest)
|
||||||
|
|
||||||
|
assert.Nilf(t, err, "error message %s", src)
|
||||||
|
assert.FileExists(t, dest, "CopyFile error")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCopyErrSrcFileNotExist(t *testing.T) {
|
||||||
|
src := filepath.Join(TEST_SRC_DIR, "inconnu")
|
||||||
|
dest := filepath.Join(TEST_DEST_DIR, "inconnu")
|
||||||
|
|
||||||
|
err := CopyFile(src, dest)
|
||||||
|
|
||||||
|
assert.NotNilf(t, err, "CopyFile error %s", src)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCopyFileErrCreate(t *testing.T){
|
||||||
|
src := filepath.Join(TEST_SRC_DIR, "fichier1")
|
||||||
|
dest := filepath.Join("/INCONNU", "fichier1")
|
||||||
|
|
||||||
|
err := CopyFile(src, dest)
|
||||||
|
|
||||||
|
assert.NotNilf(t, err, "error message %s", src)
|
||||||
|
assert.NoFileExists(t, dest, "CopyFile error")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCopyErrSrcWrite(t *testing.T) {
|
||||||
|
src := "/"
|
||||||
|
dest := filepath.Join(TEST_DEST_DIR, "inconnu")
|
||||||
|
|
||||||
|
err := CopyFile(src, dest)
|
||||||
|
|
||||||
|
assert.NotNilf(t, err, "CopyFile error %s", src)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCopyContentFile(t *testing.T) {
|
||||||
|
content := "TestCopyContentFileExist"
|
||||||
|
dest := filepath.Join(TEST_DEST_DIR, "fichier1")
|
||||||
|
|
||||||
|
err := CopyContentFile(content, dest)
|
||||||
|
|
||||||
|
assert.Nilf(t, err, "error message")
|
||||||
|
assert.FileExists(t, dest, "CopyFile error")
|
||||||
|
}
|
||||||
72
src/utils/download.go
Normal file
72
src/utils/download.go
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
// "fmt"
|
||||||
|
"os"
|
||||||
|
"io"
|
||||||
|
"path"
|
||||||
|
"net/http"
|
||||||
|
"archive/tar"
|
||||||
|
"compress/gzip"
|
||||||
|
)
|
||||||
|
|
||||||
|
func DownloadFromUrl(dest string, url string, chmod os.FileMode) error {
|
||||||
|
|
||||||
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
out, err := os.Create(dest)
|
||||||
|
defer out.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = io.Copy(out, resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
os.Chmod(dest, chmod)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func ExtractTarGz(dest string, gzipStream io.Reader) error {
|
||||||
|
uncompressedStream, err := gzip.NewReader(gzipStream)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
tarReader := tar.NewReader(uncompressedStream)
|
||||||
|
|
||||||
|
for {
|
||||||
|
header, err := tarReader.Next()
|
||||||
|
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
switch header.Typeflag {
|
||||||
|
case tar.TypeDir:
|
||||||
|
// if err := os.Mkdir(dest + "/" + header.Name, 0755); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
case tar.TypeReg:
|
||||||
|
outName := dest + "/" + path.Base( header.Name)
|
||||||
|
outFile, _ := os.Create(outName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := io.Copy(outFile, tarReader); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
outFile.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
28
src/utils/download_test.go
Normal file
28
src/utils/download_test.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
// https://pkg.go.dev/github.com/stretchr/testify/assert#Nilf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/jarcoal/httpmock"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDownload(t *testing.T) {
|
||||||
|
httpmock.Activate()
|
||||||
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
|
url := "http://test.download.com"
|
||||||
|
|
||||||
|
httpmock.RegisterResponder("GET", url,
|
||||||
|
httpmock.NewStringResponder(200, `CONTENU_URL`))
|
||||||
|
|
||||||
|
dest := filepath.Join(TEST_DEST_DIR, "url")
|
||||||
|
|
||||||
|
err := DownloadFromUrl(dest, url, 777)
|
||||||
|
assert.Nilf(t, err, "error message %s", url)
|
||||||
|
assert.FileExists(t, dest, "DownloadFromUrl error")
|
||||||
|
}
|
||||||
23
src/utils/main_test.go
Normal file
23
src/utils/main_test.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
var TEST_DEST_DIR = "../wrk_utils"
|
||||||
|
var TEST_SRC_DIR = filepath.Join("../../test", "utils")
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
10
src/utils/slice.go
Normal file
10
src/utils/slice.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
func StringInSlice(a string, list []string) bool {
|
||||||
|
for _, b := range list {
|
||||||
|
if b == a {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
23
src/versionOc/main_test.go
Normal file
23
src/versionOc/main_test.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package versionOc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
var TEST_DEST_DIR = "../wrk_versionOc"
|
||||||
|
var TEST_SRC_DIR = filepath.Join("../../test", "versionOc")
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
71
src/versionOc/offline.go
Normal file
71
src/versionOc/offline.go
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
// Package :
|
||||||
|
package versionOc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"path/filepath"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
"oc-deploy/occonst"
|
||||||
|
)
|
||||||
|
|
||||||
|
type versionInput struct {
|
||||||
|
Version string `yaml:"version"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get : Retourne la version
|
||||||
|
func GetFromOffline(version string) (string, string, error) {
|
||||||
|
|
||||||
|
version2 := version
|
||||||
|
if version == "latest" {
|
||||||
|
versionLatest, err := readLatestFromOffline()
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
version2 = versionLatest
|
||||||
|
}
|
||||||
|
|
||||||
|
ficversion := fmt.Sprintf("oc_%s.yml", version2)
|
||||||
|
src := filepath.Join(occonst.OFFLINE_DIR, ficversion)
|
||||||
|
if _, err := os.Stat(src); err != nil {
|
||||||
|
log.Log().Debug().Msg(err.Error())
|
||||||
|
return "", "", errors.New("Version non disponible")
|
||||||
|
}
|
||||||
|
|
||||||
|
fin, err := os.Open(src)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
defer fin.Close()
|
||||||
|
byteValue, err := io.ReadAll(fin)
|
||||||
|
|
||||||
|
return version2, string(byteValue), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// readLatestFile : Lit le numéro de la version dans le fichier lastest.yml
|
||||||
|
func readLatestFromOffline() (string, error) {
|
||||||
|
src := filepath.Join(occonst.OFFLINE_DIR, "latest.yml")
|
||||||
|
|
||||||
|
fin, err := os.Open(src)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer fin.Close()
|
||||||
|
|
||||||
|
byteValue, err := io.ReadAll(fin)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
var objmap versionInput
|
||||||
|
|
||||||
|
err = yaml.Unmarshal(byteValue, &objmap)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return objmap.Version, nil
|
||||||
|
}
|
||||||
27
src/versionOc/offline_test.go
Normal file
27
src/versionOc/offline_test.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package versionOc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"oc-deploy/occonst"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetOffline(t *testing.T) {
|
||||||
|
|
||||||
|
_, _, err := GetFromOffline("99.1")
|
||||||
|
assert.NotNilf(t, err, "error message %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetLatest(t *testing.T) {
|
||||||
|
|
||||||
|
occonst.OFFLINE_DIR = filepath.Join(TEST_SRC_DIR, "offline")
|
||||||
|
|
||||||
|
version, _, err := GetFromOffline("latest")
|
||||||
|
assert.Nilf(t, err, "error message %s", err)
|
||||||
|
assert.Equal(t, "99.1", version, "TestGetFromFile error")
|
||||||
|
|
||||||
|
}
|
||||||
104
src/versionOc/online.go
Normal file
104
src/versionOc/online.go
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
package versionOc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"errors"
|
||||||
|
"net/http"
|
||||||
|
"encoding/json"
|
||||||
|
"encoding/base64"
|
||||||
|
|
||||||
|
"oc-deploy/occonst"
|
||||||
|
log "oc-deploy/log_wrapper"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func GetFromOnline(version string) (string, string, error) {
|
||||||
|
|
||||||
|
version2 := version
|
||||||
|
if version == "latest" {
|
||||||
|
versionLatest, err := readLatestFromOnline()
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
version2 = versionLatest
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err := getFileVersion(version2)
|
||||||
|
if err != nil {
|
||||||
|
log.Log().Debug().Msg(err.Error())
|
||||||
|
return "", "", errors.New("Version non disponible")
|
||||||
|
}
|
||||||
|
|
||||||
|
return version2, content, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type releaseStruct struct {
|
||||||
|
Id int `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ocJsonStruct struct {
|
||||||
|
Value string `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cherche dans Online la dernière version (non draft, non pre-releases)
|
||||||
|
func readLatestFromOnline() (string, error) {
|
||||||
|
|
||||||
|
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/latest",
|
||||||
|
occonst.ONLINE_URL,
|
||||||
|
occonst.ONLINE_VERSION)
|
||||||
|
|
||||||
|
res, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
body, err := io.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
var data releaseStruct
|
||||||
|
|
||||||
|
err = json.Unmarshal(body, &data)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.Name, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Récupère le fichier version de la version
|
||||||
|
func getFileVersion(version string) (string, error) {
|
||||||
|
|
||||||
|
url := fmt.Sprintf("%s/%s/releases/download/%s/oc.json",
|
||||||
|
occonst.ONLINE_URL,
|
||||||
|
occonst.ONLINE_VERSION,
|
||||||
|
version)
|
||||||
|
|
||||||
|
res, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
body, err := io.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if string(body) == "Not Found\n" {
|
||||||
|
return "", fmt.Errorf("Not found %s", version)
|
||||||
|
}
|
||||||
|
|
||||||
|
var data ocJsonStruct
|
||||||
|
err = json.Unmarshal(body, &data)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
data64, err64 := base64.StdEncoding.DecodeString(data.Value)
|
||||||
|
if err64 != nil {
|
||||||
|
return "", err64
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(data64), nil
|
||||||
|
}
|
||||||
62
src/versionOc/online_test.go
Normal file
62
src/versionOc/online_test.go
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package versionOc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
// "encoding/base64"
|
||||||
|
|
||||||
|
"oc-deploy/occonst"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/jarcoal/httpmock"
|
||||||
|
)
|
||||||
|
|
||||||
|
//
|
||||||
|
func TestGetOnline(t *testing.T) {
|
||||||
|
|
||||||
|
httpmock.Activate()
|
||||||
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
|
version := "99.1"
|
||||||
|
url := fmt.Sprintf("%s/%s/releases/download/%s/oc.json",
|
||||||
|
occonst.ONLINE_URL,
|
||||||
|
occonst.ONLINE_VERSION,
|
||||||
|
version)
|
||||||
|
|
||||||
|
httpmock.RegisterResponder("GET", url,
|
||||||
|
httpmock.NewStringResponder(200, `{"value": "e30K"}`))
|
||||||
|
|
||||||
|
res, _, err := GetFromOnline(version)
|
||||||
|
assert.Nilf(t, err, "error message %s", err)
|
||||||
|
assert.Equal(t, version, res, "TestGetOnline error")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetOnlineLatest(t *testing.T) {
|
||||||
|
|
||||||
|
httpmock.Activate()
|
||||||
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
|
// version := "99.1"
|
||||||
|
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/latest",
|
||||||
|
occonst.ONLINE_URL,
|
||||||
|
occonst.ONLINE_VERSION)
|
||||||
|
|
||||||
|
httpmock.RegisterResponder("GET", url,
|
||||||
|
httpmock.NewStringResponder(200, `{"name": "99.0", "id": 2}`))
|
||||||
|
|
||||||
|
version := "99.0"
|
||||||
|
url2 := fmt.Sprintf("%s/%s/releases/download/%s/oc.json",
|
||||||
|
occonst.ONLINE_URL,
|
||||||
|
occonst.ONLINE_VERSION,
|
||||||
|
version)
|
||||||
|
|
||||||
|
httpmock.RegisterResponder("GET", url2,
|
||||||
|
httpmock.NewStringResponder(200, `{"value": "e30K"}`))
|
||||||
|
|
||||||
|
|
||||||
|
version, _, err := GetFromOnline("latest")
|
||||||
|
assert.Nilf(t, err, "error message %s", err)
|
||||||
|
assert.Equal(t, "99.0", version, "TestGetFromFile error")
|
||||||
|
fmt.Println("TestGetOnlineLatest ", version, err)
|
||||||
|
|
||||||
|
}
|
||||||
30
src/versionOc/versionOc.go
Normal file
30
src/versionOc/versionOc.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
// Package :
|
||||||
|
package versionOc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"io"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetFromFile(fileversion string) (string, error) {
|
||||||
|
fin, err := os.Open(fileversion)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer fin.Close()
|
||||||
|
|
||||||
|
byteValue, err := io.ReadAll(fin)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
var objmap versionInput
|
||||||
|
|
||||||
|
err = yaml.Unmarshal(byteValue, &objmap)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return objmap.Version, nil
|
||||||
|
}
|
||||||
34
src/versionOc/versionOc_test.go
Normal file
34
src/versionOc/versionOc_test.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package versionOc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetFromFile(t *testing.T) {
|
||||||
|
|
||||||
|
ocyaml := filepath.Join(TEST_SRC_DIR, "oc.yml")
|
||||||
|
version, err := GetFromFile(ocyaml)
|
||||||
|
|
||||||
|
assert.Nilf(t, err, "error message %s", ocyaml)
|
||||||
|
assert.Equal(t, "99.0", version, "TestGetFromFile error")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetFromFileErr(t *testing.T) {
|
||||||
|
|
||||||
|
ocyaml := filepath.Join(TEST_SRC_DIR, "inconnu.yml")
|
||||||
|
_, err := GetFromFile(ocyaml)
|
||||||
|
|
||||||
|
assert.NotNilf(t, err, "error message %s", ocyaml)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetFromFileErr2(t *testing.T) {
|
||||||
|
|
||||||
|
ocyaml := filepath.Join(TEST_SRC_DIR, "oc_error.yml")
|
||||||
|
_, err := GetFromFile(ocyaml)
|
||||||
|
|
||||||
|
assert.NotNilf(t, err, "error message %s", ocyaml)
|
||||||
|
}
|
||||||
BIN
test/bin/helm
Executable file
BIN
test/bin/helm
Executable file
Binary file not shown.
BIN
test/bin/kubectl
Executable file
BIN
test/bin/kubectl
Executable file
Binary file not shown.
21
test/chart/oc.yml
Normal file
21
test/chart/oc.yml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
opencloud:
|
||||||
|
- repository:
|
||||||
|
name: bitnami
|
||||||
|
url: https://charts.bitnami.com/bitnami # Repository des Charts
|
||||||
|
charts:
|
||||||
|
- name: wordpress
|
||||||
|
chart: bitnami/wordpress
|
||||||
|
version: 23.1.0
|
||||||
|
values: {}
|
||||||
|
|
||||||
|
- name: phpmyadmin
|
||||||
|
chart: bitnami/phpmyadmin
|
||||||
|
version: 17.0.4
|
||||||
|
values: {}
|
||||||
|
|
||||||
|
- charts:
|
||||||
|
- name: myfirstrelease
|
||||||
|
chart: myfirstchart-0.1.0.tgz
|
||||||
|
url: https://zzzz/myfirstchart-0.1.0.tgz
|
||||||
663
test/helm/helm_status.json
Normal file
663
test/helm/helm_status.json
Normal file
@@ -0,0 +1,663 @@
|
|||||||
|
{
|
||||||
|
"name": "oc-catalog",
|
||||||
|
"info": {
|
||||||
|
"first_deployed": "2024-09-05T19:06:44.16497388+02:00",
|
||||||
|
"last_deployed": "2024-09-05T19:06:44.16497388+02:00",
|
||||||
|
"deleted": "",
|
||||||
|
"description": "Install complete",
|
||||||
|
"status": "deployed",
|
||||||
|
"resources": {
|
||||||
|
"v1/Pod(related)": [
|
||||||
|
{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"kind": "Pod",
|
||||||
|
"metadata": {
|
||||||
|
"annotations": {
|
||||||
|
"cni.projectcalico.org/containerID": "bc524c3ff4a2fceaeb9a996a9324807c0fddfc4c3e02cd59d73a9945d27d5f1b",
|
||||||
|
"cni.projectcalico.org/podIP": "10.42.2.10/32",
|
||||||
|
"cni.projectcalico.org/podIPs": "10.42.2.10/32"
|
||||||
|
},
|
||||||
|
"creationTimestamp": "2024-09-05T17:06:44Z",
|
||||||
|
"generateName": "oc-catalog-oc-catalog-",
|
||||||
|
"labels": {
|
||||||
|
"app": "oc-catalog",
|
||||||
|
"apps.kubernetes.io/pod-index": "0",
|
||||||
|
"controller-revision-hash": "oc-catalog-oc-catalog-7d7859dd76",
|
||||||
|
"statefulset.kubernetes.io/pod-name": "oc-catalog-oc-catalog-0"
|
||||||
|
},
|
||||||
|
"managedFields": [
|
||||||
|
{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"fieldsType": "FieldsV1",
|
||||||
|
"fieldsV1": {
|
||||||
|
"f:metadata": {
|
||||||
|
"f:annotations": {
|
||||||
|
".": {},
|
||||||
|
"f:cni.projectcalico.org/containerID": {},
|
||||||
|
"f:cni.projectcalico.org/podIP": {},
|
||||||
|
"f:cni.projectcalico.org/podIPs": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"manager": "calico",
|
||||||
|
"operation": "Update",
|
||||||
|
"subresource": "status",
|
||||||
|
"time": "2024-09-05T17:06:44Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"fieldsType": "FieldsV1",
|
||||||
|
"fieldsV1": {
|
||||||
|
"f:metadata": {
|
||||||
|
"f:generateName": {},
|
||||||
|
"f:labels": {
|
||||||
|
".": {},
|
||||||
|
"f:app": {},
|
||||||
|
"f:apps.kubernetes.io/pod-index": {},
|
||||||
|
"f:controller-revision-hash": {},
|
||||||
|
"f:statefulset.kubernetes.io/pod-name": {}
|
||||||
|
},
|
||||||
|
"f:ownerReferences": {
|
||||||
|
".": {},
|
||||||
|
"k:{\"uid\":\"10aa222e-dc37-451e-a5ee-e88f88b4e136\"}": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"f:spec": {
|
||||||
|
"f:containers": {
|
||||||
|
"k:{\"name\":\"oc-catalog\"}": {
|
||||||
|
".": {},
|
||||||
|
"f:env": {
|
||||||
|
".": {},
|
||||||
|
"k:{\"name\":\"MONGO_DATABASE\"}": {
|
||||||
|
".": {},
|
||||||
|
"f:name": {},
|
||||||
|
"f:value": {}
|
||||||
|
},
|
||||||
|
"k:{\"name\":\"MONGO_URI\"}": {
|
||||||
|
".": {},
|
||||||
|
"f:name": {},
|
||||||
|
"f:value": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"f:image": {},
|
||||||
|
"f:imagePullPolicy": {},
|
||||||
|
"f:name": {},
|
||||||
|
"f:ports": {
|
||||||
|
".": {},
|
||||||
|
"k:{\"containerPort\":8080,\"protocol\":\"TCP\"}": {
|
||||||
|
".": {},
|
||||||
|
"f:containerPort": {},
|
||||||
|
"f:protocol": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"f:resources": {},
|
||||||
|
"f:terminationMessagePath": {},
|
||||||
|
"f:terminationMessagePolicy": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"f:dnsPolicy": {},
|
||||||
|
"f:enableServiceLinks": {},
|
||||||
|
"f:hostname": {},
|
||||||
|
"f:imagePullSecrets": {
|
||||||
|
".": {},
|
||||||
|
"k:{\"name\":\"regcred\"}": {}
|
||||||
|
},
|
||||||
|
"f:restartPolicy": {},
|
||||||
|
"f:schedulerName": {},
|
||||||
|
"f:securityContext": {},
|
||||||
|
"f:subdomain": {},
|
||||||
|
"f:terminationGracePeriodSeconds": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"manager": "kube-controller-manager",
|
||||||
|
"operation": "Update",
|
||||||
|
"time": "2024-09-05T17:06:44Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"fieldsType": "FieldsV1",
|
||||||
|
"fieldsV1": {
|
||||||
|
"f:status": {
|
||||||
|
"f:conditions": {
|
||||||
|
"k:{\"type\":\"ContainersReady\"}": {
|
||||||
|
".": {},
|
||||||
|
"f:lastProbeTime": {},
|
||||||
|
"f:lastTransitionTime": {},
|
||||||
|
"f:status": {},
|
||||||
|
"f:type": {}
|
||||||
|
},
|
||||||
|
"k:{\"type\":\"Initialized\"}": {
|
||||||
|
".": {},
|
||||||
|
"f:lastProbeTime": {},
|
||||||
|
"f:lastTransitionTime": {},
|
||||||
|
"f:status": {},
|
||||||
|
"f:type": {}
|
||||||
|
},
|
||||||
|
"k:{\"type\":\"Ready\"}": {
|
||||||
|
".": {},
|
||||||
|
"f:lastProbeTime": {},
|
||||||
|
"f:lastTransitionTime": {},
|
||||||
|
"f:status": {},
|
||||||
|
"f:type": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"f:containerStatuses": {},
|
||||||
|
"f:hostIP": {},
|
||||||
|
"f:phase": {},
|
||||||
|
"f:podIP": {},
|
||||||
|
"f:podIPs": {
|
||||||
|
".": {},
|
||||||
|
"k:{\"ip\":\"10.42.2.10\"}": {
|
||||||
|
".": {},
|
||||||
|
"f:ip": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"f:startTime": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"manager": "kubelet",
|
||||||
|
"operation": "Update",
|
||||||
|
"subresource": "status",
|
||||||
|
"time": "2024-09-05T17:06:46Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "oc-catalog-oc-catalog-0",
|
||||||
|
"namespace": "default",
|
||||||
|
"ownerReferences": [
|
||||||
|
{
|
||||||
|
"apiVersion": "apps/v1",
|
||||||
|
"blockOwnerDeletion": true,
|
||||||
|
"controller": true,
|
||||||
|
"kind": "StatefulSet",
|
||||||
|
"name": "oc-catalog-oc-catalog",
|
||||||
|
"uid": "10aa222e-dc37-451e-a5ee-e88f88b4e136"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"resourceVersion": "7811984",
|
||||||
|
"uid": "f2b3e7d0-68de-4f60-a8b7-75446ee3ebf1"
|
||||||
|
},
|
||||||
|
"spec": {
|
||||||
|
"containers": [
|
||||||
|
{
|
||||||
|
"env": [
|
||||||
|
{
|
||||||
|
"name": "MONGO_DATABASE",
|
||||||
|
"value": "DC_myDC"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "MONGO_URI",
|
||||||
|
"value": "mongodb://mongo:27017"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"image": "harbor.dtf/dev/oc-catalog:1.0",
|
||||||
|
"imagePullPolicy": "IfNotPresent",
|
||||||
|
"name": "oc-catalog",
|
||||||
|
"ports": [
|
||||||
|
{
|
||||||
|
"containerPort": 8080,
|
||||||
|
"protocol": "TCP"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"resources": {},
|
||||||
|
"terminationMessagePath": "/dev/termination-log",
|
||||||
|
"terminationMessagePolicy": "File",
|
||||||
|
"volumeMounts": [
|
||||||
|
{
|
||||||
|
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount",
|
||||||
|
"name": "kube-api-access-lpks6",
|
||||||
|
"readOnly": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dnsPolicy": "ClusterFirst",
|
||||||
|
"enableServiceLinks": true,
|
||||||
|
"hostname": "oc-catalog-oc-catalog-0",
|
||||||
|
"imagePullSecrets": [
|
||||||
|
{
|
||||||
|
"name": "regcred"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nodeName": "rke2-worker1",
|
||||||
|
"preemptionPolicy": "PreemptLowerPriority",
|
||||||
|
"priority": 0,
|
||||||
|
"restartPolicy": "Always",
|
||||||
|
"schedulerName": "default-scheduler",
|
||||||
|
"securityContext": {},
|
||||||
|
"serviceAccount": "default",
|
||||||
|
"serviceAccountName": "default",
|
||||||
|
"subdomain": "oc-catalog-oc-catalog",
|
||||||
|
"terminationGracePeriodSeconds": 30,
|
||||||
|
"tolerations": [
|
||||||
|
{
|
||||||
|
"effect": "NoExecute",
|
||||||
|
"key": "node.kubernetes.io/not-ready",
|
||||||
|
"operator": "Exists",
|
||||||
|
"tolerationSeconds": 300
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"effect": "NoExecute",
|
||||||
|
"key": "node.kubernetes.io/unreachable",
|
||||||
|
"operator": "Exists",
|
||||||
|
"tolerationSeconds": 300
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"volumes": [
|
||||||
|
{
|
||||||
|
"name": "kube-api-access-lpks6",
|
||||||
|
"projected": {
|
||||||
|
"defaultMode": 420,
|
||||||
|
"sources": [
|
||||||
|
{
|
||||||
|
"serviceAccountToken": {
|
||||||
|
"expirationSeconds": 3607,
|
||||||
|
"path": "token"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"configMap": {
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"key": "ca.crt",
|
||||||
|
"path": "ca.crt"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "kube-root-ca.crt"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"downwardAPI": {
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"fieldRef": {
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"fieldPath": "metadata.namespace"
|
||||||
|
},
|
||||||
|
"path": "namespace"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"conditions": [
|
||||||
|
{
|
||||||
|
"lastProbeTime": null,
|
||||||
|
"lastTransitionTime": "2024-09-05T17:06:44Z",
|
||||||
|
"status": "True",
|
||||||
|
"type": "Initialized"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"lastProbeTime": null,
|
||||||
|
"lastTransitionTime": "2024-09-05T17:06:46Z",
|
||||||
|
"status": "True",
|
||||||
|
"type": "Ready"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"lastProbeTime": null,
|
||||||
|
"lastTransitionTime": "2024-09-05T17:06:46Z",
|
||||||
|
"status": "True",
|
||||||
|
"type": "ContainersReady"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"lastProbeTime": null,
|
||||||
|
"lastTransitionTime": "2024-09-05T17:06:44Z",
|
||||||
|
"status": "True",
|
||||||
|
"type": "PodScheduled"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"containerStatuses": [
|
||||||
|
{
|
||||||
|
"containerID": "containerd://b50252d915ab1bdf1ade5c9afff589e8f6b7cd98e1c507eb5f398c390d7f120c",
|
||||||
|
"image": "harbor.dtf/dev/oc-catalog:1.0",
|
||||||
|
"imageID": "harbor.dtf/dev/oc-catalog@sha256:b4e135ecc4e69b93636118f42e436eb0948f9781ffbec4911bb944b79fd415b3",
|
||||||
|
"lastState": {},
|
||||||
|
"name": "oc-catalog",
|
||||||
|
"ready": true,
|
||||||
|
"restartCount": 0,
|
||||||
|
"started": true,
|
||||||
|
"state": {
|
||||||
|
"running": {
|
||||||
|
"startedAt": "2024-09-05T17:06:46Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"hostIP": "172.17.40.249",
|
||||||
|
"phase": "Running",
|
||||||
|
"podIP": "10.42.2.10",
|
||||||
|
"podIPs": [
|
||||||
|
{
|
||||||
|
"ip": "10.42.2.10"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"qosClass": "BestEffort",
|
||||||
|
"startTime": "2024-09-05T17:06:44Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"kind": "PodList",
|
||||||
|
"metadata": {
|
||||||
|
"resourceVersion": "8001092"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"v1/Service": [
|
||||||
|
{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"kind": "Service",
|
||||||
|
"metadata": {
|
||||||
|
"annotations": {
|
||||||
|
"meta.helm.sh/release-name": "oc-catalog",
|
||||||
|
"meta.helm.sh/release-namespace": "default"
|
||||||
|
},
|
||||||
|
"creationTimestamp": "2024-09-05T17:06:44Z",
|
||||||
|
"labels": {
|
||||||
|
"app.kubernetes.io/managed-by": "Helm"
|
||||||
|
},
|
||||||
|
"managedFields": [
|
||||||
|
{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"fieldsType": "FieldsV1",
|
||||||
|
"fieldsV1": {
|
||||||
|
"f:metadata": {
|
||||||
|
"f:annotations": {
|
||||||
|
".": {},
|
||||||
|
"f:meta.helm.sh/release-name": {},
|
||||||
|
"f:meta.helm.sh/release-namespace": {}
|
||||||
|
},
|
||||||
|
"f:labels": {
|
||||||
|
".": {},
|
||||||
|
"f:app.kubernetes.io/managed-by": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"f:spec": {
|
||||||
|
"f:externalTrafficPolicy": {},
|
||||||
|
"f:internalTrafficPolicy": {},
|
||||||
|
"f:ports": {
|
||||||
|
".": {},
|
||||||
|
"k:{\"port\":8087,\"protocol\":\"TCP\"}": {
|
||||||
|
".": {},
|
||||||
|
"f:port": {},
|
||||||
|
"f:protocol": {},
|
||||||
|
"f:targetPort": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"f:selector": {},
|
||||||
|
"f:sessionAffinity": {},
|
||||||
|
"f:type": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"manager": "helm",
|
||||||
|
"operation": "Update",
|
||||||
|
"time": "2024-09-05T17:06:44Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "oc-catalog-oc-catalog",
|
||||||
|
"namespace": "default",
|
||||||
|
"resourceVersion": "7811955",
|
||||||
|
"uid": "bb9f6cd3-298c-4d98-9f6a-59cbd70ddac2"
|
||||||
|
},
|
||||||
|
"spec": {
|
||||||
|
"clusterIP": "10.43.6.251",
|
||||||
|
"clusterIPs": [
|
||||||
|
"10.43.6.251"
|
||||||
|
],
|
||||||
|
"externalTrafficPolicy": "Cluster",
|
||||||
|
"internalTrafficPolicy": "Cluster",
|
||||||
|
"ipFamilies": [
|
||||||
|
"IPv4"
|
||||||
|
],
|
||||||
|
"ipFamilyPolicy": "SingleStack",
|
||||||
|
"ports": [
|
||||||
|
{
|
||||||
|
"nodePort": 32692,
|
||||||
|
"port": 8087,
|
||||||
|
"protocol": "TCP",
|
||||||
|
"targetPort": 8080
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"selector": {
|
||||||
|
"app": "oc-catalog"
|
||||||
|
},
|
||||||
|
"sessionAffinity": "None",
|
||||||
|
"type": "NodePort"
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"loadBalancer": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"v1/StatefulSet": [
|
||||||
|
{
|
||||||
|
"apiVersion": "apps/v1",
|
||||||
|
"kind": "StatefulSet",
|
||||||
|
"metadata": {
|
||||||
|
"annotations": {
|
||||||
|
"meta.helm.sh/release-name": "oc-catalog",
|
||||||
|
"meta.helm.sh/release-namespace": "default"
|
||||||
|
},
|
||||||
|
"creationTimestamp": "2024-09-05T17:06:44Z",
|
||||||
|
"generation": 1,
|
||||||
|
"labels": {
|
||||||
|
"app": "oc-catalog",
|
||||||
|
"app.kubernetes.io/managed-by": "Helm"
|
||||||
|
},
|
||||||
|
"managedFields": [
|
||||||
|
{
|
||||||
|
"apiVersion": "apps/v1",
|
||||||
|
"fieldsType": "FieldsV1",
|
||||||
|
"fieldsV1": {
|
||||||
|
"f:metadata": {
|
||||||
|
"f:annotations": {
|
||||||
|
".": {},
|
||||||
|
"f:meta.helm.sh/release-name": {},
|
||||||
|
"f:meta.helm.sh/release-namespace": {}
|
||||||
|
},
|
||||||
|
"f:labels": {
|
||||||
|
".": {},
|
||||||
|
"f:app": {},
|
||||||
|
"f:app.kubernetes.io/managed-by": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"f:spec": {
|
||||||
|
"f:persistentVolumeClaimRetentionPolicy": {
|
||||||
|
".": {},
|
||||||
|
"f:whenDeleted": {},
|
||||||
|
"f:whenScaled": {}
|
||||||
|
},
|
||||||
|
"f:podManagementPolicy": {},
|
||||||
|
"f:replicas": {},
|
||||||
|
"f:revisionHistoryLimit": {},
|
||||||
|
"f:selector": {},
|
||||||
|
"f:serviceName": {},
|
||||||
|
"f:template": {
|
||||||
|
"f:metadata": {
|
||||||
|
"f:labels": {
|
||||||
|
".": {},
|
||||||
|
"f:app": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"f:spec": {
|
||||||
|
"f:containers": {
|
||||||
|
"k:{\"name\":\"oc-catalog\"}": {
|
||||||
|
".": {},
|
||||||
|
"f:env": {
|
||||||
|
".": {},
|
||||||
|
"k:{\"name\":\"MONGO_DATABASE\"}": {
|
||||||
|
".": {},
|
||||||
|
"f:name": {},
|
||||||
|
"f:value": {}
|
||||||
|
},
|
||||||
|
"k:{\"name\":\"MONGO_URI\"}": {
|
||||||
|
".": {},
|
||||||
|
"f:name": {},
|
||||||
|
"f:value": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"f:image": {},
|
||||||
|
"f:imagePullPolicy": {},
|
||||||
|
"f:name": {},
|
||||||
|
"f:ports": {
|
||||||
|
".": {},
|
||||||
|
"k:{\"containerPort\":8080,\"protocol\":\"TCP\"}": {
|
||||||
|
".": {},
|
||||||
|
"f:containerPort": {},
|
||||||
|
"f:protocol": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"f:resources": {},
|
||||||
|
"f:terminationMessagePath": {},
|
||||||
|
"f:terminationMessagePolicy": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"f:dnsPolicy": {},
|
||||||
|
"f:imagePullSecrets": {
|
||||||
|
".": {},
|
||||||
|
"k:{\"name\":\"regcred\"}": {}
|
||||||
|
},
|
||||||
|
"f:restartPolicy": {},
|
||||||
|
"f:schedulerName": {},
|
||||||
|
"f:securityContext": {},
|
||||||
|
"f:terminationGracePeriodSeconds": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"f:updateStrategy": {
|
||||||
|
"f:rollingUpdate": {
|
||||||
|
".": {},
|
||||||
|
"f:partition": {}
|
||||||
|
},
|
||||||
|
"f:type": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"manager": "helm",
|
||||||
|
"operation": "Update",
|
||||||
|
"time": "2024-09-05T17:06:44Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"apiVersion": "apps/v1",
|
||||||
|
"fieldsType": "FieldsV1",
|
||||||
|
"fieldsV1": {
|
||||||
|
"f:status": {
|
||||||
|
"f:availableReplicas": {},
|
||||||
|
"f:collisionCount": {},
|
||||||
|
"f:currentReplicas": {},
|
||||||
|
"f:currentRevision": {},
|
||||||
|
"f:observedGeneration": {},
|
||||||
|
"f:readyReplicas": {},
|
||||||
|
"f:replicas": {},
|
||||||
|
"f:updateRevision": {},
|
||||||
|
"f:updatedReplicas": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"manager": "kube-controller-manager",
|
||||||
|
"operation": "Update",
|
||||||
|
"subresource": "status",
|
||||||
|
"time": "2024-09-05T17:06:46Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "oc-catalog-oc-catalog",
|
||||||
|
"namespace": "default",
|
||||||
|
"resourceVersion": "7811987",
|
||||||
|
"uid": "10aa222e-dc37-451e-a5ee-e88f88b4e136"
|
||||||
|
},
|
||||||
|
"spec": {
|
||||||
|
"persistentVolumeClaimRetentionPolicy": {
|
||||||
|
"whenDeleted": "Retain",
|
||||||
|
"whenScaled": "Retain"
|
||||||
|
},
|
||||||
|
"podManagementPolicy": "OrderedReady",
|
||||||
|
"replicas": 1,
|
||||||
|
"revisionHistoryLimit": 10,
|
||||||
|
"selector": {
|
||||||
|
"matchLabels": {
|
||||||
|
"app": "oc-catalog"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"serviceName": "oc-catalog-oc-catalog",
|
||||||
|
"template": {
|
||||||
|
"metadata": {
|
||||||
|
"creationTimestamp": null,
|
||||||
|
"labels": {
|
||||||
|
"app": "oc-catalog"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"spec": {
|
||||||
|
"containers": [
|
||||||
|
{
|
||||||
|
"env": [
|
||||||
|
{
|
||||||
|
"name": "MONGO_DATABASE",
|
||||||
|
"value": "DC_myDC"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "MONGO_URI",
|
||||||
|
"value": "mongodb://mongo:27017"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"image": "harbor.dtf/dev/oc-catalog:1.0",
|
||||||
|
"imagePullPolicy": "IfNotPresent",
|
||||||
|
"name": "oc-catalog",
|
||||||
|
"ports": [
|
||||||
|
{
|
||||||
|
"containerPort": 8080,
|
||||||
|
"protocol": "TCP"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"resources": {},
|
||||||
|
"terminationMessagePath": "/dev/termination-log",
|
||||||
|
"terminationMessagePolicy": "File"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dnsPolicy": "ClusterFirst",
|
||||||
|
"imagePullSecrets": [
|
||||||
|
{
|
||||||
|
"name": "regcred"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"restartPolicy": "Always",
|
||||||
|
"schedulerName": "default-scheduler",
|
||||||
|
"securityContext": {},
|
||||||
|
"terminationGracePeriodSeconds": 30
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"updateStrategy": {
|
||||||
|
"rollingUpdate": {
|
||||||
|
"partition": 0
|
||||||
|
},
|
||||||
|
"type": "RollingUpdate"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"availableReplicas": 1,
|
||||||
|
"collisionCount": 0,
|
||||||
|
"currentReplicas": 1,
|
||||||
|
"currentRevision": "oc-catalog-oc-catalog-7d7859dd76",
|
||||||
|
"observedGeneration": 1,
|
||||||
|
"readyReplicas": 1,
|
||||||
|
"replicas": 1,
|
||||||
|
"updateRevision": "oc-catalog-oc-catalog-7d7859dd76",
|
||||||
|
"updatedReplicas": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"image": {
|
||||||
|
"repository": "harbor.dtf/dev/oc-catalog",
|
||||||
|
"tag": "1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"manifest": "---\n# Source: oc-catalog/templates/service.yml\napiVersion: v1\nkind: Service\nmetadata:\n name: oc-catalog-oc-catalog\nspec:\n selector:\n app: oc-catalog\n ports:\n - protocol: TCP\n port: 8087\n targetPort: 8080\n type: NodePort\n---\n# Source: oc-catalog/templates/statefulset.yml\napiVersion: apps/v1\nkind: StatefulSet\nmetadata:\n name: oc-catalog-oc-catalog\n labels:\n app: oc-catalog\nspec:\n serviceName: \"oc-catalog-oc-catalog\"\n replicas: 1\n selector:\n matchLabels:\n app: oc-catalog\n template:\n metadata:\n labels:\n app: oc-catalog\n spec:\n containers:\n - name: oc-catalog\n image: \"harbor.dtf/dev/oc-catalog:1.0\"\n ports:\n - containerPort: 8080\n env:\n - name: MONGO_DATABASE\n value: \"DC_myDC\"\n - name: MONGO_URI\n value: \"mongodb://mongo:27017\"\n imagePullSecrets:\n - name: regcred\n",
|
||||||
|
"version": 1,
|
||||||
|
"namespace": "default"
|
||||||
|
}
|
||||||
7
test/tool/oc.yml
Normal file
7
test/tool/oc.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
tools:
|
||||||
|
- name: kubectl
|
||||||
|
url: https://dl.k8s.io/release/%s/bin/linux/amd64/kubectl
|
||||||
|
version: v1.30.3
|
||||||
|
|
||||||
1
test/utils/fichier1
Normal file
1
test/utils/fichier1
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Fichier1
|
||||||
3
test/versionOc/oc.yml
Normal file
3
test/versionOc/oc.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
version: 99.0
|
||||||
1
test/versionOc/oc_error.yml
Normal file
1
test/versionOc/oc_error.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
N'est pas un fichier
|
||||||
3
test/versionOc/offline/latest.yml
Normal file
3
test/versionOc/offline/latest.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
version: 99.1
|
||||||
1
test/versionOc/offline/oc_99.1.yml
Normal file
1
test/versionOc/offline/oc_99.1.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
---
|
||||||
Reference in New Issue
Block a user