creating services inside the argo manifest
This commit is contained in:
@@ -13,6 +13,13 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type ServiceType string
|
||||
|
||||
const (
|
||||
NodePort ServiceType = "NodePort"
|
||||
ClusterIP ServiceType = "ClusterIP"
|
||||
)
|
||||
|
||||
// TODO : refactor this method or the deserialization process in oc-lib to get rid of the mongo code
|
||||
func getExposeContract(expose resource_model.Model) map[string]map[string]string {
|
||||
contract := make(map[string]map[string]string,0)
|
||||
@@ -41,7 +48,7 @@ func getExposeContract(expose resource_model.Model) map[string]map[string]string
|
||||
}
|
||||
|
||||
|
||||
func (b *ArgoBuilder) CreateService(processing graph.GraphItem) models.Service{
|
||||
func (b *ArgoBuilder) CreateKubeService(processing graph.GraphItem, service_type ServiceType) models.Service{
|
||||
|
||||
// model {
|
||||
// Type : "dict",
|
||||
@@ -58,23 +65,24 @@ func (b *ArgoBuilder) CreateService(processing graph.GraphItem) models.Service{
|
||||
// }
|
||||
|
||||
|
||||
new_service := models.Service{APIVersion: "v1",
|
||||
Kind: "Service",
|
||||
Metadata: models.Metadata{
|
||||
Name: "workflow-service-" ,
|
||||
},
|
||||
Spec: models.ServiceSpec{
|
||||
Selector: map[string]string{"app": "service-" + fakelish.GenerateFakeWord(5, 8)},
|
||||
Ports: []models.ServicePort{
|
||||
},
|
||||
Type: "NodePort",
|
||||
},
|
||||
}
|
||||
|
||||
new_service := models.Service{
|
||||
Manifest: models.Manifest{
|
||||
ApiVersion: "v1",
|
||||
Kind: "Service",
|
||||
Metadata: models.Metadata{
|
||||
Name: "workflow-service-"+ processing.Processing.Name + "-" + processing.ID ,
|
||||
},
|
||||
},
|
||||
Spec: models.ServiceSpec{
|
||||
Selector: map[string]string{"app": "service-" + fakelish.GenerateFakeWord(5, 8)},
|
||||
Ports: []models.ServicePort{
|
||||
},
|
||||
Type: string(service_type),
|
||||
},
|
||||
}
|
||||
|
||||
completeServicePorts(&new_service, processing)
|
||||
yamlified, _ := yaml.Marshal(new_service)
|
||||
x := string(yamlified)
|
||||
_ = x
|
||||
|
||||
return new_service
|
||||
}
|
||||
|
||||
@@ -91,7 +99,7 @@ func completeServicePorts(service *models.Service, processing graph.GraphItem) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// This condition allows us to create NodePort if PAT is filled or a ClusterIP that only expose port 80 and 443 (for Ingress)
|
||||
if _, ok := translation_dict["PAT"]; ok{
|
||||
port_translation, err := strconv.ParseInt(translation_dict["PAT"], 10, 64)
|
||||
if err != nil {
|
||||
@@ -99,8 +107,6 @@ func completeServicePorts(service *models.Service, processing graph.GraphItem) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
|
||||
new_port_translation := models.ServicePort{
|
||||
Name: strings.ToLower(processing.Processing.Name) + processing.ID,
|
||||
Port: port_translation-30000,
|
||||
@@ -109,17 +115,34 @@ func completeServicePorts(service *models.Service, processing graph.GraphItem) {
|
||||
Protocol: "TCP",
|
||||
}
|
||||
service.Spec.Ports = append(service.Spec.Ports, new_port_translation)
|
||||
}
|
||||
} else {
|
||||
port_spec := []models.ServicePort{
|
||||
models.ServicePort{
|
||||
Name: strings.ToLower(processing.Processing.Name) + processing.ID + "-80",
|
||||
Port: 80,
|
||||
TargetPort: 80,
|
||||
Protocol: "TCP",
|
||||
},
|
||||
models.ServicePort{
|
||||
Name: strings.ToLower(processing.Processing.Name) + processing.ID + "-443",
|
||||
Port: 443,
|
||||
TargetPort: 443,
|
||||
Protocol: "TCP",
|
||||
},
|
||||
|
||||
}
|
||||
service.Spec.Ports = append(service.Spec.Ports,port_spec...)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
// The k8s service passed as the parameter only expose one port because it is the result of CreateService()
|
||||
// we check if this port is already exposed by a service in the workflow and we proceed to the creation of a new service OR
|
||||
// add the port to the list of port exposed by an existing if portAlreadyExposed is false
|
||||
func (b *ArgoBuilder) addServiceToWorkflow(service models.Service, processing_name string, processing_id string) (label string) {
|
||||
func (b *ArgoBuilder) addKubeServiceToWorkflow(service models.Service, processing_name string, processing_id string) (label string) {
|
||||
if exposed, service_available_port := b.portAlreadyExposed(service.Spec.Ports[0].TargetPort); exposed && service_available_port != nil{
|
||||
// The port you want to expose is already exposed by all the existing services
|
||||
service_available_port.Spec.Ports = append(service_available_port.Spec.Ports, service.Spec.Ports...)
|
||||
@@ -178,4 +201,15 @@ func (b *ArgoBuilder) portAlreadyExposed(port int64) (exposed bool, service *mod
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// If contract has a reverse value
|
||||
// Test if service already exist for the argo service
|
||||
// Yes : create ingress, associate it with the existing kube service (name + exposed port on service)
|
||||
// No :
|
||||
// - create template for a service that expose the port of the argo service (pod)
|
||||
// - store the name of the service and its port exposed
|
||||
// - create template for an ingress : manifest must contain the path, name of the service and port exposed on the service
|
||||
func (b *ArgoBuilder) addIngress(){
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user