From 133503d8acbf5979279e32b5a1ff28882c70212a Mon Sep 17 00:00:00 2001 From: Sambhav Kothari Date: Wed, 25 Sep 2024 19:15:44 +0100 Subject: [PATCH] Refactor driver selection to allow registering new drivers Signed-off-by: Sambhav Kothari --- go.mod | 1 + go.sum | 166 ++++++++++++++++++++++++++++- main.go | 132 +---------------------- pkg/app/app.go | 139 ++++++++++++++++++++++++ pkg/drivers/config.go | 16 +++ pkg/drivers/dqlite/dqlite.go | 11 +- pkg/drivers/dqlite/no_dqlite.go | 11 +- pkg/drivers/factory.go | 43 ++++++++ pkg/drivers/http/http.go | 17 +++ pkg/drivers/mysql/mysql.go | 27 ++--- pkg/drivers/nats/new.go | 17 ++- pkg/drivers/pgsql/pgsql.go | 23 ++-- pkg/drivers/registry.go | 36 +++++++ pkg/drivers/sqlite/sqlite.go | 21 ++-- pkg/drivers/sqlite/sqlite_nocgo.go | 13 ++- pkg/endpoint/endpoint.go | 128 ++++------------------ pkg/endpoint/init.go | 11 ++ pkg/util/network.go | 13 +++ 18 files changed, 542 insertions(+), 283 deletions(-) create mode 100644 pkg/app/app.go create mode 100644 pkg/drivers/config.go create mode 100644 pkg/drivers/factory.go create mode 100644 pkg/drivers/http/http.go create mode 100644 pkg/drivers/registry.go create mode 100644 pkg/endpoint/init.go create mode 100644 pkg/util/network.go diff --git a/go.mod b/go.mod index 62704cd7..a99ad736 100644 --- a/go.mod +++ b/go.mod @@ -68,6 +68,7 @@ require ( github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/soheilhy/cmux v0.1.5 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/stretchr/testify v1.9.0 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 // indirect github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect diff --git a/go.sum b/go.sum index 8bb3823b..76c2f5a6 100644 --- a/go.sum +++ b/go.sum @@ -1,16 +1,134 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.110.7 h1:rJyC7nWRg2jWGZ4wSJ5nY65GTdYJkg0cd/uXb+ACI6o= +cloud.google.com/go v0.110.7/go.mod h1:+EYjdK8e5RME/VY/qLCAtuyALQ9q67dvuum8i+H5xsI= +cloud.google.com/go/accessapproval v1.7.1/go.mod h1:JYczztsHRMK7NTXb6Xw+dwbs/WnOJxbo/2mTI+Kgg68= +cloud.google.com/go/accesscontextmanager v1.8.1/go.mod h1:JFJHfvuaTC+++1iL1coPiG1eu5D24db2wXCDWDjIrxo= +cloud.google.com/go/aiplatform v1.48.0/go.mod h1:Iu2Q7sC7QGhXUeOhAj/oCK9a+ULz1O4AotZiqjQ8MYA= +cloud.google.com/go/analytics v0.21.3/go.mod h1:U8dcUtmDmjrmUTnnnRnI4m6zKn/yaA5N9RlEkYFHpQo= +cloud.google.com/go/apigateway v1.6.1/go.mod h1:ufAS3wpbRjqfZrzpvLC2oh0MFlpRJm2E/ts25yyqmXA= +cloud.google.com/go/apigeeconnect v1.6.1/go.mod h1:C4awq7x0JpLtrlQCr8AzVIzAaYgngRqWf9S5Uhg+wWs= +cloud.google.com/go/apigeeregistry v0.7.1/go.mod h1:1XgyjZye4Mqtw7T9TsY4NW10U7BojBvG4RMD+vRDrIw= +cloud.google.com/go/appengine v1.8.1/go.mod h1:6NJXGLVhZCN9aQ/AEDvmfzKEfoYBlfB80/BHiKVputY= +cloud.google.com/go/area120 v0.8.1/go.mod h1:BVfZpGpB7KFVNxPiQBuHkX6Ed0rS51xIgmGyjrAfzsg= +cloud.google.com/go/artifactregistry v1.14.1/go.mod h1:nxVdG19jTaSTu7yA7+VbWL346r3rIdkZ142BSQqhn5E= +cloud.google.com/go/asset v1.14.1/go.mod h1:4bEJ3dnHCqWCDbWJ/6Vn7GVI9LerSi7Rfdi03hd+WTQ= +cloud.google.com/go/assuredworkloads v1.11.1/go.mod h1:+F04I52Pgn5nmPG36CWFtxmav6+7Q+c5QyJoL18Lry0= +cloud.google.com/go/automl v1.13.1/go.mod h1:1aowgAHWYZU27MybSCFiukPO7xnyawv7pt3zK4bheQE= +cloud.google.com/go/baremetalsolution v1.1.1/go.mod h1:D1AV6xwOksJMV4OSlWHtWuFNZZYujJknMAP4Qa27QIA= +cloud.google.com/go/batch v1.3.1/go.mod h1:VguXeQKXIYaeeIYbuozUmBR13AfL4SJP7IltNPS+A4A= +cloud.google.com/go/beyondcorp v1.0.0/go.mod h1:YhxDWw946SCbmcWo3fAhw3V4XZMSpQ/VYfcKGAEU8/4= +cloud.google.com/go/bigquery v1.53.0/go.mod h1:3b/iXjRQGU4nKa87cXeg6/gogLjO8C6PmuM8i5Bi/u4= +cloud.google.com/go/billing v1.16.0/go.mod h1:y8vx09JSSJG02k5QxbycNRrN7FGZB6F3CAcgum7jvGA= +cloud.google.com/go/binaryauthorization v1.6.1/go.mod h1:TKt4pa8xhowwffiBmbrbcxijJRZED4zrqnwZ1lKH51U= +cloud.google.com/go/certificatemanager v1.7.1/go.mod h1:iW8J3nG6SaRYImIa+wXQ0g8IgoofDFRp5UMzaNk1UqI= +cloud.google.com/go/channel v1.16.0/go.mod h1:eN/q1PFSl5gyu0dYdmxNXscY/4Fi7ABmeHCJNf/oHmc= +cloud.google.com/go/cloudbuild v1.13.0/go.mod h1:lyJg7v97SUIPq4RC2sGsz/9tNczhyv2AjML/ci4ulzU= +cloud.google.com/go/clouddms v1.6.1/go.mod h1:Ygo1vL52Ov4TBZQquhz5fiw2CQ58gvu+PlS6PVXCpZI= +cloud.google.com/go/cloudtasks v1.12.1/go.mod h1:a9udmnou9KO2iulGscKR0qBYjreuX8oHwpmFsKspEvM= cloud.google.com/go/compute v1.23.0 h1:tP41Zoavr8ptEqaW6j+LQOnyBBhO7OkOMAGrgLopTwY= cloud.google.com/go/compute v1.23.0/go.mod h1:4tCnrn48xsqlwSAiLf1HXMQk8CONslYbdiEZc9FEIbM= cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= +cloud.google.com/go/contactcenterinsights v1.10.0/go.mod h1:bsg/R7zGLYMVxFFzfh9ooLTruLRCG9fnzhH9KznHhbM= +cloud.google.com/go/container v1.24.0/go.mod h1:lTNExE2R7f+DLbAN+rJiKTisauFCaoDq6NURZ83eVH4= +cloud.google.com/go/containeranalysis v0.10.1/go.mod h1:Ya2jiILITMY68ZLPaogjmOMNkwsDrWBSTyBubGXO7j0= +cloud.google.com/go/datacatalog v1.16.0/go.mod h1:d2CevwTG4yedZilwe+v3E3ZBDRMobQfSG/a6cCCN5R4= +cloud.google.com/go/dataflow v0.9.1/go.mod h1:Wp7s32QjYuQDWqJPFFlnBKhkAtiFpMTdg00qGbnIHVw= +cloud.google.com/go/dataform v0.8.1/go.mod h1:3BhPSiw8xmppbgzeBbmDvmSWlwouuJkXsXsb8UBih9M= +cloud.google.com/go/datafusion v1.7.1/go.mod h1:KpoTBbFmoToDExJUso/fcCiguGDk7MEzOWXUsJo0wsI= +cloud.google.com/go/datalabeling v0.8.1/go.mod h1:XS62LBSVPbYR54GfYQsPXZjTW8UxCK2fkDciSrpRFdY= +cloud.google.com/go/dataplex v1.9.0/go.mod h1:7TyrDT6BCdI8/38Uvp0/ZxBslOslP2X2MPDucliyvSE= +cloud.google.com/go/dataproc/v2 v2.0.1/go.mod h1:7Ez3KRHdFGcfY7GcevBbvozX+zyWGcwLJvvAMwCaoZ4= +cloud.google.com/go/dataqna v0.8.1/go.mod h1:zxZM0Bl6liMePWsHA8RMGAfmTG34vJMapbHAxQ5+WA8= +cloud.google.com/go/datastore v1.13.0/go.mod h1:KjdB88W897MRITkvWWJrg2OUtrR5XVj1EoLgSp6/N70= +cloud.google.com/go/datastream v1.10.0/go.mod h1:hqnmr8kdUBmrnk65k5wNRoHSCYksvpdZIcZIEl8h43Q= +cloud.google.com/go/deploy v1.13.0/go.mod h1:tKuSUV5pXbn67KiubiUNUejqLs4f5cxxiCNCeyl0F2g= +cloud.google.com/go/dialogflow v1.40.0/go.mod h1:L7jnH+JL2mtmdChzAIcXQHXMvQkE3U4hTaNltEuxXn4= +cloud.google.com/go/dlp v1.10.1/go.mod h1:IM8BWz1iJd8njcNcG0+Kyd9OPnqnRNkDV8j42VT5KOI= +cloud.google.com/go/documentai v1.22.0/go.mod h1:yJkInoMcK0qNAEdRnqY/D5asy73tnPe88I1YTZT+a8E= +cloud.google.com/go/domains v0.9.1/go.mod h1:aOp1c0MbejQQ2Pjf1iJvnVyT+z6R6s8pX66KaCSDYfE= +cloud.google.com/go/edgecontainer v1.1.1/go.mod h1:O5bYcS//7MELQZs3+7mabRqoWQhXCzenBu0R8bz2rwk= +cloud.google.com/go/errorreporting v0.3.0/go.mod h1:xsP2yaAp+OAW4OIm60An2bbLpqIhKXdWR/tawvl7QzU= +cloud.google.com/go/essentialcontacts v1.6.2/go.mod h1:T2tB6tX+TRak7i88Fb2N9Ok3PvY3UNbUsMag9/BARh4= +cloud.google.com/go/eventarc v1.13.0/go.mod h1:mAFCW6lukH5+IZjkvrEss+jmt2kOdYlN8aMx3sRJiAI= +cloud.google.com/go/filestore v1.7.1/go.mod h1:y10jsorq40JJnjR/lQ8AfFbbcGlw3g+Dp8oN7i7FjV4= +cloud.google.com/go/firestore v1.12.0/go.mod h1:b38dKhgzlmNNGTNZZwe7ZRFEuRab1Hay3/DBsIGKKy4= +cloud.google.com/go/functions v1.15.1/go.mod h1:P5yNWUTkyU+LvW/S9O6V+V423VZooALQlqoXdoPz5AE= +cloud.google.com/go/gkebackup v1.3.0/go.mod h1:vUDOu++N0U5qs4IhG1pcOnD1Mac79xWy6GoBFlWCWBU= +cloud.google.com/go/gkeconnect v0.8.1/go.mod h1:KWiK1g9sDLZqhxB2xEuPV8V9NYzrqTUmQR9shJHpOZw= +cloud.google.com/go/gkehub v0.14.1/go.mod h1:VEXKIJZ2avzrbd7u+zeMtW00Y8ddk/4V9511C9CQGTY= +cloud.google.com/go/gkemulticloud v1.0.0/go.mod h1:kbZ3HKyTsiwqKX7Yw56+wUGwwNZViRnxWK2DVknXWfw= +cloud.google.com/go/gsuiteaddons v1.6.1/go.mod h1:CodrdOqRZcLp5WOwejHWYBjZvfY0kOphkAKpF/3qdZY= +cloud.google.com/go/iam v1.1.1/go.mod h1:A5avdyVL2tCppe4unb0951eI9jreack+RJ0/d+KUZOU= +cloud.google.com/go/iap v1.8.1/go.mod h1:sJCbeqg3mvWLqjZNsI6dfAtbbV1DL2Rl7e1mTyXYREQ= +cloud.google.com/go/ids v1.4.1/go.mod h1:np41ed8YMU8zOgv53MMMoCntLTn2lF+SUzlM+O3u/jw= +cloud.google.com/go/iot v1.7.1/go.mod h1:46Mgw7ev1k9KqK1ao0ayW9h0lI+3hxeanz+L1zmbbbk= +cloud.google.com/go/kms v1.15.0/go.mod h1:c9J991h5DTl+kg7gi3MYomh12YEENGrf48ee/N/2CDM= +cloud.google.com/go/language v1.10.1/go.mod h1:CPp94nsdVNiQEt1CNjF5WkTcisLiHPyIbMhvR8H2AW0= +cloud.google.com/go/lifesciences v0.9.1/go.mod h1:hACAOd1fFbCGLr/+weUKRAJas82Y4vrL3O5326N//Wc= +cloud.google.com/go/logging v1.7.0/go.mod h1:3xjP2CjkM3ZkO73aj4ASA5wRPGGCRrPIAeNqVNkzY8M= +cloud.google.com/go/longrunning v0.5.1/go.mod h1:spvimkwdz6SPWKEt/XBij79E9fiTkHSQl/fRUUQJYJc= +cloud.google.com/go/managedidentities v1.6.1/go.mod h1:h/irGhTN2SkZ64F43tfGPMbHnypMbu4RB3yl8YcuEak= +cloud.google.com/go/maps v1.4.0/go.mod h1:6mWTUv+WhnOwAgjVsSW2QPPECmW+s3PcRyOa9vgG/5s= +cloud.google.com/go/mediatranslation v0.8.1/go.mod h1:L/7hBdEYbYHQJhX2sldtTO5SZZ1C1vkapubj0T2aGig= +cloud.google.com/go/memcache v1.10.1/go.mod h1:47YRQIarv4I3QS5+hoETgKO40InqzLP6kpNLvyXuyaA= +cloud.google.com/go/metastore v1.12.0/go.mod h1:uZuSo80U3Wd4zi6C22ZZliOUJ3XeM/MlYi/z5OAOWRA= +cloud.google.com/go/monitoring v1.15.1/go.mod h1:lADlSAlFdbqQuwwpaImhsJXu1QSdd3ojypXrFSMr2rM= +cloud.google.com/go/networkconnectivity v1.12.1/go.mod h1:PelxSWYM7Sh9/guf8CFhi6vIqf19Ir/sbfZRUwXh92E= +cloud.google.com/go/networkmanagement v1.8.0/go.mod h1:Ho/BUGmtyEqrttTgWEe7m+8vDdK74ibQc+Be0q7Fof0= +cloud.google.com/go/networksecurity v0.9.1/go.mod h1:MCMdxOKQ30wsBI1eI659f9kEp4wuuAueoC9AJKSPWZQ= +cloud.google.com/go/notebooks v1.9.1/go.mod h1:zqG9/gk05JrzgBt4ghLzEepPHNwE5jgPcHZRKhlC1A8= +cloud.google.com/go/optimization v1.4.1/go.mod h1:j64vZQP7h9bO49m2rVaTVoNM0vEBEN5eKPUPbZyXOrk= +cloud.google.com/go/orchestration v1.8.1/go.mod h1:4sluRF3wgbYVRqz7zJ1/EUNc90TTprliq9477fGobD8= +cloud.google.com/go/orgpolicy v1.11.1/go.mod h1:8+E3jQcpZJQliP+zaFfayC2Pg5bmhuLK755wKhIIUCE= +cloud.google.com/go/osconfig v1.12.1/go.mod h1:4CjBxND0gswz2gfYRCUoUzCm9zCABp91EeTtWXyz0tE= +cloud.google.com/go/oslogin v1.10.1/go.mod h1:x692z7yAue5nE7CsSnoG0aaMbNoRJRXO4sn73R+ZqAs= +cloud.google.com/go/phishingprotection v0.8.1/go.mod h1:AxonW7GovcA8qdEk13NfHq9hNx5KPtfxXNeUxTDxB6I= +cloud.google.com/go/policytroubleshooter v1.8.0/go.mod h1:tmn5Ir5EToWe384EuboTcVQT7nTag2+DuH3uHmKd1HU= +cloud.google.com/go/privatecatalog v0.9.1/go.mod h1:0XlDXW2unJXdf9zFz968Hp35gl/bhF4twwpXZAW50JA= +cloud.google.com/go/pubsub v1.33.0/go.mod h1:f+w71I33OMyxf9VpMVcZbnG5KSUkCOUHYpFd5U1GdRc= +cloud.google.com/go/pubsublite v1.8.1/go.mod h1:fOLdU4f5xldK4RGJrBMm+J7zMWNj/k4PxwEZXy39QS0= +cloud.google.com/go/recaptchaenterprise/v2 v2.7.2/go.mod h1:kR0KjsJS7Jt1YSyWFkseQ756D45kaYNTlDPPaRAvDBU= +cloud.google.com/go/recommendationengine v0.8.1/go.mod h1:MrZihWwtFYWDzE6Hz5nKcNz3gLizXVIDI/o3G1DLcrE= +cloud.google.com/go/recommender v1.10.1/go.mod h1:XFvrE4Suqn5Cq0Lf+mCP6oBHD/yRMA8XxP5sb7Q7gpA= +cloud.google.com/go/redis v1.13.1/go.mod h1:VP7DGLpE91M6bcsDdMuyCm2hIpB6Vp2hI090Mfd1tcg= +cloud.google.com/go/resourcemanager v1.9.1/go.mod h1:dVCuosgrh1tINZ/RwBufr8lULmWGOkPS8gL5gqyjdT8= +cloud.google.com/go/resourcesettings v1.6.1/go.mod h1:M7mk9PIZrC5Fgsu1kZJci6mpgN8o0IUzVx3eJU3y4Jw= +cloud.google.com/go/retail v1.14.1/go.mod h1:y3Wv3Vr2k54dLNIrCzenyKG8g8dhvhncT2NcNjb/6gE= +cloud.google.com/go/run v1.2.0/go.mod h1:36V1IlDzQ0XxbQjUx6IYbw8H3TJnWvhii963WW3B/bo= +cloud.google.com/go/scheduler v1.10.1/go.mod h1:R63Ldltd47Bs4gnhQkmNDse5w8gBRrhObZ54PxgR2Oo= +cloud.google.com/go/secretmanager v1.11.1/go.mod h1:znq9JlXgTNdBeQk9TBW/FnR/W4uChEKGeqQWAJ8SXFw= +cloud.google.com/go/security v1.15.1/go.mod h1:MvTnnbsWnehoizHi09zoiZob0iCHVcL4AUBj76h9fXA= +cloud.google.com/go/securitycenter v1.23.0/go.mod h1:8pwQ4n+Y9WCWM278R8W3nF65QtY172h4S8aXyI9/hsQ= +cloud.google.com/go/servicedirectory v1.11.0/go.mod h1:Xv0YVH8s4pVOwfM/1eMTl0XJ6bzIOSLDt8f8eLaGOxQ= +cloud.google.com/go/shell v1.7.1/go.mod h1:u1RaM+huXFaTojTbW4g9P5emOrrmLE69KrxqQahKn4g= +cloud.google.com/go/spanner v1.47.0/go.mod h1:IXsJwVW2j4UKs0eYDqodab6HgGuA1bViSqW4uH9lfUI= +cloud.google.com/go/speech v1.19.0/go.mod h1:8rVNzU43tQvxDaGvqOhpDqgkJTFowBpDvCJ14kGlJYo= +cloud.google.com/go/storagetransfer v1.10.0/go.mod h1:DM4sTlSmGiNczmV6iZyceIh2dbs+7z2Ayg6YAiQlYfA= +cloud.google.com/go/talent v1.6.2/go.mod h1:CbGvmKCG61mkdjcqTcLOkb2ZN1SrQI8MDyma2l7VD24= +cloud.google.com/go/texttospeech v1.7.1/go.mod h1:m7QfG5IXxeneGqTapXNxv2ItxP/FS0hCZBwXYqucgSk= +cloud.google.com/go/tpu v1.6.1/go.mod h1:sOdcHVIgDEEOKuqUoi6Fq53MKHJAtOwtz0GuKsWSH3E= +cloud.google.com/go/trace v1.10.1/go.mod h1:gbtL94KE5AJLH3y+WVpfWILmqgc6dXcqgNXdOPAQTYk= +cloud.google.com/go/translate v1.8.2/go.mod h1:d1ZH5aaOA0CNhWeXeC8ujd4tdCFw8XoNWRljklu5RHs= +cloud.google.com/go/video v1.19.0/go.mod h1:9qmqPqw/Ib2tLqaeHgtakU+l5TcJxCJbhFXM7UJjVzU= +cloud.google.com/go/videointelligence v1.11.1/go.mod h1:76xn/8InyQHarjTWsBR058SmlPCwQjgcvoW0aZykOvo= +cloud.google.com/go/vision/v2 v2.7.2/go.mod h1:jKa8oSYBWhYiXarHPvP4USxYANYUEdEsQrloLjrSwJU= +cloud.google.com/go/vmmigration v1.7.1/go.mod h1:WD+5z7a/IpZ5bKK//YmT9E047AD+rjycCAvyMxGJbro= +cloud.google.com/go/vmwareengine v1.0.0/go.mod h1:Px64x+BvjPZwWuc4HdmVhoygcXqEkGHXoa7uyfTgSI0= +cloud.google.com/go/vpcaccess v1.7.1/go.mod h1:FogoD46/ZU+JUBX9D606X21EnxiszYi2tArQwLY4SXs= +cloud.google.com/go/webrisk v1.9.1/go.mod h1:4GCmXKcOa2BZcZPn6DCEvE7HypmEJcJkr4mtM+sqYPc= +cloud.google.com/go/websecurityscanner v1.6.1/go.mod h1:Njgaw3rttgRHXzwCB8kgCYqv5/rGpFCsBOvPbYgszpg= +cloud.google.com/go/workflows v1.11.1/go.mod h1:Z+t10G1wF7h8LgdY/EmRcQY8ptBD/nvofaL6FqlET6g= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/Rican7/retry v0.1.0 h1:FqK94z34ly8Baa6K+G8Mmza9rYWTKOJk+yckIBB5qVk= github.com/Rican7/retry v0.1.0/go.mod h1:FgOROf8P5bebcC1DS0PdOQiqGUridaZvikzUmkFW6gg= +github.com/alecthomas/kingpin/v2 v2.3.2/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE= +github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/canonical/go-dqlite v1.5.1 h1:1YjtIrFsC1A3XlgsX38ARAiKhvkZS63PqsEd8z3T4yU= @@ -18,10 +136,12 @@ github.com/canonical/go-dqlite v1.5.1/go.mod h1:wp00vfMvPYgNCyxcPdHB5XExmDoCGoPU github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+gqO04wryn5h75LSazbRlnya1k= github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cockroachdb/datadriven v1.0.2 h1:H9MtNqVoVhvd9nCBwOyDjUEdZCREqbIdCJD93PBm/jA= @@ -32,30 +152,40 @@ github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzA github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/emicklei/go-restful/v3 v3.9.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.11.1/go.mod h1:uhMcXKCQMEJHiAb0w+YGefQLaTEw+YhGluxZkrTmD0g= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA= github.com/envoyproxy/protoc-gen-validate v1.0.2/go.mod h1:GpiZQP3dDbg4JouG/NNS7QWXpgx6x8QiMKdmN72jogE= +github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= +github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= +github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= @@ -64,6 +194,7 @@ github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo= github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -78,6 +209,7 @@ github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4= github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA= +github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -86,9 +218,13 @@ github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8 github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw= github.com/grpc-ecosystem/go-grpc-middleware v1.3.0/go.mod h1:z0ButlSOZa5vEBq9m2m2hlwIgKw+rp3sdCBRoJY+30Y= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= @@ -97,6 +233,8 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4 github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= +github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa h1:s+4MhCQ6YrzisK6hFJUX53drDT4UsSW3DEhKn0ifuHw= github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa/go.mod h1:a/s9Lp5W7n/DD0VrVoyJ00FbP2ytTPDVOivvn2bMlds= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= @@ -109,8 +247,11 @@ github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ= github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.14.4/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= @@ -122,17 +263,22 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI= github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g= github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= +github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= github.com/nats-io/jsm.go v0.0.31-0.20220317133147-fe318f464eee h1:+l6i7zS8N1LOokm7dzShezI9STRGrzp0O49Pw8Jetdk= github.com/nats-io/jsm.go v0.0.31-0.20220317133147-fe318f464eee/go.mod h1:EKSYvbvWAoh0hIfuZ+ieWm8u0VOTRTeDfuQvNPKRqEg= github.com/nats-io/jwt/v2 v2.2.1-0.20220113022732-58e87895b296/go.mod h1:0tqz9Hlu6bCBFLWAASKhE5vUA4c24L9KPUUgvwumE/k= @@ -149,7 +295,10 @@ github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI= github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= +github.com/onsi/ginkgo/v2 v2.9.4/go.mod h1:gCQYp2Q+kSoIj7ykSVb9nskRSsR6PUj4AiLywzIhbKM= +github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -176,22 +325,25 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/soheilhy/cmux v0.1.5 h1:jjzc5WVemNEDTLwv9tlmemhC73tI08BNOIGwBOo10Js= github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0= +github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tidwall/btree v1.6.0 h1:LDZfKfQIBHGHWSwckhXI0RPSXzlo+KYdjK7FWSqOzzg= github.com/tidwall/btree v1.6.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 h1:uruHq4dN7GR16kFc5fp3d1RIYzJW5onx8Ybykw2YQFA= github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI= github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM= +github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw= @@ -214,6 +366,7 @@ go.etcd.io/etcd/raft/v3 v3.5.13 h1:7r/NKAOups1YnKcfro2RvGGo2PTuizF/xh26Z2CTAzA= go.etcd.io/etcd/raft/v3 v3.5.13/go.mod h1:uUFibGLn2Ksm2URMxN1fICGhk8Wu96EfDQyuLhAcAmw= go.etcd.io/etcd/server/v3 v3.5.13 h1:V6KG+yMfMSqWt+lGnhFpP5z5dRUj1BDRJ5k1fQ9DFok= go.etcd.io/etcd/server/v3 v3.5.13/go.mod h1:K/8nbsGupHqmr5MkgaZpLlH1QdX1pcNQLAkODy44XcQ= +go.etcd.io/gofail v0.1.0/go.mod h1:VZBCXYGZhHAinaBiiqYvuDynvahNsAyLFwB3kEHKz1M= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.0 h1:PzIubN4/sjByhDRHLviCjJuweBXWFZWhghjg7cS28+M= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.0/go.mod h1:Ct6zzQEuGK3WpJs2n4dn+wfJYzd/+hNnxMRTWjGn30M= go.opentelemetry.io/otel v1.20.0 h1:vsb/ggIY+hUjD/zCAQHpzTmndPqv/ml2ArbsbfBYTAc= @@ -233,6 +386,7 @@ go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v8 go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= @@ -254,6 +408,7 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -296,6 +451,7 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -312,6 +468,7 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -349,6 +506,7 @@ google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHh gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= @@ -362,13 +520,17 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +k8s.io/api v0.28.6/go.mod h1:AM6Ys6g9MY3dl/XNaNfg/GePI0FT7WBGu8efU/lirAo= k8s.io/apimachinery v0.28.6 h1:RsTeR4z6S07srPg6XYrwXpTJVMXsjPXn0ODakMytSW0= k8s.io/apimachinery v0.28.6/go.mod h1:QFNX/kCl/EMT2WTSz8k4WLCv2XnkOLMaL8GAVRMdpsA= k8s.io/client-go v0.28.6 h1:Gge6ziyIdafRchfoBKcpaARuz7jfrK1R1azuwORIsQI= k8s.io/client-go v0.28.6/go.mod h1:+nu0Yp21Oeo/cBCsprNVXB2BfJTV51lFfe5tXl2rUL8= k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= +k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9/go.mod h1:wZK2AVp1uHCp4VamDVgBP2COHZjqD1T68Rf0CM3YjSM= k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 h1:qY1Ad8PODbnymg2pRbkyMT/ylpTrCM8P2RJ0yroCyIk= k8s.io/utils v0.0.0-20230406110748-d93618cff8a2/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= +sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E= sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= diff --git a/main.go b/main.go index 76ec48b7..caff9a5a 100644 --- a/main.go +++ b/main.go @@ -3,145 +3,17 @@ package main import ( "context" "errors" - "fmt" "os" - "time" - "github.com/k3s-io/kine/pkg/endpoint" - "github.com/k3s-io/kine/pkg/metrics" - "github.com/k3s-io/kine/pkg/signals" - "github.com/k3s-io/kine/pkg/version" + "github.com/k3s-io/kine/pkg/app" "github.com/sirupsen/logrus" - "github.com/urfave/cli/v2" -) - -var ( - config endpoint.Config - metricsConfig metrics.Config ) func main() { - app := cli.NewApp() - app.Name = "kine" - app.Usage = "Minimal etcd v3 API to support custom Kubernetes storage engines" - app.Version = fmt.Sprintf("%s (%s)", version.Version, version.GitCommit) - app.Flags = []cli.Flag{ - &cli.StringFlag{ - Name: "listen-address", - Value: "0.0.0.0:2379", - Destination: &config.Listener, - }, - &cli.StringFlag{ - Name: "endpoint", - Usage: "Storage endpoint (default is sqlite)", - Destination: &config.Endpoint, - }, - &cli.StringFlag{ - Name: "ca-file", - Usage: "CA cert for DB connection", - Destination: &config.BackendTLSConfig.CAFile, - }, - &cli.StringFlag{ - Name: "cert-file", - Usage: "Certificate for DB connection", - Destination: &config.BackendTLSConfig.CertFile, - }, - &cli.StringFlag{ - Name: "key-file", - Usage: "Key file for DB connection", - Destination: &config.BackendTLSConfig.KeyFile, - }, - &cli.BoolFlag{ - Name: "skip-verify", - Usage: "Whether the TLS client should verify the server certificate.", - Destination: &config.BackendTLSConfig.SkipVerify, - Value: false, - }, - &cli.StringFlag{ - Name: "metrics-bind-address", - Usage: "The address the metric endpoint binds to. Default :8080, set 0 to disable metrics serving.", - Destination: &metricsConfig.ServerAddress, - Value: ":8080", - }, - &cli.StringFlag{ - Name: "server-cert-file", - Usage: "Certificate for etcd connection", - Destination: &config.ServerTLSConfig.CertFile, - }, - &cli.StringFlag{ - Name: "server-key-file", - Usage: "Key file for etcd connection", - Destination: &config.ServerTLSConfig.KeyFile, - }, - &cli.IntFlag{ - Name: "datastore-max-idle-connections", - Usage: "Maximum number of idle connections retained by datastore. If value = 0, the system default will be used. If value < 0, idle connections will not be reused.", - Destination: &config.ConnectionPoolConfig.MaxIdle, - Value: 0, - }, - &cli.IntFlag{ - Name: "datastore-max-open-connections", - Usage: "Maximum number of open connections used by datastore. If value <= 0, then there is no limit", - Destination: &config.ConnectionPoolConfig.MaxOpen, - Value: 0, - }, - &cli.DurationFlag{ - Name: "datastore-connection-max-lifetime", - Usage: "Maximum amount of time a connection may be reused. If value <= 0, then there is no limit.", - Destination: &config.ConnectionPoolConfig.MaxLifetime, - Value: 0, - }, - &cli.DurationFlag{ - Name: "slow-sql-threshold", - Usage: "The duration which SQL executed longer than will be logged. Default 1s, set <= 0 to disable slow SQL log.", - Destination: &metrics.SlowSQLThreshold, - Value: time.Second, - }, - &cli.BoolFlag{ - Name: "metrics-enable-profiling", - Usage: "Enable net/http/pprof handlers on the metrics bind address. Default is false.", - Destination: &metricsConfig.EnableProfiling, - }, - &cli.DurationFlag{ - Name: "watch-progress-notify-interval", - Usage: "Interval between periodic watch progress notifications. Default is 5s to ensure support for watch progress notifications.", - Destination: &config.NotifyInterval, - Value: time.Second * 5, - }, - &cli.StringFlag{ - Name: "emulated-etcd-version", - Usage: "The emulated etcd version to return on a call to the status endpoint. Defaults to 3.5.13, in order to indicate support for watch progress notifications.", - Destination: &config.EmulatedETCDVersion, - Value: "3.5.13", - }, - &cli.BoolFlag{Name: "debug"}, - } - app.Action = run - + app := app.New() if err := app.Run(os.Args); err != nil { if !errors.Is(err, context.Canceled) { logrus.Fatal(err) } } } - -func run(c *cli.Context) error { - logrus.SetFormatter(&logrus.TextFormatter{ - FullTimestamp: true, - TimestampFormat: time.RFC3339Nano, - }) - if c.Bool("debug") { - logrus.SetLevel(logrus.TraceLevel) - } - ctx := signals.SetupSignalContext() - - metricsConfig.ServerTLSConfig = config.ServerTLSConfig - go metrics.Serve(ctx, metricsConfig) - config.MetricsRegisterer = metrics.Registry - _, err := endpoint.Listen(ctx, config) - if err != nil { - return err - } - <-ctx.Done() - return ctx.Err() -} diff --git a/pkg/app/app.go b/pkg/app/app.go new file mode 100644 index 00000000..f7521a28 --- /dev/null +++ b/pkg/app/app.go @@ -0,0 +1,139 @@ +package app + +import ( + "fmt" + "time" + + "github.com/k3s-io/kine/pkg/endpoint" + "github.com/k3s-io/kine/pkg/metrics" + "github.com/k3s-io/kine/pkg/signals" + "github.com/k3s-io/kine/pkg/version" + "github.com/sirupsen/logrus" + "github.com/urfave/cli/v2" +) + +var ( + config endpoint.Config + metricsConfig metrics.Config +) + +func New() *cli.App { + app := cli.NewApp() + app.Name = "kine" + app.Usage = "Minimal etcd v3 API to support custom Kubernetes storage engines" + app.Version = fmt.Sprintf("%s (%s)", version.Version, version.GitCommit) + app.Flags = []cli.Flag{ + &cli.StringFlag{ + Name: "listen-address", + Value: "0.0.0.0:2379", + Destination: &config.Listener, + }, + &cli.StringFlag{ + Name: "endpoint", + Usage: "Storage endpoint (default is sqlite)", + Destination: &config.Endpoint, + }, + &cli.StringFlag{ + Name: "ca-file", + Usage: "CA cert for DB connection", + Destination: &config.BackendTLSConfig.CAFile, + }, + &cli.StringFlag{ + Name: "cert-file", + Usage: "Certificate for DB connection", + Destination: &config.BackendTLSConfig.CertFile, + }, + &cli.StringFlag{ + Name: "key-file", + Usage: "Key file for DB connection", + Destination: &config.BackendTLSConfig.KeyFile, + }, + &cli.BoolFlag{ + Name: "skip-verify", + Usage: "Whether the TLS client should verify the server certificate.", + Destination: &config.BackendTLSConfig.SkipVerify, + Value: false, + }, + &cli.StringFlag{ + Name: "metrics-bind-address", + Usage: "The address the metric endpoint binds to. Default :8080, set 0 to disable metrics serving.", + Destination: &metricsConfig.ServerAddress, + Value: ":8080", + }, + &cli.StringFlag{ + Name: "server-cert-file", + Usage: "Certificate for etcd connection", + Destination: &config.ServerTLSConfig.CertFile, + }, + &cli.StringFlag{ + Name: "server-key-file", + Usage: "Key file for etcd connection", + Destination: &config.ServerTLSConfig.KeyFile, + }, + &cli.IntFlag{ + Name: "datastore-max-idle-connections", + Usage: "Maximum number of idle connections retained by datastore. If value = 0, the system default will be used. If value < 0, idle connections will not be reused.", + Destination: &config.ConnectionPoolConfig.MaxIdle, + Value: 0, + }, + &cli.IntFlag{ + Name: "datastore-max-open-connections", + Usage: "Maximum number of open connections used by datastore. If value <= 0, then there is no limit", + Destination: &config.ConnectionPoolConfig.MaxOpen, + Value: 0, + }, + &cli.DurationFlag{ + Name: "datastore-connection-max-lifetime", + Usage: "Maximum amount of time a connection may be reused. If value <= 0, then there is no limit.", + Destination: &config.ConnectionPoolConfig.MaxLifetime, + Value: 0, + }, + &cli.DurationFlag{ + Name: "slow-sql-threshold", + Usage: "The duration which SQL executed longer than will be logged. Default 1s, set <= 0 to disable slow SQL log.", + Destination: &metrics.SlowSQLThreshold, + Value: time.Second, + }, + &cli.BoolFlag{ + Name: "metrics-enable-profiling", + Usage: "Enable net/http/pprof handlers on the metrics bind address. Default is false.", + Destination: &metricsConfig.EnableProfiling, + }, + &cli.DurationFlag{ + Name: "watch-progress-notify-interval", + Usage: "Interval between periodic watch progress notifications. Default is 5s to ensure support for watch progress notifications.", + Destination: &config.NotifyInterval, + Value: time.Second * 5, + }, + &cli.StringFlag{ + Name: "emulated-etcd-version", + Usage: "The emulated etcd version to return on a call to the status endpoint. Defaults to 3.5.13, in order to indicate support for watch progress notifications.", + Destination: &config.EmulatedETCDVersion, + Value: "3.5.13", + }, + &cli.BoolFlag{Name: "debug"}, + } + app.Action = run + return app +} + +func run(c *cli.Context) error { + logrus.SetFormatter(&logrus.TextFormatter{ + FullTimestamp: true, + TimestampFormat: time.RFC3339Nano, + }) + if c.Bool("debug") { + logrus.SetLevel(logrus.TraceLevel) + } + ctx := signals.SetupSignalContext() + + metricsConfig.ServerTLSConfig = config.ServerTLSConfig + go metrics.Serve(ctx, metricsConfig) + config.MetricsRegisterer = metrics.Registry + _, err := endpoint.Listen(ctx, config) + if err != nil { + return err + } + <-ctx.Done() + return ctx.Err() +} diff --git a/pkg/drivers/config.go b/pkg/drivers/config.go new file mode 100644 index 00000000..d72efd43 --- /dev/null +++ b/pkg/drivers/config.go @@ -0,0 +1,16 @@ +package drivers + +import ( + "github.com/k3s-io/kine/pkg/drivers/generic" + "github.com/k3s-io/kine/pkg/tls" + "github.com/prometheus/client_golang/prometheus" +) + +type Config struct { + MetricsRegisterer prometheus.Registerer + Endpoint string + Scheme string + DataSourceName string + ConnectionPoolConfig generic.ConnectionPoolConfig + BackendTLSConfig tls.Config +} diff --git a/pkg/drivers/dqlite/dqlite.go b/pkg/drivers/dqlite/dqlite.go index 9c7602dd..f1c8bedd 100644 --- a/pkg/drivers/dqlite/dqlite.go +++ b/pkg/drivers/dqlite/dqlite.go @@ -15,11 +15,11 @@ import ( "github.com/canonical/go-dqlite" "github.com/canonical/go-dqlite/client" "github.com/canonical/go-dqlite/driver" + "github.com/k3s-io/kine/pkg/drivers" "github.com/k3s-io/kine/pkg/drivers/generic" "github.com/k3s-io/kine/pkg/drivers/sqlite" "github.com/k3s-io/kine/pkg/server" "github.com/pkg/errors" - "github.com/prometheus/client_golang/prometheus" "github.com/sirupsen/logrus" ) @@ -29,6 +29,7 @@ var ( ) func init() { + generic.RegisterDriver("dqlite", New) // We assume SQLite will be used multi-threaded if err := dqlite.ConfigMultiThread(); err != nil { panic(errors.Wrap(err, "failed to set dqlite multithreaded mode")) @@ -69,7 +70,8 @@ outer: return nil } -func New(ctx context.Context, datasourceName string, connPoolConfig generic.ConnectionPoolConfig, metricsRegisterer prometheus.Registerer) (server.Backend, error) { +func New(ctx context.Context, cfg *drivers.Config) (bool, server.Backend, error) { + dataSourceName = cfg.Address opts, err := parseOpts(datasourceName) if err != nil { return nil, err @@ -98,7 +100,8 @@ func New(ctx context.Context, datasourceName string, connPoolConfig generic.Conn } sql.Register("dqlite", d) - backend, generic, err := sqlite.NewVariant(ctx, "dqlite", opts.dsn, connPoolConfig, metricsRegisterer) + cfg.Address = opts.dsn + backend, generic, err := sqlite.NewVariant(ctx, "dqlite", cfg) if err != nil { return nil, errors.Wrap(err, "sqlite client") } @@ -120,7 +123,7 @@ func New(ctx context.Context, datasourceName string, connPoolConfig generic.Conn return err } - return backend, nil + return true, backend, nil } func migrate(ctx context.Context, newDB *sql.DB) (exitErr error) { diff --git a/pkg/drivers/dqlite/no_dqlite.go b/pkg/drivers/dqlite/no_dqlite.go index 751e9d78..078ba06b 100644 --- a/pkg/drivers/dqlite/no_dqlite.go +++ b/pkg/drivers/dqlite/no_dqlite.go @@ -7,11 +7,14 @@ import ( "context" "errors" - "github.com/k3s-io/kine/pkg/drivers/generic" + "github.com/k3s-io/kine/pkg/drivers" "github.com/k3s-io/kine/pkg/server" - "github.com/prometheus/client_golang/prometheus" ) -func New(ctx context.Context, datasourceName string, connPoolConfig generic.ConnectionPoolConfig, metricsRegisterer prometheus.Registerer) (server.Backend, error) { - return nil, errors.New(`this binary is built without dqlite support, compile with "-tags dqlite"`) +func New(ctx context.Context, cfg *drivers.Config) (bool, server.Backend, error) { + return false, nil, errors.New(`this binary is built without dqlite support, compile with "-tags dqlite"`) +} + +func init() { + drivers.Register("dqlite", New) } diff --git a/pkg/drivers/factory.go b/pkg/drivers/factory.go new file mode 100644 index 00000000..07dcd2cb --- /dev/null +++ b/pkg/drivers/factory.go @@ -0,0 +1,43 @@ +package drivers + +import ( + "context" + "errors" + "strings" + + "github.com/k3s-io/kine/pkg/server" + "github.com/k3s-io/kine/pkg/util" +) + +var ErrUnknownDriver = errors.New("unknown driver") + +func New(ctx context.Context, cfg *Config) (leaderElect bool, backend server.Backend, err error) { + if cfg.Endpoint == "" { + driver := GetDefault() + if driver == nil { + return false, nil, errors.New("no default driver found") + } + return driver(ctx, cfg) + } + + if err := validateDSNuri(cfg.Endpoint); err != nil { + return false, nil, err + } + + cfg.Scheme, cfg.DataSourceName = util.SchemeAndAddress(cfg.Endpoint) + + driver, ok := Get(cfg.Scheme) + if !ok { + return false, nil, ErrUnknownDriver + } + return driver(ctx, cfg) +} + +// validateDSNuri ensure that the given string is of that format +func validateDSNuri(str string) error { + parts := strings.SplitN(str, "://", 2) + if len(parts) > 1 { + return nil + } + return errors.New("invalid datastore endpoint; endpoint should be a DSN URI in the format ://") +} diff --git a/pkg/drivers/http/http.go b/pkg/drivers/http/http.go new file mode 100644 index 00000000..e827134d --- /dev/null +++ b/pkg/drivers/http/http.go @@ -0,0 +1,17 @@ +package http + +import ( + "context" + + "github.com/k3s-io/kine/pkg/drivers" + "github.com/k3s-io/kine/pkg/server" +) + +func New(ctx context.Context, cfg *drivers.Config) (leaderElect bool, backend server.Backend, err error) { + return true, nil, nil +} + +func init() { + drivers.Register("http", New) + drivers.Register("https", New) +} diff --git a/pkg/drivers/mysql/mysql.go b/pkg/drivers/mysql/mysql.go index a67c6f75..2cf01b0d 100644 --- a/pkg/drivers/mysql/mysql.go +++ b/pkg/drivers/mysql/mysql.go @@ -9,14 +9,13 @@ import ( "strconv" "github.com/go-sql-driver/mysql" - "github.com/prometheus/client_golang/prometheus" "github.com/sirupsen/logrus" + "github.com/k3s-io/kine/pkg/drivers" "github.com/k3s-io/kine/pkg/drivers/generic" "github.com/k3s-io/kine/pkg/logstructured" "github.com/k3s-io/kine/pkg/logstructured/sqllog" "github.com/k3s-io/kine/pkg/server" - "github.com/k3s-io/kine/pkg/tls" "github.com/k3s-io/kine/pkg/util" ) @@ -55,28 +54,28 @@ var ( createDB = "CREATE DATABASE IF NOT EXISTS `%s`;" ) -func New(ctx context.Context, dataSourceName string, tlsInfo tls.Config, connPoolConfig generic.ConnectionPoolConfig, metricsRegisterer prometheus.Registerer) (server.Backend, error) { - tlsConfig, err := tlsInfo.ClientConfig() +func New(ctx context.Context, cfg *drivers.Config) (bool, server.Backend, error) { + tlsConfig, err := cfg.BackendTLSConfig.ClientConfig() if err != nil { - return nil, err + return false, nil, err } if tlsConfig != nil { tlsConfig.MinVersion = cryptotls.VersionTLS11 } - parsedDSN, err := prepareDSN(dataSourceName, tlsConfig) + parsedDSN, err := prepareDSN(cfg.DataSourceName, tlsConfig) if err != nil { - return nil, err + return false, nil, err } if err := createDBIfNotExist(parsedDSN); err != nil { - return nil, err + return false, nil, err } - dialect, err := generic.Open(ctx, "mysql", parsedDSN, connPoolConfig, "?", false, metricsRegisterer) + dialect, err := generic.Open(ctx, "mysql", parsedDSN, cfg.ConnectionPoolConfig, "?", false, cfg.MetricsRegisterer) if err != nil { - return nil, err + return false, nil, err } dialect.LastInsertID = true @@ -117,11 +116,11 @@ func New(ctx context.Context, dataSourceName string, tlsInfo tls.Config, connPoo return err.Error() } if err := setup(dialect.DB); err != nil { - return nil, err + return false, nil, err } dialect.Migrate(context.Background()) - return logstructured.New(sqllog.New(dialect)), nil + return true, logstructured.New(sqllog.New(dialect)), nil } func setup(db *sql.DB) error { @@ -231,3 +230,7 @@ func prepareDSN(dataSourceName string, tlsConfig *cryptotls.Config) (string, err return parsedDSN, nil } + +func init() { + drivers.Register("mysql", New) +} diff --git a/pkg/drivers/nats/new.go b/pkg/drivers/nats/new.go index 667dbf82..23466477 100644 --- a/pkg/drivers/nats/new.go +++ b/pkg/drivers/nats/new.go @@ -8,6 +8,7 @@ import ( "os/signal" "time" + "github.com/k3s-io/kine/pkg/drivers" natsserver "github.com/k3s-io/kine/pkg/drivers/nats/server" "github.com/k3s-io/kine/pkg/server" "github.com/k3s-io/kine/pkg/tls" @@ -43,14 +44,17 @@ var ( // New return an implementation of server.Backend using NATS + JetStream. // See the `examples/nats.md` file for examples of connection strings. -func New(ctx context.Context, connection string, tlsInfo tls.Config) (server.Backend, error) { - return newBackend(ctx, connection, tlsInfo, false) +func New(ctx context.Context, cfg *drivers.Config) (bool, server.Backend, error) { + backend, err := newBackend(ctx, cfg.Endpoint, cfg.BackendTLSConfig, false) + return true, backend, err } // NewLegacy return an implementation of server.Backend using NATS + JetStream // with legacy jetstream:// behavior, ignoring the embedded server. -func NewLegacy(ctx context.Context, connection string, tlsInfo tls.Config) (server.Backend, error) { - return newBackend(ctx, connection, tlsInfo, true) +func NewLegacy(ctx context.Context, cfg *drivers.Config) (bool, server.Backend, error) { + backend, err := newBackend(ctx, cfg.DataSourceName, cfg.BackendTLSConfig, true) + return true, backend, err + } func newBackend(ctx context.Context, connection string, tlsInfo tls.Config, legacy bool) (server.Backend, error) { @@ -264,3 +268,8 @@ func ensureDirectGets(ctx context.Context, js jetstream.JetStream, config *Confi return nil } } + +func init() { + drivers.Register("nats", New) + drivers.Register("jetstream", NewLegacy) +} diff --git a/pkg/drivers/pgsql/pgsql.go b/pkg/drivers/pgsql/pgsql.go index 28ddc43f..79710608 100644 --- a/pkg/drivers/pgsql/pgsql.go +++ b/pkg/drivers/pgsql/pgsql.go @@ -14,13 +14,13 @@ import ( "github.com/jackc/pgerrcode" "github.com/jackc/pgx/v5/pgconn" _ "github.com/jackc/pgx/v5/stdlib" // sql driver + "github.com/k3s-io/kine/pkg/drivers" "github.com/k3s-io/kine/pkg/drivers/generic" "github.com/k3s-io/kine/pkg/logstructured" "github.com/k3s-io/kine/pkg/logstructured/sqllog" "github.com/k3s-io/kine/pkg/server" "github.com/k3s-io/kine/pkg/tls" "github.com/k3s-io/kine/pkg/util" - "github.com/prometheus/client_golang/prometheus" "github.com/sirupsen/logrus" ) @@ -59,19 +59,19 @@ var ( createDB = `CREATE DATABASE "%s";` ) -func New(ctx context.Context, dataSourceName string, tlsInfo tls.Config, connPoolConfig generic.ConnectionPoolConfig, metricsRegisterer prometheus.Registerer) (server.Backend, error) { - parsedDSN, err := prepareDSN(dataSourceName, tlsInfo) +func New(ctx context.Context, cfg *drivers.Config) (bool, server.Backend, error) { + parsedDSN, err := prepareDSN(cfg.DataSourceName, cfg.BackendTLSConfig) if err != nil { - return nil, err + return false, nil, err } if err := createDBIfNotExist(parsedDSN); err != nil { - return nil, err + return false, nil, err } - dialect, err := generic.Open(ctx, "pgx", parsedDSN, connPoolConfig, "$", true, metricsRegisterer) + dialect, err := generic.Open(ctx, "pgx", parsedDSN, cfg.ConnectionPoolConfig, "$", true, cfg.MetricsRegisterer) if err != nil { - return nil, err + return false, nil, err } listSQL := ` SELECT @@ -155,11 +155,11 @@ func New(ctx context.Context, dataSourceName string, tlsInfo tls.Config, connPoo } if err := setup(dialect.DB); err != nil { - return nil, err + return false, nil, err } dialect.Migrate(context.Background()) - return logstructured.New(sqllog.New(dialect)), nil + return true, logstructured.New(sqllog.New(dialect)), nil } func setup(db *sql.DB) error { @@ -296,3 +296,8 @@ func prepareDSN(dataSourceName string, tlsInfo tls.Config) (string, error) { u.RawQuery = params.Encode() return u.String(), nil } + +func init() { + drivers.Register("postgres", New) + drivers.Register("postgresql", New) +} diff --git a/pkg/drivers/registry.go b/pkg/drivers/registry.go new file mode 100644 index 00000000..de8563de --- /dev/null +++ b/pkg/drivers/registry.go @@ -0,0 +1,36 @@ +package drivers + +import ( + "context" + + "github.com/k3s-io/kine/pkg/server" +) + +// Constructor is a function that takes a context and a config and returns a leaderElect bool, a server.Backend and an error +type Constructor func(ctx context.Context, cfg *Config) (leaderElect bool, backend server.Backend, err error) + +var driverRegistry = map[string]Constructor{} +var defaultScheme string + +// Register registers a constructor for the given scheme +func Register(scheme string, constructor Constructor) { + driverRegistry[scheme] = constructor +} + +// SetDefault sets the default driver scheme +// The default driver is used when an endpoint is not specified +func SetDefault(scheme string) { + defaultScheme = scheme +} + +// GetDefault returns the default driver +func GetDefault() Constructor { + return driverRegistry[defaultScheme] +} + +// Get returns the constructor for the given scheme +// The second return value is true if the scheme is registered, false otherwise +func Get(scheme string) (Constructor, bool) { + constructor, ok := driverRegistry[scheme] + return constructor, ok +} diff --git a/pkg/drivers/sqlite/sqlite.go b/pkg/drivers/sqlite/sqlite.go index 1313b298..298ac88f 100644 --- a/pkg/drivers/sqlite/sqlite.go +++ b/pkg/drivers/sqlite/sqlite.go @@ -10,6 +10,7 @@ import ( "os" "time" + "github.com/k3s-io/kine/pkg/drivers" "github.com/k3s-io/kine/pkg/drivers/generic" "github.com/k3s-io/kine/pkg/logstructured" "github.com/k3s-io/kine/pkg/logstructured/sqllog" @@ -17,11 +18,7 @@ import ( "github.com/k3s-io/kine/pkg/util" "github.com/mattn/go-sqlite3" "github.com/pkg/errors" - "github.com/prometheus/client_golang/prometheus" "github.com/sirupsen/logrus" - - // sqlite db driver - _ "github.com/mattn/go-sqlite3" ) var ( @@ -47,12 +44,13 @@ var ( } ) -func New(ctx context.Context, dataSourceName string, connPoolConfig generic.ConnectionPoolConfig, metricsRegisterer prometheus.Registerer) (server.Backend, error) { - backend, _, err := NewVariant(ctx, "sqlite3", dataSourceName, connPoolConfig, metricsRegisterer) - return backend, err +func New(ctx context.Context, cfg *drivers.Config) (bool, server.Backend, error) { + backend, _, err := NewVariant(ctx, "sqlite3", cfg) + return false, backend, err } -func NewVariant(ctx context.Context, driverName, dataSourceName string, connPoolConfig generic.ConnectionPoolConfig, metricsRegisterer prometheus.Registerer) (server.Backend, *generic.Generic, error) { +func NewVariant(ctx context.Context, driverName string, cfg *drivers.Config) (server.Backend, *generic.Generic, error) { + dataSourceName := cfg.DataSourceName if dataSourceName == "" { if err := os.MkdirAll("./db", 0700); err != nil { return nil, nil, err @@ -60,7 +58,7 @@ func NewVariant(ctx context.Context, driverName, dataSourceName string, connPool dataSourceName = "./db/state.db?_journal=WAL&cache=shared&_busy_timeout=30000" } - dialect, err := generic.Open(ctx, driverName, dataSourceName, connPoolConfig, "?", false, metricsRegisterer) + dialect, err := generic.Open(ctx, driverName, dataSourceName, cfg.ConnectionPoolConfig, "?", false, cfg.MetricsRegisterer) if err != nil { return nil, nil, err } @@ -138,3 +136,8 @@ func setup(db *sql.DB) error { logrus.Infof("Database tables and indexes are up to date") return nil } + +func init() { + drivers.Register("sqlite", New) + drivers.SetDefault("sqlite") +} diff --git a/pkg/drivers/sqlite/sqlite_nocgo.go b/pkg/drivers/sqlite/sqlite_nocgo.go index d730b406..24878802 100644 --- a/pkg/drivers/sqlite/sqlite_nocgo.go +++ b/pkg/drivers/sqlite/sqlite_nocgo.go @@ -8,21 +8,26 @@ import ( "database/sql" "errors" + "github.com/k3s-io/kine/pkg/drivers" "github.com/k3s-io/kine/pkg/drivers/generic" "github.com/k3s-io/kine/pkg/server" - "github.com/prometheus/client_golang/prometheus" ) var errNoCgo = errors.New("this binary is built without CGO, sqlite is disabled") -func New(ctx context.Context, dataSourceName string, connPoolConfig generic.ConnectionPoolConfig, metricsRegisterer prometheus.Registerer) (server.Backend, error) { - return nil, errNoCgo +func New(ctx context.Context, cfg drivers.Config) (bool, server.Backend, error) { + return false, nil, errNoCgo } -func NewVariant(driverName, dataSourceName string, connPoolConfig generic.ConnectionPoolConfig, metricsRegisterer prometheus.Registerer) (server.Backend, *generic.Generic, error) { +func NewVariant(driverName, cfg drivers.Config) (server.Backend, *generic.Generic, error) { return nil, nil, errNoCgo } func setup(db *sql.DB) error { return errNoCgo } + +func init() { + generic.RegisterDriver("sqlite", New) + generic.SetDefaultDriver("sqlite") +} diff --git a/pkg/endpoint/endpoint.go b/pkg/endpoint/endpoint.go index ac9c9dba..58d669ad 100644 --- a/pkg/endpoint/endpoint.go +++ b/pkg/endpoint/endpoint.go @@ -2,21 +2,17 @@ package endpoint import ( "context" - "fmt" "net" "os" "strings" "time" - "github.com/k3s-io/kine/pkg/drivers/dqlite" + "github.com/k3s-io/kine/pkg/drivers" "github.com/k3s-io/kine/pkg/drivers/generic" - "github.com/k3s-io/kine/pkg/drivers/mysql" - "github.com/k3s-io/kine/pkg/drivers/nats" - "github.com/k3s-io/kine/pkg/drivers/pgsql" - "github.com/k3s-io/kine/pkg/drivers/sqlite" "github.com/k3s-io/kine/pkg/metrics" "github.com/k3s-io/kine/pkg/server" "github.com/k3s-io/kine/pkg/tls" + "github.com/k3s-io/kine/pkg/util" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/sirupsen/logrus" @@ -27,14 +23,7 @@ import ( ) const ( - KineSocket = "unix://kine.sock" - SQLiteBackend = "sqlite" - DQLiteBackend = "dqlite" - ETCDBackend = "etcd3" - JetStreamBackend = "jetstream" - NATSBackend = "nats" - MySQLBackend = "mysql" - PostgresBackend = "postgres" + KineSocket = "unix://kine.sock" ) type Config struct { @@ -56,24 +45,25 @@ type ETCDConfig struct { } func Listen(ctx context.Context, config Config) (ETCDConfig, error) { - driver, dsn, err := ParseStorageEndpoint(config.Endpoint) + leaderElect, backend, err := drivers.New(ctx, &drivers.Config{ + MetricsRegisterer: config.MetricsRegisterer, + Endpoint: config.Endpoint, + BackendTLSConfig: config.BackendTLSConfig, + ConnectionPoolConfig: config.ConnectionPoolConfig, + }) + if err != nil { - return ETCDConfig{}, errors.Wrap(err, "parsing storage endpoint") + return ETCDConfig{}, errors.Wrap(err, "building kine") } - if driver == ETCDBackend { + if backend == nil { return ETCDConfig{ Endpoints: strings.Split(config.Endpoint, ","), TLSConfig: config.BackendTLSConfig, - LeaderElect: true, + LeaderElect: leaderElect, }, nil } - leaderelect, backend, err := getKineStorageBackend(ctx, driver, dsn, config) - if err != nil { - return ETCDConfig{}, errors.Wrap(err, "building kine") - } - if config.MetricsRegisterer != nil { config.MetricsRegisterer.MustRegister( metrics.SQLTotal, @@ -110,7 +100,7 @@ func Listen(ctx context.Context, config Config) (ETCDConfig, error) { logrus.Infof("Kine available at %s", endpoint) return ETCDConfig{ - LeaderElect: leaderelect, + LeaderElect: leaderElect, Endpoints: []string{endpoint}, TLSConfig: tls.Config{ CAFile: config.ServerTLSConfig.CAFile, @@ -141,17 +131,17 @@ func endpointScheme(config Config) string { config.Listener = KineSocket } - network, _ := networkAndAddress(config.Listener) - if network != "unix" { - network = "http" + scheme, _ := util.SchemeAndAddress(config.Listener) + if scheme != "unix" { + scheme = "http" } if config.ServerTLSConfig.CertFile != "" && config.ServerTLSConfig.KeyFile != "" { // yes, etcd supports the "unixs" scheme for TLS over unix sockets - network += "s" + scheme += "s" } - return network + return scheme } // createListener returns a listener bound to the requested protocol and address. @@ -159,9 +149,9 @@ func createListener(config Config) (ret net.Listener, rerr error) { if config.Listener == "" { config.Listener = KineSocket } - network, address := networkAndAddress(config.Listener) + scheme, address := util.SchemeAndAddress(config.Listener) - if network == "unix" { + if scheme == "unix" { if err := os.Remove(address); err != nil && !os.IsNotExist(err) { logrus.Warnf("failed to remove socket %s: %v", address, err) } @@ -171,10 +161,10 @@ func createListener(config Config) (ret net.Listener, rerr error) { } }() } else { - network = "tcp" + scheme = "tcp" } - return net.Listen(network, address) + return net.Listen(scheme, address) } // grpcServer returns either a preconfigured GRPC server, or builds a new GRPC @@ -205,75 +195,3 @@ func grpcServer(config Config) (*grpc.Server, error) { return grpc.NewServer(gopts...), nil } - -// getKineStorageBackend parses the driver string, and returns a bool -// indicating whether the backend requires leader election, and a suitable -// backend datastore connection. -func getKineStorageBackend(ctx context.Context, driver, dsn string, cfg Config) (bool, server.Backend, error) { - var ( - backend server.Backend - leaderElect = true - err error - ) - switch driver { - case SQLiteBackend: - leaderElect = false - backend, err = sqlite.New(ctx, dsn, cfg.ConnectionPoolConfig, cfg.MetricsRegisterer) - case DQLiteBackend: - backend, err = dqlite.New(ctx, dsn, cfg.ConnectionPoolConfig, cfg.MetricsRegisterer) - case PostgresBackend: - backend, err = pgsql.New(ctx, dsn, cfg.BackendTLSConfig, cfg.ConnectionPoolConfig, cfg.MetricsRegisterer) - case MySQLBackend: - backend, err = mysql.New(ctx, dsn, cfg.BackendTLSConfig, cfg.ConnectionPoolConfig, cfg.MetricsRegisterer) - case JetStreamBackend: - backend, err = nats.NewLegacy(ctx, dsn, cfg.BackendTLSConfig) - case NATSBackend: - backend, err = nats.New(ctx, dsn, cfg.BackendTLSConfig) - default: - return false, nil, fmt.Errorf("storage backend is not defined") - } - - return leaderElect, backend, err -} - -// ParseStorageEndpoint returns the driver name and endpoint string from a datastore endpoint URL. -func ParseStorageEndpoint(storageEndpoint string) (string, string, error) { - if storageEndpoint == "" { - return SQLiteBackend, "", nil - } - - if err := validateDSNuri(storageEndpoint); err != nil { - return "", "", err - } - - network, address := networkAndAddress(storageEndpoint) - - switch network { - case "nats": - return NATSBackend, storageEndpoint, nil - case "http": - fallthrough - case "https": - return ETCDBackend, address, nil - } - return network, address, nil -} - -// validateDSNuri ensure that the given string is of that format -func validateDSNuri(str string) error { - parts := strings.SplitN(str, "://", 2) - if len(parts) > 1 { - return nil - } - return errors.New("invalid datastore endpoint; endpoint should be a DSN URI in the format ://") -} - -// networkAndAddress crudely splits a URL string into network (scheme) and address, -// where the address includes everything after the scheme/authority separator. -func networkAndAddress(str string) (string, string) { - parts := strings.SplitN(str, "://", 2) - if len(parts) > 1 { - return parts[0], parts[1] - } - return "", parts[0] -} diff --git a/pkg/endpoint/init.go b/pkg/endpoint/init.go new file mode 100644 index 00000000..ade555e8 --- /dev/null +++ b/pkg/endpoint/init.go @@ -0,0 +1,11 @@ +package endpoint + +import ( + // Import all the default drivers + _ "github.com/k3s-io/kine/pkg/drivers/dqlite" + _ "github.com/k3s-io/kine/pkg/drivers/http" + _ "github.com/k3s-io/kine/pkg/drivers/mysql" + _ "github.com/k3s-io/kine/pkg/drivers/nats" + _ "github.com/k3s-io/kine/pkg/drivers/pgsql" + _ "github.com/k3s-io/kine/pkg/drivers/sqlite" +) diff --git a/pkg/util/network.go b/pkg/util/network.go new file mode 100644 index 00000000..0a2257e1 --- /dev/null +++ b/pkg/util/network.go @@ -0,0 +1,13 @@ +package util + +import "strings" + +// SchemeAndAddress crudely splits a URL string into scheme and address, +// where the address includes everything after the scheme/authority separator. +func SchemeAndAddress(str string) (string, string) { + parts := strings.SplitN(str, "://", 2) + if len(parts) > 1 { + return parts[0], parts[1] + } + return "", parts[0] +}