chore(refacto): fix secret and use katenary schema
- add possibility to use a katenary.yaml file to setup values - fix secret generation
This commit is contained in:
13
generator/labels/labelStructs/configMap.go
Normal file
13
generator/labels/labelStructs/configMap.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package labelStructs
|
||||
|
||||
import "gopkg.in/yaml.v3"
|
||||
|
||||
type ConfigMapFile []string
|
||||
|
||||
func ConfigMapFileFrom(data string) (ConfigMapFile, error) {
|
||||
var mapping ConfigMapFile
|
||||
if err := yaml.Unmarshal([]byte(data), &mapping); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mapping, nil
|
||||
}
|
18
generator/labels/labelStructs/cronJob.go
Normal file
18
generator/labels/labelStructs/cronJob.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package labelStructs
|
||||
|
||||
import "gopkg.in/yaml.v3"
|
||||
|
||||
type CronJob struct {
|
||||
Image string `yaml:"image,omitempty" json:"image,omitempty"`
|
||||
Command string `yaml:"command" json:"command,omitempty"`
|
||||
Schedule string `yaml:"schedule" json:"schedule,omitempty"`
|
||||
Rbac bool `yaml:"rbac" json:"rbac,omitempty"`
|
||||
}
|
||||
|
||||
func CronJobFrom(data string) (*CronJob, error) {
|
||||
var mapping CronJob
|
||||
if err := yaml.Unmarshal([]byte(data), &mapping); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &mapping, nil
|
||||
}
|
21
generator/labels/labelStructs/dependencies.go
Normal file
21
generator/labels/labelStructs/dependencies.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package labelStructs
|
||||
|
||||
import "gopkg.in/yaml.v3"
|
||||
|
||||
// Dependency is a dependency of a chart to other charts.
|
||||
type Dependency struct {
|
||||
Values map[string]any `yaml:"-" json:"values,omitempty"`
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Version string `yaml:"version" json:"version"`
|
||||
Repository string `yaml:"repository" json:"repository"`
|
||||
Alias string `yaml:"alias,omitempty" json:"alias,omitempty"`
|
||||
}
|
||||
|
||||
// DependenciesFrom returns a slice of dependencies from the given string.
|
||||
func DependenciesFrom(data string) ([]Dependency, error) {
|
||||
var mapping []Dependency
|
||||
if err := yaml.Unmarshal([]byte(data), &mapping); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mapping, nil
|
||||
}
|
2
generator/labels/labelStructs/doc.go
Normal file
2
generator/labels/labelStructs/doc.go
Normal file
@@ -0,0 +1,2 @@
|
||||
// labelStructs is a package that contains the structs used to represent the labels in the yaml files.
|
||||
package labelStructs
|
14
generator/labels/labelStructs/envFrom.go
Normal file
14
generator/labels/labelStructs/envFrom.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package labelStructs
|
||||
|
||||
import "gopkg.in/yaml.v3"
|
||||
|
||||
type EnvFrom []string
|
||||
|
||||
// EnvFromFrom returns a EnvFrom from the given string.
|
||||
func EnvFromFrom(data string) (EnvFrom, error) {
|
||||
var mapping EnvFrom
|
||||
if err := yaml.Unmarshal([]byte(data), &mapping); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mapping, nil
|
||||
}
|
33
generator/labels/labelStructs/ingress.go
Normal file
33
generator/labels/labelStructs/ingress.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package labelStructs
|
||||
|
||||
import "gopkg.in/yaml.v3"
|
||||
|
||||
type TLS struct {
|
||||
Enabled bool `yaml:"enabled" json:"enabled,omitempty"`
|
||||
}
|
||||
|
||||
type Ingress struct {
|
||||
Port *int32 `yaml:"port,omitempty" jsonschema:"nullable" json:"port,omitempty"`
|
||||
Annotations map[string]string `yaml:"annotations,omitempty" jsonschema:"nullable" json:"annotations,omitempty"`
|
||||
Hostname string `yaml:"hostname" json:"hostname,omitempty"`
|
||||
Path string `yaml:"path" json:"path,omitempty"`
|
||||
Class string `yaml:"class" json:"class,omitempty" jsonschema:"default:-"`
|
||||
Enabled bool `yaml:"enabled" json:"enabled,omitempty"`
|
||||
TLS *TLS `yaml:"tls,omitempty" json:"tls,omitempty"`
|
||||
}
|
||||
|
||||
// IngressFrom creates a new Ingress from a compose service.
|
||||
func IngressFrom(data string) (*Ingress, error) {
|
||||
mapping := Ingress{
|
||||
Hostname: "",
|
||||
Path: "/",
|
||||
Enabled: false,
|
||||
Class: "-",
|
||||
Port: nil,
|
||||
TLS: &TLS{Enabled: true},
|
||||
}
|
||||
if err := yaml.Unmarshal([]byte(data), &mapping); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &mapping, nil
|
||||
}
|
14
generator/labels/labelStructs/mapenv.go
Normal file
14
generator/labels/labelStructs/mapenv.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package labelStructs
|
||||
|
||||
import "gopkg.in/yaml.v3"
|
||||
|
||||
type MapEnv map[string]string
|
||||
|
||||
// MapEnvFrom returns a MapEnv from the given string.
|
||||
func MapEnvFrom(data string) (MapEnv, error) {
|
||||
var mapping MapEnv
|
||||
if err := yaml.Unmarshal([]byte(data), &mapping); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mapping, nil
|
||||
}
|
14
generator/labels/labelStructs/ports.go
Normal file
14
generator/labels/labelStructs/ports.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package labelStructs
|
||||
|
||||
import "gopkg.in/yaml.v3"
|
||||
|
||||
type Ports []uint32
|
||||
|
||||
// PortsFrom returns a Ports from the given string.
|
||||
func PortsFrom(data string) (Ports, error) {
|
||||
var mapping Ports
|
||||
if err := yaml.Unmarshal([]byte(data), &mapping); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mapping, nil
|
||||
}
|
56
generator/labels/labelStructs/probes.go
Normal file
56
generator/labels/labelStructs/probes.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package labelStructs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
type HealthCheck struct {
|
||||
LivenessProbe *corev1.Probe `yaml:"livenessProbe,omitempty" json:"livenessProbe,omitempty"`
|
||||
ReadinessProbe *corev1.Probe `yaml:"readinessProbe,omitempty" json:"readinessProbe,omitempty"`
|
||||
}
|
||||
|
||||
func ProbeFrom(data string) (*HealthCheck, error) {
|
||||
mapping := HealthCheck{}
|
||||
tmp := map[string]any{}
|
||||
err := yaml.Unmarshal([]byte(data), &tmp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if livenessProbe, ok := tmp["livenessProbe"]; ok {
|
||||
livenessProbeBytes, err := json.Marshal(livenessProbe)
|
||||
if err != nil {
|
||||
log.Printf("Error marshalling livenessProbe: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
livenessProbe := &corev1.Probe{}
|
||||
err = json.Unmarshal(livenessProbeBytes, livenessProbe)
|
||||
if err != nil {
|
||||
log.Printf("Error unmarshalling livenessProbe: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
mapping.LivenessProbe = livenessProbe
|
||||
}
|
||||
|
||||
if readinessProbe, ok := tmp["readinessProbe"]; ok {
|
||||
readinessProbeBytes, err := json.Marshal(readinessProbe)
|
||||
if err != nil {
|
||||
log.Printf("Error marshalling readinessProbe: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
readinessProbe := &corev1.Probe{}
|
||||
err = json.Unmarshal(readinessProbeBytes, readinessProbe)
|
||||
if err != nil {
|
||||
log.Printf("Error unmarshalling readinessProbe: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
mapping.ReadinessProbe = readinessProbe
|
||||
|
||||
}
|
||||
|
||||
return &mapping, err
|
||||
}
|
13
generator/labels/labelStructs/secrets.go
Normal file
13
generator/labels/labelStructs/secrets.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package labelStructs
|
||||
|
||||
import "gopkg.in/yaml.v3"
|
||||
|
||||
type Secrets []string
|
||||
|
||||
func SecretsFrom(data string) (Secrets, error) {
|
||||
var mapping Secrets
|
||||
if err := yaml.Unmarshal([]byte(data), &mapping); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mapping, nil
|
||||
}
|
Reference in New Issue
Block a user