From 2089f595a68e3fc60c871562b93421f2a20c011a Mon Sep 17 00:00:00 2001 From: Aditya Bisht Date: Sun, 30 Jul 2023 21:56:12 +0530 Subject: [PATCH] Add dynamic ingress host --- Makefile | 1 - config.sample.toml | 7 +------ configs/types.go | 12 +++--------- kubernetes/{manifests => templates}/gogs.yml | 2 +- kubernetes/templates/mongo.yml | 2 +- kubernetes/templates/mysql.yml | 2 +- lib/utils/kube.go | 1 + services/challengedeployerservice/helper.go | 3 ++- types/deployment.go | 1 + 9 files changed, 11 insertions(+), 20 deletions(-) rename kubernetes/{manifests => templates}/gogs.yml (98%) diff --git a/Makefile b/Makefile index a618519a..0d5cdc94 100644 --- a/Makefile +++ b/Makefile @@ -83,7 +83,6 @@ set-env: build minikube start --driver=docker && \ minikube addons enable ingress && \ kubectl apply -f $(MANIFEST) && \ - sudo -- sh -c "echo \"$(minikube service nginx-ingress-controller --url -n kube-system | awk '{print substr($0,8)}' | awk '{print substr($0, 1, length($0)-6)}' | head -1) katana.local\" >> /etc/hosts" &&\ cp config.sample.toml config.toml && \ ./bin/katana run diff --git a/config.sample.toml b/config.sample.toml index 25a01261..b5891953 100644 --- a/config.sample.toml +++ b/config.sample.toml @@ -1,6 +1,7 @@ kubeconfig = "" kubehost = "0.0.0.0" backendurl = "http://192.168.49.1:3000" +ingresshost = "katana.local" rootdirectory = "/opt/katana" kubenamespace = "default" timeout = 20 @@ -19,11 +20,6 @@ templated_manifests = [ host = "0.0.0.0" port = 3000 -[services.challengedeployer] -host = "challengedeployer.katana.local" -port = 8002 -teamclientport = 3004 - [teamvm] teampodname = "katana-team-master-pod" containername = "teamvm" @@ -43,7 +39,6 @@ username = "adminuser" password = "password123" port = "32000" mongosh_version = "1.6.1" -cluster_url = "challengedeployer.katana.local" [mysql] username = "root" diff --git a/configs/types.go b/configs/types.go index 4a73a1e8..8d760540 100644 --- a/configs/types.go +++ b/configs/types.go @@ -13,21 +13,14 @@ type ClusterCfg struct { TemplatedManifests []string `toml:"templated_manifests"` } -type ChallengeDeployerCfg struct { - Host string `toml:"host"` - Port uint `toml:"port"` - TeamClientPort uint `toml:"teamclientport"` -} - type AdminCfg struct { Username string `toml:"username"` Password string `toml:"password"` } type ServicesCfg struct { - API API `toml:"api"` - ChallengeDeployer ChallengeDeployerCfg `toml:"challengedeployer"` - SSHProvider SSHProviderCfg `toml:"sshprovider"` + API API `toml:"api"` + SSHProvider SSHProviderCfg `toml:"sshprovider"` } type TeamChallengeConfig struct { @@ -75,6 +68,7 @@ type KatanaCfg struct { Harbor HarborCfg `toml:"harbor"` TimeOut int `toml:"timeout"` TeamDeployment int32 `toml:"numberofdeployments"` + IngressHost string `toml:"ingresshost"` } type HarborCfg struct { diff --git a/kubernetes/manifests/gogs.yml b/kubernetes/templates/gogs.yml similarity index 98% rename from kubernetes/manifests/gogs.yml rename to kubernetes/templates/gogs.yml index 0228f7d8..8a651cb9 100644 --- a/kubernetes/manifests/gogs.yml +++ b/kubernetes/templates/gogs.yml @@ -103,7 +103,7 @@ metadata: spec: ingressClassName: nginx rules: - - host: gogs.katana.local + - host: {{ printf "gogs." .IngressHost }} http: paths: - path: / diff --git a/kubernetes/templates/mongo.yml b/kubernetes/templates/mongo.yml index e67fdb30..49e211be 100644 --- a/kubernetes/templates/mongo.yml +++ b/kubernetes/templates/mongo.yml @@ -114,7 +114,7 @@ metadata: spec: ingressClassName: nginx rules: - - host: mongo.katana.local + - host: {{ printf "mongo." .IngressHost }} http: paths: - path: / diff --git a/kubernetes/templates/mysql.yml b/kubernetes/templates/mysql.yml index b10a925d..7c97f6de 100644 --- a/kubernetes/templates/mysql.yml +++ b/kubernetes/templates/mysql.yml @@ -90,7 +90,7 @@ metadata: spec: ingressClassName: nginx rules: - - host: mysql.katana.local + - host: {{ printf "mysql." .IngressHost }} http: paths: - path: / diff --git a/lib/utils/kube.go b/lib/utils/kube.go index 986c496f..c7da934a 100644 --- a/lib/utils/kube.go +++ b/lib/utils/kube.go @@ -197,6 +197,7 @@ func DeploymentConfig() types.ManifestConfig { ChallengDir: g.TeamVmConfig.ChallengeDir, TempDir: g.TeamVmConfig.TempDir, InitFile: g.TeamVmConfig.InitFile, + IngressHost: g.KatanaConfig.IngressHost, DaemonPort: g.TeamVmConfig.DaemonPort, MongoUsername: Base64Encode(g.KatanaConfig.Mongo.Username), MongoPassword: Base64Encode(g.KatanaConfig.Mongo.Password), diff --git a/services/challengedeployerservice/helper.go b/services/challengedeployerservice/helper.go index c5dada0e..7c39a495 100644 --- a/services/challengedeployerservice/helper.go +++ b/services/challengedeployerservice/helper.go @@ -8,6 +8,7 @@ import ( git "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/config" + configs "github.com/sdslabs/katana/configs" g "github.com/sdslabs/katana/configs" "github.com/sdslabs/katana/lib/utils" v1 "k8s.io/api/core/v1" @@ -83,7 +84,7 @@ func createServiceAndIngressForChallenge(challengeName, teamName string, targetP // Create ingress ingressName := challengeName + "-ingress" - ingressHost := fmt.Sprintf("%s.%s.%s", challengeName, teamName, "katana.local") + ingressHost := fmt.Sprintf("%s.%s.%s", challengeName, teamName, configs.KatanaConfig.IngressHost) utils.CreateIngress(kubeclient, ingressName, teamNamespace, serviceName, port, ingressHost) log.Printf("Created ingress %s for challenge %s in namespace %s", ingressName, challengeName, teamNamespace) diff --git a/types/deployment.go b/types/deployment.go index c435a012..5a20d6bf 100644 --- a/types/deployment.go +++ b/types/deployment.go @@ -16,6 +16,7 @@ type ManifestConfig struct { ChallengDir string TempDir string InitFile string + IngressHost string DaemonPort uint MongoUsername string MongoPassword string