3 Commits

Author SHA1 Message Date
584bcc6033 Fix typo
not important but...
2025-09-14 14:18:53 +02:00
aeff9215aa Fixup comments remove hard coded tagname 2025-09-14 14:16:19 +02:00
33e74b9758 feat(install)
All checks were successful
Go-Tests / tests (pull_request) Successful in 1m38s
Go-Tests / sonar (pull_request) Successful in 39s
Installation should now be taken from katenary.io
2025-09-05 10:11:16 +02:00
23 changed files with 209 additions and 321 deletions

View File

@@ -67,7 +67,7 @@ jobs:
echo "Building binary version $VERSION"
mkdir -p dist
GOARCH=${{ matrix.goarch }} GOOS=${{ matrix.goos }}\
go build -ldflags="-X 'repo.katenary.io/katenary/katenary/internal/generator.Version=v$VERSION'" \
go build -ldflags="-X 'repo.katenary.io/katenary/katenary/internal/generator.Version=$VERSION'" \
-trimpath -o dist/katenary-${{ matrix.goos }}-${{ matrix.goarch }} ./cmd/katenary
- name: Package (Linux)

View File

@@ -5,18 +5,10 @@ on:
types:
- opened
- edited
paths-ignore:
- "doc/**"
- "README.md"
- "*.sh"
push:
branches:
- "master"
- "main"
paths-ignore:
- "doc/**"
- "README.md"
- "*.sh"
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
@@ -41,9 +33,7 @@ jobs:
- name: Launch Test
run: |
go vet ./...
go test -tags ci -coverprofile=coverprofile.out -v ./...
go test -tags ci -coverprofile=coverprofile.out -json -v ./... > gotest.json
go tool cover -func=coverprofile.out
go test -coverprofile=coverprofile.out -json -v ./... > gotest.json
# - uses: actions/upload-artifact@v4
- name: Upload artifact
uses: christopherhx/gitea-upload-artifact@v4

View File

@@ -35,7 +35,7 @@ var Version = "master" // changed at compile time
```
<a name="Convert"></a>
## func [Convert](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/converter.go#L101>)
## func [Convert](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/converter.go#L100>)
```go
func Convert(config ConvertOptions, dockerComposeFile ...string) error
@@ -107,7 +107,7 @@ func UnWrapTPL(in []byte) []byte
UnWrapTPL removes the line wrapping from a template.
<a name="ChartTemplate"></a>
## type [ChartTemplate](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/chart.go#L23-L26>)
## type [ChartTemplate](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/chart.go#L22-L25>)
ChartTemplate is a template of a chart. It contains the content of the template and the name of the service. This is used internally to generate the templates.
@@ -119,7 +119,7 @@ type ChartTemplate struct {
```
<a name="ConfigMap"></a>
## type [ConfigMap](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L39-L44>)
## type [ConfigMap](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L38-L43>)
ConfigMap is a kubernetes ConfigMap. Implements the DataMap interface.
@@ -131,7 +131,7 @@ type ConfigMap struct {
```
<a name="NewConfigMap"></a>
### func [NewConfigMap](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L48>)
### func [NewConfigMap](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L47>)
```go
func NewConfigMap(service types.ServiceConfig, appName string, forFile bool) *ConfigMap
@@ -140,7 +140,7 @@ func NewConfigMap(service types.ServiceConfig, appName string, forFile bool) *Co
NewConfigMap creates a new ConfigMap from a compose service. The appName is the name of the application taken from the project name. The ConfigMap is filled by environment variables and labels "map\-env".
<a name="NewConfigMapFromDirectory"></a>
### func [NewConfigMapFromDirectory](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L121>)
### func [NewConfigMapFromDirectory](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L120>)
```go
func NewConfigMapFromDirectory(service types.ServiceConfig, appName, path string) *ConfigMap
@@ -149,7 +149,7 @@ func NewConfigMapFromDirectory(service types.ServiceConfig, appName, path string
NewConfigMapFromDirectory creates a new ConfigMap from a compose service. This path is the path to the file or directory. If the path is a directory, all files in the directory are added to the ConfigMap. Each subdirectory are ignored. Note that the Generate\(\) function will create the subdirectories ConfigMaps.
<a name="ConfigMap.AddBinaryData"></a>
### func \(\*ConfigMap\) [AddBinaryData](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L159>)
### func \(\*ConfigMap\) [AddBinaryData](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L158>)
```go
func (c *ConfigMap) AddBinaryData(key string, value []byte)
@@ -158,7 +158,7 @@ func (c *ConfigMap) AddBinaryData(key string, value []byte)
AddBinaryData adds binary data to the configmap. Append or overwrite the value if the key already exists.
<a name="ConfigMap.AddData"></a>
### func \(\*ConfigMap\) [AddData](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L154>)
### func \(\*ConfigMap\) [AddData](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L153>)
```go
func (c *ConfigMap) AddData(key, value string)
@@ -167,7 +167,7 @@ func (c *ConfigMap) AddData(key, value string)
AddData adds a key value pair to the configmap. Append or overwrite the value if the key already exists.
<a name="ConfigMap.AppendDir"></a>
### func \(\*ConfigMap\) [AppendDir](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L168>)
### func \(\*ConfigMap\) [AppendDir](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L167>)
```go
func (c *ConfigMap) AppendDir(path string) error
@@ -176,7 +176,7 @@ func (c *ConfigMap) AppendDir(path string) error
AppendDir adds files from given path to the configmap. It is not recursive, to add all files in a directory, you need to call this function for each subdirectory.
<a name="ConfigMap.AppendFile"></a>
### func \(\*ConfigMap\) [AppendFile](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L215>)
### func \(\*ConfigMap\) [AppendFile](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L214>)
```go
func (c *ConfigMap) AppendFile(path string) error
@@ -185,7 +185,7 @@ func (c *ConfigMap) AppendFile(path string) error
<a name="ConfigMap.Filename"></a>
### func \(\*ConfigMap\) [Filename](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L239>)
### func \(\*ConfigMap\) [Filename](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L238>)
```go
func (c *ConfigMap) Filename() string
@@ -194,7 +194,7 @@ func (c *ConfigMap) Filename() string
Filename returns the filename of the configmap. If the configmap is used for files, the filename contains the path.
<a name="ConfigMap.SetData"></a>
### func \(\*ConfigMap\) [SetData](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L249>)
### func \(\*ConfigMap\) [SetData](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L248>)
```go
func (c *ConfigMap) SetData(data map[string]string)
@@ -203,7 +203,7 @@ func (c *ConfigMap) SetData(data map[string]string)
SetData sets the data of the configmap. It replaces the entire data.
<a name="ConfigMap.Yaml"></a>
### func \(\*ConfigMap\) [Yaml](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L254>)
### func \(\*ConfigMap\) [Yaml](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L253>)
```go
func (c *ConfigMap) Yaml() ([]byte, error)
@@ -212,7 +212,7 @@ func (c *ConfigMap) Yaml() ([]byte, error)
Yaml returns the yaml representation of the configmap
<a name="ConfigMapMount"></a>
## type [ConfigMapMount](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L30-L33>)
## type [ConfigMapMount](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L29-L32>)
@@ -223,7 +223,7 @@ type ConfigMapMount struct {
```
<a name="ConvertOptions"></a>
## type [ConvertOptions](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/chart.go#L29-L38>)
## type [ConvertOptions](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/chart.go#L28-L37>)
ConvertOptions are the options to convert a compose project to a helm chart.
@@ -301,7 +301,7 @@ type DataMap interface {
```
<a name="Deployment"></a>
## type [Deployment](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L36-L46>)
## type [Deployment](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L35-L45>)
Deployment is a kubernetes Deployment.
@@ -313,7 +313,7 @@ type Deployment struct {
```
<a name="NewDeployment"></a>
### func [NewDeployment](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L50>)
### func [NewDeployment](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L49>)
```go
func NewDeployment(service types.ServiceConfig, chart *HelmChart) *Deployment
@@ -322,7 +322,7 @@ func NewDeployment(service types.ServiceConfig, chart *HelmChart) *Deployment
NewDeployment creates a new Deployment from a compose service. The appName is the name of the application taken from the project name. It also creates the Values map that will be used to create the values.yaml file.
<a name="Deployment.AddContainer"></a>
### func \(\*Deployment\) [AddContainer](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L117>)
### func \(\*Deployment\) [AddContainer](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L116>)
```go
func (d *Deployment) AddContainer(service types.ServiceConfig)
@@ -331,7 +331,7 @@ func (d *Deployment) AddContainer(service types.ServiceConfig)
AddContainer adds a container to the deployment.
<a name="Deployment.AddHealthCheck"></a>
### func \(\*Deployment\) [AddHealthCheck](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L164>)
### func \(\*Deployment\) [AddHealthCheck](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L163>)
```go
func (d *Deployment) AddHealthCheck(service types.ServiceConfig, container *corev1.Container)
@@ -340,7 +340,7 @@ func (d *Deployment) AddHealthCheck(service types.ServiceConfig, container *core
<a name="Deployment.AddIngress"></a>
### func \(\*Deployment\) [AddIngress](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L193>)
### func \(\*Deployment\) [AddIngress](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L192>)
```go
func (d *Deployment) AddIngress(service types.ServiceConfig, appName string) *Ingress
@@ -349,7 +349,7 @@ func (d *Deployment) AddIngress(service types.ServiceConfig, appName string) *In
AddIngress adds an ingress to the deployment. It creates the ingress object.
<a name="Deployment.AddLegacyVolume"></a>
### func \(\*Deployment\) [AddLegacyVolume](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L223>)
### func \(\*Deployment\) [AddLegacyVolume](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L222>)
```go
func (d *Deployment) AddLegacyVolume(name, kind string)
@@ -358,7 +358,7 @@ func (d *Deployment) AddLegacyVolume(name, kind string)
<a name="Deployment.AddVolumes"></a>
### func \(\*Deployment\) [AddVolumes](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L199>)
### func \(\*Deployment\) [AddVolumes](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L198>)
```go
func (d *Deployment) AddVolumes(service types.ServiceConfig, appName string)
@@ -367,7 +367,7 @@ func (d *Deployment) AddVolumes(service types.ServiceConfig, appName string)
AddVolumes adds a volume to the deployment. It does not create the PVC, it only adds the volumes to the deployment. If the volume is a bind volume it will warn the user that it is not supported yet.
<a name="Deployment.BindFrom"></a>
### func \(\*Deployment\) [BindFrom](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L244>)
### func \(\*Deployment\) [BindFrom](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L243>)
```go
func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment)
@@ -376,7 +376,7 @@ func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment)
<a name="Deployment.BindMapFilesToContainer"></a>
### func \(\*Deployment\) [BindMapFilesToContainer](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L378>)
### func \(\*Deployment\) [BindMapFilesToContainer](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L377>)
```go
func (d *Deployment) BindMapFilesToContainer(service types.ServiceConfig, secrets []string, appName string) (*corev1.Container, int)
@@ -385,7 +385,7 @@ func (d *Deployment) BindMapFilesToContainer(service types.ServiceConfig, secret
<a name="Deployment.DependsOn"></a>
### func \(\*Deployment\) [DependsOn](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L272>)
### func \(\*Deployment\) [DependsOn](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L271>)
```go
func (d *Deployment) DependsOn(to *Deployment, servicename string) error
@@ -394,7 +394,7 @@ func (d *Deployment) DependsOn(to *Deployment, servicename string) error
DependsOn adds a initContainer to the deployment that will wait for the service to be up.
<a name="Deployment.Filename"></a>
### func \(\*Deployment\) [Filename](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L303>)
### func \(\*Deployment\) [Filename](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L302>)
```go
func (d *Deployment) Filename() string
@@ -403,7 +403,7 @@ func (d *Deployment) Filename() string
Filename returns the filename of the deployment.
<a name="Deployment.MountExchangeVolumes"></a>
### func \(\*Deployment\) [MountExchangeVolumes](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L429>)
### func \(\*Deployment\) [MountExchangeVolumes](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L428>)
```go
func (d *Deployment) MountExchangeVolumes()
@@ -412,7 +412,7 @@ func (d *Deployment) MountExchangeVolumes()
<a name="Deployment.SetEnvFrom"></a>
### func \(\*Deployment\) [SetEnvFrom](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L308>)
### func \(\*Deployment\) [SetEnvFrom](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L307>)
```go
func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string, samePod ...bool)
@@ -421,7 +421,7 @@ func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string, sam
SetEnvFrom sets the environment variables to a configmap. The configmap is created.
<a name="Deployment.Yaml"></a>
### func \(\*Deployment\) [Yaml](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L453>)
### func \(\*Deployment\) [Yaml](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L452>)
```go
func (d *Deployment) Yaml() ([]byte, error)
@@ -430,7 +430,7 @@ func (d *Deployment) Yaml() ([]byte, error)
Yaml returns the yaml representation of the deployment.
<a name="FileMapUsage"></a>
## type [FileMapUsage](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L23>)
## type [FileMapUsage](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/configMap.go#L22>)
FileMapUsage is the usage of the filemap.
@@ -448,7 +448,7 @@ const (
```
<a name="HelmChart"></a>
## type [HelmChart](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/chart.go#L42-L55>)
## type [HelmChart](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/chart.go#L41-L54>)
HelmChart is a Helm Chart representation. It contains all the templates, values, versions, helpers...
@@ -491,7 +491,7 @@ The Generate function will create the HelmChart object this way:
- Merge the same\-pod services.
<a name="NewChart"></a>
### func [NewChart](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/chart.go#L58>)
### func [NewChart](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/chart.go#L57>)
```go
func NewChart(name string) *HelmChart
@@ -500,7 +500,7 @@ func NewChart(name string) *HelmChart
NewChart creates a new empty chart with the given name.
<a name="HelmChart.SaveTemplates"></a>
### func \(\*HelmChart\) [SaveTemplates](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/chart.go#L73>)
### func \(\*HelmChart\) [SaveTemplates](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/chart.go#L72>)
```go
func (chart *HelmChart) SaveTemplates(templateDir string)

View File

@@ -12,7 +12,7 @@ A katenary file, named "katenary.yml" or "katenary.yaml", is a file where you ca
Formely, the file describe the same structure as in labels, and so that can be validated and completed by LSP. It also ease the use of katenary.
## func [GenerateSchema](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/katenaryfile/main.go#L137>)
## func [GenerateSchema](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/katenaryfile/main.go#L138>)
```go
func GenerateSchema() string
@@ -21,7 +21,7 @@ func GenerateSchema() string
GenerateSchema generates the schema for the katenary.yaml file.
<a name="OverrideWithConfig"></a>
## func [OverrideWithConfig](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/katenaryfile/main.go#L49>)
## func [OverrideWithConfig](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/katenaryfile/main.go#L50>)
```go
func OverrideWithConfig(project *types.Project)
@@ -30,7 +30,7 @@ func OverrideWithConfig(project *types.Project)
OverrideWithConfig overrides the project with the katenary.yaml file. It will set the labels of the services with the values from the katenary.yaml file. It work in memory, so it will not modify the original project.
<a name="Service"></a>
## type [Service](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/katenaryfile/main.go#L27-L44>)
## type [Service](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/katenaryfile/main.go#L28-L45>)
Service is a struct that contains the service configuration for katenary
@@ -56,7 +56,7 @@ type Service struct {
```
<a name="StringOrMap"></a>
## type [StringOrMap](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/katenaryfile/main.go#L24>)
## type [StringOrMap](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/katenaryfile/main.go#L25>)
StringOrMap is a struct that can be either a string or a map of strings. It's a helper struct to unmarshal the katenary.yaml file and produce the schema

View File

@@ -1,83 +0,0 @@
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
# logger
```go
import "katenary.io/internal/logger"
```
Package logger provides simple logging functions with icons and colors.
## func [Failure](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/logger/logger.go#L43>)
```go
func Failure(msg ...any)
```
Failure prints a failure message.
<a name="Info"></a>
## func [Info](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/logger/logger.go#L26>)
```go
func Info(msg ...any)
```
Info prints an informational message.
<a name="Log"></a>
## func [Log](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/logger/logger.go#L49>)
```go
func Log(icon Icon, msg ...any)
```
Log prints a message with a custom icon.
<a name="Success"></a>
## func [Success](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/logger/logger.go#L37>)
```go
func Success(msg ...any)
```
Success prints a success message.
<a name="Warn"></a>
## func [Warn](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/logger/logger.go#L31>)
```go
func Warn(msg ...any)
```
Warn prints a warning message.
<a name="Icon"></a>
## type [Icon](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/logger/logger.go#L5>)
Icon is a unicode icon
```go
type Icon string
```
<a name="IconSuccess"></a>Icons used in katenary.
```go
const (
IconSuccess Icon = "✅"
IconFailure Icon = "❌"
IconWarning Icon = "❕"
IconNote Icon = "📝"
IconWorld Icon = "🌐"
IconPlug Icon = "🔌"
IconPackage Icon = "📦"
IconCabinet Icon = "🗄️"
IconInfo Icon = "🔵"
IconSecret Icon = "🔒"
IconConfig Icon = "🔧"
IconDependency Icon = "🔗"
)
```
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)

View File

@@ -17,7 +17,7 @@ const DirectoryPermission = 0o755
```
<a name="AsResourceName"></a>
## func [AsResourceName](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L197>)
## func [AsResourceName](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L196>)
```go
func AsResourceName(name string) string
@@ -26,16 +26,16 @@ func AsResourceName(name string) string
AsResourceName returns a resource name with underscores to respect the kubernetes naming convention. It's the opposite of FixedResourceName.
<a name="Confirm"></a>
## func [Confirm](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L165>)
## func [Confirm](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L164>)
```go
func Confirm(question string, icon ...logger.Icon) bool
func Confirm(question string, icon ...Icon) bool
```
Confirm asks a question and returns true if the answer is y.
<a name="CountStartingSpaces"></a>
## func [CountStartingSpaces](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L42>)
## func [CountStartingSpaces](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L41>)
```go
func CountStartingSpaces(line string) int
@@ -44,7 +44,7 @@ func CountStartingSpaces(line string) int
CountStartingSpaces counts the number of spaces at the beginning of a string.
<a name="EncodeBasicYaml"></a>
## func [EncodeBasicYaml](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L179>)
## func [EncodeBasicYaml](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L178>)
```go
func EncodeBasicYaml(data any) ([]byte, error)
@@ -53,7 +53,7 @@ func EncodeBasicYaml(data any) ([]byte, error)
EncodeBasicYaml encodes a basic yaml from an interface.
<a name="FixedResourceName"></a>
## func [FixedResourceName](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L191>)
## func [FixedResourceName](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L190>)
```go
func FixedResourceName(name string) string
@@ -62,7 +62,7 @@ func FixedResourceName(name string) string
FixedResourceName returns a resource name without underscores to respect the kubernetes naming convention.
<a name="GetContainerByName"></a>
## func [GetContainerByName](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L88>)
## func [GetContainerByName](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L87>)
```go
func GetContainerByName(name string, containers []corev1.Container) (*corev1.Container, int)
@@ -71,7 +71,7 @@ func GetContainerByName(name string, containers []corev1.Container) (*corev1.Con
GetContainerByName returns a container by name and its index in the array. It returns nil, \-1 if not found.
<a name="GetKind"></a>
## func [GetKind](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L55>)
## func [GetKind](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L54>)
```go
func GetKind(path string) (kind string)
@@ -80,7 +80,7 @@ func GetKind(path string) (kind string)
GetKind returns the kind of the resource from the file path.
<a name="GetServiceNameByPort"></a>
## func [GetServiceNameByPort](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L78>)
## func [GetServiceNameByPort](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L77>)
```go
func GetServiceNameByPort(port int) string
@@ -89,7 +89,7 @@ func GetServiceNameByPort(port int) string
GetServiceNameByPort returns the service name for a port. It the service name is not found, it returns an empty string.
<a name="GetValuesFromLabel"></a>
## func [GetValuesFromLabel](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L130>)
## func [GetValuesFromLabel](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L129>)
```go
func GetValuesFromLabel(service types.ServiceConfig, LabelValues string) map[string]*EnvConfig
@@ -107,7 +107,7 @@ func HashComposefiles(files []string) (string, error)
HashComposefiles returns a hash of the compose files.
<a name="Int32Ptr"></a>
## func [Int32Ptr](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L36>)
## func [Int32Ptr](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L35>)
```go
func Int32Ptr(i int32) *int32
@@ -116,7 +116,7 @@ func Int32Ptr(i int32) *int32
Int32Ptr returns a pointer to an int32.
<a name="PathToName"></a>
## func [PathToName](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L107>)
## func [PathToName](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L106>)
```go
func PathToName(path string) string
@@ -125,7 +125,7 @@ func PathToName(path string) string
PathToName converts a path to a kubernetes complient name.
<a name="StrPtr"></a>
## func [StrPtr](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L39>)
## func [StrPtr](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L38>)
```go
func StrPtr(s string) *string
@@ -134,7 +134,7 @@ func StrPtr(s string) *string
StrPtr returns a pointer to a string.
<a name="TplName"></a>
## func [TplName](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L23>)
## func [TplName](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L22>)
```go
func TplName(serviceName, appname string, suffix ...string) string
@@ -143,7 +143,7 @@ func TplName(serviceName, appname string, suffix ...string) string
TplName returns the name of the kubernetes resource as a template string. It is used in the templates and defined in \_helper.tpl file.
<a name="TplValue"></a>
## func [TplValue](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L98>)
## func [TplValue](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L97>)
```go
func TplValue(serviceName, variable string, pipes ...string) string
@@ -151,8 +151,17 @@ func TplValue(serviceName, variable string, pipes ...string) string
TplValue returns a string that can be used in a template to access a value from the values file.
<a name="Warn"></a>
## func [Warn](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/icons.go#L25>)
```go
func Warn(msg ...any)
```
Warn prints a warning message
<a name="WordWrap"></a>
## func [WordWrap](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L160>)
## func [WordWrap](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L159>)
```go
func WordWrap(text string, lineWidth int) string
@@ -161,7 +170,7 @@ func WordWrap(text string, lineWidth int) string
WordWrap wraps a string to a given line width. Warning: it may break the string. You need to check the result.
<a name="Wrap"></a>
## func [Wrap](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L72>)
## func [Wrap](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L71>)
```go
func Wrap(src, above, below string) string
@@ -170,7 +179,7 @@ func Wrap(src, above, below string) string
Wrap wraps a string with a string above and below. It will respect the indentation of the src string.
<a name="EnvConfig"></a>
## type [EnvConfig](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L124-L127>)
## type [EnvConfig](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L123-L126>)
EnvConfig is a struct to hold the description of an environment variable.
@@ -181,4 +190,32 @@ type EnvConfig struct {
}
```
<a name="Icon"></a>
## type [Icon](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/icons.go#L6>)
Icon is a unicode icon
```go
type Icon string
```
<a name="IconSuccess"></a>Icons used in katenary.
```go
const (
IconSuccess Icon = "✅"
IconFailure Icon = "❌"
IconWarning Icon = "❕"
IconNote Icon = "📝"
IconWorld Icon = "🌐"
IconPlug Icon = "🔌"
IconPackage Icon = "📦"
IconCabinet Icon = "🗄️"
IconInfo Icon = "🔵"
IconSecret Icon = "🔒"
IconConfig Icon = "🔧"
IconDependency Icon = "🔗"
)
```
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)

View File

@@ -4,20 +4,25 @@
# Can be launched with the following command:
# sh <(curl -sSL https://raw.githubusercontent.com/Katenary/katenary/master/install.sh)
set -e
# Detect the OS and architecture
OS=$(uname)
ARCH=$(uname -m)
for c in curl grep cut tr; do
if ! command -v $c >/dev/null 2>&1; then
echo "Error: $c is not installed"
exit 1
fi
done
# Detect the home directory "bin" directory, it is commonly:
# - $HOME/.local/bin
# - $HOME/.bin
# - $HOME/bin
COMON_INSTALL_PATHS="$HOME/.local/bin $HOME/.bin $HOME/bin"
COMMON_INSTALL_PATHS="$HOME/.local/bin $HOME/.bin $HOME/bin"
INSTALL_PATH=""
for p in $COMON_INSTALL_PATHS; do
for p in $COMMON_INSTALL_PATHS; do
if [ -d $p ]; then
INSTALL_PATH=$p
break
@@ -43,20 +48,20 @@ if ! echo "$PATH" | grep -q "$INSTALL_PATH"; then
fi
# Where to download the binary
BASE="https://github.com/Katenary/katenary/releases/latest/download/"
TAG=$(curl -sLf https://repo.katenary.io/api/v1/repos/katenary/katenary/releases/latest 2>/dev/null | grep -Po '"tag_name":\s*"[^"]*"' | cut -d ":" -f2 | tr -d '"')
# for compatibility with older ARM versions
# use the right names for the OS and architecture
if [ $ARCH = "x86_64" ]; then
ARCH="amd64"
fi
BIN_URL="$BASE/katenary-$OS-$ARCH"
BIN_URL="https://repo.katenary.io/api/packages/Katenary/generic/katenary/$TAG/katenary-$OS-$ARCH"
echo
echo "Downloading $BIN_URL"
T=$(mktemp -u)
curl -SL -# $BIN_URL -o $T || (echo "Failed to download katenary" && rm -f $T && exit 1)
curl -sLf -# $BIN_URL -o $T 2>/dev/null || (echo -e "Failed to download katenary version $TAG.\n\nPlease open an issue and explain the problem, following the link:\nhttps://repo.katenary.io/Katenary/katenary/issues/new?title=[install.sh]%20Install%20$TAG%20failed" && rm -f $T && exit 1)
mv "$T" "${INSTALL_PATH}/katenary"
chmod +x "${INSTALL_PATH}/katenary"

View File

@@ -11,7 +11,6 @@ import (
"katenary.io/internal/generator/labels"
"katenary.io/internal/generator/labels/labelstructs"
"katenary.io/internal/logger"
"katenary.io/internal/utils"
"github.com/compose-spec/compose-go/types"
@@ -78,36 +77,36 @@ func (chart *HelmChart) SaveTemplates(templateDir string) {
// t = addModeline(t)
kind := utils.GetKind(name)
var icon logger.Icon
var icon utils.Icon
switch kind {
case "deployment":
icon = logger.IconPackage
icon = utils.IconPackage
case "service":
icon = logger.IconPlug
icon = utils.IconPlug
case "ingress":
icon = logger.IconWorld
icon = utils.IconWorld
case "volumeclaim":
icon = logger.IconCabinet
icon = utils.IconCabinet
case "configmap":
icon = logger.IconConfig
icon = utils.IconConfig
case "secret":
icon = logger.IconSecret
icon = utils.IconSecret
default:
icon = logger.IconInfo
icon = utils.IconInfo
}
servicename := template.Servicename
if err := os.MkdirAll(filepath.Join(templateDir, servicename), utils.DirectoryPermission); err != nil {
logger.Failure(err.Error())
fmt.Println(utils.IconFailure, err)
os.Exit(1)
}
logger.Log(icon, "Creating ", kind, " ", name)
fmt.Println(icon, "Creating", kind, servicename)
// if the name is a path, create the directory
if strings.Contains(name, string(filepath.Separator)) {
name = filepath.Join(templateDir, name)
err := os.MkdirAll(filepath.Dir(name), utils.DirectoryPermission)
if err != nil {
logger.Failure(err.Error())
fmt.Println(utils.IconFailure, err)
os.Exit(1)
}
} else {
@@ -117,14 +116,14 @@ func (chart *HelmChart) SaveTemplates(templateDir string) {
}
f, err := os.Create(name)
if err != nil {
fmt.Println(logger.IconFailure, err)
fmt.Println(utils.IconFailure, err)
os.Exit(1)
}
defer f.Close()
if _, err := f.Write(t); err != nil {
logger.Failure("error wrting template file: ", err.Error())
os.Exit(1)
log.Fatal("error writing template file:", err)
}
}
}
@@ -145,15 +144,14 @@ func (chart *HelmChart) generateConfigMapsAndSecrets(project *types.Project) err
if v, ok := s.Labels[labels.LabelSecrets]; ok {
list, err := labelstructs.SecretsFrom(v)
if err != nil {
logger.Failure("error unmarshaling secrets label:", err)
os.Exit(1)
log.Fatal("error unmarshaling secrets label:", err)
}
for _, secret := range list {
if secret == "" {
continue
}
if _, ok := s.Environment[secret]; !ok {
fmt.Printf("%s secret %s not found in environment", logger.IconWarning, secret)
fmt.Printf("%s secret %s not found in environment", utils.IconWarning, secret)
continue
}
secretsVar[secret] = s.Environment[secret]
@@ -197,7 +195,7 @@ func (chart *HelmChart) generateDeployment(service types.ServiceConfig, deployme
// isgnored service
if isIgnored(service) {
logger.Info("Ignoring service ", service.Name)
fmt.Printf("%s Ignoring service %s\n", utils.IconInfo, service.Name)
return nil
}
@@ -307,7 +305,7 @@ func (chart *HelmChart) setDependencies(service types.ServiceConfig) (bool, erro
}
for _, dep := range d {
logger.Log(logger.IconDependency, "Adding dependency to ", dep.Name)
fmt.Printf("%s Adding dependency to %s\n", utils.IconDependency, dep.Name)
chart.Dependencies = append(chart.Dependencies, dep)
name := dep.Name
if dep.Alias != "" {

View File

@@ -11,7 +11,6 @@ import (
"katenary.io/internal/generator/labels"
"katenary.io/internal/generator/labels/labelstructs"
"katenary.io/internal/logger"
"katenary.io/internal/utils"
"github.com/compose-spec/compose-go/types"
@@ -179,7 +178,7 @@ func (c *ConfigMap) AppendDir(path string) error {
}
for _, file := range files {
if file.IsDir() {
logger.Warn("Subdirectories are ignored for the moment, skipping", filepath.Join(path, file.Name()))
utils.Warn("Subdirectories are ignored for the moment, skipping", filepath.Join(path, file.Name()))
continue
}
path := filepath.Join(path, file.Name())

View File

@@ -10,7 +10,6 @@ import (
"katenary.io/internal/generator/labels"
"github.com/compose-spec/compose-go/types"
appv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
"sigs.k8s.io/yaml"
)
@@ -118,15 +117,9 @@ services:
io.WriteString(fooFp, fooTxt)
fooFp.Close()
cmOutput := internalCompileTestForce(t, "-s", "templates/web/statics/configmap.yaml")
depOutput := internalCompileTestForce(t, "-s", "templates/web/deployment.yaml")
output := internalCompileTest(t, "-s", "templates/web/statics/configmap.yaml")
configMap := v1.ConfigMap{}
if err := yaml.Unmarshal([]byte(cmOutput), &configMap); err != nil {
t.Errorf(unmarshalError, err)
}
deployment := appv1.Deployment{}
if err := yaml.Unmarshal([]byte(depOutput), &deployment); err != nil {
if err := yaml.Unmarshal([]byte(output), &configMap); err != nil {
t.Errorf(unmarshalError, err)
}
if configMap.Data == nil {
@@ -137,12 +130,4 @@ services:
if !valid.MatchString(configMap.Name) {
t.Errorf("ConfigMap name %s is not valid", configMap.Name)
}
// the volume mount should be named "configmap-<configmap name>"
if deployment.Spec.Template.Spec.Volumes[0].Name != deployment.Spec.Template.Spec.Containers[0].VolumeMounts[0].Name {
t.Errorf("Expected volume name to be %s, got %s",
deployment.Spec.Template.Spec.Containers[0].VolumeMounts[0].Name,
deployment.Spec.Template.Spec.Volumes[0].Name,
)
}
}

View File

@@ -16,7 +16,6 @@ import (
"katenary.io/internal/generator/katenaryfile"
"katenary.io/internal/generator/labels"
"katenary.io/internal/generator/labels/labelstructs"
"katenary.io/internal/logger"
"katenary.io/internal/parser"
"katenary.io/internal/utils"
@@ -112,13 +111,12 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) error {
currentDir, _ := os.Getwd()
// go to the root of the project
if err := os.Chdir(filepath.Dir(dockerComposeFile[0])); err != nil {
logger.Failure(err.Error())
fmt.Println(utils.IconFailure, err)
return err
}
defer func() {
if err := os.Chdir(currentDir); err != nil { // after the generation, go back to the original directory
logger.Failure(err.Error())
os.Exit(1)
log.Fatal(err)
}
}()
@@ -136,7 +134,7 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) error {
// check older version of labels
if err := checkOldLabels(project); err != nil {
logger.Failure(err.Error())
fmt.Println(utils.IconFailure, err)
return err
}
@@ -149,7 +147,7 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) error {
if _, err := os.Stat(config.OutputDir); err == nil {
overwrite := utils.Confirm(
"The chart directory "+config.OutputDir+" already exists, do you want to overwrite it?",
logger.IconWarning,
utils.IconWarning,
)
if !overwrite {
fmt.Println("Aborting")
@@ -401,7 +399,7 @@ func addMainTagAppDoc(values []byte, project *types.Project) []byte {
} else if v == "false" || v == "no" || v == "0" {
continue
} else {
logger.Log(logger.IconConfig, "Adding main tag app doc for service", service.Name)
fmt.Printf("%s Adding main tag app doc %s\n", utils.IconConfig, service.Name)
}
lines = addMainAppDoc(lines, service)
@@ -581,15 +579,15 @@ func buildValues(chart *HelmChart, project *types.Project, valuesPath string) {
func callHelmUpdate(config ConvertOptions) {
executeAndHandleError := func(fn func(ConvertOptions) error, config ConvertOptions, message string) {
if err := fn(config); err != nil {
logger.Failure("Helm command failed, please check the output above", err.Error())
fmt.Println(utils.IconFailure, err)
os.Exit(1)
}
logger.Success(message)
fmt.Println(utils.IconSuccess, message)
}
if config.HelmUpdate {
executeAndHandleError(helmUpdate, config, "Helm dependencies updated")
executeAndHandleError(helmLint, config, "Helm chart linted")
logger.Success("Helm chart created successfully")
fmt.Println(utils.IconSuccess, "Helm chart created successfully")
}
}
@@ -629,7 +627,7 @@ func removeUnwantedLines(values []byte) []byte {
func writeContent(path string, content []byte) {
f, err := os.Create(path)
if err != nil {
logger.Failure("Cannot create file "+path, err.Error())
fmt.Println(utils.IconFailure, err)
os.Exit(1)
}
defer f.Close()
@@ -642,10 +640,10 @@ func writeContent(path string, content []byte) {
// helmLint runs "helm lint" on the output directory.
func helmLint(config ConvertOptions) error {
logger.Info("Linting...")
fmt.Println(utils.IconInfo, "Linting...")
helm, err := exec.LookPath("helm")
if err != nil {
logger.Failure("Helm is not installed or not in your PATH", err.Error())
fmt.Println(utils.IconFailure, err)
os.Exit(1)
}
cmd := exec.Command(helm, "lint", config.OutputDir)
@@ -657,10 +655,10 @@ func helmLint(config ConvertOptions) error {
// helmUpdate runs "helm dependency update" on the output directory.
func helmUpdate(config ConvertOptions) error {
// lookup for "helm" binary
logger.Info("Updating helm dependencies...")
fmt.Println(utils.IconInfo, "Updating helm dependencies...")
helm, err := exec.LookPath("helm")
if err != nil {
fmt.Println(logger.IconFailure, err)
fmt.Println(utils.IconFailure, err)
os.Exit(1)
}
// run "helm dependency update"

View File

@@ -11,7 +11,6 @@ import (
"katenary.io/internal/generator/labels"
"katenary.io/internal/generator/labels/labelstructs"
"katenary.io/internal/logger"
"katenary.io/internal/utils"
"github.com/compose-spec/compose-go/types"
@@ -120,7 +119,7 @@ func (d *Deployment) AddContainer(service types.ServiceConfig) {
for _, port := range service.Ports {
name := utils.GetServiceNameByPort(int(port.Target))
if name == "" {
logger.Warn("Port name not found for port ", port.Target, " in service ", service.Name, ". Using port number instead")
utils.Warn("Port name not found for port ", port.Target, " in service ", service.Name, ". Using port number instead")
name = fmt.Sprintf("port-%d", port.Target)
}
ports = append(ports, corev1.ContainerPort{
@@ -275,7 +274,7 @@ func (d *Deployment) DependsOn(to *Deployment, servicename string) error {
for _, container := range to.Spec.Template.Spec.Containers {
commands := []string{}
if len(container.Ports) == 0 {
logger.Warn("No ports found for service ",
utils.Warn("No ports found for service ",
servicename,
". You should declare a port in the service or use "+
labels.LabelPorts+
@@ -341,7 +340,7 @@ func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string, sam
_, ok := service.Environment[secret]
if !ok {
drop = append(drop, secret)
logger.Warn("Secret " + secret + " not found in service " + service.Name + " - skpped")
utils.Warn("Secret " + secret + " not found in service " + service.Name + " - skpped")
continue
}
secrets = append(secrets, secret)
@@ -358,7 +357,7 @@ func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string, sam
val, ok := service.Environment[value]
if !ok {
drop = append(drop, value)
logger.Warn("Environment variable " + value + " not found in service " + service.Name + " - skpped")
utils.Warn("Environment variable " + value + " not found in service " + service.Name + " - skpped")
continue
}
if d.chart.Values[service.Name].(*Value).Environment == nil {
@@ -414,7 +413,7 @@ func (d *Deployment) BindMapFilesToContainer(service types.ServiceConfig, secret
container, index := utils.GetContainerByName(service.ContainerName, d.Spec.Template.Spec.Containers)
if container == nil {
logger.Warn("Container not found for service " + service.Name)
utils.Warn("Container not found for service " + service.Name)
return nil, -1
}
@@ -678,7 +677,7 @@ func (d *Deployment) bindVolumes(volume types.ServiceVolumeConfig, isSamePod boo
}(d, container, index)
if _, found := tobind[volume.Source]; !isSamePod && volume.Type == "bind" && !found {
logger.Warn(
utils.Warn(
"Bind volumes are not supported yet, " +
"excepting for those declared as " +
labels.LabelConfigMapFiles +
@@ -689,7 +688,7 @@ func (d *Deployment) bindVolumes(volume types.ServiceVolumeConfig, isSamePod boo
}
if container == nil {
logger.Warn("Container not found for volume", volume.Source)
utils.Warn("Container not found for volume", volume.Source)
return
}

View File

@@ -15,6 +15,7 @@ func TestReadMeFile_Basic(t *testing.T) {
}
result := ReadMeFile("testchart", "A test chart", values)
t.Logf("Generated README content:\n%s", result)
paramerRegExp := regexp.MustCompile(`\|\s+` + "`" + `(.*?)` + "`" + `\s+\|\s+` + "`" + `(.*?)` + "`" + `\s+\|`)
matches := paramerRegExp.FindAllStringSubmatch(result, -1)
if len(matches) != 3 {

View File

@@ -233,6 +233,7 @@ func fixResourceNames(project *types.Project) error {
return err
}
for varname, bind := range *vf {
log.Printf("service %s, varname %s, bind %s", service.Name, varname, bind)
bind := strings.ReplaceAll(bind, service.Name, fixed)
(*vf)[varname] = bind
}
@@ -277,7 +278,6 @@ func addStaticVolumes(deployments map[string]*Deployment, service types.ServiceC
if y, err = config.configMap.Yaml(); err != nil {
log.Fatal(err)
}
// add the configmap to the chart
d.chart.Templates[config.configMap.Filename()] = &ChartTemplate{
Content: y,
@@ -285,10 +285,6 @@ func addStaticVolumes(deployments map[string]*Deployment, service types.ServiceC
}
// add the moint path to the container
for _, m := range config.mountPath {
// volumeName can be empty, in this case we generate a name
if volumeName == "" {
volumeName = utils.PathToName(m.subPath)
}
container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{
Name: utils.PathToName(volumeName),
MountPath: m.mountPath,

View File

@@ -3,6 +3,7 @@ package katenaryfile
import (
"bytes"
"encoding/json"
"fmt"
"log"
"os"
"reflect"
@@ -10,7 +11,7 @@ import (
"katenary.io/internal/generator/labels"
"katenary.io/internal/generator/labels/labelstructs"
"katenary.io/internal/logger"
"katenary.io/internal/utils"
"github.com/compose-spec/compose-go/types"
"github.com/invopop/jsonschema"
@@ -59,7 +60,7 @@ func OverrideWithConfig(project *types.Project) {
// no katenary file found
return
}
logger.Info("Using katenary file", yamlFile)
fmt.Println(utils.IconInfo, "Using katenary file", yamlFile)
services := make(map[string]Service)
fp, err := os.Open(yamlFile)
@@ -101,7 +102,7 @@ func OverrideWithConfig(project *types.Project) {
mustGetLabelContent(s.ValuesFrom, &project.Services[i], labels.LabelValuesFrom)
}
}
logger.Info("Katenary file loaded successfully, the services are now configured.")
fmt.Println(utils.IconInfo, "Katenary file loaded successfully, the services are now configured.")
}
func getLabelContent(o any, service *types.ServiceConfig, labelName string) error {

View File

@@ -1,6 +1,7 @@
package katenaryfile
import (
"log"
"os"
"path/filepath"
"testing"
@@ -38,15 +39,18 @@ webapp:
composeFile := filepath.Join(tmpDir, "compose.yaml")
katenaryFile := filepath.Join(tmpDir, "katenary.yaml")
os.MkdirAll(tmpDir, 0o755)
if err := os.WriteFile(composeFile, []byte(composeContent), 0o644); err != nil {
os.MkdirAll(tmpDir, 0755)
if err := os.WriteFile(composeFile, []byte(composeContent), 0644); err != nil {
t.Log(err)
}
if err := os.WriteFile(katenaryFile, []byte(katenaryfileContent), 0o644); err != nil {
if err := os.WriteFile(katenaryFile, []byte(katenaryfileContent), 0644); err != nil {
t.Log(err)
}
defer os.RemoveAll(tmpDir)
c, _ := os.ReadFile(composeFile)
log.Println(string(c))
// chand dir to this directory
os.Chdir(tmpDir)
options, _ := cli.NewProjectOptions(nil,
@@ -88,15 +92,18 @@ webapp:
composeFile := filepath.Join(tmpDir, "compose.yaml")
katenaryFile := filepath.Join(tmpDir, "katenary.yaml")
os.MkdirAll(tmpDir, 0o755)
if err := os.WriteFile(composeFile, []byte(composeContent), 0o644); err != nil {
os.MkdirAll(tmpDir, 0755)
if err := os.WriteFile(composeFile, []byte(composeContent), 0644); err != nil {
t.Log(err)
}
if err := os.WriteFile(katenaryFile, []byte(katenaryfileContent), 0o644); err != nil {
if err := os.WriteFile(katenaryFile, []byte(katenaryfileContent), 0644); err != nil {
t.Log(err)
}
defer os.RemoveAll(tmpDir)
c, _ := os.ReadFile(composeFile)
log.Println(string(c))
// chand dir to this directory
os.Chdir(tmpDir)
options, _ := cli.NewProjectOptions(nil,
@@ -143,15 +150,18 @@ webapp:
composeFile := filepath.Join(tmpDir, "compose.yaml")
katenaryFile := filepath.Join(tmpDir, "katenary.yaml")
os.MkdirAll(tmpDir, 0o755)
if err := os.WriteFile(composeFile, []byte(composeContent), 0o644); err != nil {
os.MkdirAll(tmpDir, 0755)
if err := os.WriteFile(composeFile, []byte(composeContent), 0644); err != nil {
t.Log(err)
}
if err := os.WriteFile(katenaryFile, []byte(katenaryfileContent), 0o644); err != nil {
if err := os.WriteFile(katenaryFile, []byte(katenaryfileContent), 0644); err != nil {
t.Log(err)
}
defer os.RemoveAll(tmpDir)
c, _ := os.ReadFile(composeFile)
log.Println(string(c))
// chand dir to this directory
os.Chdir(tmpDir)
options, _ := cli.NewProjectOptions(nil,

View File

@@ -29,22 +29,13 @@ func teardown(tmpDir string) {
}
}
// internalCompileTestForce is like internalCompileTest but with the force option enabled to rewrite the chart.
func internalCompileTestForce(t *testing.T, options ...string) string {
return compileTest(t, true, options...)
}
// internalCompileTest is like compileTest but without the force option enabled to rewrite the chart.
func internalCompileTest(t *testing.T, options ...string) string {
return compileTest(t, false, options...)
}
func compileTest(t *testing.T, force bool, options ...string) string {
_, err := parser.Parse(nil, nil, "compose.yml")
if err != nil {
t.Fatalf("Failed to parse the project: %s", err)
}
force := false
outputDir := "./chart"
profiles := make([]string, 0)
helmdepUpdate := true

View File

@@ -5,6 +5,7 @@ import (
"image"
"image/color"
"image/png"
"log"
"os"
"path/filepath"
"testing"
@@ -172,6 +173,7 @@ services:
`
composeFile = fmt.Sprintf(composeFile, labels.KatenaryLabelPrefix)
tmpDir := setup(composeFile)
log.Println(tmpDir)
defer teardown(tmpDir)
os.Mkdir(filepath.Join(tmpDir, "images"), utils.DirectoryPermission)
@@ -241,6 +243,7 @@ services:
`
composeFile = fmt.Sprintf(composeFile, labels.KatenaryLabelPrefix)
tmpDir := setup(composeFile)
log.Println(tmpDir)
defer teardown(tmpDir)
os.Mkdir(filepath.Join(tmpDir, "images"), utils.DirectoryPermission)

View File

@@ -1,51 +0,0 @@
// Package logger provides simple logging functions with icons and colors.
package logger
// Icon is a unicode icon
type Icon string
// Icons used in katenary.
const (
IconSuccess Icon = "✅"
IconFailure Icon = "❌"
IconWarning Icon = "❕"
IconNote Icon = "📝"
IconWorld Icon = "🌐"
IconPlug Icon = "🔌"
IconPackage Icon = "📦"
IconCabinet Icon = "🗄️"
IconInfo Icon = "🔵"
IconSecret Icon = "🔒"
IconConfig Icon = "🔧"
IconDependency Icon = "🔗"
)
const reset = "\033[0m"
// Info prints an informational message.
func Info(msg ...any) {
message("", IconInfo, msg...)
}
// Warn prints a warning message.
func Warn(msg ...any) {
orange := "\033[38;5;214m"
message(orange, IconWarning, msg...)
}
// Success prints a success message.
func Success(msg ...any) {
green := "\033[38;5;34m"
message(green, IconSuccess, msg...)
}
// Failure prints a failure message.
func Failure(msg ...any) {
red := "\033[38;5;196m"
message(red, IconFailure, msg...)
}
// Log prints a message with a custom icon.
func Log(icon Icon, msg ...any) {
message("", icon, msg...)
}

View File

@@ -1,12 +0,0 @@
//go:build !ci
// +build !ci
package logger
import "fmt"
func message(color string, icon Icon, msg ...any) {
fmt.Print(icon, " ", color)
fmt.Print(msg...)
fmt.Println(reset)
}

View File

@@ -1,9 +0,0 @@
//go:build ci
// +build ci
package logger
// CI should be no-op
func message(color string, icon Icon, msg ...any) {
// no-op
}

31
internal/utils/icons.go Normal file
View File

@@ -0,0 +1,31 @@
package utils
import "fmt"
// Icon is a unicode icon
type Icon string
// Icons used in katenary.
const (
IconSuccess Icon = "✅"
IconFailure Icon = "❌"
IconWarning Icon = "❕"
IconNote Icon = "📝"
IconWorld Icon = "🌐"
IconPlug Icon = "🔌"
IconPackage Icon = "📦"
IconCabinet Icon = "🗄️"
IconInfo Icon = "🔵"
IconSecret Icon = "🔒"
IconConfig Icon = "🔧"
IconDependency Icon = "🔗"
)
// Warn prints a warning message
func Warn(msg ...any) {
orange := "\033[38;5;214m"
reset := "\033[0m"
fmt.Print(IconWarning, orange, " ")
fmt.Print(msg...)
fmt.Println(reset)
}

View File

@@ -12,7 +12,6 @@ import (
"github.com/thediveo/netdb"
"gopkg.in/yaml.v3"
corev1 "k8s.io/api/core/v1"
"katenary.io/internal/logger"
)
// DirectoryPermission is the default values for permissions apply to created directories.
@@ -65,7 +64,7 @@ func GetKind(path string) (kind string) {
} else {
kind = strings.Split(path, ".")[1]
}
return kind
return
}
// Wrap wraps a string with a string above and below. It will respect the indentation of the src string.
@@ -162,7 +161,7 @@ func WordWrap(text string, lineWidth int) string {
}
// Confirm asks a question and returns true if the answer is y.
func Confirm(question string, icon ...logger.Icon) bool {
func Confirm(question string, icon ...Icon) bool {
if len(icon) > 0 {
fmt.Printf("%s %s [y/N] ", icon[0], question)
} else {