Add healtcheck + some fixes

- better docs
- add healtcheck based on docker-compoe commands or labels
- fix some problems on secret names
- better dependency check
This commit is contained in:
2022-02-14 14:37:09 +01:00
parent 8164603b47
commit 5a4d9e396d
7 changed files with 395 additions and 209 deletions

View File

@@ -40,13 +40,46 @@ type ContainerPort struct {
}
type Container struct {
Name string `yaml:"name,omitempty"`
Image string `yaml:"image"`
Ports []*ContainerPort `yaml:"ports,omitempty"`
Env []Value `yaml:"env,omitempty"`
EnvFrom []map[string]map[string]string `yaml:"envFrom,omitempty"`
Command []string `yaml:"command,omitempty"`
VolumeMounts []interface{} `yaml:"volumeMounts,omitempty"`
Name string `yaml:"name,omitempty"`
Image string `yaml:"image"`
Ports []*ContainerPort `yaml:"ports,omitempty"`
Env []Value `yaml:"env,omitempty"`
EnvFrom []map[string]map[string]string `yaml:"envFrom,omitempty"`
Command []string `yaml:"command,omitempty"`
VolumeMounts []interface{} `yaml:"volumeMounts,omitempty"`
LivenessProbe *Probe `yaml:"livenessProbe,omitempty"`
}
type HttpGet struct {
Path string `yaml:"path"`
Port int `yaml:"port"`
}
type Exec struct {
Command []string `yaml:"command"`
}
type TCP struct {
Port int `yaml:"port"`
}
type Probe struct {
HttpGet *HttpGet `yaml:"httpGet,omitempty"`
Exec *Exec `yaml:"exec,omitempty"`
TCP *TCP `yaml:"tcp,omitempty"`
Period int `yaml:"periodSeconds"`
Success int `yaml:"successThreshold"`
Failure int `yaml:"failureThreshold"`
InitialDelay int `yaml:"initialDelaySeconds"`
}
func NewProbe(period, initialDelaySeconds, success, failure int) *Probe {
return &Probe{
Period: period,
Success: success,
Failure: failure,
InitialDelay: initialDelaySeconds,
}
}
func NewContainer(name, image string, environment, labels map[string]string) *Container {

View File

@@ -1,11 +1,13 @@
package helm
import (
"bytes"
"crypto/sha1"
"fmt"
"io/ioutil"
"os"
"strings"
"text/template"
)
const K = "katenary.io"
@@ -16,8 +18,35 @@ const (
LABEL_INGRESS = K + "/ingress"
LABEL_ENV_SERVICE = K + "/env-to-service"
LABEL_VOL_CM = K + "/configmap-volumes"
LABEL_HEALTHCHECK = K + "/healthcheck"
)
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
{{.LABEL_PORT | printf "%-33s"}}: set the port to expose as a service
{{.LABEL_INGRESS | printf "%-33s"}}: set the port to expose in an ingress
{{.LABEL_ENV_SERVICE | printf "%-33s"}}: specifies that the environment variable points on a service name
{{.LABEL_VOL_CM | printf "%-33s"}}: specifies that the volume points on a configmap
{{.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,
})
return buff.String()
}
var (
Appname = ""
Version = "1.0" // should be set from main.Version