oc-monitord/models/ingress.go

102 lines
2.1 KiB
Go
Raw Normal View History

package models
import "strconv"
// apiVersion: networking.k8s.io/v1
// kind: Ingress
// metadata:
// name: example-ingress
// namespace: argo
// annotations:
// traefik.ingress.kubernetes.io/router.entrypoints: web # Utilisation de l'entrypoint HTTP standard
// spec:
// rules:
// - http:
// paths:
// - path: /dtf
// pathType: Prefix
// backend:
// service:
// name: workflow-service-qtjk2
// port:
// number: 80
var ingress_manifest = &Manifest{
ApiVersion: "networking.k8s.io/v1",
Kind: "Ingress",
Metadata: Metadata{
GenerateName: "ingress-argo-",
},
}
type Ingress struct {
ApiVersion string `yaml:"apiVersion,omitempty"`
Kind string `yaml:"kind,omitempty"`
Metadata Metadata `yaml:"metadata,omitempty"`
Spec IngressSpec `yaml:"spec,omitempty"`
}
type IngressSpec struct {
Rules []Rule `yaml:"rules,omitempty"`
}
type Rule struct {
HTTP HTTP `yaml:"http,omitempty"`
}
type HTTP struct {
Paths []Path `yaml:"paths,omitempty"`
}
type Path struct {
Path string `yaml:"path,omitempty"`
PathType string `yaml:"pathType,omitempty"`
Backend Backend `yaml:"backend,omitempty"`
}
type Backend struct {
ServiceName string `yaml:"serviceName,omitempty"`
ServicePort int64 `yaml:"servicePort,omitempty"`
}
func NewIngress(contract map[string]map[string]string, serviceName string) Ingress {
new_ingr := Ingress{
ApiVersion: "networking.k8s.io/v1",
Kind: "Ingress",
Metadata: Metadata{
GenerateName: "ingress-argo-",
},
Spec: IngressSpec{
Rules: []Rule{
{
HTTP: HTTP{
Paths: []Path{},
},
},
},
},
}
for port_to_reverse_str, translations := range contract{
port, _ := strconv.ParseInt(port_to_reverse_str,10,64)
port_reverse := Path{
Path: translations["reverse"],
PathType: "Prefix",
Backend: Backend{
ServiceName: serviceName,
ServicePort:port,
},
}
new_ingr.Spec.Rules[0].HTTP.Paths = append(new_ingr.Spec.Rules[0].HTTP.Paths, port_reverse)
}
return new_ingr
}