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
This commit is contained in:
2022-05-06 20:18:10 +02:00
parent baeb8a612a
commit b1b96d8318
8 changed files with 68 additions and 22 deletions

View File

@@ -21,12 +21,15 @@ type ConfigMap struct {
}
// NewConfigMap returns a new initialzed ConfigMap.
func NewConfigMap(name string) *ConfigMap {
func NewConfigMap(name, path string) *ConfigMap {
base := NewBase()
base.ApiVersion = "v1"
base.Kind = "ConfigMap"
base.Metadata.Name = ReleaseNameTpl + "-" + name
base.Metadata.Labels[K+"/component"] = name
if path != "" {
base.Metadata.Labels[K+"/path"] = path
}
return &ConfigMap{
K8sBase: base,
Data: make(map[string]string),
@@ -72,12 +75,15 @@ type Secret struct {
}
// NewSecret returns a new initialzed Secret.
func NewSecret(name string) *Secret {
func NewSecret(name, path string) *Secret {
base := NewBase()
base.ApiVersion = "v1"
base.Kind = "Secret"
base.Metadata.Name = ReleaseNameTpl + "-" + name
base.Metadata.Labels[K+"/component"] = name
if path != "" {
base.Metadata.Labels[K+"/path"] = path
}
return &Secret{
K8sBase: base,
Data: make(map[string]string),

View File

@@ -38,7 +38,6 @@ func NewContainer(name, image string, environment types.MappingWithEquals, label
container := &Container{
Image: image,
Name: name,
Env: make([]*Value, len(environment)),
EnvFrom: make([]map[string]map[string]string, 0),
}

View File

@@ -4,6 +4,7 @@ import (
"crypto/sha1"
"fmt"
"io/ioutil"
"strings"
)
// Metadata is the metadata for a kubernetes object.
@@ -34,7 +35,7 @@ func NewBase() *K8sBase {
Metadata: NewMetadata(),
}
// add some information of the build
b.Metadata.Labels[K+"/project"] = GetProjectName()
b.Metadata.Labels[K+"/project"] = "{{ .Chart.Name }}"
b.Metadata.Labels[K+"/release"] = ReleaseNameTpl
b.Metadata.Annotations[K+"/version"] = Version
return b
@@ -56,3 +57,17 @@ func (k *K8sBase) Get() string {
func (k *K8sBase) Name() string {
return k.Metadata.Name
}
func (k *K8sBase) GetType() string {
if n, ok := k.Metadata.Labels[K+"/type"]; ok {
return n
}
return strings.ToLower(k.Kind)
}
func (k *K8sBase) GetPathRessource() string {
if p, ok := k.Metadata.Labels[K+"/path"]; ok {
return p
}
return ""
}