2025-07-06 14:34:16 +02:00
|
|
|
package labelstructs
|
2024-11-18 17:12:12 +01:00
|
|
|
|
2024-11-22 15:55:59 +01:00
|
|
|
import (
|
|
|
|
"fmt"
|
2025-08-19 23:09:50 +02:00
|
|
|
|
|
|
|
"repo.katenary.io/katenary/katenary/internal/utils"
|
2024-11-22 15:55:59 +01:00
|
|
|
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
)
|
2024-11-18 17:12:12 +01:00
|
|
|
|
|
|
|
type TLS struct {
|
|
|
|
Enabled bool `yaml:"enabled" json:"enabled,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Ingress struct {
|
2024-11-22 15:55:59 +01:00
|
|
|
Port *int32 `yaml:"port,omitempty" json:"port,omitempty"`
|
2024-11-18 17:12:12 +01:00
|
|
|
Annotations map[string]string `yaml:"annotations,omitempty" jsonschema:"nullable" json:"annotations,omitempty"`
|
2025-07-06 15:31:21 +02:00
|
|
|
Hostname string `yaml:"hostname,omitempty" json:"hostname,omitempty"`
|
2024-11-22 15:55:59 +01:00
|
|
|
Path *string `yaml:"path,omitempty" json:"path,omitempty"`
|
|
|
|
Class *string `yaml:"class,omitempty" json:"class,omitempty" jsonschema:"default:-"`
|
2025-07-06 15:31:21 +02:00
|
|
|
Enabled bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
|
2024-11-18 17:12:12 +01:00
|
|
|
TLS *TLS `yaml:"tls,omitempty" json:"tls,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IngressFrom creates a new Ingress from a compose service.
|
|
|
|
func IngressFrom(data string) (*Ingress, error) {
|
|
|
|
mapping := Ingress{
|
|
|
|
Hostname: "",
|
2024-11-25 11:54:00 +01:00
|
|
|
Path: utils.StrPtr("/"),
|
2024-11-18 17:12:12 +01:00
|
|
|
Enabled: false,
|
2024-11-25 11:54:00 +01:00
|
|
|
Class: utils.StrPtr("-"),
|
2024-11-18 17:12:12 +01:00
|
|
|
Port: nil,
|
|
|
|
TLS: &TLS{Enabled: true},
|
|
|
|
}
|
|
|
|
if err := yaml.Unmarshal([]byte(data), &mapping); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-11-22 15:55:59 +01:00
|
|
|
if mapping.Port == nil {
|
|
|
|
return nil, fmt.Errorf("port is required in ingress definition")
|
|
|
|
}
|
2024-11-18 17:12:12 +01:00
|
|
|
return &mapping, nil
|
|
|
|
}
|