Compare commits
5 Commits
3e4ac40109
...
services_d
| Author | SHA1 | Date | |
|---|---|---|---|
| 2f9b2fb464 | |||
| d1dab992cf | |||
| 52278609bd | |||
| ed48fc0a55 | |||
| 03ad8c084d |
18
.vscode/launch.json
vendored
Normal file
18
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Launch Package",
|
||||||
|
"type": "go",
|
||||||
|
"request": "launch",
|
||||||
|
"mode": "auto",
|
||||||
|
"program": "${fileDirname}",
|
||||||
|
"args": ["-e","e3b7772e-dc9f-4bc1-9f5d-533e23e6cd57" ,"-u","http://127.0.0.1:3100","-m" ,"mongodb://127.0.0.1:27017","-d","DC_myDC"],
|
||||||
|
"env": {"OCMONITOR_LOKIURL":"http://127.0.0.1:3100","OCMONITOR_WORKFLOW":"8d0f1814-b5ca-436c-ba3f-116d99198fd2","KUBERNETES_SERVICE_HOST":"","OCMONITOR_MONGOURL":"mongodb://127.0.0.1:27017","OCMONITOR_DATABASE":"DC_myDC","test_service":"true"}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
70
README.md
70
README.md
@@ -47,6 +47,76 @@ In rules add a new entry :
|
|||||||
|
|
||||||
This command **must return "yes"**
|
This command **must return "yes"**
|
||||||
|
|
||||||
|
## Allow services to be joined with reverse proxy
|
||||||
|
|
||||||
|
Since the development has been realised in a K3S environment, we will use the lightweight solution provided by **traefik**.
|
||||||
|
|
||||||
|
We need to install **metallb** to expose our cluster to the exterior and allow packets to reach traefik.
|
||||||
|
|
||||||
|
### Deploy traefik and metallb
|
||||||
|
|
||||||
|
- Make sure that helm is installed, else visit : https://helm.sh/docs/intro/install/
|
||||||
|
|
||||||
|
- Add the repositories for traefik and metallb
|
||||||
|
> helm repo add metallb https://metallb.github.io/metallb
|
||||||
|
> helm repo add traefik https://helm.traefik.io/traefik
|
||||||
|
|
||||||
|
>helm repo update
|
||||||
|
|
||||||
|
- Create the namespaces for each
|
||||||
|
> kubectl create ns traefik-ingress
|
||||||
|
> kubectl create ns metallb-system
|
||||||
|
|
||||||
|
- Configure the deployment
|
||||||
|
|
||||||
|
```
|
||||||
|
cat > traefik-values.yaml <<EOF
|
||||||
|
globalArguments:
|
||||||
|
deployment:
|
||||||
|
kind: DaemonSet
|
||||||
|
providers:
|
||||||
|
kubernetesCRD:
|
||||||
|
enabled: true
|
||||||
|
service:
|
||||||
|
type: LoadBalancer
|
||||||
|
ingressRoute:
|
||||||
|
dashboard:
|
||||||
|
enabled: false
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
- Launch the installs
|
||||||
|
> helm upgrade --install metallb metallb/metallb --namespace metallb-system
|
||||||
|
|
||||||
|
> helm install --namespace=traefik-ingress traefik traefik/traefik --values=./traefik-values.yaml
|
||||||
|
|
||||||
|
### Configure metallb
|
||||||
|
|
||||||
|
```
|
||||||
|
cat << 'EOF' | kubectl apply -f -
|
||||||
|
apiVersion: metallb.io/v1beta1
|
||||||
|
kind: IPAddressPool
|
||||||
|
metadata:
|
||||||
|
name: default-pool
|
||||||
|
namespace: metallb-system
|
||||||
|
spec:
|
||||||
|
addresses:
|
||||||
|
- 192.168.0.200-192.168.0.250
|
||||||
|
---
|
||||||
|
apiVersion: metallb.io/v1beta1
|
||||||
|
kind: L2Advertisement
|
||||||
|
metadata:
|
||||||
|
name: default
|
||||||
|
namespace: metallb-system
|
||||||
|
spec:
|
||||||
|
ipAddressPools:
|
||||||
|
- default-pool
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
- Check that the services created in traefik-ingress have an external IP
|
||||||
|
|
||||||
|
> kubectl get service -n traefik-ingress -o wide
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
|
|||||||
30
demo_nginx/nginx.conf
Normal file
30
demo_nginx/nginx.conf
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# nginx.conf
|
||||||
|
user nginx;
|
||||||
|
worker_processes auto;
|
||||||
|
error_log /var/log/nginx/error.log warn;
|
||||||
|
pid /var/run/nginx.pid;
|
||||||
|
events {
|
||||||
|
worker_connections 1024;
|
||||||
|
}
|
||||||
|
http {
|
||||||
|
include /etc/nginx/mime.types;
|
||||||
|
default_type application/octet-stream;
|
||||||
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||||
|
'$status $body_bytes_sent "$http_referer" '
|
||||||
|
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||||
|
access_log /var/log/nginx/access.log main;
|
||||||
|
sendfile on;
|
||||||
|
#tcp_nopush on;
|
||||||
|
|
||||||
|
keepalive_timeout 65;
|
||||||
|
#gzip on;
|
||||||
|
#include /etc/nginx/conf.d/*.conf;
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
location / {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html index.htm;
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
go.mod
12
go.mod
@@ -3,7 +3,7 @@ module oc-monitord
|
|||||||
go 1.22.0
|
go 1.22.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240924075418-021b461b0a7d
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240904135449-4f0ab6a3760f
|
||||||
github.com/akamensky/argparse v1.4.0
|
github.com/akamensky/argparse v1.4.0
|
||||||
github.com/goraz/onion v0.1.3
|
github.com/goraz/onion v0.1.3
|
||||||
github.com/nats-io/nats-server/v2 v2.10.18
|
github.com/nats-io/nats-server/v2 v2.10.18
|
||||||
@@ -17,10 +17,10 @@ require (
|
|||||||
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/go-playground/validator/v10 v10.22.1 // indirect
|
github.com/go-playground/validator/v10 v10.22.0 // indirect
|
||||||
github.com/golang/snappy v0.0.4 // indirect
|
github.com/golang/snappy v0.0.4 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/klauspost/compress v1.17.10 // indirect
|
github.com/klauspost/compress v1.17.9 // indirect
|
||||||
github.com/leodido/go-urn v1.4.0 // indirect
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
@@ -38,9 +38,9 @@ require (
|
|||||||
github.com/xdg-go/scram v1.1.2 // indirect
|
github.com/xdg-go/scram v1.1.2 // indirect
|
||||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
github.com/xdg-go/stringprep v1.0.4 // indirect
|
||||||
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
|
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
|
||||||
go.mongodb.org/mongo-driver v1.17.0 // indirect
|
go.mongodb.org/mongo-driver v1.16.1 // indirect
|
||||||
golang.org/x/crypto v0.27.0 // indirect
|
golang.org/x/crypto v0.26.0 // indirect
|
||||||
golang.org/x/net v0.29.0 // indirect
|
golang.org/x/net v0.28.0 // indirect
|
||||||
golang.org/x/sync v0.8.0 // indirect
|
golang.org/x/sync v0.8.0 // indirect
|
||||||
golang.org/x/sys v0.25.0 // indirect
|
golang.org/x/sys v0.25.0 // indirect
|
||||||
golang.org/x/text v0.18.0 // indirect
|
golang.org/x/text v0.18.0 // indirect
|
||||||
|
|||||||
18
go.sum
18
go.sum
@@ -40,12 +40,8 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20240826085916-d0e1474f8f34 h1:40XQgwR9HxXSn
|
|||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240826085916-d0e1474f8f34/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240826085916-d0e1474f8f34/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240828135227-14d6a5f11c4e h1:/KWO/gIcP5f7T4r00715fNz0Y/Hil6Bj3J1ycuES1Zw=
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240828135227-14d6a5f11c4e h1:/KWO/gIcP5f7T4r00715fNz0Y/Hil6Bj3J1ycuES1Zw=
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240828135227-14d6a5f11c4e/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240828135227-14d6a5f11c4e/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240830071403-db78c70dc349 h1:bEIY1lCsA78/mJqFE0gV6likAv5ZifH3RMnLJxiSk3o=
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240904135449-4f0ab6a3760f h1:v9mw3uNg/DJswOvHooMu8/BMedA+vIXbma+8iUwsjUI=
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240830071403-db78c70dc349/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240904135449-4f0ab6a3760f/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240830131445-af18dba5563c h1:4ZoM9ONJiaeLHSi0s8gsCe4lHuRHXkfK+eDSnTCspa0=
|
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240830131445-af18dba5563c/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
|
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240924075418-021b461b0a7d h1:f8cT/NunF+eoZLU5B9gmiT4ky99zPmnQBbj4tj23KuA=
|
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240924075418-021b461b0a7d/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
|
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/akamensky/argparse v1.4.0 h1:YGzvsTqCvbEZhL8zZu2AiA5nq805NZh75JNj4ajn1xc=
|
github.com/akamensky/argparse v1.4.0 h1:YGzvsTqCvbEZhL8zZu2AiA5nq805NZh75JNj4ajn1xc=
|
||||||
github.com/akamensky/argparse v1.4.0/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA=
|
github.com/akamensky/argparse v1.4.0/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA=
|
||||||
@@ -71,8 +67,6 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
|
|||||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||||
github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4Bx7ia+JlgcnOao=
|
github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4Bx7ia+JlgcnOao=
|
||||||
github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
||||||
github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA=
|
|
||||||
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
|
||||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
@@ -91,8 +85,6 @@ github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7
|
|||||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||||
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
||||||
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||||
github.com/klauspost/compress v1.17.10 h1:oXAz+Vh0PMUvJczoi+flxpnBEPxoER1IaAnU/NMPtT0=
|
|
||||||
github.com/klauspost/compress v1.17.10/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
|
|
||||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||||
@@ -175,8 +167,6 @@ go.mongodb.org/mongo-driver v1.16.0 h1:tpRsfBJMROVHKpdGyc1BBEzzjDUWjItxbVSZ8Ls4B
|
|||||||
go.mongodb.org/mongo-driver v1.16.0/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw=
|
go.mongodb.org/mongo-driver v1.16.0/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw=
|
||||||
go.mongodb.org/mongo-driver v1.16.1 h1:rIVLL3q0IHM39dvE+z2ulZLp9ENZKThVfuvN/IiN4l8=
|
go.mongodb.org/mongo-driver v1.16.1 h1:rIVLL3q0IHM39dvE+z2ulZLp9ENZKThVfuvN/IiN4l8=
|
||||||
go.mongodb.org/mongo-driver v1.16.1/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw=
|
go.mongodb.org/mongo-driver v1.16.1/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw=
|
||||||
go.mongodb.org/mongo-driver v1.17.0 h1:Hp4q2MCjvY19ViwimTs00wHi7G4yzxh4/2+nTx8r40k=
|
|
||||||
go.mongodb.org/mongo-driver v1.17.0/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4=
|
|
||||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
@@ -185,8 +175,6 @@ golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
|
|||||||
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
|
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
|
||||||
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
|
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
|
||||||
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
|
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
|
||||||
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
|
|
||||||
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
|
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
@@ -197,8 +185,6 @@ golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
|
|||||||
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
|
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
|
||||||
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
|
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
|
||||||
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
|
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
|
||||||
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
|
|
||||||
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||||
|
|||||||
7
main.go
7
main.go
@@ -19,7 +19,6 @@ import (
|
|||||||
oclib "cloud.o-forge.io/core/oc-lib"
|
oclib "cloud.o-forge.io/core/oc-lib"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/logs"
|
"cloud.o-forge.io/core/oc-lib/logs"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
||||||
|
|
||||||
"github.com/akamensky/argparse"
|
"github.com/akamensky/argparse"
|
||||||
@@ -47,8 +46,6 @@ const localConfigFile = "./conf/local_ocmonitord_conf.json"
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
os.Setenv("test_service", "true") // Only for service demo, delete before merging on main
|
|
||||||
|
|
||||||
monitorLocal = false
|
monitorLocal = false
|
||||||
// Test if monitor is launched outside (with parameters) or in a k8s environment (env variables sets)
|
// Test if monitor is launched outside (with parameters) or in a k8s environment (env variables sets)
|
||||||
if os.Getenv("KUBERNETES_SERVICE_HOST") == "" {
|
if os.Getenv("KUBERNETES_SERVICE_HOST") == "" {
|
||||||
@@ -256,6 +253,7 @@ func setConf(is_k8s bool, o *onion.Onion, parser *argparse.Parser) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func initOnion(o *onion.Onion) *onion.Onion {
|
func initOnion(o *onion.Onion) *onion.Onion {
|
||||||
logger = logs.CreateLogger("oc-monitord")
|
logger = logs.CreateLogger("oc-monitord")
|
||||||
configFile := ""
|
configFile := ""
|
||||||
@@ -307,11 +305,10 @@ func checkStatus(current string, previous string) {
|
|||||||
func updateStatus(status string) {
|
func updateStatus(status string) {
|
||||||
exec_id := conf.GetConfig().ExecutionID
|
exec_id := conf.GetConfig().ExecutionID
|
||||||
|
|
||||||
wf_exec := &workflow_execution.WorkflowExecution{AbstractObject: utils.AbstractObject{UUID: conf.GetConfig().ExecutionID}}
|
wf_exec := &workflow_execution.WorkflowExecution{}
|
||||||
wf_exec.ArgoStatusToState(status)
|
wf_exec.ArgoStatusToState(status)
|
||||||
|
|
||||||
serialized := wf_exec.Serialize()
|
serialized := wf_exec.Serialize()
|
||||||
|
|
||||||
res := oclib.UpdateOne(oclib.LibDataEnum(oclib.WORKFLOW_EXECUTION), serialized, exec_id)
|
res := oclib.UpdateOne(oclib.LibDataEnum(oclib.WORKFLOW_EXECUTION), serialized, exec_id)
|
||||||
|
|
||||||
if res.Code != 200 {
|
if res.Code != 200 {
|
||||||
|
|||||||
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 {
|
type Service struct {
|
||||||
APIVersion string `yaml:"apiVersion"`
|
Manifest
|
||||||
Kind string `yaml:"kind"`
|
|
||||||
Metadata Metadata `yaml:"metadata"`
|
|
||||||
Spec ServiceSpec `yaml:"spec"`
|
Spec ServiceSpec `yaml:"spec"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Metadata struct {
|
|
||||||
Name string `yaml:"name"`
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// ServiceSpec is the specification of the Kubernetes Service
|
// ServiceSpec is the specification of the Kubernetes Service
|
||||||
type ServiceSpec struct {
|
type ServiceSpec struct {
|
||||||
|
|||||||
BIN
oc-monitord
BIN
oc-monitord
Binary file not shown.
11
traefik-values.yaml
Normal file
11
traefik-values.yaml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
globalArguments:
|
||||||
|
deployment:
|
||||||
|
kind: DaemonSet
|
||||||
|
providers:
|
||||||
|
kubernetesCRD:
|
||||||
|
enabled: true
|
||||||
|
service:
|
||||||
|
type: LoadBalancer
|
||||||
|
ingressRoute:
|
||||||
|
dashboard:
|
||||||
|
enabled: false
|
||||||
@@ -5,14 +5,17 @@
|
|||||||
package workflow_builder
|
package workflow_builder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"oc-monitord/models"
|
||||||
. "oc-monitord/models"
|
. "oc-monitord/models"
|
||||||
"os"
|
"os"
|
||||||
"slices"
|
"slices"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
oclib "cloud.o-forge.io/core/oc-lib"
|
oclib "cloud.o-forge.io/core/oc-lib"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/workflow/graph"
|
"cloud.o-forge.io/core/oc-lib/models/resources/workflow/graph"
|
||||||
w "cloud.o-forge.io/core/oc-lib/models/workflow"
|
w "cloud.o-forge.io/core/oc-lib/models/workflow"
|
||||||
"github.com/nwtgck/go-fakelish"
|
"github.com/nwtgck/go-fakelish"
|
||||||
@@ -22,23 +25,26 @@ import (
|
|||||||
|
|
||||||
var logger zerolog.Logger
|
var logger zerolog.Logger
|
||||||
|
|
||||||
|
type ServiceExposure int
|
||||||
|
const (
|
||||||
|
PAT ServiceExposure = iota
|
||||||
|
Reverse
|
||||||
|
Both
|
||||||
|
)
|
||||||
|
|
||||||
type ArgoBuilder struct {
|
type ArgoBuilder struct {
|
||||||
OriginWorkflow w.Workflow
|
OriginWorkflow w.Workflow
|
||||||
Workflow Workflow
|
Workflow Workflow
|
||||||
Services *Service
|
Services []Service
|
||||||
Timeout int
|
Timeout int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Workflow struct {
|
type Workflow struct {
|
||||||
ApiVersion string `yaml:"apiVersion"`
|
Manifest
|
||||||
Kind string `yaml:"kind"`
|
Spec ArgoSpec `yaml:"spec,omitempty"`
|
||||||
Metadata struct {
|
|
||||||
Name string `yaml:"name"`
|
|
||||||
} `yaml:"metadata"`
|
|
||||||
Spec Spec `yaml:"spec,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Spec struct {
|
type ArgoSpec struct {
|
||||||
Entrypoint string `yaml:"entrypoint"`
|
Entrypoint string `yaml:"entrypoint"`
|
||||||
Arguments []Parameter `yaml:"arguments,omitempty"`
|
Arguments []Parameter `yaml:"arguments,omitempty"`
|
||||||
Volumes []VolumeClaimTemplate `yaml:"volumeClaimTemplates,omitempty"`
|
Volumes []VolumeClaimTemplate `yaml:"volumeClaimTemplates,omitempty"`
|
||||||
@@ -46,13 +52,12 @@ type Spec struct {
|
|||||||
Timeout int `yaml:"activeDeadlineSeconds,omitempty"`
|
Timeout int `yaml:"activeDeadlineSeconds,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (b *ArgoBuilder) CreateDAG() (string, error) {
|
func (b *ArgoBuilder) CreateDAG() (string, error) {
|
||||||
|
|
||||||
// handle services by checking if there is only one processing with hostname and port
|
// handle services by checking if there is only one processing with hostname and port
|
||||||
|
|
||||||
b.createNginxVolumes()
|
|
||||||
|
|
||||||
|
|
||||||
b.createTemplates()
|
b.createTemplates()
|
||||||
b.createDAGstep()
|
b.createDAGstep()
|
||||||
b.createVolumes()
|
b.createVolumes()
|
||||||
@@ -62,7 +67,7 @@ func (b *ArgoBuilder) CreateDAG() (string, error) {
|
|||||||
b.Workflow.Spec.Timeout = b.Timeout
|
b.Workflow.Spec.Timeout = b.Timeout
|
||||||
}
|
}
|
||||||
b.Workflow.Spec.Entrypoint = "dag"
|
b.Workflow.Spec.Entrypoint = "dag"
|
||||||
b.Workflow.ApiVersion = "argoproj.io/v1alpha1"
|
b.Workflow.Manifest.ApiVersion = "argoproj.io/v1alpha1"
|
||||||
b.Workflow.Kind = "Workflow"
|
b.Workflow.Kind = "Workflow"
|
||||||
random_name := generateWfName()
|
random_name := generateWfName()
|
||||||
b.Workflow.Metadata.Name = "oc-monitor-" + random_name
|
b.Workflow.Metadata.Name = "oc-monitor-" + random_name
|
||||||
@@ -91,6 +96,7 @@ func (b *ArgoBuilder) createTemplates() {
|
|||||||
var command string
|
var command string
|
||||||
var args string
|
var args string
|
||||||
var env string
|
var env string
|
||||||
|
var serv models.Service
|
||||||
|
|
||||||
comp_res := comp.Processing
|
comp_res := comp.Processing
|
||||||
|
|
||||||
@@ -114,24 +120,39 @@ func (b *ArgoBuilder) createTemplates() {
|
|||||||
new_temp := Template{Name: argo_name, Container: temp_container}
|
new_temp := Template{Name: argo_name, Container: temp_container}
|
||||||
new_temp.Inputs.Parameters = inputs_container
|
new_temp.Inputs.Parameters = inputs_container
|
||||||
new_temp.Container.VolumeMounts = append(new_temp.Container.VolumeMounts, VolumeMount{Name: "workdir", MountPath: "/mnt/vol"}) // TODO : replace this with a search of the storage / data source name
|
new_temp.Container.VolumeMounts = append(new_temp.Container.VolumeMounts, VolumeMount{Name: "workdir", MountPath: "/mnt/vol"}) // TODO : replace this with a search of the storage / data source name
|
||||||
new_temp.Container.VolumeMounts = append(new_temp.Container.VolumeMounts, VolumeMount{Name: "nginx-demo", MountPath: "/usr/share/nginx"}) // Used for processing services' demo with nginx
|
|
||||||
|
|
||||||
if (b.isService(comp.ID)){
|
if (b.isService(comp.ID)){
|
||||||
serv := b.CreateService(comp)
|
|
||||||
b.createService(serv, argo_name, comp.ID)
|
serv_type := getServiceExposure(*comp.Processing)
|
||||||
new_temp.Metadata.Labels = make(map[string]string)
|
if serv_type == PAT || serv_type == Both{
|
||||||
new_temp.Metadata.Labels["app"] = "oc-service" // Construct the template for the k8s service and add a link in graph between k8s service and processing
|
serv = b.CreateKubeService(comp, NodePort)
|
||||||
|
b.addKubeServiceToWorkflow(serv, argo_name, comp.ID)
|
||||||
|
new_temp.Metadata.Labels = make(map[string]string)
|
||||||
|
new_temp.Metadata.Labels["app"] = serv.Spec.Selector["app"] // Construct the template for the k8s service and add a link in graph between k8s service and processing
|
||||||
|
b.addServiceToArgo(serv)
|
||||||
|
ingress := b.CreateIngress(comp,serv)
|
||||||
|
b.addIngressToWorfklow(ingress, argo_name, comp.ID)
|
||||||
|
|
||||||
|
}
|
||||||
|
if serv_type == Reverse || serv_type == Both{
|
||||||
|
serv = b.CreateKubeService(comp, ClusterIP)
|
||||||
|
// create ingress by passing the service and the processing (or reverse)
|
||||||
|
b.addKubeServiceToWorkflow(serv, argo_name, comp.ID)
|
||||||
|
new_temp.Metadata.Labels = make(map[string]string)
|
||||||
|
new_temp.Metadata.Labels["app"] = serv.Spec.Selector["app"] // Construct the template for the k8s service and add a link in graph between k8s service and processing
|
||||||
|
b.addServiceToArgo(serv)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// // TODO
|
// // TODO
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
b.Workflow.Spec.Templates = append(b.Workflow.Spec.Templates, new_temp)
|
b.Workflow.Spec.Templates = append(b.Workflow.Spec.Templates, new_temp)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.Services != nil {
|
|
||||||
b.addServiceToArgo()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,8 +174,9 @@ func (b *ArgoBuilder) createDAGstep() {
|
|||||||
new_dag.Tasks = append(new_dag.Tasks, step)
|
new_dag.Tasks = append(new_dag.Tasks, step)
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.Services != nil {
|
for i, _ := range b.Services {
|
||||||
new_dag.Tasks = append(new_dag.Tasks, Task{Name:"workflow-service-pod", Template: "workflow-service-pod"})
|
name := "workflow-service-pod-"+strconv.Itoa(i + 1)
|
||||||
|
new_dag.Tasks = append(new_dag.Tasks, Task{Name: name , Template: name})
|
||||||
}
|
}
|
||||||
|
|
||||||
b.Workflow.Spec.Templates = append(b.Workflow.Spec.Templates, Template{Name: "dag", Dag: new_dag})
|
b.Workflow.Spec.Templates = append(b.Workflow.Spec.Templates, Template{Name: "dag", Dag: new_dag})
|
||||||
@@ -170,15 +192,6 @@ func (b *ArgoBuilder) createVolumes() {
|
|||||||
b.Workflow.Spec.Volumes = append(b.Workflow.Spec.Volumes, new_volume)
|
b.Workflow.Spec.Volumes = append(b.Workflow.Spec.Volumes, new_volume)
|
||||||
}
|
}
|
||||||
|
|
||||||
// For demo purposes, until we implement the use of storage ressources
|
|
||||||
func (b *ArgoBuilder) createNginxVolumes() {
|
|
||||||
new_volume := VolumeClaimTemplate{}
|
|
||||||
new_volume.Metadata.Name = "nginx-demo"
|
|
||||||
new_volume.Spec.AccessModes = []string{"ReadWriteOnce"}
|
|
||||||
new_volume.Spec.Resources.Requests.Storage = "1Gi"
|
|
||||||
|
|
||||||
b.Workflow.Spec.Volumes = append(b.Workflow.Spec.Volumes, new_volume)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func (b *ArgoBuilder) getDependency(current_computing_id string) (dependencies []string) {
|
func (b *ArgoBuilder) getDependency(current_computing_id string) (dependencies []string) {
|
||||||
@@ -319,14 +332,29 @@ func (b *ArgoBuilder) isService(id string) bool{
|
|||||||
return is_exposed
|
return is_exposed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getServiceExposure(service processing.ProcessingResource) ServiceExposure{
|
||||||
|
var exposure_type ServiceExposure
|
||||||
|
|
||||||
func (b *ArgoBuilder) addLabel(name string, id string) {
|
contract := getExposeContract(service.ResourceModel.Model["expose"])
|
||||||
argo_name := getArgoName(name,id)
|
_, pat := contract["PAT"]
|
||||||
for _, template := range b.Workflow.Spec.Templates{
|
_, reverse := contract["reverse"]
|
||||||
if template.Name == argo_name{
|
|
||||||
template.Metadata.Labels["app"] = "service-workflow"
|
if pat && reverse {
|
||||||
return
|
exposure_type= Both
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if pat {
|
||||||
|
exposure_type = PAT
|
||||||
|
}
|
||||||
|
if reverse{
|
||||||
|
exposure_type = Reverse
|
||||||
|
}
|
||||||
|
|
||||||
|
return exposure_type
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *ArgoBuilder) CreateIngress(processing processing.ProcessingResource, service Service) Ingress{
|
||||||
|
contract := getExposeContract(processing.ResourceModel.Model["expose"])
|
||||||
|
new_ingress := models.NewIngress(contract,service.Metadata.Name)
|
||||||
|
return new_ingress
|
||||||
|
}
|
||||||
@@ -7,11 +7,19 @@ import (
|
|||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/workflow/graph"
|
"cloud.o-forge.io/core/oc-lib/models/resources/workflow/graph"
|
||||||
|
"github.com/nwtgck/go-fakelish"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
"gopkg.in/yaml.v3"
|
"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
|
// 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 {
|
func getExposeContract(expose resource_model.Model) map[string]map[string]string {
|
||||||
contract := make(map[string]map[string]string,0)
|
contract := make(map[string]map[string]string,0)
|
||||||
@@ -40,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 {
|
// model {
|
||||||
// Type : "dict",
|
// Type : "dict",
|
||||||
@@ -57,23 +65,24 @@ func (b *ArgoBuilder) CreateService(processing graph.GraphItem) models.Service{
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
new_service := models.Service{APIVersion: "v1",
|
new_service := models.Service{
|
||||||
Kind: "Service",
|
Manifest: models.Manifest{
|
||||||
Metadata: models.Metadata{
|
ApiVersion: "v1",
|
||||||
Name: "workflow-service" ,
|
Kind: "Service",
|
||||||
},
|
Metadata: models.Metadata{
|
||||||
Spec: models.ServiceSpec{
|
Name: "workflow-service-"+ processing.Processing.Name + "-" + processing.ID ,
|
||||||
Selector: map[string]string{"app": "oc-service"},
|
},
|
||||||
Ports: []models.ServicePort{
|
},
|
||||||
},
|
Spec: models.ServiceSpec{
|
||||||
Type: "NodePort",
|
Selector: map[string]string{"app": "service-" + fakelish.GenerateFakeWord(5, 8)},
|
||||||
},
|
Ports: []models.ServicePort{
|
||||||
}
|
},
|
||||||
|
Type: string(service_type),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
completeServicePorts(&new_service, processing)
|
completeServicePorts(&new_service, processing)
|
||||||
yamlified, _ := yaml.Marshal(new_service)
|
|
||||||
x := string(yamlified)
|
|
||||||
_ = x
|
|
||||||
return new_service
|
return new_service
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +99,7 @@ func completeServicePorts(service *models.Service, processing graph.GraphItem) {
|
|||||||
return
|
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{
|
if _, ok := translation_dict["PAT"]; ok{
|
||||||
port_translation, err := strconv.ParseInt(translation_dict["PAT"], 10, 64)
|
port_translation, err := strconv.ParseInt(translation_dict["PAT"], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -98,8 +107,6 @@ func completeServicePorts(service *models.Service, processing graph.GraphItem) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
new_port_translation := models.ServicePort{
|
new_port_translation := models.ServicePort{
|
||||||
Name: strings.ToLower(processing.Processing.Name) + processing.ID,
|
Name: strings.ToLower(processing.Processing.Name) + processing.ID,
|
||||||
Port: port_translation-30000,
|
Port: port_translation-30000,
|
||||||
@@ -108,32 +115,52 @@ func completeServicePorts(service *models.Service, processing graph.GraphItem) {
|
|||||||
Protocol: "TCP",
|
Protocol: "TCP",
|
||||||
}
|
}
|
||||||
service.Spec.Ports = append(service.Spec.Ports, new_port_translation)
|
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) 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...)
|
||||||
|
return service_available_port.Spec.Selector["app"]
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
b.Services = append(b.Services, service)
|
||||||
|
return service.Spec.Selector["app"]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *ArgoBuilder) createService(service models.Service, processing_name string, processing_id string) {
|
func (b *ArgoBuilder) addServiceToArgo(service models.Service) error {
|
||||||
if b.Services != nil{
|
service_manifest, err := yaml.Marshal(service)
|
||||||
b.Services.Spec.Ports = append(b.Services.Spec.Ports, service.Spec.Ports...)
|
|
||||||
}else {
|
|
||||||
b.Services = &service
|
|
||||||
}
|
|
||||||
|
|
||||||
b.addLabel(processing_name,processing_id)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *ArgoBuilder) addServiceToArgo() error {
|
|
||||||
service_manifest, err := yaml.Marshal(b.Services)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error().Msg("Could not marshal service manifest")
|
logger.Error().Msg("Could not marshal service manifest")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
service_template := models.Template{Name: "workflow-service-pod",
|
service_template := models.Template{Name: "workflow-service-pod-" + strconv.Itoa(len(b.Services)),
|
||||||
Resource: models.ServiceResource{
|
Resource: models.ServiceResource{
|
||||||
Action: "create",
|
Action: "create",
|
||||||
SuccessCondition: "status.succeeded > 0",
|
SuccessCondition: "status.succeeded > 0",
|
||||||
@@ -146,3 +173,43 @@ func (b *ArgoBuilder) addServiceToArgo() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (b *ArgoBuilder) addLabel(name string, id string) {
|
||||||
|
argo_name := getArgoName(name,id)
|
||||||
|
for _, template := range b.Workflow.Spec.Templates{
|
||||||
|
if template.Name == argo_name{
|
||||||
|
template.Metadata.Labels["app"] = "service-workflow"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ArgoBuilder) portAlreadyExposed(port int64) (exposed bool, service *models.Service ){
|
||||||
|
// For all already existing k8s services, test if the port in parameter is already exposed and returns the first service that doesn't yet expose this port
|
||||||
|
for _, s := range b.Services {
|
||||||
|
i := 0
|
||||||
|
port_exposed := false
|
||||||
|
for !port_exposed {
|
||||||
|
if s.Spec.Ports[i].TargetPort == port {
|
||||||
|
port_exposed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !port_exposed {
|
||||||
|
return false, &s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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