From c53658e87b277d39e19bcc8c11da7c37ef6e4f06 Mon Sep 17 00:00:00 2001 From: Jonas L Date: Fri, 21 Jun 2024 09:56:18 +0200 Subject: [PATCH] refactor: move packages to `internal` (#626) Clean up the root directory and move all non-public packages (all except `cmd`) into the `internal` namespace. --- .dockerignore | 7 +------ cmd/aio/main.go | 8 ++++---- cmd/controller/main.go | 8 ++++---- cmd/node/main.go | 6 +++--- {api => internal/api}/helper.go | 2 +- {api => internal/api}/volume.go | 4 ++-- {api => internal/api}/volume_test.go | 4 ++-- {app => internal/app}/app.go | 4 ++-- {csi => internal/csi}/server.go | 0 {csi => internal/csi}/volume.go | 0 {driver => internal/driver}/controller.go | 4 ++-- {driver => internal/driver}/controller_test.go | 6 +++--- {driver => internal/driver}/driver.go | 0 {driver => internal/driver}/helper.go | 0 {driver => internal/driver}/helper_test.go | 0 {driver => internal/driver}/identity.go | 0 {driver => internal/driver}/identity_test.go | 0 {driver => internal/driver}/node.go | 2 +- {driver => internal/driver}/node_test.go | 4 ++-- {driver => internal/driver}/sanity_test.go | 4 ++-- {metrics => internal/metrics}/metrics.go | 0 {mock => internal/mock}/volume.go | 4 ++-- {volumes => internal/volumes}/cryptsetup.go | 0 {volumes => internal/volumes}/idempotency.go | 2 +- {volumes => internal/volumes}/idempotency_test.go | 6 +++--- {volumes => internal/volumes}/mount.go | 0 {volumes => internal/volumes}/mount_test.go | 0 {volumes => internal/volumes}/resize.go | 0 {volumes => internal/volumes}/resize_test.go | 0 {volumes => internal/volumes}/service.go | 2 +- {volumes => internal/volumes}/stats.go | 0 {volumes => internal/volumes}/stats_test.go | 0 test/integration/cryptsetup_test.go | 2 +- test/integration/volumes_test.go | 2 +- 34 files changed, 38 insertions(+), 43 deletions(-) rename {api => internal/api}/helper.go (91%) rename {api => internal/api}/volume.go (98%) rename {api => internal/api}/volume_test.go (95%) rename {app => internal/app}/app.go (98%) rename {csi => internal/csi}/server.go (100%) rename {csi => internal/csi}/volume.go (100%) rename {driver => internal/driver}/controller.go (99%) rename {driver => internal/driver}/controller_test.go (99%) rename {driver => internal/driver}/driver.go (100%) rename {driver => internal/driver}/helper.go (100%) rename {driver => internal/driver}/helper_test.go (100%) rename {driver => internal/driver}/identity.go (100%) rename {driver => internal/driver}/identity_test.go (100%) rename {driver => internal/driver}/node.go (99%) rename {driver => internal/driver}/node_test.go (98%) rename {driver => internal/driver}/sanity_test.go (98%) rename {metrics => internal/metrics}/metrics.go (100%) rename {mock => internal/mock}/volume.go (97%) rename {volumes => internal/volumes}/cryptsetup.go (100%) rename {volumes => internal/volumes}/idempotency.go (98%) rename {volumes => internal/volumes}/idempotency_test.go (98%) rename {volumes => internal/volumes}/mount.go (100%) rename {volumes => internal/volumes}/mount_test.go (100%) rename {volumes => internal/volumes}/resize.go (100%) rename {volumes => internal/volumes}/resize_test.go (100%) rename {volumes => internal/volumes}/service.go (96%) rename {volumes => internal/volumes}/stats.go (100%) rename {volumes => internal/volumes}/stats_test.go (100%) diff --git a/.dockerignore b/.dockerignore index 9b08426b..838f068e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,10 +1,5 @@ * -!api/ -!app/ !cmd/ -!csi/ -!driver/ -!metrics/ -!volumes/ +!internal/ !go.mod !go.sum diff --git a/cmd/aio/main.go b/cmd/aio/main.go index 461d218e..75849ffe 100644 --- a/cmd/aio/main.go +++ b/cmd/aio/main.go @@ -10,10 +10,10 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" - "github.com/hetznercloud/csi-driver/api" - "github.com/hetznercloud/csi-driver/app" - "github.com/hetznercloud/csi-driver/driver" - "github.com/hetznercloud/csi-driver/volumes" + "github.com/hetznercloud/csi-driver/internal/api" + "github.com/hetznercloud/csi-driver/internal/app" + "github.com/hetznercloud/csi-driver/internal/driver" + "github.com/hetznercloud/csi-driver/internal/volumes" "github.com/hetznercloud/hcloud-go/v2/hcloud/metadata" ) diff --git a/cmd/controller/main.go b/cmd/controller/main.go index 2121f47f..533009cd 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -7,10 +7,10 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" - "github.com/hetznercloud/csi-driver/api" - "github.com/hetznercloud/csi-driver/app" - "github.com/hetznercloud/csi-driver/driver" - "github.com/hetznercloud/csi-driver/volumes" + "github.com/hetznercloud/csi-driver/internal/api" + "github.com/hetznercloud/csi-driver/internal/app" + "github.com/hetznercloud/csi-driver/internal/driver" + "github.com/hetznercloud/csi-driver/internal/volumes" "github.com/hetznercloud/hcloud-go/v2/hcloud/metadata" ) diff --git a/cmd/node/main.go b/cmd/node/main.go index dec6af3b..086e718d 100644 --- a/cmd/node/main.go +++ b/cmd/node/main.go @@ -10,9 +10,9 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" - "github.com/hetznercloud/csi-driver/app" - "github.com/hetznercloud/csi-driver/driver" - "github.com/hetznercloud/csi-driver/volumes" + "github.com/hetznercloud/csi-driver/internal/app" + "github.com/hetznercloud/csi-driver/internal/driver" + "github.com/hetznercloud/csi-driver/internal/volumes" "github.com/hetznercloud/hcloud-go/v2/hcloud/metadata" ) diff --git a/api/helper.go b/internal/api/helper.go similarity index 91% rename from api/helper.go rename to internal/api/helper.go index 386eafd0..0193d75b 100644 --- a/api/helper.go +++ b/internal/api/helper.go @@ -1,7 +1,7 @@ package api import ( - "github.com/hetznercloud/csi-driver/csi" + "github.com/hetznercloud/csi-driver/internal/csi" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) diff --git a/api/volume.go b/internal/api/volume.go similarity index 98% rename from api/volume.go rename to internal/api/volume.go index 01d50272..8357bf46 100644 --- a/api/volume.go +++ b/internal/api/volume.go @@ -7,8 +7,8 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" - "github.com/hetznercloud/csi-driver/csi" - "github.com/hetznercloud/csi-driver/volumes" + "github.com/hetznercloud/csi-driver/internal/csi" + "github.com/hetznercloud/csi-driver/internal/volumes" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) diff --git a/api/volume_test.go b/internal/api/volume_test.go similarity index 95% rename from api/volume_test.go rename to internal/api/volume_test.go index d1974187..34d3b839 100644 --- a/api/volume_test.go +++ b/internal/api/volume_test.go @@ -9,9 +9,9 @@ import ( "github.com/go-kit/log" "github.com/stretchr/testify/assert" - "github.com/hetznercloud/csi-driver/csi" + "github.com/hetznercloud/csi-driver/internal/csi" "github.com/hetznercloud/csi-driver/internal/mocked" - "github.com/hetznercloud/csi-driver/volumes" + "github.com/hetznercloud/csi-driver/internal/volumes" "github.com/hetznercloud/hcloud-go/v2/hcloud" "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) diff --git a/app/app.go b/internal/app/app.go similarity index 98% rename from app/app.go rename to internal/app/app.go index 09b31348..5d8f9b8e 100644 --- a/app/app.go +++ b/internal/app/app.go @@ -16,8 +16,8 @@ import ( "github.com/prometheus/client_golang/prometheus" "google.golang.org/grpc" - "github.com/hetznercloud/csi-driver/driver" - "github.com/hetznercloud/csi-driver/metrics" + "github.com/hetznercloud/csi-driver/internal/driver" + "github.com/hetznercloud/csi-driver/internal/metrics" "github.com/hetznercloud/hcloud-go/v2/hcloud" "github.com/hetznercloud/hcloud-go/v2/hcloud/metadata" ) diff --git a/csi/server.go b/internal/csi/server.go similarity index 100% rename from csi/server.go rename to internal/csi/server.go diff --git a/csi/volume.go b/internal/csi/volume.go similarity index 100% rename from csi/volume.go rename to internal/csi/volume.go diff --git a/driver/controller.go b/internal/driver/controller.go similarity index 99% rename from driver/controller.go rename to internal/driver/controller.go index cede3c34..f004eb1c 100644 --- a/driver/controller.go +++ b/internal/driver/controller.go @@ -12,8 +12,8 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "github.com/hetznercloud/csi-driver/csi" - "github.com/hetznercloud/csi-driver/volumes" + "github.com/hetznercloud/csi-driver/internal/csi" + "github.com/hetznercloud/csi-driver/internal/volumes" ) type ControllerService struct { diff --git a/driver/controller_test.go b/internal/driver/controller_test.go similarity index 99% rename from driver/controller_test.go rename to internal/driver/controller_test.go index e442c504..d8e2b0e2 100644 --- a/driver/controller_test.go +++ b/internal/driver/controller_test.go @@ -10,9 +10,9 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "github.com/hetznercloud/csi-driver/csi" - "github.com/hetznercloud/csi-driver/mock" - "github.com/hetznercloud/csi-driver/volumes" + "github.com/hetznercloud/csi-driver/internal/csi" + "github.com/hetznercloud/csi-driver/internal/mock" + "github.com/hetznercloud/csi-driver/internal/volumes" ) var _ proto.ControllerServer = (*ControllerService)(nil) diff --git a/driver/driver.go b/internal/driver/driver.go similarity index 100% rename from driver/driver.go rename to internal/driver/driver.go diff --git a/driver/helper.go b/internal/driver/helper.go similarity index 100% rename from driver/helper.go rename to internal/driver/helper.go diff --git a/driver/helper_test.go b/internal/driver/helper_test.go similarity index 100% rename from driver/helper_test.go rename to internal/driver/helper_test.go diff --git a/driver/identity.go b/internal/driver/identity.go similarity index 100% rename from driver/identity.go rename to internal/driver/identity.go diff --git a/driver/identity_test.go b/internal/driver/identity_test.go similarity index 100% rename from driver/identity_test.go rename to internal/driver/identity_test.go diff --git a/driver/node.go b/internal/driver/node.go similarity index 99% rename from driver/node.go rename to internal/driver/node.go index 481292f8..ca69fdbe 100644 --- a/driver/node.go +++ b/internal/driver/node.go @@ -10,7 +10,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "github.com/hetznercloud/csi-driver/volumes" + "github.com/hetznercloud/csi-driver/internal/volumes" ) type NodeService struct { diff --git a/driver/node_test.go b/internal/driver/node_test.go similarity index 98% rename from driver/node_test.go rename to internal/driver/node_test.go index f83fac83..6336be20 100644 --- a/driver/node_test.go +++ b/internal/driver/node_test.go @@ -10,8 +10,8 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "github.com/hetznercloud/csi-driver/mock" - "github.com/hetznercloud/csi-driver/volumes" + "github.com/hetznercloud/csi-driver/internal/mock" + "github.com/hetznercloud/csi-driver/internal/volumes" ) var _ proto.NodeServer = (*NodeService)(nil) diff --git a/driver/sanity_test.go b/internal/driver/sanity_test.go similarity index 98% rename from driver/sanity_test.go rename to internal/driver/sanity_test.go index d10705e8..bec0c08d 100644 --- a/driver/sanity_test.go +++ b/internal/driver/sanity_test.go @@ -15,8 +15,8 @@ import ( "github.com/kubernetes-csi/csi-test/v5/pkg/sanity" "google.golang.org/grpc" - "github.com/hetznercloud/csi-driver/csi" - "github.com/hetznercloud/csi-driver/volumes" + "github.com/hetznercloud/csi-driver/internal/csi" + "github.com/hetznercloud/csi-driver/internal/volumes" ) func TestSanity(t *testing.T) { diff --git a/metrics/metrics.go b/internal/metrics/metrics.go similarity index 100% rename from metrics/metrics.go rename to internal/metrics/metrics.go diff --git a/mock/volume.go b/internal/mock/volume.go similarity index 97% rename from mock/volume.go rename to internal/mock/volume.go index 3d44a363..cc44f4ee 100644 --- a/mock/volume.go +++ b/internal/mock/volume.go @@ -3,8 +3,8 @@ package mock import ( "context" - "github.com/hetznercloud/csi-driver/csi" - "github.com/hetznercloud/csi-driver/volumes" + "github.com/hetznercloud/csi-driver/internal/csi" + "github.com/hetznercloud/csi-driver/internal/volumes" "github.com/hetznercloud/hcloud-go/v2/hcloud" ) diff --git a/volumes/cryptsetup.go b/internal/volumes/cryptsetup.go similarity index 100% rename from volumes/cryptsetup.go rename to internal/volumes/cryptsetup.go diff --git a/volumes/idempotency.go b/internal/volumes/idempotency.go similarity index 98% rename from volumes/idempotency.go rename to internal/volumes/idempotency.go index b2eee912..8fa150bf 100644 --- a/volumes/idempotency.go +++ b/internal/volumes/idempotency.go @@ -6,7 +6,7 @@ import ( "github.com/go-kit/log" "github.com/go-kit/log/level" - "github.com/hetznercloud/csi-driver/csi" + "github.com/hetznercloud/csi-driver/internal/csi" ) // IdempotentService wraps a volume service and provides idempotency as required by the CSI spec. diff --git a/volumes/idempotency_test.go b/internal/volumes/idempotency_test.go similarity index 98% rename from volumes/idempotency_test.go rename to internal/volumes/idempotency_test.go index 7bc14155..01e54265 100644 --- a/volumes/idempotency_test.go +++ b/internal/volumes/idempotency_test.go @@ -7,9 +7,9 @@ import ( "github.com/go-kit/log" - "github.com/hetznercloud/csi-driver/csi" - "github.com/hetznercloud/csi-driver/mock" - "github.com/hetznercloud/csi-driver/volumes" + "github.com/hetznercloud/csi-driver/internal/csi" + "github.com/hetznercloud/csi-driver/internal/mock" + "github.com/hetznercloud/csi-driver/internal/volumes" ) var _ volumes.Service = (*volumes.IdempotentService)(nil) diff --git a/volumes/mount.go b/internal/volumes/mount.go similarity index 100% rename from volumes/mount.go rename to internal/volumes/mount.go diff --git a/volumes/mount_test.go b/internal/volumes/mount_test.go similarity index 100% rename from volumes/mount_test.go rename to internal/volumes/mount_test.go diff --git a/volumes/resize.go b/internal/volumes/resize.go similarity index 100% rename from volumes/resize.go rename to internal/volumes/resize.go diff --git a/volumes/resize_test.go b/internal/volumes/resize_test.go similarity index 100% rename from volumes/resize_test.go rename to internal/volumes/resize_test.go diff --git a/volumes/service.go b/internal/volumes/service.go similarity index 96% rename from volumes/service.go rename to internal/volumes/service.go index fcb3e137..f67baa02 100644 --- a/volumes/service.go +++ b/internal/volumes/service.go @@ -4,7 +4,7 @@ import ( "context" "errors" - "github.com/hetznercloud/csi-driver/csi" + "github.com/hetznercloud/csi-driver/internal/csi" ) var ( diff --git a/volumes/stats.go b/internal/volumes/stats.go similarity index 100% rename from volumes/stats.go rename to internal/volumes/stats.go diff --git a/volumes/stats_test.go b/internal/volumes/stats_test.go similarity index 100% rename from volumes/stats_test.go rename to internal/volumes/stats_test.go diff --git a/test/integration/cryptsetup_test.go b/test/integration/cryptsetup_test.go index bcf09025..56c5353b 100644 --- a/test/integration/cryptsetup_test.go +++ b/test/integration/cryptsetup_test.go @@ -6,7 +6,7 @@ import ( "github.com/go-kit/log" - "github.com/hetznercloud/csi-driver/volumes" + "github.com/hetznercloud/csi-driver/internal/volumes" ) func TestCryptSetup(t *testing.T) { diff --git a/test/integration/volumes_test.go b/test/integration/volumes_test.go index 5a039706..8d9a3d63 100644 --- a/test/integration/volumes_test.go +++ b/test/integration/volumes_test.go @@ -10,7 +10,7 @@ import ( "github.com/go-kit/log" - "github.com/hetznercloud/csi-driver/volumes" + "github.com/hetznercloud/csi-driver/internal/volumes" ) func TestVolumePublishUnpublish(t *testing.T) {