From 26eff2dbcc684732acb9770b699193b06bc0e9bc Mon Sep 17 00:00:00 2001 From: Naren Date: Thu, 24 Feb 2022 08:54:29 -0500 Subject: [PATCH 1/3] Fix bug to support Endpoints with trailing slashes --- pkg/controllers/init_db.go | 4 ++-- pkg/controllers/init_db_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/controllers/init_db.go b/pkg/controllers/init_db.go index 33cacf54b..c7b4c911c 100644 --- a/pkg/controllers/init_db.go +++ b/pkg/controllers/init_db.go @@ -439,7 +439,7 @@ func (g *GenericDatabaseInitializer) getCommunalEndpoint() string { prefix := []string{"https://", "http://"} for _, pref := range prefix { if i := strings.Index(g.Vdb.Spec.Communal.Endpoint, pref); i == 0 { - return g.Vdb.Spec.Communal.Endpoint[len(pref):] + return strings.TrimSuffix(g.Vdb.Spec.Communal.Endpoint[len(pref):], "/") } } return g.Vdb.Spec.Communal.Endpoint @@ -491,7 +491,7 @@ func getEndpointHostPort(blobEndpoint string) string { if len(m) == 0 || len(m[0]) < 3 { return blobEndpoint } - return m[0][2] + return strings.TrimSuffix(m[0][2], "/") } // getHadoopConfDir gets the string to include in the auth parms for diff --git a/pkg/controllers/init_db_test.go b/pkg/controllers/init_db_test.go index 02c8f50e7..6b2f3fe62 100644 --- a/pkg/controllers/init_db_test.go +++ b/pkg/controllers/init_db_test.go @@ -59,12 +59,19 @@ var _ = Describe("init_db", func() { } Expect(g.getCommunalEndpoint()).Should(Equal("192.168.0.1")) + Expect(g.getEnableHTTPS()).Should(Equal("1")) vdb.Spec.Communal.Endpoint = "http://fqdn.example.com:8080" Expect(g.getCommunalEndpoint()).Should(Equal("fqdn.example.com:8080")) Expect(g.getEnableHTTPS()).Should(Equal("0")) + + vdb.Spec.Communal.Endpoint = "https://minio/" + Expect(g.getCommunalEndpoint()).Should(Equal("minio")) + + vdb.Spec.Communal.Endpoint = "https://minio:3000/" + Expect(g.getCommunalEndpoint()).Should(Equal("minio:3000")) }) It("should fail to get host list if some pods not running", func() { @@ -199,7 +206,10 @@ var _ = Describe("init_db", func() { Expect(getEndpointHostPort("http://hostname")).Should(Equal("hostname")) Expect(getEndpointHostPort("https://tlsHost:3000")).Should(Equal("tlsHost:3000")) Expect(getEndpointHostPort("account@myhost")).Should(Equal("account@myhost")) + Expect(getEndpointHostPort("azb://devopsvertica/vertica-fleeting/mspilchen/db/")).Should(Equal("devopsvertica/vertica-fleeting/mspilchen/db")) + }) + }) func contructAuthParmsHelper(ctx context.Context, vdb *vapi.VerticaDB, mustHaveCmd string) []cmds.CmdHistory { From e1eedbf4b85019c6f892db76de497e8a5f2dd151 Mon Sep 17 00:00:00 2001 From: Naren Date: Thu, 24 Feb 2022 16:46:42 -0500 Subject: [PATCH 2/3] Add changie entry and make the test line shorter --- changes/unreleased/Fixed-20220224-164528.yaml | 5 +++++ pkg/controllers/init_db_test.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changes/unreleased/Fixed-20220224-164528.yaml diff --git a/changes/unreleased/Fixed-20220224-164528.yaml b/changes/unreleased/Fixed-20220224-164528.yaml new file mode 100644 index 000000000..4d6fcfcd6 --- /dev/null +++ b/changes/unreleased/Fixed-20220224-164528.yaml @@ -0,0 +1,5 @@ +kind: Fixed +body: Tolerate slashes being at the end of the communal endpoint url +time: 2022-02-24T16:45:28.95511728-05:00 +custom: + Issue: "161" diff --git a/pkg/controllers/init_db_test.go b/pkg/controllers/init_db_test.go index 6b2f3fe62..29cf9fbec 100644 --- a/pkg/controllers/init_db_test.go +++ b/pkg/controllers/init_db_test.go @@ -206,7 +206,7 @@ var _ = Describe("init_db", func() { Expect(getEndpointHostPort("http://hostname")).Should(Equal("hostname")) Expect(getEndpointHostPort("https://tlsHost:3000")).Should(Equal("tlsHost:3000")) Expect(getEndpointHostPort("account@myhost")).Should(Equal("account@myhost")) - Expect(getEndpointHostPort("azb://devopsvertica/vertica-fleeting/mspilchen/db/")).Should(Equal("devopsvertica/vertica-fleeting/mspilchen/db")) + Expect(getEndpointHostPort("azb://mspilchen/db/")).Should(Equal("mspilchen/db")) }) From 0d3e47d50105c77d9628eb0dcd09c318e59ed594 Mon Sep 17 00:00:00 2001 From: Naren Date: Thu, 24 Feb 2022 16:55:11 -0500 Subject: [PATCH 3/3] Change the test endpoint name --- pkg/controllers/init_db_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controllers/init_db_test.go b/pkg/controllers/init_db_test.go index 29cf9fbec..4750d47d2 100644 --- a/pkg/controllers/init_db_test.go +++ b/pkg/controllers/init_db_test.go @@ -206,7 +206,7 @@ var _ = Describe("init_db", func() { Expect(getEndpointHostPort("http://hostname")).Should(Equal("hostname")) Expect(getEndpointHostPort("https://tlsHost:3000")).Should(Equal("tlsHost:3000")) Expect(getEndpointHostPort("account@myhost")).Should(Equal("account@myhost")) - Expect(getEndpointHostPort("azb://mspilchen/db/")).Should(Equal("mspilchen/db")) + Expect(getEndpointHostPort("azb://account/container/db/")).Should(Equal("account/container/db")) })