Files
katenary/helm/container.go
Patrice Ferlet b1b96d8318 A big commit to fix more things, see details
- ingress can now have annotations
- configmaps are better named and there is a label to know from where
  the content is taken
- fixed bad "nil" pointer checks
- we force to not resolve paths from compose file, this should be a
  problem when we call the compose file from outside. So, TODO: check
  this!
- the "project" label is now the Chart Name, not a static string
- minor fixes
2022-05-06 20:18:10 +02:00

66 lines
2.0 KiB
Go

package helm
import (
"katenary/logger"
"strings"
"github.com/compose-spec/compose-go/types"
)
type EnvValue interface{}
// ContainerPort represent a port mapping.
type ContainerPort struct {
Name string
ContainerPort int `yaml:"containerPort"`
}
// Value represent a environment variable with name and value.
type Value struct {
Name string `yaml:"name"`
Value EnvValue `yaml:"value"`
}
// Container represent a container with name, image, and environment variables. It is used in Deployment.
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"`
LivenessProbe *Probe `yaml:"livenessProbe,omitempty"`
}
// NewContainer creates a new container with name, image, labels and environment variables.
func NewContainer(name, image string, environment types.MappingWithEquals, labels map[string]string) *Container {
container := &Container{
Image: image,
Name: name,
EnvFrom: make([]map[string]map[string]string, 0),
}
// find bound environment variable to a service
toServices := make([]string, 0)
if bound, ok := labels[LABEL_ENV_SERVICE]; ok {
toServices = strings.Split(bound, ",")
}
if len(toServices) > 0 {
// warn, it's deprecated now
logger.ActivateColors = true
logger.Yellowf(
"[deprecated] in \"%s\" service: label %s is deprecated and **ignored**, please use %s instead\n"+
"e.g.\n"+
" labels:\n"+
" FOO: {{ .Release.Name }}-fooservice\n",
name,
LABEL_ENV_SERVICE,
LABEL_MAP_ENV,
)
logger.ActivateColors = false
}
return container
}