From f42f81243fc6ba1c95b7e28367cc083e9ab86a0e Mon Sep 17 00:00:00 2001 From: afeiszli Date: Wed, 18 Aug 2021 14:55:41 -0400 Subject: [PATCH] adding some rqlite vars --- config/config.go | 1 + config/environments/dev.yaml | 1 + database/database.go | 6 ++-- functions/local.go | 16 ++++++++- kube/netmaker-template.yaml | 65 ++++++++++++++---------------------- main.go | 1 - servercfg/serverconf.go | 11 ++++++ 7 files changed, 57 insertions(+), 44 deletions(-) diff --git a/config/config.go b/config/config.go index 119735c2..e6f370c1 100644 --- a/config/config.go +++ b/config/config.go @@ -52,6 +52,7 @@ type ServerConfig struct { DisableDefaultNet string `yaml:"disabledefaultnet"` GRPCSSL string `yaml:"grpcssl"` Version string `yaml:"version"` + SQLConn string `yaml:"sqlconn"` DefaultNodeLimit int32 `yaml:"defaultnodelimit"` Verbosity int32 `yaml:"verbosity"` } diff --git a/config/environments/dev.yaml b/config/environments/dev.yaml index 60b8cde4..c448796c 100644 --- a/config/environments/dev.yaml +++ b/config/environments/dev.yaml @@ -9,5 +9,6 @@ server: agentbackend: "" # defaults to "on" or AGENT_BACKEND (if set) clientmode: "" # defaults to "on" or CLIENT_MODE (if set) dnsmode: "" # defaults to "on" or DNS_MODE (if set) + sqlconn: "" # defaults to "http://" or SQL_CONN (if set) disableremoteipcheck: "" # defaults to "false" or DISABLE_REMOTE_IP_CHECK (if set) version: "0.7.1" # version of server \ No newline at end of file diff --git a/database/database.go b/database/database.go index 1362ae4e..c7705e3a 100644 --- a/database/database.go +++ b/database/database.go @@ -3,7 +3,8 @@ package database import ( "encoding/json" "errors" - + "log" + "github.com/gravitl/netmaker/servercfg" "github.com/rqlite/gorqlite" ) @@ -25,7 +26,8 @@ var Database gorqlite.Connection func InitializeDatabase() error { - conn, err := gorqlite.Open("http://") + //log.Println("sql conn value:",servercfg.GetSQLConn()) + conn, err := gorqlite.Open(servercfg.GetSQLConn()) if err != nil { return err } diff --git a/functions/local.go b/functions/local.go index 6b0dc888..cd28a4d2 100644 --- a/functions/local.go +++ b/functions/local.go @@ -20,11 +20,25 @@ func SetDNSDir() error { } _, err = os.Stat(dir + "/config/dnsconfig") if os.IsNotExist(err) { - os.Mkdir(dir+"/config/dnsconfig", 744) + os.Mkdir(dir+"/config/dnsconfig", 0744) } else if err != nil { PrintUserLog("","couldnt find or create /config/dnsconfig",0) return err } + _, err = os.Stat(dir + "/config/dnsconfig/Corefile") + if os.IsNotExist(err) { + err = SetCorefile("example.com") + if err != nil { + PrintUserLog("",err.Error(),0) + } + } + _, err = os.Stat(dir + "/config/dnsconfig/netmaker.hosts") + if os.IsNotExist(err) { + _, err = os.Create(dir + "/config/dnsconfig/netmaker.hosts") + if err != nil { + PrintUserLog("",err.Error(),0) + } + } return nil } diff --git a/kube/netmaker-template.yaml b/kube/netmaker-template.yaml index dbdc3ddb..c30fdd2d 100644 --- a/kube/netmaker-template.yaml +++ b/kube/netmaker-template.yaml @@ -1,62 +1,56 @@ apiVersion: v1 kind: Service metadata: - name: mongo + name: rqlite labels: - name: mongo + name: rqlite spec: ports: - - port: 27017 - targetPort: 27017 + - port: 4001 + targetPort: 4001 clusterIP: None selector: - role: mongo + role: rqlite --- apiVersion: apps/v1 kind: StatefulSet metadata: - name: mongo + name: rqlite spec: - serviceName: "mongo" + serviceName: "rqlite" replicas: 1 selector: matchLabels: - role: mongo + role: rqlite template: metadata: labels: - app: mongo - role: mongo + app: rqlite + role: rqlite spec: containers: - - name: mongo - image: mongo - env: - - name: MONGO_INITDB_ROOT_USERNAME - value: mongoadmin - - name: MONGO_INITDB_ROOT_PASSWORD - value: mongopass - securityContext: - privileged: true + - name: rqlite + image: rqlite/rqlite + ports: + - containerPort: 4001 volumeMounts: - - name: mongovol - mountPath: /data/db + - name: rqlitevol + mountPath: /rqlite/file/data volumes: - - name: mongovol + - name: rqlitevol persistentVolumeClaim: - claimName: mongodb-pvc + claimName: rqlite-pvc --- apiVersion: v1 kind: PersistentVolumeClaim metadata: - name: mongodb-pvc + name: rqlite-pvc spec: accessModes: - ReadWriteOnce resources: requests: - storage: 7Gi - storageClassName: microk8s-hostpath + storage: 1Gi --- apiVersion: apps/v1 kind: Deployment @@ -89,6 +83,8 @@ spec: value: "grpc.NETMAKER_BASE_DOMAIN:443" - name: COREDNS_ADDR value: "10.152.183.53" + - name: SQL_CONN + value: "http://rqlite-0:4001" - name: GRPC_SSL value: "on" - name: SERVER_HTTP_HOST @@ -103,20 +99,10 @@ spec: value: "off" - name: MASTER_KEY value: "Unkn0wn!" - - name: SERVER_GRPC_WIREGUARD - value: "off" - name: MASTER_KEY value: "secretkey" - name: CORS_ALLOWED_ORIGIN value: "*" - - name: MONGO_ADMIN - value: "mongoadmin" - - name: MONGO_PASS - value: "mongopass" - - name: MONGO_HOST - value: "mongo-0.mongo" - - name: MONGO_OPTS - value: "/?authSource=admin" volumes: - name: nm-pvc persistentVolumeClaim: @@ -132,7 +118,6 @@ spec: resources: requests: storage: 128Mi - storageClassName: microk8s-hostpath --- apiVersion: v1 kind: Service @@ -288,7 +273,7 @@ metadata: cert-manager.io/cluster-issuer: "letsencrypt-prod" nginx.ingress.kubernetes.io/ssl-redirect: 'true' spec: - ingressClassName: public + ingressClassName: nginx tls: - hosts: - api.NETMAKER_BASE_DOMAIN @@ -314,7 +299,7 @@ metadata: nginx.ingress.kubernetes.io/ssl-redirect: 'true' nginx.ingress.kubernetes.io/backend-protocol: "GRPC" spec: - ingressClassName: public + ingressClassName: nginx tls: - hosts: - grpc.NETMAKER_BASE_DOMAIN @@ -340,7 +325,7 @@ metadata: cert-manager.io/cluster-issuer: "letsencrypt-prod" nginx.ingress.kubernetes.io/ssl-redirect: 'true' spec: - ingressClassName: public + ingressClassName: nginx tls: - hosts: - dashboard.NETMAKER_BASE_DOMAIN diff --git a/main.go b/main.go index aab474a6..80253051 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,6 @@ import ( "os/signal" "strconv" "sync" - controller "github.com/gravitl/netmaker/controllers" "github.com/gravitl/netmaker/database" "github.com/gravitl/netmaker/functions" diff --git a/servercfg/serverconf.go b/servercfg/serverconf.go index 44b257ad..001b41b1 100644 --- a/servercfg/serverconf.go +++ b/servercfg/serverconf.go @@ -31,6 +31,7 @@ func GetServerConfig() config.ServerConfig { cfg.AllowedOrigin = GetAllowedOrigin() cfg.RestBackend = "off" cfg.Verbosity = GetVerbose() + cfg.SQLConn = GetSQLConn() if IsRestBackend() { cfg.RestBackend = "on" } @@ -307,3 +308,13 @@ func GetVerbose() int32 { } return int32(level) } + +func GetSQLConn() string { + sqlconn := "http://" + if os.Getenv("SQL_CONN") != "" { + sqlconn = os.Getenv("SQL_CONN") + } else if config.Config.Server.SQLConn != "" { + sqlconn = config.Config.Server.SQLConn + } + return sqlconn +} \ No newline at end of file