oc-monitord/workflow_builder/argo_services.go

65 lines
1.8 KiB
Go
Raw Normal View History

2024-09-03 15:54:20 +02:00
package workflow_builder
import (
"oc-monitord/models"
"strings"
2024-10-11 13:44:16 +02:00
"cloud.o-forge.io/core/oc-lib/models/resources/processing"
2024-09-03 15:54:20 +02:00
"gopkg.in/yaml.v3"
)
2024-10-11 13:44:16 +02:00
func (b *ArgoBuilder) CreateService(id string, processing *processing.ProcessingResource) {
new_service := models.Service{
APIVersion: "v1",
Kind: "Service",
Metadata: models.Metadata{
Name: "workflow-service",
},
Spec: models.ServiceSpec{
Selector: map[string]string{"app": "oc-service"},
Ports: []models.ServicePort{},
Type: "NodePort",
},
2024-09-03 15:54:20 +02:00
}
2024-10-11 13:44:16 +02:00
if processing == nil {
return
}
b.completeServicePorts(&new_service, id, processing)
b.Services = append(b.Services, &new_service)
2024-09-03 15:54:20 +02:00
}
2024-10-11 13:44:16 +02:00
func (b *ArgoBuilder) completeServicePorts(service *models.Service, id string, processing *processing.ProcessingResource) {
for _, execute := range processing.Expose {
if execute.PAT != 0 {
2024-09-03 15:54:20 +02:00
new_port_translation := models.ServicePort{
2024-10-11 13:44:16 +02:00
Name: strings.ToLower(processing.Name) + id,
Port: execute.Port,
TargetPort: execute.PAT,
Protocol: "TCP",
2024-09-03 15:54:20 +02:00
}
service.Spec.Ports = append(service.Spec.Ports, new_port_translation)
}
2024-10-11 13:44:16 +02:00
}
2024-09-03 15:54:20 +02:00
}
func (b *ArgoBuilder) addServiceToArgo() error {
2024-10-11 13:44:16 +02:00
for _, service := range b.Services {
service_manifest, err := yaml.Marshal(service)
if err != nil {
logger.Error().Msg("Could not marshal service manifest : " + err.Error())
return err
}
service_template := models.Template{Name: "workflow-service-pod",
Resource: models.ServiceResource{
Action: "create",
SuccessCondition: "status.succeeded > 0",
FailureCondition: "status.failed > 3",
SetOwnerReference: true,
Manifest: string(service_manifest),
},
}
b.Workflow.Spec.Templates = append(b.Workflow.Spec.Templates, service_template)
2024-09-03 15:54:20 +02:00
}
return nil
2024-10-11 13:44:16 +02:00
}