diff --git a/.gitignore b/.gitignore index 1fda1d7..88f15a1 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,5 @@ __pycache__ .rpmmacros *.gpg + +katenary diff --git a/doc/docs/.markdownlint.yaml b/doc/docs/.markdownlint.yaml index f6df9d2..ccc15b1 100644 --- a/doc/docs/.markdownlint.yaml +++ b/doc/docs/.markdownlint.yaml @@ -2,4 +2,5 @@ MD012: false MD013: false MD022: false MD033: false +MD041: false MD046: false diff --git a/doc/docs/packages/generator.md b/doc/docs/packages/generator.md index ad75de0..95faa04 100644 --- a/doc/docs/packages/generator.md +++ b/doc/docs/packages/generator.md @@ -731,7 +731,7 @@ func (s *Secret) Yaml() ([]byte, error) Yaml returns the yaml representation of the secret. -## type [Service]() +## type [Service]() Service is a kubernetes Service. @@ -743,7 +743,7 @@ type Service struct { ``` -### func [NewService]() +### func [NewService]() ```go func NewService(service types.ServiceConfig, appName string) *Service @@ -752,7 +752,7 @@ func NewService(service types.ServiceConfig, appName string) *Service NewService creates a new Service from a compose service. -### func \(\*Service\) [AddPort]() +### func \(\*Service\) [AddPort]() ```go func (s *Service) AddPort(port types.ServicePortConfig, serviceName ...string) @@ -761,7 +761,7 @@ func (s *Service) AddPort(port types.ServicePortConfig, serviceName ...string) AddPort adds a port to the service. -### func \(\*Service\) [Filename]() +### func \(\*Service\) [Filename]() ```go func (s *Service) Filename() string @@ -770,7 +770,7 @@ func (s *Service) Filename() string Filename returns the filename of the service. -### func \(\*Service\) [Yaml]() +### func \(\*Service\) [Yaml]() ```go func (s *Service) Yaml() ([]byte, error) diff --git a/doc/docs/usage.md b/doc/docs/usage.md index 3c010f4..cae2ac7 100644 --- a/doc/docs/usage.md +++ b/doc/docs/usage.md @@ -145,7 +145,7 @@ For more complete label usage, see [the labels page](labels.md). ### Work with Depends On? -Kubernetes does not provide service or pod starting detection from others pods. But katenary will create init containers +Kubernetes does not provide service or pod starting detection from others pods. But Katenary will create `initContainer` to make you able to wait for a service to respond. But you'll probably need to adapt a bit the compose file. See this compose file: diff --git a/doc/requirements.txt b/doc/requirements.txt index 18a915f..c545563 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -5,3 +5,5 @@ pymdown-extensions==10.* mkdocs-material==9.* mkdocs-material-extensions==1.* mkdocs-plugin-inline-svg-mod +beautifulsoup4==4.* +mkdocs-manpage[preprocess] diff --git a/generator/service.go b/generator/service.go index 5573e06..730577f 100644 --- a/generator/service.go +++ b/generator/service.go @@ -1,6 +1,7 @@ package generator import ( + "fmt" "katenary/utils" "regexp" "strings" @@ -59,6 +60,7 @@ func (s *Service) AddPort(port types.ServicePortConfig, serviceName ...string) { if targetPort := utils.GetServiceNameByPort(int(port.Target)); targetPort == "" { finalport = intstr.FromInt(int(port.Target)) + name = fmt.Sprintf("port-%d", port.Target) } else { finalport = intstr.FromString(targetPort) name = targetPort diff --git a/generator/service_test.go b/generator/service_test.go index 205c944..1afad1f 100644 --- a/generator/service_test.go +++ b/generator/service_test.go @@ -47,3 +47,37 @@ services: t.Errorf("Expected 2 ports, got %d", foundPort) } } + +func TestWithSeveralUnknownPorts(t *testing.T) { + composeFile := ` +services: + multi: + image: nginx + ports: + - 12443 + - 12480 + labels: + katenary.v3/ingress: |- + port: 12443 +` + tmpDir := setup(composeFile) + defer teardown(tmpDir) + + currentDir, _ := os.Getwd() + os.Chdir(tmpDir) + defer os.Chdir(currentDir) + + output := internalCompileTest(t, "-s", "templates/multi/service.yaml") + service := v1.Service{} + if err := yaml.Unmarshal([]byte(output), &service); err != nil { + t.Errorf(unmarshalError, err) + } + + if len(service.Spec.Ports) != 2 { + t.Errorf("Expected 2 ports, got %d", len(service.Spec.Ports)) + } + // ensure that both port names are different + if service.Spec.Ports[0].Name == service.Spec.Ports[1].Name { + t.Errorf("Expected different port names, got %s and %s", service.Spec.Ports[0].Name, service.Spec.Ports[1].Name) + } +}