diff --git a/CHANGELOG.md b/CHANGELOG.md index d25dda269..a4ddaec50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Change Log ## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A) +- (Bugfix) Fix make manifests-crd-file command +- (Improvement) Allow tcp:// and ssl:// protocols in endpoints for members +- (Maintenance) Reorganize package imports / move common code to separate repos - (Maintenance) Remove support for RELATED_IMAGE_UBI, RELATED_IMAGE_DATABASE and RELATED_IMAGE_METRICSEXPORTER env vars ## [1.2.33](https://github.com/arangodb/kube-arangodb/tree/1.2.33) (2023-09-27) diff --git a/Makefile b/Makefile index 63d5aa1fc..04ad0016d 100644 --- a/Makefile +++ b/Makefile @@ -456,10 +456,9 @@ manifests: .PHONY: manifests-crd-file manifests-crd-file: @echo Building manifests for CRD - $(MANIFESTPATHCRD) - @echo -n > $(MANIFESTPATHCRD) - @$(foreach FILE,$(CRDS),echo '---\n# File: chart/kube-arangodb/crds/$(FILE).yaml' >> $(MANIFESTPATHCRD) && \ - cat '$(ROOT)/chart/kube-arangodb/crds/$(FILE).yaml' >> $(MANIFESTPATHCRD) && \ - echo '\n' >> $(MANIFESTPATHCRD);) + @printf "" > $(MANIFESTPATHCRD) + @$(foreach FILE,$(CRDS),printf '%s\n# File: chart/kube-arangodb/crds/%s.yaml\n' '---' $(FILE) >> $(MANIFESTPATHCRD) && \ + cat '$(ROOT)/chart/kube-arangodb/crds/$(FILE).yaml' >> $(MANIFESTPATHCRD);) manifests: manifests-crd-file .PHONY: manifests-crd-kustomize diff --git a/cmd/cmd.go b/cmd/cmd.go index d1052aa46..e62092f30 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -48,7 +48,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/api" "github.com/arangodb/kube-arangodb/pkg/crd" - "github.com/arangodb/kube-arangodb/pkg/deployment/agency/cache" + agencyConfig "github.com/arangodb/kube-arangodb/pkg/deployment/agency/config" "github.com/arangodb/kube-arangodb/pkg/deployment/features" "github.com/arangodb/kube-arangodb/pkg/deployment/reconcile" "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/scheme" @@ -230,7 +230,7 @@ func init() { if err := features.Init(&cmdMain); err != nil { panic(err.Error()) } - if err := cache.Init(&cmdMain); err != nil { + if err := agencyConfig.Init(&cmdMain); err != nil { panic(err.Error()) } if err := reconcile.ActionsConfigGlobal.Init(&cmdMain); err != nil { diff --git a/go.mod b/go.mod index f9bbd114f..e1b8e5f94 100644 --- a/go.mod +++ b/go.mod @@ -24,11 +24,13 @@ replace ( require ( github.com/arangodb-helper/go-certificates v0.0.0-20180821055445-9fca24fc2680 + github.com/arangodb-helper/go-helper v0.4.2 github.com/arangodb/arangosync-client v0.9.0 - github.com/arangodb/go-driver v1.4.1 - github.com/arangodb/go-driver/v2 v2.0.0-20211021031401-d92dcd5a4c83 + github.com/arangodb/go-driver v1.6.0 + github.com/arangodb/go-driver/v2 v2.0.0-20230616090327-3b9171814ae4 github.com/arangodb/go-upgrade-rules v0.0.0-20180809110947-031b4774ff21 //github.com/arangodb/rebalancer v0.1.1 + //github.com/arangodb/go-agency-helper v0.3.0 github.com/cenkalti/backoff v2.2.1+incompatible github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9 github.com/gin-gonic/gin v1.9.1 @@ -47,7 +49,7 @@ require ( github.com/rs/zerolog v1.19.0 github.com/spf13/cobra v1.4.0 github.com/spf13/pflag v1.0.5 - github.com/stretchr/testify v1.8.3 + github.com/stretchr/testify v1.8.4 golang.org/x/sync v0.1.0 golang.org/x/sys v0.10.0 golang.org/x/text v0.11.0 diff --git a/go.sum b/go.sum index 98ec20374..5423894ac 100644 --- a/go.sum +++ b/go.sum @@ -72,12 +72,14 @@ github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kd github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220418222510-f25a4f6275ed/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY= github.com/arangodb-helper/go-certificates v0.0.0-20180821055445-9fca24fc2680 h1:5YCGq0gkf/sCEkDFIsMBPj59GOm5cMibGqDBH2OWWfQ= github.com/arangodb-helper/go-certificates v0.0.0-20180821055445-9fca24fc2680/go.mod h1:xDyzBwyYzcEhsaDXtmxCNM4p5BrtuoVYYsRTuJqmCeg= +github.com/arangodb-helper/go-helper v0.4.2 h1:Ekf8EtPYQdhlwtqJAEn17i7zbtuavksWamasxcyOGWQ= +github.com/arangodb-helper/go-helper v0.4.2/go.mod h1:RHgEwQTFWdJ9wFDGUCgUZzaz9NLaFUskSsHgOPM5XR4= github.com/arangodb/arangosync-client v0.9.0 h1:XhY+5gGGpl9Gk8Prqmdv0SpK3HydFUXvN2CmTIKUxKI= github.com/arangodb/arangosync-client v0.9.0/go.mod h1:kU2UaOkv2AeHLAFMEo4Ug3qLbUQVKOuRtkfr6pZqmuk= github.com/arangodb/go-driver v1.2.1 h1:HREDHhDmzdIWxHmfkfTESbYUnRjESjPh4WUuXq7FZa8= github.com/arangodb/go-driver v1.2.1/go.mod h1:zdDkJJnCj8DAkfbtIjIXnsTrWIiy6VhP3Vy14p+uQeY= -github.com/arangodb/go-driver/v2 v2.0.0-20211021031401-d92dcd5a4c83 h1:PCbi3alUFastUw6InBKGEXqniveJJcQuMYspubJMRS8= -github.com/arangodb/go-driver/v2 v2.0.0-20211021031401-d92dcd5a4c83/go.mod h1:B8byYwvt1mDOQzpjiMuDTP5jOif/Y5dcEJtkdvPB7HY= +github.com/arangodb/go-driver/v2 v2.0.0-20230616090327-3b9171814ae4 h1:LpIIPBcrbZ/mVDG2ioZN92Pbgb5HQ2Vnqj/UaQAyN4E= +github.com/arangodb/go-driver/v2 v2.0.0-20230616090327-3b9171814ae4/go.mod h1:bnCd24JXOgd5rpG8uwSpHPsF6NCcH4m6rKtKh1EJ7Lo= github.com/arangodb/go-upgrade-rules v0.0.0-20180809110947-031b4774ff21 h1:+W7D5ttxi/Ygh/39vialtypE23p9KI7P0J2qtoqUV4w= github.com/arangodb/go-upgrade-rules v0.0.0-20180809110947-031b4774ff21/go.mod h1:RkPIG6JJ2pcJUoymc18NxAJGraZd+iAEVnOTDjZey/w= github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e h1:Xg+hGrY2LcQBbxd0ZFdbGSyRKTYMZCfBbw/pMJFOk1g= @@ -190,7 +192,6 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= diff --git a/pkg/deployment/agency/cache.go b/pkg/deployment/agency/cache.go index 4310bc443..10f3ba640 100644 --- a/pkg/deployment/agency/cache.go +++ b/pkg/deployment/agency/cache.go @@ -27,12 +27,13 @@ import ( "github.com/rs/zerolog" + agencyCache "github.com/arangodb-helper/go-helper/pkg/arangod/agency/cache" + "github.com/arangodb-helper/go-helper/pkg/arangod/conn" + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - agencyCache "github.com/arangodb/kube-arangodb/pkg/deployment/agency/cache" "github.com/arangodb/kube-arangodb/pkg/deployment/agency/state" "github.com/arangodb/kube-arangodb/pkg/generated/metric_descriptions" "github.com/arangodb/kube-arangodb/pkg/logging" - "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/metrics" diff --git a/pkg/deployment/agency/config.go b/pkg/deployment/agency/config.go index 15f977cc4..9bd1a57e8 100644 --- a/pkg/deployment/agency/config.go +++ b/pkg/deployment/agency/config.go @@ -24,7 +24,8 @@ import ( "context" "net/http" - "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn" + "github.com/arangodb-helper/go-helper/pkg/arangod/conn" + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) diff --git a/pkg/deployment/agency/cache/config.go b/pkg/deployment/agency/config/config.go similarity index 99% rename from pkg/deployment/agency/cache/config.go rename to pkg/deployment/agency/config/config.go index 44a91a03b..d355c25a9 100644 --- a/pkg/deployment/agency/cache/config.go +++ b/pkg/deployment/agency/config/config.go @@ -18,7 +18,7 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package cache +package config import ( "time" diff --git a/pkg/deployment/agency/leader.go b/pkg/deployment/agency/leader.go index 899bf3ca1..75aa06170 100644 --- a/pkg/deployment/agency/leader.go +++ b/pkg/deployment/agency/leader.go @@ -23,8 +23,8 @@ package agency import ( "context" - agencyCache "github.com/arangodb/kube-arangodb/pkg/deployment/agency/cache" - "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn" + agencyCache "github.com/arangodb-helper/go-helper/pkg/arangod/agency/cache" + "github.com/arangodb-helper/go-helper/pkg/arangod/conn" ) func StaticLeaderDiscovery(in conn.Connection) agencyCache.LeaderDiscovery { diff --git a/pkg/deployment/agency/loader.community.go b/pkg/deployment/agency/loader.community.go index 6ef09edb9..0ddbc52a5 100644 --- a/pkg/deployment/agency/loader.community.go +++ b/pkg/deployment/agency/loader.community.go @@ -22,7 +22,7 @@ package agency -import agencyCache "github.com/arangodb/kube-arangodb/pkg/deployment/agency/cache" +import agencyCache "github.com/arangodb-helper/go-helper/pkg/arangod/agency/cache" func getLoaderBase[T interface{}]() agencyCache.StateLoader[T] { return NewSimpleStateLoader[T]() diff --git a/pkg/deployment/agency/loader.go b/pkg/deployment/agency/loader.go index 98e080f46..0b6ca45fd 100644 --- a/pkg/deployment/agency/loader.go +++ b/pkg/deployment/agency/loader.go @@ -25,7 +25,9 @@ import ( "sync" "time" - agencyCache "github.com/arangodb/kube-arangodb/pkg/deployment/agency/cache" + agencyCache "github.com/arangodb-helper/go-helper/pkg/arangod/agency/cache" + + agencyConfig "github.com/arangodb/kube-arangodb/pkg/deployment/agency/config" "github.com/arangodb/kube-arangodb/pkg/util/globals" ) @@ -36,25 +38,14 @@ func getLoader[T interface{}]() agencyCache.StateLoader[T] { loader = InvalidateOnErrorLoader[T](loader) - loader = DelayLoader[T](loader, agencyCache.GlobalConfig().RefreshDelay) - loader = RefreshLoader[T](loader, agencyCache.GlobalConfig().RefreshInterval) + loader = DelayLoader[T](loader, agencyConfig.GlobalConfig().RefreshDelay) + loader = RefreshLoader[T](loader, agencyConfig.GlobalConfig().RefreshInterval) - loader = RetryLoader[T](loader, agencyCache.GlobalConfig().Retries) + loader = RetryLoader[T](loader, agencyConfig.GlobalConfig().Retries) return loader } -type StateLoader[T interface{}] interface { - State() (*T, uint64, bool) - - Invalidate() - Valid() bool - - UpdateTime() time.Time - - Refresh(ctx context.Context, discovery agencyCache.LeaderDiscovery) error -} - func NewSimpleStateLoader[T interface{}]() agencyCache.StateLoader[T] { return &simpleStateLoader[T]{} } diff --git a/pkg/deployment/agency/loader_delayer.go b/pkg/deployment/agency/loader_delayer.go index 510a89366..9998009ea 100644 --- a/pkg/deployment/agency/loader_delayer.go +++ b/pkg/deployment/agency/loader_delayer.go @@ -25,7 +25,7 @@ import ( "sync" "time" - agencyCache "github.com/arangodb/kube-arangodb/pkg/deployment/agency/cache" + agencyCache "github.com/arangodb-helper/go-helper/pkg/arangod/agency/cache" ) func DelayLoader[T interface{}](loader agencyCache.StateLoader[T], delay time.Duration) agencyCache.StateLoader[T] { diff --git a/pkg/deployment/agency/loader_invalidate.go b/pkg/deployment/agency/loader_invalidate.go index 0b10b1b4d..2707afad6 100644 --- a/pkg/deployment/agency/loader_invalidate.go +++ b/pkg/deployment/agency/loader_invalidate.go @@ -25,7 +25,7 @@ import ( "sync" "time" - agencyCache "github.com/arangodb/kube-arangodb/pkg/deployment/agency/cache" + agencyCache "github.com/arangodb-helper/go-helper/pkg/arangod/agency/cache" ) func InvalidateOnErrorLoader[T interface{}](loader agencyCache.StateLoader[T]) agencyCache.StateLoader[T] { diff --git a/pkg/deployment/agency/loader_refresher.go b/pkg/deployment/agency/loader_refresher.go index 006744353..ebb9c352e 100644 --- a/pkg/deployment/agency/loader_refresher.go +++ b/pkg/deployment/agency/loader_refresher.go @@ -25,7 +25,7 @@ import ( "sync" "time" - agencyCache "github.com/arangodb/kube-arangodb/pkg/deployment/agency/cache" + agencyCache "github.com/arangodb-helper/go-helper/pkg/arangod/agency/cache" ) func RefreshLoader[T interface{}](loader agencyCache.StateLoader[T], delay time.Duration) agencyCache.StateLoader[T] { diff --git a/pkg/deployment/agency/loader_retry.go b/pkg/deployment/agency/loader_retry.go index 2b81142a3..b2092b9fd 100644 --- a/pkg/deployment/agency/loader_retry.go +++ b/pkg/deployment/agency/loader_retry.go @@ -25,7 +25,7 @@ import ( "sync" "time" - agencyCache "github.com/arangodb/kube-arangodb/pkg/deployment/agency/cache" + agencyCache "github.com/arangodb-helper/go-helper/pkg/arangod/agency/cache" ) func RetryLoader[T interface{}](loader agencyCache.StateLoader[T], retries int) agencyCache.StateLoader[T] { diff --git a/pkg/deployment/agency/loader_timeout.go b/pkg/deployment/agency/loader_timeout.go index 775c2d7b7..912cfbf4e 100644 --- a/pkg/deployment/agency/loader_timeout.go +++ b/pkg/deployment/agency/loader_timeout.go @@ -24,7 +24,7 @@ import ( "context" "time" - agencyCache "github.com/arangodb/kube-arangodb/pkg/deployment/agency/cache" + agencyCache "github.com/arangodb-helper/go-helper/pkg/arangod/agency/cache" ) func TimeoutLoader[T interface{}](loader agencyCache.StateLoader[T], timeout time.Duration) agencyCache.StateLoader[T] { diff --git a/pkg/deployment/agency/state.go b/pkg/deployment/agency/state.go index ea2f9eb59..15e6d1ad3 100644 --- a/pkg/deployment/agency/state.go +++ b/pkg/deployment/agency/state.go @@ -24,7 +24,8 @@ import ( "context" "net/http" - "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn" + "github.com/arangodb-helper/go-helper/pkg/arangod/conn" + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) diff --git a/pkg/deployment/client/client_cache.go b/pkg/deployment/client/client_cache.go index 28412cbd1..785c0f754 100644 --- a/pkg/deployment/client/client_cache.go +++ b/pkg/deployment/client/client_cache.go @@ -26,6 +26,7 @@ import ( "strconv" "sync" + "github.com/arangodb-helper/go-helper/pkg/arangod/conn" driver "github.com/arangodb/go-driver" "github.com/arangodb/go-driver/agency" @@ -33,7 +34,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/apis/shared" "github.com/arangodb/kube-arangodb/pkg/deployment/reconciler" "github.com/arangodb/kube-arangodb/pkg/handlers/utils" - "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" ) diff --git a/pkg/deployment/context_impl.go b/pkg/deployment/context_impl.go index dcd3f7445..61298e3df 100644 --- a/pkg/deployment/context_impl.go +++ b/pkg/deployment/context_impl.go @@ -34,6 +34,7 @@ import ( meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "github.com/arangodb-helper/go-helper/pkg/arangod/conn" "github.com/arangodb/arangosync-client/client" driver "github.com/arangodb/go-driver" "github.com/arangodb/go-driver/agency" @@ -52,7 +53,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/deployment/resources" "github.com/arangodb/kube-arangodb/pkg/operator/scope" "github.com/arangodb/kube-arangodb/pkg/replication" - "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn" "github.com/arangodb/kube-arangodb/pkg/util/constants" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/globals" diff --git a/pkg/deployment/deployment.go b/pkg/deployment/deployment.go index bfb6cfbb1..d265d139a 100644 --- a/pkg/deployment/deployment.go +++ b/pkg/deployment/deployment.go @@ -33,6 +33,7 @@ import ( "k8s.io/client-go/informers" "k8s.io/client-go/tools/record" + "github.com/arangodb-helper/go-helper/pkg/arangod/conn" "github.com/arangodb/arangosync-client/client" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" @@ -54,7 +55,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/operator/scope" "github.com/arangodb/kube-arangodb/pkg/util" "github.com/arangodb/kube-arangodb/pkg/util/arangod" - "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" diff --git a/pkg/deployment/deployment_suite_test.go b/pkg/deployment/deployment_suite_test.go index 466c34572..2e9ca515c 100644 --- a/pkg/deployment/deployment_suite_test.go +++ b/pkg/deployment/deployment_suite_test.go @@ -38,6 +38,7 @@ import ( "k8s.io/client-go/kubernetes/fake" recordfake "k8s.io/client-go/tools/record" + "github.com/arangodb-helper/go-helper/pkg/arangod/conn" driver "github.com/arangodb/go-driver" "github.com/arangodb/go-driver/jwt" @@ -50,7 +51,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/deployment/resources/inspector" arangofake "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/fake" "github.com/arangodb/kube-arangodb/pkg/util" - "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn" "github.com/arangodb/kube-arangodb/pkg/util/constants" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle" diff --git a/pkg/deployment/reconcile/action_backup_restore.go b/pkg/deployment/reconcile/action_backup_restore.go index 36622f710..7d80bf86b 100644 --- a/pkg/deployment/reconcile/action_backup_restore.go +++ b/pkg/deployment/reconcile/action_backup_restore.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,11 +24,11 @@ import ( "context" "time" + "github.com/arangodb-helper/go-helper/pkg/arangod/conn" "github.com/arangodb/go-driver" backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" - "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/globals" ) diff --git a/pkg/deployment/reconcile/action_rebuild_outsynced_shards.go b/pkg/deployment/reconcile/action_rebuild_outsynced_shards.go index 22f56b385..20904785e 100644 --- a/pkg/deployment/reconcile/action_rebuild_outsynced_shards.go +++ b/pkg/deployment/reconcile/action_rebuild_outsynced_shards.go @@ -26,11 +26,11 @@ import ( "path" "time" + "github.com/arangodb-helper/go-helper/pkg/arangod/conn" "github.com/arangodb/go-driver" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/deployment/features" - "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn" "github.com/arangodb/kube-arangodb/pkg/util/errors" ) diff --git a/pkg/deployment/reconcile/context.go b/pkg/deployment/reconcile/context.go index ee3147d84..0c051b468 100644 --- a/pkg/deployment/reconcile/context.go +++ b/pkg/deployment/reconcile/context.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,12 +23,13 @@ package reconcile import ( "context" + "github.com/arangodb-helper/go-helper/pkg/arangod/conn" + backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/deployment/acs/sutil" "github.com/arangodb/kube-arangodb/pkg/deployment/member" "github.com/arangodb/kube-arangodb/pkg/deployment/reconciler" - "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn" ) type CreateMemberMod func(s *api.DeploymentStatus, g api.ServerGroup, m *api.MemberStatus) error diff --git a/pkg/deployment/reconcile/plan_builder_context.go b/pkg/deployment/reconcile/plan_builder_context.go index f93ef2203..eb3fdea4b 100644 --- a/pkg/deployment/reconcile/plan_builder_context.go +++ b/pkg/deployment/reconcile/plan_builder_context.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,11 +23,12 @@ package reconcile import ( "context" + "github.com/arangodb-helper/go-helper/pkg/arangod/conn" + backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1" "github.com/arangodb/kube-arangodb/pkg/deployment/acs/sutil" "github.com/arangodb/kube-arangodb/pkg/deployment/member" "github.com/arangodb/kube-arangodb/pkg/deployment/reconciler" - "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn" ) // PlanBuilderContext contains context methods provided to plan builders. diff --git a/pkg/deployment/reconcile/plan_builder_test.go b/pkg/deployment/reconcile/plan_builder_test.go index cd599bb11..7f7bfa642 100644 --- a/pkg/deployment/reconcile/plan_builder_test.go +++ b/pkg/deployment/reconcile/plan_builder_test.go @@ -34,6 +34,7 @@ import ( meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" + "github.com/arangodb-helper/go-helper/pkg/arangod/conn" "github.com/arangodb/arangosync-client/client" "github.com/arangodb/go-driver" "github.com/arangodb/go-driver/agency" @@ -54,7 +55,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned" "github.com/arangodb/kube-arangodb/pkg/logging" "github.com/arangodb/kube-arangodb/pkg/util" - "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/errors/panics" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" diff --git a/pkg/exporter/monitor.go b/pkg/exporter/monitor.go index 6373c16f5..773628443 100644 --- a/pkg/exporter/monitor.go +++ b/pkg/exporter/monitor.go @@ -34,6 +34,7 @@ import ( "time" "github.com/arangodb/go-driver" + "github.com/arangodb/go-driver/util" "github.com/arangodb/kube-arangodb/pkg/apis/shared" "github.com/arangodb/kube-arangodb/pkg/logging" @@ -51,7 +52,7 @@ var logger = logging.Global().RegisterAndGetLogger("monitor", logging.Info) var currentMembersStatus atomic.Value func NewMonitor(arangodbEndpoint string, auth Authentication, sslVerify bool, timeout time.Duration) *monitor { - uri, err := setPath(arangodbEndpoint, shared.ArangoExporterClusterHealthEndpoint) + uri, err := prepareEndpointURL(arangodbEndpoint, shared.ArangoExporterClusterHealthEndpoint) if err != nil { logger.Err(err).Error("Fatal") os.Exit(1) @@ -75,14 +76,14 @@ func (m monitor) UpdateMonitorStatus(ctx context.Context) { health, err := m.GetClusterHealth() if err != nil { - logger.Err(err).Error("GetClusterHealth error") + logger.Err(err).Info("GetClusterHealth error") sleep = failRefreshInterval } else { var output strings.Builder for key, value := range health.Health { entry, err := m.GetMemberStatus(key, value) if err != nil { - logger.Err(err).Error("GetMemberStatus error") + logger.Err(err).Info("GetMemberStatus error") sleep = failRefreshInterval } output.WriteString(entry) @@ -134,7 +135,7 @@ func (m monitor) GetMemberStatus(id driver.ServerID, member driver.ServerHealth) return result, err } - req.URL, err = setPath(member.Endpoint, shared.ArangoExporterStatusEndpoint) + req.URL, err = prepareEndpointURL(member.Endpoint, shared.ArangoExporterStatusEndpoint) if err != nil { return result, err } @@ -155,7 +156,9 @@ func (m monitor) GetMemberStatus(id driver.ServerID, member driver.ServerHealth) return fmt.Sprintf(monitorMetricTemplate, member.Role, id, 1), nil } -func setPath(uri, uriPath string) (*url.URL, error) { +func prepareEndpointURL(uri, uriPath string) (*url.URL, error) { + uri = util.FixupEndpointURLScheme(uri) + u, err := url.Parse(uri) if err != nil { return u, err diff --git a/pkg/deployment/agency/cache/interfaces.go b/pkg/exporter/monitor_test.go similarity index 54% rename from pkg/deployment/agency/cache/interfaces.go rename to pkg/exporter/monitor_test.go index e03482254..c919a6bac 100644 --- a/pkg/deployment/agency/cache/interfaces.go +++ b/pkg/exporter/monitor_test.go @@ -18,26 +18,27 @@ // Copyright holder is ArangoDB GmbH, Cologne, Germany // -package cache +package exporter import ( - "context" - "time" + "testing" - "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn" + "github.com/stretchr/testify/require" ) -type LeaderDiscovery interface { - Discover(ctx context.Context) (conn.Connection, error) -} - -type StateLoader[T interface{}] interface { - State() (*T, uint64, bool) - - Invalidate() - Valid() bool - - UpdateTime() time.Time - - Refresh(ctx context.Context, discovery LeaderDiscovery) error +func Test_prepareEndpointURL(t *testing.T) { + tcs := []struct { + url, path, expected string + }{ + {"http://some-host", "health", "http://some-host/health"}, + {"https://some-host", "health", "https://some-host/health"}, + {"tcp://some-host", "health", "http://some-host/health"}, + {"ssl://some-host", "health", "https://some-host/health"}, + } + + for i, tc := range tcs { + u, err := prepareEndpointURL(tc.url, tc.path) + require.NoErrorf(t, err, "case %d", i) + require.Equalf(t, tc.expected, u.String(), "case %d", i) + } } diff --git a/pkg/util/arangod/conn/async.go b/pkg/util/arangod/conn/async.go deleted file mode 100644 index 2c75450c3..000000000 --- a/pkg/util/arangod/conn/async.go +++ /dev/null @@ -1,112 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package conn - -import ( - "context" - "net/http" - "path" - - "github.com/arangodb/go-driver" - - "github.com/arangodb/kube-arangodb/pkg/util/constants" - "github.com/arangodb/kube-arangodb/pkg/util/errors" -) - -type ConnectionWrap func(c driver.Connection) driver.Connection - -func NewAsyncConnection(c driver.Connection) driver.Connection { - return async{ - connectionPass: connectionPass{ - c: c, - wrap: asyncConnectionWrap, - }, - } -} - -func asyncConnectionWrap(c driver.Connection) (driver.Connection, error) { - return NewAsyncConnection(c), nil -} - -type async struct { - connectionPass -} - -func (a async) isAsyncIDSet(ctx context.Context) (string, bool) { - if ctx != nil { - if q := ctx.Value(asyncOperatorContextKey); q != nil { - if v, ok := q.(string); ok { - return v, true - } - } - } - - return "", false -} - -func (a async) Do(ctx context.Context, req driver.Request) (driver.Response, error) { - if id, ok := a.isAsyncIDSet(ctx); ok { - // We have ID Set, request should be done to fetch job id - req, err := a.c.NewRequest(http.MethodPut, path.Join("/_api/job", id)) - if err != nil { - return nil, err - } - - resp, err := a.c.Do(ctx, req) - if err != nil { - return nil, err - } - - switch resp.StatusCode() { - case http.StatusNotFound: - return nil, newAsyncErrorNotFound(id) - case http.StatusNoContent: - asyncID := resp.Header(constants.ArangoHeaderAsyncIDKey) - if asyncID == id { - // Job is done - return resp, nil - } - - // Job is in progress - return nil, newAsyncJobInProgress(id) - default: - return resp, nil - } - } else { - req.SetHeader(constants.ArangoHeaderAsyncKey, constants.ArangoHeaderAsyncValue) - - resp, err := a.c.Do(ctx, req) - if err != nil { - return nil, err - } - - switch resp.StatusCode() { - case http.StatusAccepted: - if v := resp.Header(constants.ArangoHeaderAsyncIDKey); len(v) == 0 { - return nil, errors.Newf("Missing async key response") - } else { - return nil, newAsyncJobInProgress(v) - } - default: - return nil, resp.CheckStatus(http.StatusAccepted) - } - } -} diff --git a/pkg/util/arangod/conn/async_errors.go b/pkg/util/arangod/conn/async_errors.go deleted file mode 100644 index 2bb1c45ab..000000000 --- a/pkg/util/arangod/conn/async_errors.go +++ /dev/null @@ -1,79 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package conn - -import ( - "fmt" - - "github.com/arangodb/kube-arangodb/pkg/util/errors" -) - -func IsAsyncErrorNotFound(err error) bool { - if err == nil { - return false - } - - if _, ok := err.(asyncErrorNotFound); ok { - return true - } - - return IsAsyncErrorNotFound(errors.CauseWithNil(err)) -} - -func newAsyncErrorNotFound(id string) error { - return asyncErrorNotFound{ - jobID: id, - } -} - -type asyncErrorNotFound struct { - jobID string -} - -func (a asyncErrorNotFound) Error() string { - return fmt.Sprintf("Job with ID %s not found", a.jobID) -} - -func IsAsyncJobInProgress(err error) (string, bool) { - if err == nil { - return "", false - } - - if v, ok := err.(asyncJobInProgress); ok { - return v.jobID, true - } - - return IsAsyncJobInProgress(errors.CauseWithNil(err)) -} - -func newAsyncJobInProgress(id string) error { - return asyncJobInProgress{ - jobID: id, - } -} - -type asyncJobInProgress struct { - jobID string -} - -func (a asyncJobInProgress) Error() string { - return fmt.Sprintf("Job with ID %s in progress", a.jobID) -} diff --git a/pkg/util/arangod/conn/async_errors_test.go b/pkg/util/arangod/conn/async_errors_test.go deleted file mode 100644 index d5551fb30..000000000 --- a/pkg/util/arangod/conn/async_errors_test.go +++ /dev/null @@ -1,38 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package conn - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/arangodb/kube-arangodb/pkg/util/errors" -) - -func Test_IsAsyncErrorNotFound_Loop(t *testing.T) { - require.False(t, IsAsyncErrorNotFound(errors.Newf("Error"))) -} - -func Test_IsAsyncJobInProgress_Loop(t *testing.T) { - _, ok := IsAsyncJobInProgress(errors.Newf("Error")) - require.False(t, ok) -} diff --git a/pkg/util/arangod/conn/async_test.go b/pkg/util/arangod/conn/async_test.go deleted file mode 100644 index a9724e3fd..000000000 --- a/pkg/util/arangod/conn/async_test.go +++ /dev/null @@ -1,80 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package conn - -import ( - "context" - "net/http" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/arangodb/go-driver" - - "github.com/arangodb/kube-arangodb/pkg/util/tests" -) - -func Test_Async(t *testing.T) { - s := tests.NewServer(t) - - c := s.NewConnection() - - c = NewAsyncConnection(c) - - client, err := driver.NewClient(driver.ClientConfig{ - Connection: c, - }) - require.NoError(t, err) - - a := tests.NewAsyncHandler(t, s, http.MethodGet, "/_api/version", http.StatusOK, driver.VersionInfo{ - Server: "foo", - Version: "", - License: "", - Details: nil, - }) - - a.Start() - - _, err = client.Version(context.Background()) - require.Error(t, err) - id, ok := IsAsyncJobInProgress(err) - require.True(t, ok) - require.Equal(t, a.ID(), id) - - a.InProgress() - - ctx := WithAsyncID(context.TODO(), a.ID()) - - _, err = client.Version(ctx) - require.Error(t, err) - id, ok = IsAsyncJobInProgress(err) - require.True(t, ok) - require.Equal(t, a.ID(), id) - - a.Done() - - v, err := client.Version(ctx) - require.NoError(t, err) - - require.Equal(t, v.Server, "foo") - - defer s.Stop() -} diff --git a/pkg/util/arangod/conn/closed.go b/pkg/util/arangod/conn/closed.go deleted file mode 100644 index 2c72a41ce..000000000 --- a/pkg/util/arangod/conn/closed.go +++ /dev/null @@ -1,73 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2023 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package conn - -import ( - "context" - - "github.com/arangodb/go-driver" -) - -func NewClosedConnection() driver.Connection { - return closedConnection{} -} - -func newClosedConnectionError() error { - return closedConnectionError{} -} - -type closedConnectionError struct { -} - -func (c closedConnectionError) Error() string { - return "Connection Closed" -} - -type closedConnection struct { -} - -func (c closedConnection) NewRequest(method, path string) (driver.Request, error) { - return nil, newClosedConnectionError() -} - -func (c closedConnection) Do(ctx context.Context, req driver.Request) (driver.Response, error) { - return nil, newClosedConnectionError() -} - -func (c closedConnection) Unmarshal(data driver.RawObject, result interface{}) error { - return newClosedConnectionError() -} - -func (c closedConnection) Endpoints() []string { - return nil -} - -func (c closedConnection) UpdateEndpoints(endpoints []string) error { - return newClosedConnectionError() -} - -func (c closedConnection) SetAuthentication(authentication driver.Authentication) (driver.Connection, error) { - return c, nil -} - -func (c closedConnection) Protocols() driver.ProtocolSet { - return nil -} diff --git a/pkg/util/arangod/conn/conn.executor.go b/pkg/util/arangod/conn/conn.executor.go deleted file mode 100644 index debff5ed0..000000000 --- a/pkg/util/arangod/conn/conn.executor.go +++ /dev/null @@ -1,83 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2023 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package conn - -import ( - "bytes" - "context" - "encoding/json" - "io" - "net/http" - "reflect" - - "github.com/arangodb/kube-arangodb/pkg/util/metrics/nctx" -) - -func NewExecutor[IN, OUT interface{}](conn Connection) Executor[IN, OUT] { - return executor[IN, OUT]{ - conn: conn, - } -} - -type executor[IN, OUT interface{}] struct { - conn Connection -} - -func (e executor[IN, OUT]) ExecuteGet(ctx context.Context, endpoint string) (*OUT, int, error) { - var t IN - return e.Execute(ctx, http.MethodGet, endpoint, t) -} - -func (e executor[IN, OUT]) Execute(ctx context.Context, method string, endpoint string, in IN) (*OUT, int, error) { - var reader io.Reader - if q := reflect.ValueOf(in); q.IsValid() && !q.IsZero() && !q.IsNil() { - data, err := json.Marshal(in) - if err != nil { - return nil, 0, err - } - - reader = bytes.NewReader(data) - } - - resp, code, err := e.conn.Execute(ctx, method, endpoint, reader) - if err != nil { - return nil, 0, err - } - - if resp == nil { - return nil, code, nil - } - - defer resp.Close() - - var out OUT - - if err := json.NewDecoder(nctx.WithRequestReadBytes(ctx, resp)).Decode(&out); err != nil { - return nil, 0, err - } - - return &out, code, err -} - -type Executor[IN, OUT interface{}] interface { - ExecuteGet(ctx context.Context, endpoint string) (*OUT, int, error) - Execute(ctx context.Context, method string, endpoint string, in IN) (*OUT, int, error) -} diff --git a/pkg/util/arangod/conn/conn.go b/pkg/util/arangod/conn/conn.go deleted file mode 100644 index 4ee7f9a7d..000000000 --- a/pkg/util/arangod/conn/conn.go +++ /dev/null @@ -1,64 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2023 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package conn - -import ( - "context" - "fmt" - "io" - "net/http" -) - -type Connection interface { - Execute(ctx context.Context, method string, endpoint string, body io.Reader) (io.ReadCloser, int, error) -} - -type connection struct { - client *http.Client - - auth *string - - host string -} - -func (c connection) Execute(ctx context.Context, method string, endpoint string, body io.Reader) (io.ReadCloser, int, error) { - req, err := http.NewRequest(method, fmt.Sprintf("%s%s", c.host, endpoint), body) - if err != nil { - return nil, 0, err - } - - req = req.WithContext(ctx) - - if a := c.auth; a != nil { - req.Header.Add("Authorization", *a) - } - - resp, err := c.client.Do(req) - if err != nil { - return nil, 0, err - } - - if b := resp.Body; b != nil { - return b, resp.StatusCode, nil - } - - return nil, resp.StatusCode, nil -} diff --git a/pkg/util/arangod/conn/connection.pass.go b/pkg/util/arangod/conn/connection.pass.go deleted file mode 100644 index 051d8723d..000000000 --- a/pkg/util/arangod/conn/connection.pass.go +++ /dev/null @@ -1,72 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package conn - -import ( - "context" - - "github.com/arangodb/go-driver" -) - -type connectionWrap func(c driver.Connection) (driver.Connection, error) - -var _ driver.Connection = connectionPass{} - -type connectionPass struct { - c driver.Connection - wrap connectionWrap -} - -func (c connectionPass) NewRequest(method, path string) (driver.Request, error) { - return c.c.NewRequest(method, path) -} - -func (c connectionPass) Do(ctx context.Context, req driver.Request) (driver.Response, error) { - return c.c.Do(ctx, req) -} - -func (c connectionPass) Unmarshal(data driver.RawObject, result interface{}) error { - return c.c.Unmarshal(data, result) -} - -func (c connectionPass) Endpoints() []string { - return c.c.Endpoints() -} - -func (c connectionPass) UpdateEndpoints(endpoints []string) error { - return c.c.UpdateEndpoints(endpoints) -} - -func (c connectionPass) SetAuthentication(authentication driver.Authentication) (driver.Connection, error) { - newC, err := c.c.SetAuthentication(authentication) - if err != nil { - return nil, err - } - - if f := c.wrap; f != nil { - return f(newC) - } - return newC, nil -} - -func (c connectionPass) Protocols() driver.ProtocolSet { - return c.c.Protocols() -} diff --git a/pkg/util/arangod/conn/context.go b/pkg/util/arangod/conn/context.go deleted file mode 100644 index da19b0655..000000000 --- a/pkg/util/arangod/conn/context.go +++ /dev/null @@ -1,37 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package conn - -import "context" - -type ContextKey string - -const ( - asyncOperatorContextKey ContextKey = "operator-async-id" -) - -func WithAsyncID(ctx context.Context, id string) context.Context { - if ctx == nil { - ctx = context.Background() - } - - return context.WithValue(ctx, asyncOperatorContextKey, id) -} diff --git a/pkg/util/arangod/conn/factory.go b/pkg/util/arangod/conn/factory.go deleted file mode 100644 index 480e44e37..000000000 --- a/pkg/util/arangod/conn/factory.go +++ /dev/null @@ -1,184 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// Adam Janikowski -// - -package conn - -import ( - http2 "net/http" - - "github.com/arangodb/go-driver" - "github.com/arangodb/go-driver/agency" - "github.com/arangodb/go-driver/http" - - "github.com/arangodb/kube-arangodb/pkg/util" - "github.com/arangodb/kube-arangodb/pkg/util/errors" -) - -type Auth func() (driver.Authentication, error) -type Config func() (http.ConnectionConfig, error) - -type Factory interface { - Connection(hosts ...string) (driver.Connection, error) - AgencyConnection(hosts ...string) (driver.Connection, error) - - Client(hosts ...string) (driver.Client, error) - Agency(hosts ...string) (agency.Agency, error) - - RawConnection(host string) (Connection, error) - - GetAuth() Auth -} - -func NewFactory(auth Auth, config Config) Factory { - return &factory{ - auth: auth, - config: config, - } -} - -type factory struct { - auth Auth - config Config -} - -func (f factory) RawConnection(host string) (Connection, error) { - cfg, err := f.config() - if err != nil { - return nil, err - } - - var authString *string - - if f.auth != nil { - auth, err := f.auth() - if err != nil { - return nil, err - } - - if auth != nil { - if auth.Type() != driver.AuthenticationTypeRaw { - return nil, errors.Newf("Only RAW Authentication is supported") - } - - authString = util.NewType(auth.Get("value")) - } - } - - return connection{ - auth: authString, - host: host, - client: &http2.Client{ - Transport: cfg.Transport, - CheckRedirect: func(req *http2.Request, via []*http2.Request) error { - return http2.ErrUseLastResponse - }, - }, - }, nil -} - -func (f factory) GetAuth() Auth { - return f.auth -} - -func (f factory) AgencyConnection(hosts ...string) (driver.Connection, error) { - cfg, err := f.config() - if err != nil { - return nil, err - } - - cfg.Endpoints = hosts - - conn, err := agency.NewAgencyConnection(cfg) - if err != nil { - return nil, err - } - - if f.auth == nil { - return conn, nil - } - auth, err := f.auth() - if err != nil { - return nil, err - } - if auth == nil { - return conn, nil - } - return conn.SetAuthentication(auth) -} - -func (f factory) Client(hosts ...string) (driver.Client, error) { - conn, err := f.Connection(hosts...) - if err != nil { - return nil, err - } - - config := driver.ClientConfig{ - Connection: conn, - } - - if f.auth != nil { - auth, err := f.auth() - if err != nil { - return nil, err - } - - if auth != nil { - config.Authentication = auth - } - } - - return driver.NewClient(config) -} - -func (f factory) Agency(hosts ...string) (agency.Agency, error) { - conn, err := f.AgencyConnection(hosts...) - if err != nil { - return nil, err - } - - return agency.NewAgency(conn) -} - -func (f factory) Connection(hosts ...string) (driver.Connection, error) { - cfg, err := f.config() - if err != nil { - return nil, err - } - - cfg.Endpoints = hosts - - conn, err := http.NewConnection(cfg) - if err != nil { - return nil, err - } - - if f.auth == nil { - return conn, nil - } - auth, err := f.auth() - if err != nil { - return nil, err - } - if auth == nil { - return conn, nil - } - return conn.SetAuthentication(auth) -} diff --git a/pkg/util/arangod/endpoint.go b/pkg/util/arangod/endpoint.go deleted file mode 100644 index 41af9a752..000000000 --- a/pkg/util/arangod/endpoint.go +++ /dev/null @@ -1,40 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package arangod - -import "net/url" - -// IsSameEndpoint returns true when the 2 given endpoints -// refer to the same server. -func IsSameEndpoint_(a, b string) bool { - if a == b { - return true - } - ua, err := url.Parse(a) - if err != nil { - return false - } - ub, err := url.Parse(b) - if err != nil { - return false - } - return ua.Hostname() == ub.Hostname() -} diff --git a/pkg/util/metrics/nctx/counter.go b/pkg/util/metrics/nctx/counter.go deleted file mode 100644 index 8096283d9..000000000 --- a/pkg/util/metrics/nctx/counter.go +++ /dev/null @@ -1,45 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2023 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package nctx - -import ( - "sync" -) - -type Counter struct { - lock sync.Mutex - - value uint64 -} - -func (c *Counter) Get() uint64 { - c.lock.Lock() - defer c.lock.Unlock() - - return c.value -} - -func (c *Counter) add(v uint64) { - c.lock.Lock() - defer c.lock.Unlock() - - c.value += v -} diff --git a/pkg/util/metrics/nctx/counter_request_read.go b/pkg/util/metrics/nctx/counter_request_read.go deleted file mode 100644 index 3c7ec42c3..000000000 --- a/pkg/util/metrics/nctx/counter_request_read.go +++ /dev/null @@ -1,65 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2023 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package nctx - -import ( - "context" - "io" -) - -const RequestReadBytesKey Key = "operator.requestReadBytes" - -func (c *Counter) WithRequestReadBytes(ctx context.Context) context.Context { - if ctx == nil { - ctx = context.Background() - } - - return context.WithValue(ctx, RequestReadBytesKey, c) -} - -type requestReadBytes struct { - c *Counter - - in io.Reader -} - -func (r requestReadBytes) Read(p []byte) (n int, err error) { - n, err = r.in.Read(p) - r.c.add(uint64(n)) - return -} - -func WithRequestReadBytes(ctx context.Context, reader io.Reader) io.Reader { - v := ctx.Value(RequestReadBytesKey) - if v == nil { - return reader - } - - z, ok := v.(*Counter) - if !ok { - return reader - } - - return requestReadBytes{ - c: z, - in: reader, - } -} diff --git a/pkg/util/metrics/nctx/counter_request_read_test.go b/pkg/util/metrics/nctx/counter_request_read_test.go deleted file mode 100644 index 601c297e5..000000000 --- a/pkg/util/metrics/nctx/counter_request_read_test.go +++ /dev/null @@ -1,53 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2023 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package nctx - -import ( - "bytes" - "context" - "io" - "testing" - - "github.com/stretchr/testify/require" -) - -func counterRequestReadMock(t *testing.T, ctx context.Context, data io.Reader) int { - data = WithRequestReadBytes(ctx, data) - dz, err := io.ReadAll(data) - require.NoError(t, err) - return len(dz) -} - -func Test_Counter_RequestRead(t *testing.T) { - data := make([]byte, 64) - - var c Counter - - t.Run("Read without wrapper", func(t *testing.T) { - require.EqualValues(t, 64, counterRequestReadMock(t, context.Background(), bytes.NewReader(data))) - require.EqualValues(t, 0, c.Get()) - }) - - t.Run("Read with wrapper", func(t *testing.T) { - require.EqualValues(t, 64, counterRequestReadMock(t, c.WithRequestReadBytes(context.Background()), bytes.NewReader(data))) - require.EqualValues(t, 64, c.Get()) - }) -} diff --git a/pkg/util/metrics/nctx/interface.go b/pkg/util/metrics/nctx/interface.go deleted file mode 100644 index 060e30e41..000000000 --- a/pkg/util/metrics/nctx/interface.go +++ /dev/null @@ -1,29 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2023 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package nctx - -import "context" - -type Key string - -type With interface { - With(ctx context.Context) context.Context -} diff --git a/pkg/util/tests/server.go b/pkg/util/tests/server.go deleted file mode 100644 index 0cab4ac33..000000000 --- a/pkg/util/tests/server.go +++ /dev/null @@ -1,210 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package tests - -import ( - "encoding/json" - "fmt" - "net" - "net/http" - "sync" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/arangodb/go-driver" - httpdriver "github.com/arangodb/go-driver/http" -) - -func NewServer(t *testing.T) Server { - s := &server{ - t: t, - stop: make(chan struct{}), - stopped: make(chan struct{}), - started: make(chan struct{}), - done: make(chan struct{}), - } - - go s.run() - - <-s.started - - return s -} - -type Server interface { - NewConnection() driver.Connection - NewClient() driver.Client - - Handle(f http.HandlerFunc) - Addr() string - Stop() -} - -type server struct { - lock sync.Mutex - - t *testing.T - - handlers []http.HandlerFunc - - port int - - stop, stopped, started, done chan struct{} -} - -func (s *server) NewClient() driver.Client { - c, err := driver.NewClient(driver.ClientConfig{ - Connection: s.NewConnection(), - }) - require.NoError(s.t, err) - - return c -} - -func (s *server) NewConnection() driver.Connection { - c, err := httpdriver.NewConnection(httpdriver.ConnectionConfig{ - Endpoints: []string{ - s.Addr(), - }, - ContentType: driver.ContentTypeJSON, - }) - require.NoError(s.t, err) - - return c -} - -func (s *server) Handle(f http.HandlerFunc) { - s.lock.Lock() - defer s.lock.Unlock() - - s.handlers = append(s.handlers, f) -} - -func (s *server) Addr() string { - return fmt.Sprintf("http://127.0.0.1:%d", s.port) -} - -func (s *server) Stop() { - s.lock.Lock() - defer s.lock.Unlock() - - close(s.stop) - - <-s.done - - if q := len(s.handlers); q > 0 { - require.Failf(s.t, "Pending messages", "Count %d", q) - } -} - -func (s *server) run() { - defer close(s.done) - - listener, err := net.Listen("tcp", "127.0.0.1:0") - require.NoError(s.t, err) - - s.port = listener.Addr().(*net.TCPAddr).Port - - m := http.NewServeMux() - - m.HandleFunc("/", s.handle) - - server := http.Server{ - Handler: m, - } - - var serverErr error - - go func() { - defer close(s.stopped) - close(s.started) - - go func() { - <-s.stop - require.NoError(s.t, server.Close()) - }() - - serverErr = server.Serve(listener) - }() - - <-s.stopped - - if serverErr != http.ErrServerClosed { - require.NoError(s.t, serverErr) - } -} -func (s *server) handle(writer http.ResponseWriter, request *http.Request) { - s.lock.Lock() - defer s.lock.Unlock() - - var handler http.HandlerFunc - - switch len(s.handlers) { - case 0: - require.Fail(s.t, "No pending messages") - case 1: - handler = s.handlers[0] - s.handlers = nil - default: - handler = s.handlers[0] - s.handlers = s.handlers[1:] - } - - handler(writer, request) -} - -func NewSimpleHandler(t *testing.T, method string, path string, resp func(t *testing.T) (int, interface{})) http.HandlerFunc { - return NewCustomRequestHandler(t, method, path, nil, nil, resp) -} - -func NewCustomRequestHandler(t *testing.T, method string, path string, reqVerify func(t *testing.T, r *http.Request), respHeaders func(t *testing.T) map[string]string, resp func(t *testing.T) (int, interface{})) http.HandlerFunc { - return func(writer http.ResponseWriter, request *http.Request) { - require.Equal(t, method, request.Method) - require.Equal(t, path, request.RequestURI) - - if reqVerify != nil { - reqVerify(t, request) - } - - code, r := resp(t) - - writer.Header().Add("content-type", "application/json") - if respHeaders != nil { - h := respHeaders(t) - - for k, v := range h { - writer.Header().Add(k, v) - } - } - - writer.WriteHeader(code) - - if r != nil { - d, err := json.Marshal(r) - require.NoError(t, err) - - s, err := writer.Write(d) - require.NoError(t, err) - require.Equal(t, len(d), s) - } - } -} diff --git a/pkg/util/tests/server_async.go b/pkg/util/tests/server_async.go deleted file mode 100644 index 9d135c617..000000000 --- a/pkg/util/tests/server_async.go +++ /dev/null @@ -1,115 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package tests - -import ( - "fmt" - "net/http" - "testing" - - "github.com/dchest/uniuri" - "github.com/stretchr/testify/require" - - "github.com/arangodb/kube-arangodb/pkg/util/constants" -) - -func NewAsyncHandler(t *testing.T, s Server, method string, path string, retCode int, ret interface{}) AsyncHandler { - return &asyncHandler{ - t: t, - s: s, - ret: ret, - retCode: retCode, - method: method, - path: path, - id: uniuri.NewLen(32), - } -} - -type AsyncHandler interface { - ID() string - - Start() - InProgress() - Missing() - Done() -} - -type asyncHandler struct { - t *testing.T - s Server - - ret interface{} - retCode int - - method, path string - - id string -} - -func (a *asyncHandler) Missing() { - p := fmt.Sprintf("/_api/job/%s", a.id) - - a.s.Handle(NewCustomRequestHandler(a.t, http.MethodPut, p, func(t *testing.T, r *http.Request) { - v := r.Header.Get(constants.ArangoHeaderAsyncKey) - require.Equal(t, "", v) - }, nil, func(t *testing.T) (int, interface{}) { - return http.StatusNotFound, nil - })) -} - -func (a *asyncHandler) Start() { - a.s.Handle(NewCustomRequestHandler(a.t, a.method, a.path, func(t *testing.T, r *http.Request) { - v := r.Header.Get(constants.ArangoHeaderAsyncKey) - require.Equal(t, constants.ArangoHeaderAsyncValue, v) - }, func(t *testing.T) map[string]string { - return map[string]string{ - constants.ArangoHeaderAsyncIDKey: a.id, - } - }, func(t *testing.T) (int, interface{}) { - return http.StatusAccepted, nil - })) -} - -func (a *asyncHandler) InProgress() { - p := fmt.Sprintf("/_api/job/%s", a.id) - - a.s.Handle(NewCustomRequestHandler(a.t, http.MethodPut, p, func(t *testing.T, r *http.Request) { - v := r.Header.Get(constants.ArangoHeaderAsyncKey) - require.Equal(t, "", v) - }, nil, func(t *testing.T) (int, interface{}) { - return http.StatusNoContent, nil - })) -} - -func (a *asyncHandler) Done() { - p := fmt.Sprintf("/_api/job/%s", a.id) - - a.s.Handle(NewCustomRequestHandler(a.t, http.MethodPut, p, func(t *testing.T, r *http.Request) { - v := r.Header.Get(constants.ArangoHeaderAsyncKey) - require.Equal(t, "", v) - }, nil, func(t *testing.T) (int, interface{}) { - return a.retCode, a.ret - })) -} - -func (a *asyncHandler) ID() string { - return a.id -}