creating services inside the argo manifest
This commit is contained in:
101
models/ingress.go
Normal file
101
models/ingress.go
Normal file
@@ -0,0 +1,101 @@
|
||||
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
|
||||
}
|
||||
|
||||
12
models/k8s_manifest.go
Normal file
12
models/k8s_manifest.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package models
|
||||
|
||||
type Manifest struct {
|
||||
ApiVersion string `yaml:"apiVersion,omitempty"`
|
||||
Kind string `yaml:"kind"`
|
||||
Metadata Metadata `yaml:"metadata,omitempty"`
|
||||
}
|
||||
|
||||
type Metadata struct {
|
||||
Name string `yaml:"name"`
|
||||
GenerateName string `yaml:"generateName"`
|
||||
}
|
||||
@@ -10,16 +10,11 @@ type ServiceResource struct {
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
APIVersion string `yaml:"apiVersion"`
|
||||
Kind string `yaml:"kind"`
|
||||
Metadata Metadata `yaml:"metadata"`
|
||||
Manifest
|
||||
Spec ServiceSpec `yaml:"spec"`
|
||||
}
|
||||
|
||||
type Metadata struct {
|
||||
Name string `yaml:"generateName"`
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ServiceSpec is the specification of the Kubernetes Service
|
||||
type ServiceSpec struct {
|
||||
|
||||
Reference in New Issue
Block a user