Use pointer for Value, change RELEASE_NAME const
This commit is contained in:
@@ -26,10 +26,6 @@ const (
|
||||
ICON_INGRESS = "🌐"
|
||||
)
|
||||
|
||||
const (
|
||||
RELEASE_NAME = helm.RELEASE_NAME
|
||||
)
|
||||
|
||||
// Values is kept in memory to create a values.yaml file.
|
||||
var (
|
||||
Values = make(map[string]map[string]interface{})
|
||||
@@ -44,7 +40,7 @@ OK=0
|
||||
echo "Checking __service__ port"
|
||||
while [ $OK != 1 ]; do
|
||||
echo -n "."
|
||||
nc -z ` + RELEASE_NAME + `-__service__ __port__ 2>&1 >/dev/null && OK=1 || sleep 1
|
||||
nc -z ` + helm.ReleaseNameTpl + `-__service__ __port__ 2>&1 >/dev/null && OK=1 || sleep 1
|
||||
done
|
||||
echo
|
||||
echo "Done"
|
||||
@@ -70,7 +66,7 @@ func parseService(name string, s types.ServiceConfig, linked map[string]types.Se
|
||||
prepareContainer(container, s, name)
|
||||
prepareEnvFromFiles(name, s, container, ret)
|
||||
|
||||
// Set the container to the deployment
|
||||
// Set the containers to the deployment
|
||||
deployment.Spec.Template.Spec.Containers = []*helm.Container{container}
|
||||
|
||||
// Prepare volumes
|
||||
@@ -208,7 +204,7 @@ func createIngress(name string, port int, s types.ServiceConfig) *helm.Ingress {
|
||||
PathType: "Prefix",
|
||||
Backend: &helm.IngressBackend{
|
||||
Service: helm.IngressService{
|
||||
Name: RELEASE_NAME + "-" + name,
|
||||
Name: helm.ReleaseNameTpl + "-" + name,
|
||||
Port: map[string]interface{}{
|
||||
"number": port,
|
||||
},
|
||||
@@ -227,7 +223,7 @@ func createIngress(name string, port int, s types.ServiceConfig) *helm.Ingress {
|
||||
func buildSelector(name string, s types.ServiceConfig) map[string]string {
|
||||
return map[string]string{
|
||||
"katenary.io/component": name,
|
||||
"katenary.io/release": RELEASE_NAME,
|
||||
"katenary.io/release": helm.ReleaseNameTpl,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,7 +351,7 @@ func prepareVolumes(deployment, name string, s types.ServiceConfig, container *h
|
||||
volname = strings.Replace(volname, "./", "", 1)
|
||||
volname = strings.ReplaceAll(volname, "/", "-")
|
||||
volname = strings.ReplaceAll(volname, ".", "-")
|
||||
cm.K8sBase.Metadata.Name = RELEASE_NAME + "-" + volname + "-" + name
|
||||
cm.K8sBase.Metadata.Name = helm.ReleaseNameTpl + "-" + volname + "-" + name
|
||||
|
||||
// build a configmap from the volume path
|
||||
volumes = append(volumes, map[string]interface{}{
|
||||
@@ -405,7 +401,7 @@ func prepareVolumes(deployment, name string, s types.ServiceConfig, container *h
|
||||
volumes = append(volumes, map[string]interface{}{
|
||||
"name": volname,
|
||||
"persistentVolumeClaim": map[string]string{
|
||||
"claimName": RELEASE_NAME + "-" + volname,
|
||||
"claimName": helm.ReleaseNameTpl + "-" + volname,
|
||||
},
|
||||
})
|
||||
mountPoints = append(mountPoints, map[string]interface{}{
|
||||
@@ -499,6 +495,7 @@ func prepareProbes(name string, s types.ServiceConfig, container *helm.Container
|
||||
}
|
||||
}
|
||||
|
||||
// buildProtoProbe builds a probe from a url that can be http or tcp.
|
||||
func buildProtoProbe(u *url.URL) *helm.Probe {
|
||||
probe := helm.NewProbe(0, 0, 0, 0)
|
||||
port, err := strconv.Atoi(u.Port())
|
||||
@@ -616,6 +613,7 @@ func prepareEnvFromFiles(name string, s types.ServiceConfig, container *helm.Con
|
||||
}
|
||||
}
|
||||
|
||||
// AddValues adds values to the values.yaml map.
|
||||
func AddValues(servicename string, values map[string]interface{}) {
|
||||
locker.Lock()
|
||||
defer locker.Unlock()
|
||||
@@ -630,6 +628,7 @@ func AddValues(servicename string, values map[string]interface{}) {
|
||||
|
||||
}
|
||||
|
||||
// AddVolumeValues add a volume to the values.yaml map for the given deployment name.
|
||||
func AddVolumeValues(deployment string, volname string, values map[string]interface{}) {
|
||||
locker.Lock()
|
||||
defer locker.Unlock()
|
||||
|
@@ -227,8 +227,8 @@ func TestEnvs(t *testing.T) {
|
||||
}
|
||||
if next {
|
||||
matched = true
|
||||
if !strings.Contains(line, helm.RELEASE_NAME+"-database") {
|
||||
t.Error("DB_HOST variable should be set to " + helm.RELEASE_NAME + "-database")
|
||||
if !strings.Contains(line, helm.ReleaseNameTpl+"-database") {
|
||||
t.Error("DB_HOST variable should be set to " + helm.ReleaseNameTpl + "-database")
|
||||
}
|
||||
break
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ func NewConfigMap(name string) *ConfigMap {
|
||||
base := NewBase()
|
||||
base.ApiVersion = "v1"
|
||||
base.Kind = "ConfigMap"
|
||||
base.Metadata.Name = RELEASE_NAME + "-" + name
|
||||
base.Metadata.Name = ReleaseNameTpl + "-" + name
|
||||
base.Metadata.Labels[K+"/component"] = name
|
||||
return &ConfigMap{
|
||||
K8sBase: base,
|
||||
@@ -72,7 +72,7 @@ func NewSecret(name string) *Secret {
|
||||
base := NewBase()
|
||||
base.ApiVersion = "v1"
|
||||
base.Kind = "Secret"
|
||||
base.Metadata.Name = RELEASE_NAME + "-" + name
|
||||
base.Metadata.Name = ReleaseNameTpl + "-" + name
|
||||
base.Metadata.Labels[K+"/component"] = name
|
||||
return &Secret{
|
||||
K8sBase: base,
|
||||
|
@@ -23,7 +23,7 @@ type Container struct {
|
||||
Name string `yaml:"name,omitempty"`
|
||||
Image string `yaml:"image"`
|
||||
Ports []*ContainerPort `yaml:"ports,omitempty"`
|
||||
Env []Value `yaml:"env,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"`
|
||||
@@ -35,7 +35,7 @@ func NewContainer(name, image string, environment types.MappingWithEquals, label
|
||||
container := &Container{
|
||||
Image: image,
|
||||
Name: name,
|
||||
Env: make([]Value, len(environment)),
|
||||
Env: make([]*Value, len(environment)),
|
||||
EnvFrom: make([]map[string]map[string]string, 0),
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@ func NewContainer(name, image string, environment types.MappingWithEquals, label
|
||||
for n, v := range environment {
|
||||
for _, name := range toServices {
|
||||
if name == n {
|
||||
*v = RELEASE_NAME + "-" + *v
|
||||
*v = ReleaseNameTpl + "-" + *v
|
||||
}
|
||||
}
|
||||
container.Env[idx] = Value{Name: n, Value: v}
|
||||
container.Env[idx] = &Value{Name: n, Value: v}
|
||||
idx++
|
||||
}
|
||||
return container
|
||||
|
@@ -8,7 +8,7 @@ type Deployment struct {
|
||||
|
||||
func NewDeployment(name string) *Deployment {
|
||||
d := &Deployment{K8sBase: NewBase(), Spec: NewDepSpec()}
|
||||
d.K8sBase.Metadata.Name = RELEASE_NAME + "-" + name
|
||||
d.K8sBase.Metadata.Name = ReleaseNameTpl + "-" + name
|
||||
d.K8sBase.ApiVersion = "apps/v1"
|
||||
d.K8sBase.Kind = "Deployment"
|
||||
d.K8sBase.Metadata.Labels[K+"/component"] = name
|
||||
|
@@ -9,7 +9,7 @@ type Ingress struct {
|
||||
func NewIngress(name string) *Ingress {
|
||||
i := &Ingress{}
|
||||
i.K8sBase = NewBase()
|
||||
i.K8sBase.Metadata.Name = RELEASE_NAME + "-" + name
|
||||
i.K8sBase.Metadata.Name = ReleaseNameTpl + "-" + name
|
||||
i.K8sBase.Kind = "Ingress"
|
||||
i.ApiVersion = "networking.k8s.io/v1"
|
||||
i.K8sBase.Metadata.Labels[K+"/component"] = name
|
||||
|
@@ -35,7 +35,7 @@ func NewBase() *K8sBase {
|
||||
}
|
||||
// add some information of the build
|
||||
b.Metadata.Labels[K+"/project"] = GetProjectName()
|
||||
b.Metadata.Labels[K+"/release"] = RELEASE_NAME
|
||||
b.Metadata.Labels[K+"/release"] = ReleaseNameTpl
|
||||
b.Metadata.Annotations[K+"/version"] = Version
|
||||
return b
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ import (
|
||||
"html/template"
|
||||
)
|
||||
|
||||
const RELEASE_NAME = "{{ .Release.Name }}"
|
||||
const ReleaseNameTpl = "{{ .Release.Name }}"
|
||||
const (
|
||||
LABEL_ENV_SECRET = K + "/secret-envfiles"
|
||||
LABEL_PORT = K + "/ports"
|
||||
|
@@ -12,7 +12,7 @@ func NewService(name string) *Service {
|
||||
K8sBase: NewBase(),
|
||||
Spec: NewServiceSpec(),
|
||||
}
|
||||
s.K8sBase.Metadata.Name = RELEASE_NAME + "-" + name
|
||||
s.K8sBase.Metadata.Name = ReleaseNameTpl + "-" + name
|
||||
s.K8sBase.Kind = "Service"
|
||||
s.K8sBase.ApiVersion = "v1"
|
||||
s.K8sBase.Metadata.Labels[K+"/component"] = name
|
||||
|
@@ -13,7 +13,7 @@ func NewPVC(name, storageName string) *Storage {
|
||||
pvc.K8sBase.Kind = "PersistentVolumeClaim"
|
||||
pvc.K8sBase.Metadata.Labels[K+"/pvc-name"] = storageName
|
||||
pvc.K8sBase.ApiVersion = "v1"
|
||||
pvc.K8sBase.Metadata.Name = RELEASE_NAME + "-" + storageName
|
||||
pvc.K8sBase.Metadata.Name = ReleaseNameTpl + "-" + storageName
|
||||
pvc.K8sBase.Metadata.Labels[K+"/component"] = name
|
||||
pvc.Spec = &PVCSpec{
|
||||
Resouces: map[string]interface{}{
|
||||
|
Reference in New Issue
Block a user