Skip to content

Commit

Permalink
Add dynamic ingress host
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisht13 committed Jul 30, 2023
1 parent 38ebbd8 commit 2089f59
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 20 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 1 addition & 6 deletions config.sample.toml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand All @@ -43,7 +39,6 @@ username = "adminuser"
password = "password123"
port = "32000"
mongosh_version = "1.6.1"
cluster_url = "challengedeployer.katana.local"

[mysql]
username = "root"
Expand Down
12 changes: 3 additions & 9 deletions configs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ metadata:
spec:
ingressClassName: nginx
rules:
- host: gogs.katana.local
- host: {{ printf "gogs." .IngressHost }}
http:
paths:
- path: /
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/templates/mongo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ metadata:
spec:
ingressClassName: nginx
rules:
- host: mongo.katana.local
- host: {{ printf "mongo." .IngressHost }}
http:
paths:
- path: /
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/templates/mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ metadata:
spec:
ingressClassName: nginx
rules:
- host: mysql.katana.local
- host: {{ printf "mysql." .IngressHost }}
http:
paths:
- path: /
Expand Down
1 change: 1 addition & 0 deletions lib/utils/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion services/challengedeployerservice/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions types/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type ManifestConfig struct {
ChallengDir string
TempDir string
InitFile string
IngressHost string
DaemonPort uint
MongoUsername string
MongoPassword string
Expand Down

0 comments on commit 2089f59

Please sign in to comment.