Develop #78
@@ -232,5 +232,9 @@ func (c *ConfigMap) SetData(data map[string]string) {
|
|||||||
|
|
||||||
// Yaml returns the yaml representation of the configmap
|
// Yaml returns the yaml representation of the configmap
|
||||||
func (c *ConfigMap) Yaml() ([]byte, error) {
|
func (c *ConfigMap) Yaml() ([]byte, error) {
|
||||||
return yaml.Marshal(c)
|
if o, err := yaml.Marshal(c); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return UnWrapTPL(o), nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
package generator
|
package generator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"katenary/generator/labelStructs"
|
||||||
|
"katenary/utils"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -9,9 +11,6 @@ import (
|
|||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
"katenary/generator/labelStructs"
|
|
||||||
"katenary/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// only used to check interface implementation
|
// only used to check interface implementation
|
||||||
@@ -120,5 +119,9 @@ func (c *CronJob) Filename() string {
|
|||||||
//
|
//
|
||||||
// Implements the Yaml interface.
|
// Implements the Yaml interface.
|
||||||
func (c *CronJob) Yaml() ([]byte, error) {
|
func (c *CronJob) Yaml() ([]byte, error) {
|
||||||
return yaml.Marshal(c)
|
if o, err := yaml.Marshal(c); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return UnWrapTPL(o), nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -370,6 +370,7 @@ func (d *Deployment) Yaml() ([]byte, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
y = UnWrapTPL(y)
|
||||||
|
|
||||||
// for each volume mount, add a condition "if values has persistence"
|
// for each volume mount, add a condition "if values has persistence"
|
||||||
changing := false
|
changing := false
|
||||||
@@ -399,6 +400,7 @@ func (d *Deployment) Yaml() ([]byte, error) {
|
|||||||
if strings.Contains(volume, "mountPath: ") {
|
if strings.Contains(volume, "mountPath: ") {
|
||||||
spaces = strings.Repeat(" ", utils.CountStartingSpaces(volume))
|
spaces = strings.Repeat(" ", utils.CountStartingSpaces(volume))
|
||||||
varName := d.volumeMap[volumeName]
|
varName := d.volumeMap[volumeName]
|
||||||
|
varName = strings.ReplaceAll(varName, "-", "_")
|
||||||
content[line] = spaces + `{{- if .Values.` + serviceName + `.persistence.` + varName + `.enabled }}` + "\n" + volume
|
content[line] = spaces + `{{- if .Values.` + serviceName + `.persistence.` + varName + `.enabled }}` + "\n" + volume
|
||||||
changing = true
|
changing = true
|
||||||
}
|
}
|
||||||
@@ -442,6 +444,7 @@ func (d *Deployment) Yaml() ([]byte, error) {
|
|||||||
if strings.Contains(line, "- name: ") && inVolumes {
|
if strings.Contains(line, "- name: ") && inVolumes {
|
||||||
spaces = strings.Repeat(" ", utils.CountStartingSpaces(line))
|
spaces = strings.Repeat(" ", utils.CountStartingSpaces(line))
|
||||||
varName := d.volumeMap[volumeName]
|
varName := d.volumeMap[volumeName]
|
||||||
|
varName = strings.ReplaceAll(varName, "-", "_")
|
||||||
content[i] = spaces + `{{- if .Values.` + serviceName + `.persistence.` + varName + `.enabled }}` + "\n" + line
|
content[i] = spaces + `{{- if .Values.` + serviceName + `.persistence.` + varName + `.enabled }}` + "\n" + line
|
||||||
changing = true
|
changing = true
|
||||||
}
|
}
|
||||||
|
@@ -271,6 +271,7 @@ func buildVolumes(service types.ServiceConfig, chart *HelmChart, deployments map
|
|||||||
}
|
}
|
||||||
switch v.Type {
|
switch v.Type {
|
||||||
case "volume":
|
case "volume":
|
||||||
|
v.Source = strings.ReplaceAll(v.Source, "-", "_")
|
||||||
pvc := NewVolumeClaim(service, v.Source, appName)
|
pvc := NewVolumeClaim(service, v.Source, appName)
|
||||||
|
|
||||||
// if the service is integrated in another deployment, we need to add the volume
|
// if the service is integrated in another deployment, we need to add the volume
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
package generator
|
package generator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"katenary/generator/labelStructs"
|
||||||
|
"katenary/utils"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -8,9 +10,6 @@ import (
|
|||||||
networkv1 "k8s.io/api/networking/v1"
|
networkv1 "k8s.io/api/networking/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
"katenary/generator/labelStructs"
|
|
||||||
"katenary/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ Yaml = (*Ingress)(nil)
|
var _ Yaml = (*Ingress)(nil)
|
||||||
@@ -129,6 +128,7 @@ func (ingress *Ingress) Yaml() ([]byte, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
ret = UnWrapTPL(ret)
|
||||||
|
|
||||||
lines := strings.Split(string(ret), "\n")
|
lines := strings.Split(string(ret), "\n")
|
||||||
out := []string{
|
out := []string{
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
package generator
|
package generator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"katenary/utils"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
rbacv1 "k8s.io/api/rbac/v1"
|
rbacv1 "k8s.io/api/rbac/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
"katenary/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -121,7 +121,11 @@ func (r *Role) Filename() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Role) Yaml() ([]byte, error) {
|
func (r *Role) Yaml() ([]byte, error) {
|
||||||
return yaml.Marshal(r)
|
if o, err := yaml.Marshal(r); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return UnWrapTPL(o), nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServiceAccount is a kubernetes ServiceAccount.
|
// ServiceAccount is a kubernetes ServiceAccount.
|
||||||
|
@@ -3,14 +3,13 @@ package generator
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"katenary/utils"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
"katenary/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -102,6 +101,7 @@ func (s *Secret) Yaml() ([]byte, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
y = UnWrapTPL(y)
|
||||||
|
|
||||||
// replace the b64 value by the real value
|
// replace the b64 value by the real value
|
||||||
for _, value := range s.Data {
|
for _, value := range s.Data {
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package generator
|
package generator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"katenary/utils"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -9,8 +10,6 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/intstr"
|
"k8s.io/apimachinery/pkg/util/intstr"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
"katenary/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ Yaml = (*Service)(nil)
|
var _ Yaml = (*Service)(nil)
|
||||||
@@ -82,6 +81,11 @@ func (s *Service) Filename() string {
|
|||||||
// Yaml returns the yaml representation of the service.
|
// Yaml returns the yaml representation of the service.
|
||||||
func (s *Service) Yaml() ([]byte, error) {
|
func (s *Service) Yaml() ([]byte, error) {
|
||||||
y, err := yaml.Marshal(s)
|
y, err := yaml.Marshal(s)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
y = UnWrapTPL(y)
|
||||||
|
|
||||||
lines := []string{}
|
lines := []string{}
|
||||||
for _, line := range strings.Split(string(y), "\n") {
|
for _, line := range strings.Split(string(y), "\n") {
|
||||||
if regexp.MustCompile(`^\s*loadBalancer:\s*`).MatchString(line) {
|
if regexp.MustCompile(`^\s*loadBalancer:\s*`).MatchString(line) {
|
||||||
|
@@ -1,16 +1,18 @@
|
|||||||
package generator
|
package generator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"katenary/generator/labelStructs"
|
||||||
|
"katenary/utils"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
|
||||||
"katenary/generator/labelStructs"
|
|
||||||
"katenary/utils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var regexpLineWrap = regexp.MustCompile(`\n\s+}}`)
|
||||||
|
|
||||||
// findDeployment finds the corresponding target deployment for a service.
|
// findDeployment finds the corresponding target deployment for a service.
|
||||||
func findDeployment(serviceName string, deployments map[string]*Deployment) *Deployment {
|
func findDeployment(serviceName string, deployments map[string]*Deployment) *Deployment {
|
||||||
for _, d := range deployments {
|
for _, d := range deployments {
|
||||||
@@ -77,3 +79,8 @@ func isIgnored(service types.ServiceConfig) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnWrapTPL removes the line wrapping from a template.
|
||||||
|
func UnWrapTPL(in []byte) []byte {
|
||||||
|
return regexpLineWrap.ReplaceAll(in, []byte(" }}"))
|
||||||
|
}
|
||||||
|
@@ -92,6 +92,7 @@ func (v *Value) AddIngress(host, path string) {
|
|||||||
|
|
||||||
// AddPersistence adds persistence configuration to the Value.
|
// AddPersistence adds persistence configuration to the Value.
|
||||||
func (v *Value) AddPersistence(volumeName string) {
|
func (v *Value) AddPersistence(volumeName string) {
|
||||||
|
volumeName = strings.ReplaceAll(volumeName, "-", "_")
|
||||||
if v.Persistence == nil {
|
if v.Persistence == nil {
|
||||||
v.Persistence = make(map[string]*PersistenceValue, 0)
|
v.Persistence = make(map[string]*PersistenceValue, 0)
|
||||||
}
|
}
|
||||||
|
@@ -76,6 +76,8 @@ func (v *VolumeClaim) Yaml() ([]byte, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out = UnWrapTPL(out)
|
||||||
|
|
||||||
// replace 1Gi to {{ .Values.serviceName.volume.size }}
|
// replace 1Gi to {{ .Values.serviceName.volume.size }}
|
||||||
out = []byte(
|
out = []byte(
|
||||||
strings.Replace(
|
strings.Replace(
|
||||||
|
Reference in New Issue
Block a user