forked from Katenary/katenary
feat(logger) Change others logs
This commit is contained in:
@@ -2,7 +2,6 @@ package generator
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"maps"
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -336,7 +335,7 @@ func (chart *HelmChart) setSharedConf(service types.ServiceConfig, deployments m
|
|||||||
// find the configmap in the chart templates
|
// find the configmap in the chart templates
|
||||||
for _, fromservice := range fromservices {
|
for _, fromservice := range fromservices {
|
||||||
if _, ok := chart.Templates[fromservice+".configmap.yaml"]; !ok {
|
if _, ok := chart.Templates[fromservice+".configmap.yaml"]; !ok {
|
||||||
log.Printf("configmap %s not found in chart templates", fromservice)
|
logger.Warnf("configmap %s not found in chart templates", fromservice)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// find the corresponding target deployment
|
// find the corresponding target deployment
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package generator
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -311,7 +310,7 @@ func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string, sam
|
|||||||
defer func() {
|
defer func() {
|
||||||
c, index := d.BindMapFilesToContainer(service, secrets, appName)
|
c, index := d.BindMapFilesToContainer(service, secrets, appName)
|
||||||
if c == nil || index == -1 {
|
if c == nil || index == -1 {
|
||||||
log.Println("Container not found for service ", service.Name)
|
logger.Warn("Container not found for service ", service.Name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
d.Spec.Template.Spec.Containers[index] = *c
|
d.Spec.Template.Spec.Containers[index] = *c
|
||||||
@@ -384,8 +383,8 @@ func (d *Deployment) BindMapFilesToContainer(service types.ServiceConfig, secret
|
|||||||
|
|
||||||
if envSize > 0 {
|
if envSize > 0 {
|
||||||
if service.Name == "db" {
|
if service.Name == "db" {
|
||||||
log.Println("Service ", service.Name, " has environment variables")
|
logger.Info("Service ", service.Name, " has environment variables")
|
||||||
log.Println(service.Environment)
|
logger.Info(service.Environment)
|
||||||
}
|
}
|
||||||
fromSources = append(fromSources, corev1.EnvFromSource{
|
fromSources = append(fromSources, corev1.EnvFromSource{
|
||||||
ConfigMapRef: &corev1.ConfigMapEnvSource{
|
ConfigMapRef: &corev1.ConfigMapEnvSource{
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
"katenary.io/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed readme.tpl
|
//go:embed readme.tpl
|
||||||
@@ -50,7 +50,7 @@ func ReadMeFile(charname, description string, values map[string]any) string {
|
|||||||
vv := map[string]any{}
|
vv := map[string]any{}
|
||||||
out, _ := yaml.Marshal(values)
|
out, _ := yaml.Marshal(values)
|
||||||
if err := yaml.Unmarshal(out, &vv); err != nil {
|
if err := yaml.Unmarshal(out, &vv); err != nil {
|
||||||
log.Printf("Error parsing values: %s", err)
|
logger.Warnf("Error parsing values: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
result := make(map[string]string)
|
result := make(map[string]string)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package generator
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -280,7 +279,7 @@ func addStaticVolumes(deployments map[string]*Deployment, service types.ServiceC
|
|||||||
var d *Deployment
|
var d *Deployment
|
||||||
var ok bool
|
var ok bool
|
||||||
if d, ok = deployments[service.Name]; !ok {
|
if d, ok = deployments[service.Name]; !ok {
|
||||||
log.Printf("service %s not found in deployments", service.Name)
|
logger.Warnf("service %s not found in deployments", service.Name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,7 +433,7 @@ func samePodVolume(service types.ServiceConfig, v types.ServiceVolumeConfig, dep
|
|||||||
// check if it has the same volume
|
// check if it has the same volume
|
||||||
for _, tv := range target.Spec.Template.Spec.Volumes {
|
for _, tv := range target.Spec.Template.Spec.Volumes {
|
||||||
if tv.Name == v.Source {
|
if tv.Name == v.Source {
|
||||||
log.Printf("found same pod volume %s in deployment %s and %s", tv.Name, service.Name, targetDeployment)
|
logger.Warnf("found same pod volume %s in deployment %s and %s", tv.Name, service.Name, targetDeployment)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package katenaryfile
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -113,7 +112,7 @@ func getLabelContent(o any, service *types.ServiceConfig, labelName string) erro
|
|||||||
|
|
||||||
c, err := yaml.Marshal(o)
|
c, err := yaml.Marshal(o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
logger.Failure(err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
val := strings.TrimSpace(string(c))
|
val := strings.TrimSpace(string(c))
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package labelstructs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
"katenary.io/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HealthCheck struct {
|
type HealthCheck struct {
|
||||||
@@ -24,13 +24,13 @@ func ProbeFrom(data string) (*HealthCheck, error) {
|
|||||||
if livenessProbe, ok := tmp["livenessProbe"]; ok {
|
if livenessProbe, ok := tmp["livenessProbe"]; ok {
|
||||||
livenessProbeBytes, err := json.Marshal(livenessProbe)
|
livenessProbeBytes, err := json.Marshal(livenessProbe)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error marshalling livenessProbe: %v", err)
|
logger.Warnf("Error marshalling livenessProbe: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
livenessProbe := &corev1.Probe{}
|
livenessProbe := &corev1.Probe{}
|
||||||
err = json.Unmarshal(livenessProbeBytes, livenessProbe)
|
err = json.Unmarshal(livenessProbeBytes, livenessProbe)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error unmarshalling livenessProbe: %v", err)
|
logger.Warnf("Error unmarshalling livenessProbe: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
mapping.LivenessProbe = livenessProbe
|
mapping.LivenessProbe = livenessProbe
|
||||||
@@ -39,13 +39,13 @@ func ProbeFrom(data string) (*HealthCheck, error) {
|
|||||||
if readinessProbe, ok := tmp["readinessProbe"]; ok {
|
if readinessProbe, ok := tmp["readinessProbe"]; ok {
|
||||||
readinessProbeBytes, err := json.Marshal(readinessProbe)
|
readinessProbeBytes, err := json.Marshal(readinessProbe)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error marshalling readinessProbe: %v", err)
|
logger.Warnf("Error marshalling readinessProbe: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
readinessProbe := &corev1.Probe{}
|
readinessProbe := &corev1.Probe{}
|
||||||
err = json.Unmarshal(readinessProbeBytes, readinessProbe)
|
err = json.Unmarshal(readinessProbeBytes, readinessProbe)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error unmarshalling readinessProbe: %v", err)
|
logger.Warnf("Error unmarshalling readinessProbe: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
mapping.ReadinessProbe = readinessProbe
|
mapping.ReadinessProbe = readinessProbe
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package generator
|
package generator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"katenary.io/internal/logger"
|
||||||
"katenary.io/internal/parser"
|
"katenary.io/internal/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ func setup(content string) string {
|
|||||||
|
|
||||||
func teardown(tmpDir string) {
|
func teardown(tmpDir string) {
|
||||||
// remove the temporary directory
|
// remove the temporary directory
|
||||||
log.Println("Removing temporary directory: ", tmpDir)
|
logger.Info("Removing temporary directory: ", tmpDir)
|
||||||
if err := os.RemoveAll(tmpDir); err != nil {
|
if err := os.RemoveAll(tmpDir); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ func compileTest(t *testing.T, force bool, options ...string) string {
|
|||||||
ChartVersion: chartVersion,
|
ChartVersion: chartVersion,
|
||||||
}
|
}
|
||||||
if err := Convert(convertOptions, "compose.yml"); err != nil {
|
if err := Convert(convertOptions, "compose.yml"); err != nil {
|
||||||
log.Printf("Failed to convert: %s", err)
|
logger.Warnf("Failed to convert: %s", err)
|
||||||
return err.Error()
|
return err.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,34 +27,72 @@ const (
|
|||||||
|
|
||||||
const reset = "\033[0m"
|
const reset = "\033[0m"
|
||||||
|
|
||||||
|
// Print prints a message without icon.
|
||||||
|
func Print(msg ...any) {
|
||||||
|
fmt.Print(msg...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Printf prints a formatted message without icon.
|
||||||
|
func Printf(format string, msg ...any) {
|
||||||
|
fmt.Printf(format, msg...)
|
||||||
|
}
|
||||||
|
|
||||||
// Info prints an informational message.
|
// Info prints an informational message.
|
||||||
func Info(msg ...any) {
|
func Info(msg ...any) {
|
||||||
message("", IconInfo, msg...)
|
message("", IconInfo, msg...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Infof prints a formatted informational message.
|
||||||
|
func Infof(format string, msg ...any) {
|
||||||
|
message("", IconInfo, fmt.Sprintf(format, msg...))
|
||||||
|
}
|
||||||
|
|
||||||
// Warn prints a warning message.
|
// Warn prints a warning message.
|
||||||
func Warn(msg ...any) {
|
func Warn(msg ...any) {
|
||||||
orange := "\033[38;5;214m"
|
orange := "\033[38;5;214m"
|
||||||
message(orange, IconWarning, msg...)
|
message(orange, IconWarning, msg...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Warnf prints a formatted warning message.
|
||||||
|
func Warnf(format string, msg ...any) {
|
||||||
|
orange := "\033[38;5;214m"
|
||||||
|
message(orange, IconWarning, fmt.Sprintf(format, msg...))
|
||||||
|
}
|
||||||
|
|
||||||
// Success prints a success message.
|
// Success prints a success message.
|
||||||
func Success(msg ...any) {
|
func Success(msg ...any) {
|
||||||
green := "\033[38;5;34m"
|
green := "\033[38;5;34m"
|
||||||
message(green, IconSuccess, msg...)
|
message(green, IconSuccess, msg...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Successf prints a formatted success message.
|
||||||
|
func Successf(format string, msg ...any) {
|
||||||
|
green := "\033[38;5;34m"
|
||||||
|
message(green, IconSuccess, fmt.Sprintf(format, msg...))
|
||||||
|
}
|
||||||
|
|
||||||
// Failure prints a failure message.
|
// Failure prints a failure message.
|
||||||
func Failure(msg ...any) {
|
func Failure(msg ...any) {
|
||||||
red := "\033[38;5;196m"
|
red := "\033[38;5;196m"
|
||||||
message(red, IconFailure, msg...)
|
message(red, IconFailure, msg...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Failuref prints a formatted failure message.
|
||||||
|
func Failuref(format string, msg ...any) {
|
||||||
|
red := "\033[38;5;196m"
|
||||||
|
message(red, IconFailure, fmt.Sprintf(format, msg...))
|
||||||
|
}
|
||||||
|
|
||||||
// Log prints a message with a custom icon.
|
// Log prints a message with a custom icon.
|
||||||
func Log(icon Icon, msg ...any) {
|
func Log(icon Icon, msg ...any) {
|
||||||
message("", icon, msg...)
|
message("", icon, msg...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logf prints a formatted message with a custom icon.
|
||||||
|
func Logf(icon Icon, format string, msg ...any) {
|
||||||
|
message("", icon, fmt.Sprintf(format, msg...))
|
||||||
|
}
|
||||||
|
|
||||||
func fatal(red string, icon Icon, msg ...any) {
|
func fatal(red string, icon Icon, msg ...any) {
|
||||||
fmt.Print(icon, " ", red)
|
fmt.Print(icon, " ", red)
|
||||||
fmt.Print(msg...)
|
fmt.Print(msg...)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -133,7 +132,7 @@ func GetValuesFromLabel(service types.ServiceConfig, LabelValues string) map[str
|
|||||||
labelContent := []any{}
|
labelContent := []any{}
|
||||||
err := yaml.Unmarshal([]byte(v), &labelContent)
|
err := yaml.Unmarshal([]byte(v), &labelContent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error parsing label %s: %s", v, err)
|
logger.Warnf("Error parsing label %s: %s", v, err)
|
||||||
logger.Fatal(err)
|
logger.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user