svc-optional

This commit is contained in:
2025-11-30 17:18:19 -06:00
parent 7230081401
commit 73be50588a
12 changed files with 61 additions and 1 deletions

View File

@@ -238,6 +238,7 @@ katenary.v3/env-from: []string Add environment variables from another service
katenary.v3/exchange-volumes: []object Add exchange volumes (empty directory on the node) to share data katenary.v3/exchange-volumes: []object Add exchange volumes (empty directory on the node) to share data
katenary.v3/health-check: object Health check to be added to the deployment. katenary.v3/health-check: object Health check to be added to the deployment.
katenary.v3/ignore: bool Ignore the service katenary.v3/ignore: bool Ignore the service
katenary.v3/svc-optional: bool Make the service optional.
katenary.v3/ingress: object Ingress rules to be added to the service. katenary.v3/ingress: object Ingress rules to be added to the service.
katenary.v3/main-app: bool Mark the service as the main app. katenary.v3/main-app: bool Mark the service as the main app.
katenary.v3/map-env: map[string]string Map env vars from the service to the deployment. katenary.v3/map-env: map[string]string Map env vars from the service to the deployment.

View File

@@ -26,6 +26,7 @@ Katenary will try to _Unmarshal_ these labels.
| `katenary.v3/exchange-volumes` | Add exchange volumes (empty directory on the node) to share data | `[]object` | | `katenary.v3/exchange-volumes` | Add exchange volumes (empty directory on the node) to share data | `[]object` |
| `katenary.v3/health-check` | Health check to be added to the deployment. | `object` | | `katenary.v3/health-check` | Health check to be added to the deployment. | `object` |
| `katenary.v3/ignore` | Ignore the service | `bool` | | `katenary.v3/ignore` | Ignore the service | `bool` |
| `katenary.v3/svc-optional` | Make the service optional | `bool` |
| `katenary.v3/ingress` | Ingress rules to be added to the service. | `object` | | `katenary.v3/ingress` | Ingress rules to be added to the service. | `object` |
| `katenary.v3/main-app` | Mark the service as the main app. | `bool` | | `katenary.v3/main-app` | Mark the service as the main app. | `bool` |
| `katenary.v3/map-env` | Map env vars from the service to the deployment. | `map[string]string` | | `katenary.v3/map-env` | Map env vars from the service to the deployment. | `map[string]string` |
@@ -270,6 +271,21 @@ labels:
katenary.v3/ignore: "true" katenary.v3/ignore: "true"
``` ```
### katenary.v3/svc-optional
Make the service optional
**Type**: `bool`
Making a service to be optional in the exported helm chart.
**Example:**
```yaml
labels:
katenary.v3/svc-optional: "true"
```
### katenary.v3/ingress ### katenary.v3/ingress

View File

@@ -45,6 +45,7 @@ type Service struct {
SamePod *string `yaml:"same-pod,omitempty" json:"same-pod,omitempty" jsonschema:"title=Same Pod,description=Service that should be in the same pod"` SamePod *string `yaml:"same-pod,omitempty" json:"same-pod,omitempty" jsonschema:"title=Same Pod,description=Service that should be in the same pod"`
Description *string `yaml:"description,omitempty" json:"description,omitempty" jsonschema:"title=Description,description=Description of the service that will be injected in the values.yaml file"` Description *string `yaml:"description,omitempty" json:"description,omitempty" jsonschema:"title=Description,description=Description of the service that will be injected in the values.yaml file"`
Ignore *bool `yaml:"ignore,omitempty" json:"ignore,omitempty" jsonschema:"title=Ignore,description=Ignore the service in the conversion"` Ignore *bool `yaml:"ignore,omitempty" json:"ignore,omitempty" jsonschema:"title=Ignore,description=Ignore the service in the conversion"`
SvcOptional *bool `yaml:"svc-optional,omitempty" json:"svc-optional,omitempty" jsonschema:"title=SvcOptional,description=SvcOptional the service in the conversion"`
Dependencies []labelstructs.Dependency `yaml:"dependencies,omitempty" json:"dependencies,omitempty" jsonschema:"title=Dependencies,description=Services that should be injected in the Chart.yaml file"` Dependencies []labelstructs.Dependency `yaml:"dependencies,omitempty" json:"dependencies,omitempty" jsonschema:"title=Dependencies,description=Services that should be injected in the Chart.yaml file"`
ConfigMapFiles *labelstructs.ConfigMapFiles `yaml:"configmap-files,omitempty" json:"configmap-files,omitempty" jsonschema:"title=ConfigMap Files,description=Files that should be injected as ConfigMap"` ConfigMapFiles *labelstructs.ConfigMapFiles `yaml:"configmap-files,omitempty" json:"configmap-files,omitempty" jsonschema:"title=ConfigMap Files,description=Files that should be injected as ConfigMap"`
MapEnv *labelstructs.MapEnv `yaml:"map-env,omitempty" json:"map-env,omitempty" jsonschema:"title=Map Env,description=Map environment variables to another value"` MapEnv *labelstructs.MapEnv `yaml:"map-env,omitempty" json:"map-env,omitempty" jsonschema:"title=Map Env,description=Map environment variables to another value"`

View File

@@ -89,6 +89,7 @@ const (
LabelSamePod Label = KatenaryLabelPrefix + "/same-pod" LabelSamePod Label = KatenaryLabelPrefix + "/same-pod"
LabelDescription Label = KatenaryLabelPrefix + "/description" LabelDescription Label = KatenaryLabelPrefix + "/description"
LabelIgnore Label = KatenaryLabelPrefix + "/ignore" LabelIgnore Label = KatenaryLabelPrefix + "/ignore"
LabelSvcOptional Label = KatenaryLabelPrefix + "/svc-optional"
LabelDependencies Label = KatenaryLabelPrefix + "/dependencies" LabelDependencies Label = KatenaryLabelPrefix + "/dependencies"
LabelConfigMapFiles Label = KatenaryLabelPrefix + "/configmap-files" LabelConfigMapFiles Label = KatenaryLabelPrefix + "/configmap-files"
LabelCronJob Label = KatenaryLabelPrefix + "/cronjob" LabelCronJob Label = KatenaryLabelPrefix + "/cronjob"

View File

@@ -102,7 +102,7 @@ Katenary transforms compose services this way:
For any other specific configuration, like binding local files as `ConfigMap`, bind variables, add values with For any other specific configuration, like binding local files as `ConfigMap`, bind variables, add values with
documentation, etc. You'll need to use labels. documentation, etc. You'll need to use labels.
Katenary can also configure containers grouping in pods, declare dependencies, ignore some services, force variables as Katenary can also configure containers grouping in pods, declare dependencies, ignore some services, make some services optional, force variables as
secrets, mount files as `configMap`, and many others things. To adapt the helm chart generation, you will need to use secrets, mount files as `configMap`, and many others things. To adapt the helm chart generation, you will need to use
some specific labels. some specific labels.

View File

@@ -200,6 +200,12 @@ func (chart *HelmChart) generateDeployment(service types.ServiceConfig, deployme
logger.Info("Ignoring service ", service.Name) logger.Info("Ignoring service ", service.Name)
return nil return nil
} }
// isgnored service
if isSvcOptional(service) {
logger.Info("Optional service ", service.Name)
return nil
}
// helm dependency // helm dependency
if isHelmDependency, err := chart.setDependencies(service); err != nil { if isHelmDependency, err := chart.setDependencies(service); err != nil {

View File

@@ -50,6 +50,9 @@ func Generate(project *types.Project) (*HelmChart, error) {
// drop all services with the "ignore" label // drop all services with the "ignore" label
dropIngoredServices(project) dropIngoredServices(project)
// optional all services with the "svc-optional" label
makeSvcOptionalServices(project)
fixContainerNames(project) fixContainerNames(project)
// rename all services name to remove dashes // rename all services name to remove dashes
@@ -223,6 +226,16 @@ func dropIngoredServices(project *types.Project) {
} }
} }
// makeSvcOptionalServices makes all services optional with the "svc-optional" label set to true (or yes).
func makeSvcOptionalServices(project *types.Project) {
for name, service := range project.Services {
if isSvcOptional(service) {
// delete(project.Services, name)
// make optional
}
}
}
// fixResourceNames renames all services and related resources to remove dashes. // fixResourceNames renames all services and related resources to remove dashes.
func fixResourceNames(project *types.Project) error { func fixResourceNames(project *types.Project) error {
// rename all services name to remove dashes // rename all services name to remove dashes

View File

@@ -34,6 +34,7 @@ type Service struct {
SamePod *string `yaml:"same-pod,omitempty" json:"same-pod,omitempty" jsonschema:"title=Same Pod,description=Service that should be in the same pod"` SamePod *string `yaml:"same-pod,omitempty" json:"same-pod,omitempty" jsonschema:"title=Same Pod,description=Service that should be in the same pod"`
Description *string `yaml:"description,omitempty" json:"description,omitempty" jsonschema:"title=Description,description=Description of the service that will be injected in the values.yaml file"` Description *string `yaml:"description,omitempty" json:"description,omitempty" jsonschema:"title=Description,description=Description of the service that will be injected in the values.yaml file"`
Ignore *bool `yaml:"ignore,omitempty" json:"ignore,omitempty" jsonschema:"title=Ignore,description=Ignore the service in the conversion"` Ignore *bool `yaml:"ignore,omitempty" json:"ignore,omitempty" jsonschema:"title=Ignore,description=Ignore the service in the conversion"`
SvcOptional *bool `yaml:"svc-optional,omitempty" json:"svc-optional,omitempty" jsonschema:"title=SvcOptional,description=SvcOptional the service in the conversion"`
Dependencies []labelstructs.Dependency `yaml:"dependencies,omitempty" json:"dependencies,omitempty" jsonschema:"title=Dependencies,description=Services that should be injected in the Chart.yaml file"` Dependencies []labelstructs.Dependency `yaml:"dependencies,omitempty" json:"dependencies,omitempty" jsonschema:"title=Dependencies,description=Services that should be injected in the Chart.yaml file"`
ConfigMapFiles *labelstructs.ConfigMapFiles `yaml:"configmap-files,omitempty" json:"configmap-files,omitempty" jsonschema:"title=ConfigMap Files,description=Files that should be injected as ConfigMap"` ConfigMapFiles *labelstructs.ConfigMapFiles `yaml:"configmap-files,omitempty" json:"configmap-files,omitempty" jsonschema:"title=ConfigMap Files,description=Files that should be injected as ConfigMap"`
MapEnv *labelstructs.MapEnv `yaml:"map-env,omitempty" json:"map-env,omitempty" jsonschema:"title=Map Env,description=Map environment variables to another value"` MapEnv *labelstructs.MapEnv `yaml:"map-env,omitempty" json:"map-env,omitempty" jsonschema:"title=Map Env,description=Map environment variables to another value"`
@@ -94,6 +95,7 @@ func OverrideWithConfig(project *types.Project) {
mustGetLabelContent(s.SamePod, labels.LabelSamePod) mustGetLabelContent(s.SamePod, labels.LabelSamePod)
mustGetLabelContent(s.Description, labels.LabelDescription) mustGetLabelContent(s.Description, labels.LabelDescription)
mustGetLabelContent(s.Ignore, labels.LabelIgnore) mustGetLabelContent(s.Ignore, labels.LabelIgnore)
mustGetLabelContent(s.SvcOptional, labels.LabelSvcOptional)
mustGetLabelContent(s.Dependencies, labels.LabelDependencies) mustGetLabelContent(s.Dependencies, labels.LabelDependencies)
mustGetLabelContent(s.ConfigMapFiles, labels.LabelConfigMapFiles) mustGetLabelContent(s.ConfigMapFiles, labels.LabelConfigMapFiles)
mustGetLabelContent(s.MapEnv, labels.LabelMapEnv) mustGetLabelContent(s.MapEnv, labels.LabelMapEnv)

View File

@@ -30,6 +30,7 @@ const (
LabelSamePod Label = KatenaryLabelPrefix + "/same-pod" LabelSamePod Label = KatenaryLabelPrefix + "/same-pod"
LabelDescription Label = KatenaryLabelPrefix + "/description" LabelDescription Label = KatenaryLabelPrefix + "/description"
LabelIgnore Label = KatenaryLabelPrefix + "/ignore" LabelIgnore Label = KatenaryLabelPrefix + "/ignore"
LabelSvcOptional Label = KatenaryLabelPrefix + "/svc-optional"
LabelDependencies Label = KatenaryLabelPrefix + "/dependencies" LabelDependencies Label = KatenaryLabelPrefix + "/dependencies"
LabelConfigMapFiles Label = KatenaryLabelPrefix + "/configmap-files" LabelConfigMapFiles Label = KatenaryLabelPrefix + "/configmap-files"
LabelCronJob Label = KatenaryLabelPrefix + "/cronjob" LabelCronJob Label = KatenaryLabelPrefix + "/cronjob"

View File

@@ -183,6 +183,12 @@
example: "labels:\n {{ .KatenaryPrefix }}/ignore: \"true\"" example: "labels:\n {{ .KatenaryPrefix }}/ignore: \"true\""
type: "bool" type: "bool"
"svc-optional":
short: "Make the service optional in the resulting helm chart"
long: "Making a service optional to be exported in helm chart."
example: "labels:\n {{ .KatenaryPrefix }}/svc-optional: \"true\""
type: "bool"
"dependencies": "dependencies":
short: "Add Helm dependencies to the service." short: "Add Helm dependencies to the service."
long: |- long: |-

View File

@@ -83,6 +83,14 @@ func isIgnored(service types.ServiceConfig) bool {
return false return false
} }
// isSvcOptionald returns true if the service is optional.
func isSvcOptional(service types.ServiceConfig) bool {
if v, ok := service.Labels[labels.LabelSvcOptional]; ok {
return v == "true" || v == "yes" || v == "1"
}
return false
}
// UnWrapTPL removes the line wrapping from a template. // UnWrapTPL removes the line wrapping from a template.
func UnWrapTPL(in []byte) []byte { func UnWrapTPL(in []byte) []byte {
return regexpLineWrap.ReplaceAll(in, []byte(" }}")) return regexpLineWrap.ReplaceAll(in, []byte(" }}"))

View File

@@ -309,6 +309,11 @@
"title": "Ignore", "title": "Ignore",
"description": "Ignore the service in the conversion" "description": "Ignore the service in the conversion"
}, },
"svc-optional": {
"type": "boolean",
"title": "SvcOptional",
"description": "Make the service optional in the conversion"
},
"dependencies": { "dependencies": {
"items": { "items": {
"$ref": "#/$defs/Dependency" "$ref": "#/$defs/Dependency"