Files
katenary/doc/docs/packages/generator.md

894 lines
19 KiB
Markdown
Raw Normal View History

<!-- Code generated by gomarkdoc. DO NOT EDIT -->
# generator
``` go
import "katenary/generator"
```
The generator package generates kubernetes objects from a compose file
and transforms them into a helm chart.
The generator package is the core of katenary. It is responsible for
generating kubernetes objects from a compose file and transforming them
into a helm chart. Convertion manipulates Yaml representation of
kubernetes object to add conditions, labels, annotations, etc. to the
objects. It also create the values to be set to the values.yaml file.
The generate.Convert() create an HelmChart object and call “Generate()”
method to convert from a compose file to a helm chart. It saves the helm
chart in the given directory.
If you want to change or override the write behavior, you can use the
HelmChart.Generate() function and implement your own write function.
This function returns the helm chart object containing all kubernetes
objects and helm chart ingormation. It does not write the helm chart to
the disk.
TODO: Manage cronjob + rbac TODO: create note.txt TODO: manage emptyDirs
## Constants
``` go
const KATENARY_PREFIX = "katenary.v3/"
```
## Variables
``` go
var (
// Standard annotationss
Annotations = map[string]string{
KATENARY_PREFIX + "version": Version,
}
)
```
Version is the version of katenary. It is set at compile time.
``` go
var Version = "master" // changed at compile time
```
## func Convert
``` go
func Convert(config ConvertOptions, dockerComposeFile ...string)
```
Convert a compose (docker, podman…) project to a helm chart. It calls
Generate() to generate the chart and then write it to the disk.
## func GetLabelHelp
``` go
func GetLabelHelp(asMarkdown bool) string
```
Generate the help for the labels.
## func GetLabelHelpFor
``` go
func GetLabelHelpFor(labelname string, asMarkdown bool) string
```
GetLabelHelpFor returns the help for a specific label.
## func GetLabelNames
``` go
func GetLabelNames() []string
```
GetLabelNames returns a sorted list of all katenary label names.
## func GetLabels
``` go
func GetLabels(serviceName, appName string) map[string]string
```
## func GetMatchLabels
``` go
func GetMatchLabels(serviceName, appName string) map[string]string
```
## func Helper
``` go
func Helper(name string) string
```
Helper returns the \_helpers.tpl file for a chart.
## func NewCronJob
``` go
func NewCronJob(service types.ServiceConfig, chart *HelmChart, appName string) (*CronJob, *RBAC)
```
NewCronJob creates a new CronJob from a compose service. The appName is
the name of the application taken from the project name.
## type ChartTemplate
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.
TODO: maybe we can set it private.
``` go
type ChartTemplate struct {
Content []byte
Servicename string
}
```
## type ConfigMap
ConfigMap is a kubernetes ConfigMap. Implements the DataMap interface.
``` go
type ConfigMap struct {
*corev1.ConfigMap
// contains filtered or unexported fields
}
```
### func NewConfigMap
``` go
func NewConfigMap(service types.ServiceConfig, appName string) *ConfigMap
```
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”.
### func NewConfigMapFromFiles
``` go
func NewConfigMapFromFiles(service types.ServiceConfig, appName string, path string) *ConfigMap
```
NewConfigMapFromFiles 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.
### func (*ConfigMap) AddData
``` go
func (c *ConfigMap) AddData(key string, value string)
```
AddData adds a key value pair to the configmap. Append or overwrite the
value if the key already exists.
### func (*ConfigMap) AppendDir
``` go
func (c *ConfigMap) AppendDir(path string)
```
AddFile 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.
### func (*ConfigMap) Filename
``` go
func (c *ConfigMap) Filename() string
```
Filename returns the filename of the configmap. If the configmap is used
for files, the filename contains the path.
### func (*ConfigMap) SetData
``` go
func (c *ConfigMap) SetData(data map[string]string)
```
SetData sets the data of the configmap. It replaces the entire data.
### func (*ConfigMap) Yaml
``` go
func (c *ConfigMap) Yaml() ([]byte, error)
```
Yaml returns the yaml representation of the configmap
## type ConvertOptions
ConvertOptions are the options to convert a compose project to a helm
chart.
``` go
type ConvertOptions struct {
Force bool // Force the chart directory deletion if it already exists.
OutputDir string // The output directory of the chart.
Profiles []string // Profile to use for the conversion.
HelmUpdate bool // If true, the "helm dep update" command will be run after the chart generation.
AppVersion *string // Set the chart "appVersion" field. If nil, the version will be set to 0.1.0.
ChartVersion string // Set the chart "version" field.
}
```
## type CronJob
CronJob is a kubernetes CronJob.
``` go
type CronJob struct {
*batchv1.CronJob
// contains filtered or unexported fields
}
```
### func (*CronJob) Filename
``` go
func (c *CronJob) Filename() string
```
Filename returns the filename of the cronjob.
Implements the Yaml interface.
### func (*CronJob) Yaml
``` go
func (c *CronJob) Yaml() ([]byte, error)
```
Yaml returns the yaml representation of the cronjob.
Implements the Yaml interface.
## type CronJobValue
CronJobValue is a cronjob configuration that will be saved in
values.yaml.
``` go
type CronJobValue struct {
Repository *RepositoryValue `yaml:"repository,omitempty"`
Environment map[string]any `yaml:"environment,omitempty"`
ImagePullPolicy string `yaml:"imagePullPolicy,omitempty"`
Schedule string `yaml:"schedule"`
}
```
## type DataMap
DataMap is a kubernetes ConfigMap or Secret. It can be used to add data
to the ConfigMap or Secret.
``` go
type DataMap interface {
SetData(map[string]string)
AddData(string, string)
}
```
### func NewFileMap
``` go
func NewFileMap(service types.ServiceConfig, appName string, kind string) DataMap
```
NewFileMap creates a new DataMap from a compose service. The appName is
the name of the application taken from the project name.
## type Dependency
Dependency is a dependency of a chart to other charts.
``` go
type Dependency struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
Repository string `yaml:"repository"`
Alias string `yaml:"alias,omitempty"`
Values map[string]any `yaml:"-"` // do not export to Chart.yaml
}
```
## type Deployment
Deployment is a kubernetes Deployment.
``` go
type Deployment struct {
*appsv1.Deployment `yaml:",inline"`
// contains filtered or unexported fields
}
```
### func NewDeployment
``` go
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.
### func (*Deployment) AddContainer
``` go
func (d *Deployment) AddContainer(service types.ServiceConfig)
```
AddContainer adds a container to the deployment.
### func (*Deployment) AddHealthCheck
``` go
func (d *Deployment) AddHealthCheck(service types.ServiceConfig, container *corev1.Container)
```
### func (*Deployment) AddIngress
``` go
func (d *Deployment) AddIngress(service types.ServiceConfig, appName string) *Ingress
```
AddIngress adds an ingress to the deployment. It creates the ingress
object.
### func (*Deployment) AddVolumes
``` go
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.
### func (*Deployment) BindFrom
``` go
func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment)
```
### func (*Deployment) DependsOn
``` go
func (d *Deployment) DependsOn(to *Deployment) error
```
DependsOn adds a initContainer to the deployment that will wait for the
service to be up.
### func (*Deployment) Filename
``` go
func (d *Deployment) Filename() string
```
### func (*Deployment) SetEnvFrom
``` go
func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string)
```
SetEnvFrom sets the environment variables to a configmap. The configmap
is created.
### func (*Deployment) Yaml
``` go
func (d *Deployment) Yaml() ([]byte, error)
```
Yaml returns the yaml representation of the deployment.
## type FileMapUsage
FileMapUsage is the usage of the filemap.
``` go
type FileMapUsage uint8
```
FileMapUsage constants.
``` go
const (
FileMapUsageConfigMap FileMapUsage = iota // pure configmap for key:values.
FileMapUsageFiles // files in a configmap.
)
```
## type HelmChart
HelmChart is a Helm Chart representation. It contains all the tempaltes,
values, versions, helpers…
``` go
type HelmChart struct {
Name string `yaml:"name"`
ApiVersion string `yaml:"apiVersion"`
Version string `yaml:"version"`
AppVersion string `yaml:"appVersion"`
Description string `yaml:"description"`
Dependencies []Dependency `yaml:"dependencies,omitempty"`
Templates map[string]*ChartTemplate `yaml:"-"` // do not export to yaml
Helper string `yaml:"-"` // do not export to yaml
Values map[string]any `yaml:"-"` // do not export to yaml
VolumeMounts map[string]any `yaml:"-"` // do not export to yaml
// contains filtered or unexported fields
}
```
### func Generate
``` go
func Generate(project *types.Project) (*HelmChart, error)
```
Generate a chart from a compose project. This does not write files to
disk, it only creates the HelmChart object.
The Generate function will create the HelmChart object this way:
1. Detect the service port name or leave the port number if not found.
2. Create a deployment for each service that are not ingnore.
3. Create a service and ingresses for each service that has ports
and/or declared ingresses.
4. Create a PVC or Configmap volumes for each volume.
5. Create init containers for each service which has dependencies to
other services.
6. Create a chart dependencies.
7. Create a configmap and secrets from the environment variables.
8. Merge the same-pod services.
### func NewChart
``` go
func NewChart(name string) *HelmChart
```
NewChart creates a new empty chart with the given name.
## type Help
Help is the documentation of a label.
``` go
type Help struct {
Short string `yaml:"short"`
Long string `yaml:"long"`
Example string `yaml:"example"`
Type string `yaml:"type"`
}
```
## type Ingress
``` go
type Ingress struct {
*networkv1.Ingress
// contains filtered or unexported fields
}
```
### func NewIngress
``` go
func NewIngress(service types.ServiceConfig, Chart *HelmChart) *Ingress
```
NewIngress creates a new Ingress from a compose service.
### func (*Ingress) Filename
``` go
func (ingress *Ingress) Filename() string
```
### func (*Ingress) Yaml
``` go
func (ingress *Ingress) Yaml() ([]byte, error)
```
## type IngressValue
IngressValue is a ingress configuration that will be saved in
values.yaml.
``` go
type IngressValue struct {
Enabled bool `yaml:"enabled"`
Host string `yaml:"host"`
Path string `yaml:"path"`
Class string `yaml:"class"`
Annotations map[string]string `yaml:"annotations"`
}
```
## type Label
Label is a katenary label to find in compose files.
``` go
type Label = string
```
Known labels.
``` go
const (
LABEL_MAIN_APP Label = KATENARY_PREFIX + "main-app"
LABEL_VALUES Label = KATENARY_PREFIX + "values"
LABEL_SECRETS Label = KATENARY_PREFIX + "secrets"
LABEL_PORTS Label = KATENARY_PREFIX + "ports"
LABEL_INGRESS Label = KATENARY_PREFIX + "ingress"
LABEL_MAP_ENV Label = KATENARY_PREFIX + "map-env"
LABEL_HEALTHCHECK Label = KATENARY_PREFIX + "health-check"
LABEL_SAME_POD Label = KATENARY_PREFIX + "same-pod"
LABEL_DESCRIPTION Label = KATENARY_PREFIX + "description"
LABEL_IGNORE Label = KATENARY_PREFIX + "ignore"
LABEL_DEPENDENCIES Label = KATENARY_PREFIX + "dependencies"
LABEL_CM_FILES Label = KATENARY_PREFIX + "configmap-files"
LABEL_CRONJOB Label = KATENARY_PREFIX + "cronjob"
LABEL_ENV_FROM Label = KATENARY_PREFIX + "env-from"
)
```
## type LabelType
LabelType identifies the type of label to generate in objects. TODO: is
this still needed?
``` go
type LabelType uint8
```
``` go
const (
DeploymentLabel LabelType = iota
ServiceLabel
)
```
## type PersistenceValue
PersistenceValue is a persistence configuration that will be saved in
values.yaml.
``` go
type PersistenceValue struct {
Enabled bool `yaml:"enabled"`
StorageClass string `yaml:"storageClass"`
Size string `yaml:"size"`
AccessMode []string `yaml:"accessMode"`
}
```
## type RBAC
RBAC is a kubernetes RBAC containing a role, a rolebinding and an
associated serviceaccount.
``` go
type RBAC struct {
RoleBinding *RoleBinding
Role *Role
ServiceAccount *ServiceAccount
}
```
### func NewRBAC
``` go
func NewRBAC(service types.ServiceConfig, appName string) *RBAC
```
NewRBAC creates a new RBAC from a compose service. The appName is the
name of the application taken from the project name.
## type RepositoryValue
RepositoryValue is a docker repository image and tag that will be saved
in values.yaml.
``` go
type RepositoryValue struct {
Image string `yaml:"image"`
Tag string `yaml:"tag"`
}
```
## type Role
Role is a kubernetes Role.
``` go
type Role struct {
*rbacv1.Role
// contains filtered or unexported fields
}
```
### func (*Role) Filename
``` go
func (r *Role) Filename() string
```
### func (*Role) Yaml
``` go
func (r *Role) Yaml() ([]byte, error)
```
## type RoleBinding
RoleBinding is a kubernetes RoleBinding.
``` go
type RoleBinding struct {
*rbacv1.RoleBinding
// contains filtered or unexported fields
}
```
### func (*RoleBinding) Filename
``` go
func (r *RoleBinding) Filename() string
```
### func (*RoleBinding) Yaml
``` go
func (r *RoleBinding) Yaml() ([]byte, error)
```
## type Secret
Secret is a kubernetes Secret.
Implements the DataMap interface.
``` go
type Secret struct {
*corev1.Secret
// contains filtered or unexported fields
}
```
### func NewSecret
``` go
func NewSecret(service types.ServiceConfig, appName string) *Secret
```
NewSecret creates a new Secret from a compose service
### func (*Secret) AddData
``` go
func (s *Secret) AddData(key string, value string)
```
AddData adds a key value pair to the secret.
### func (*Secret) Filename
``` go
func (s *Secret) Filename() string
```
Filename returns the filename of the secret.
### func (*Secret) SetData
``` go
func (s *Secret) SetData(data map[string]string)
```
SetData sets the data of the secret.
### func (*Secret) Yaml
``` go
func (s *Secret) Yaml() ([]byte, error)
```
Yaml returns the yaml representation of the secret.
## type Service
Service is a kubernetes Service.
``` go
type Service struct {
*v1.Service `yaml:",inline"`
// contains filtered or unexported fields
}
```
### func NewService
``` go
func NewService(service types.ServiceConfig, appName string) *Service
```
NewService creates a new Service from a compose service.
### func (*Service) AddPort
``` go
func (s *Service) AddPort(port types.ServicePortConfig, serviceName ...string)
```
AddPort adds a port to the service.
### func (*Service) Filename
``` go
func (s *Service) Filename() string
```
Filename returns the filename of the service.
### func (*Service) Yaml
``` go
func (s *Service) Yaml() ([]byte, error)
```
Yaml returns the yaml representation of the service.
## type ServiceAccount
ServiceAccount is a kubernetes ServiceAccount.
``` go
type ServiceAccount struct {
*corev1.ServiceAccount
// contains filtered or unexported fields
}
```
### func (*ServiceAccount) Filename
``` go
func (r *ServiceAccount) Filename() string
```
### func (*ServiceAccount) Yaml
``` go
func (r *ServiceAccount) Yaml() ([]byte, error)
```
## type Value
Value will be saved in values.yaml. It contains configuraiton for all
deployment and services. The content will be lile:
name_of_component:
repository:
image: image_name
tag: image_tag
persistence:
enabled: true
storageClass: storage_class_name
ingress:
enabled: true
host: host_name
path: path_name
environment:
ENV_VAR_1: value_1
ENV_VAR_2: value_2
``` go
type Value struct {
Repository *RepositoryValue `yaml:"repository,omitempty"`
Persistence map[string]*PersistenceValue `yaml:"persistence,omitempty"`
Ingress *IngressValue `yaml:"ingress,omitempty"`
ImagePullPolicy string `yaml:"imagePullPolicy,omitempty"`
Environment map[string]any `yaml:"environment,omitempty"`
Replicas *uint32 `yaml:"replicas,omitempty"`
CronJob *CronJobValue `yaml:"cronjob,omitempty"`
}
```
### func NewValue
``` go
func NewValue(service types.ServiceConfig, main ...bool) *Value
```
NewValue creates a new Value from a compose service. The value contains
the necessary information to deploy the service (image, tag, replicas,
etc.).
If \`main\` is true, the tag will be empty because it will be set in the
helm chart appVersion.
### func (*Value) AddIngress
``` go
func (v *Value) AddIngress(host, path string)
```
### func (*Value) AddPersistence
``` go
func (v *Value) AddPersistence(volumeName string)
```
AddPersistence adds persistence configuration to the Value.
## type VolumeClaim
VolumeClaim is a kubernetes VolumeClaim. This is a
PersistentVolumeClaim.
``` go
type VolumeClaim struct {
*v1.PersistentVolumeClaim
// contains filtered or unexported fields
}
```
### func NewVolumeClaim
``` go
func NewVolumeClaim(service types.ServiceConfig, volumeName, appName string) *VolumeClaim
```
NewVolumeClaim creates a new VolumeClaim from a compose service.
### func (*VolumeClaim) Filename
``` go
func (v *VolumeClaim) Filename() string
```
Filename returns the suggested filename for a VolumeClaim.
### func (*VolumeClaim) Yaml
``` go
func (v *VolumeClaim) Yaml() ([]byte, error)
```
Yaml marshals a VolumeClaim into yaml.
## type Yaml
Yaml is a kubernetes object that can be converted to yaml.
``` go
type Yaml interface {
Yaml() ([]byte, error)
Filename() string
}
```
Generated by [gomarkdoc](https://github.com/princjef/gomarkdoc)