2021-11-30 12:04:28 +01:00
|
|
|
package helm
|
|
|
|
|
|
|
|
import (
|
2022-02-14 14:37:09 +01:00
|
|
|
"bytes"
|
2021-11-30 12:04:28 +01:00
|
|
|
"os"
|
|
|
|
"strings"
|
2022-02-14 14:37:09 +01:00
|
|
|
"text/template"
|
2021-11-30 12:04:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const K = "katenary.io"
|
2021-12-05 09:05:48 +01:00
|
|
|
const RELEASE_NAME = "{{ .Release.Name }}"
|
2021-12-02 14:56:51 +01:00
|
|
|
const (
|
|
|
|
LABEL_ENV_SECRET = K + "/secret-envfiles"
|
|
|
|
LABEL_PORT = K + "/ports"
|
|
|
|
LABEL_INGRESS = K + "/ingress"
|
|
|
|
LABEL_ENV_SERVICE = K + "/env-to-service"
|
|
|
|
LABEL_VOL_CM = K + "/configmap-volumes"
|
2022-02-14 14:37:09 +01:00
|
|
|
LABEL_HEALTHCHECK = K + "/healthcheck"
|
2022-02-16 17:40:11 +01:00
|
|
|
LABEL_SAMEPOD = K + "/same-pod"
|
|
|
|
LABEL_EMPTYDIRS = K + "/empty-dirs"
|
2021-12-02 14:56:51 +01:00
|
|
|
)
|
2021-11-30 12:04:28 +01:00
|
|
|
|
2022-02-14 14:37:09 +01:00
|
|
|
func GetLabelsDocumentation() string {
|
|
|
|
t, _ := template.New("labels").Parse(`
|
|
|
|
# Labels
|
|
|
|
{{.LABEL_ENV_SECRET | printf "%-33s"}}: set the given file names as a secret instead of configmap
|
2022-02-16 17:48:57 +01:00
|
|
|
{{.LABEL_PORT | printf "%-33s"}}: set the ports to expose as a service (coma separated)
|
|
|
|
{{.LABEL_INGRESS | printf "%-33s"}}: set the port to expose in an ingress (coma separated)
|
|
|
|
{{.LABEL_ENV_SERVICE | printf "%-33s"}}: specifies that the environment variable points on a service name (coma separated)
|
|
|
|
{{.LABEL_VOL_CM | printf "%-33s"}}: specifies that the volumes points on a configmap (coma separated)
|
2022-02-16 17:44:25 +01:00
|
|
|
{{.LABEL_SAMEPOD | printf "%-33s"}}: specifies that the pod should be deployed in the same pod than the given service name
|
2022-02-16 17:48:57 +01:00
|
|
|
{{.LABEL_EMPTYDIRS | printf "%-33s"}}: specifies that the given volume names should be "emptyDir" instead of persistentVolumeClaim (coma separated)
|
2022-02-14 14:37:09 +01:00
|
|
|
{{.LABEL_HEALTHCHECK | printf "%-33s"}}: specifies that the container should be monitored by a healthcheck, **it overrides the docker-compose healthcheck**.
|
|
|
|
{{ printf "%-34s" ""}} You can use these form of label values:
|
|
|
|
{{ printf "%-35s" ""}}- "http://[not used address][:port][/path]" to specify an http healthcheck
|
|
|
|
{{ printf "%-35s" ""}}- "tcp://[not used address]:port" to specify a tcp healthcheck
|
|
|
|
{{ printf "%-35s" ""}}- other string is condidered as a "command" healthcheck
|
|
|
|
`)
|
|
|
|
buff := bytes.NewBuffer(nil)
|
|
|
|
t.Execute(buff, map[string]string{
|
|
|
|
"LABEL_ENV_SECRET": LABEL_ENV_SECRET,
|
|
|
|
"LABEL_ENV_SERVICE": LABEL_ENV_SERVICE,
|
|
|
|
"LABEL_PORT": LABEL_PORT,
|
|
|
|
"LABEL_INGRESS": LABEL_INGRESS,
|
|
|
|
"LABEL_VOL_CM": LABEL_VOL_CM,
|
|
|
|
"LABEL_HEALTHCHECK": LABEL_HEALTHCHECK,
|
2022-02-16 17:40:11 +01:00
|
|
|
"LABEL_SAMEPOD": LABEL_SAMEPOD,
|
|
|
|
"LABEL_EMPTYDIRS": LABEL_EMPTYDIRS,
|
2022-02-14 14:37:09 +01:00
|
|
|
})
|
|
|
|
return buff.String()
|
|
|
|
}
|
|
|
|
|
2021-12-05 09:05:48 +01:00
|
|
|
var (
|
|
|
|
Appname = ""
|
|
|
|
Version = "1.0" // should be set from main.Version
|
|
|
|
)
|
2021-11-30 12:04:28 +01:00
|
|
|
|
2022-05-05 09:43:52 +02:00
|
|
|
// Kinded represent an object with a kind.
|
2021-11-30 12:04:28 +01:00
|
|
|
type Kinded interface {
|
2022-05-05 09:43:52 +02:00
|
|
|
|
|
|
|
// Get must resturn the kind name.
|
2021-11-30 12:04:28 +01:00
|
|
|
Get() string
|
|
|
|
}
|
|
|
|
|
2022-05-05 09:43:52 +02:00
|
|
|
// Signable represents an object with a signature.
|
2021-12-01 15:17:34 +01:00
|
|
|
type Signable interface {
|
2022-05-05 09:43:52 +02:00
|
|
|
|
|
|
|
// BuildSHA must return the signature.
|
2021-12-01 15:17:34 +01:00
|
|
|
BuildSHA(filename string)
|
|
|
|
}
|
|
|
|
|
2022-05-05 09:43:52 +02:00
|
|
|
// Named represents an object with a name.
|
2021-12-02 16:07:15 +01:00
|
|
|
type Named interface {
|
2021-11-30 12:04:28 +01:00
|
|
|
|
2022-05-05 09:43:52 +02:00
|
|
|
// Name must return the name of the object (from metadata).
|
|
|
|
Name() string
|
2021-12-02 16:07:15 +01:00
|
|
|
}
|
|
|
|
|
2022-05-05 09:43:52 +02:00
|
|
|
// GetProjectName returns the name of the project.
|
2021-12-02 14:59:08 +01:00
|
|
|
func GetProjectName() string {
|
2021-12-01 15:17:34 +01:00
|
|
|
if len(Appname) > 0 {
|
|
|
|
return Appname
|
|
|
|
}
|
2021-11-30 12:04:28 +01:00
|
|
|
p, _ := os.Getwd()
|
|
|
|
path := strings.Split(p, string(os.PathSeparator))
|
|
|
|
return path[len(path)-1]
|
|
|
|
}
|