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