From 58e2dd6eb870b0808d96d9d73b46960150b61004 Mon Sep 17 00:00:00 2001 From: Andreas Fritzler Date: Wed, 20 Mar 2024 11:04:04 +0100 Subject: [PATCH] Refactor project structure Refactore the current project structure to reflect the current conventions in Go. Create top-level packages for `api`, `cmd` and keep the implementation details in the `internal` package. Also bump golang version to 1.22 and update the `golangci-lint` to v1.57.0. --- .github/workflows/golangci-lint.yml | 2 +- .reuse/dep5 | 2 +- Dockerfile | 11 +- Makefile | 24 ++-- {pkg/api => api}/api.go | 0 {iri/volume/apiutils => api}/constants.go | 5 +- {pkg/api => api}/image.go | 0 {pkg/api => api}/snapshot.go | 0 .../apiutils/apiutils.go => api/utils.go | 103 +++++++++++++++- .../bucket => cmd/bucketprovider}/app/app.go | 16 ++- .../cmd/volume => cmd/bucketprovider}/main.go | 2 +- .../volume => cmd/volumeprovider}/app/app.go | 42 +++---- .../cmd/bucket => cmd/volumeprovider}/main.go | 2 +- docs/development/setup.md | 6 +- go.mod | 2 +- {pkg => internal}/bcr/registry.go | 0 .../bucketserver}/bucket.go | 8 +- .../bucketserver}/bucket_create.go | 10 +- .../bucketserver}/bucket_create_test.go | 7 +- .../bucketserver}/bucket_delete.go | 2 +- .../bucketserver}/bucket_delete_test.go | 7 +- .../bucketserver}/bucket_list.go | 6 +- .../bucketserver}/bucket_list_test.go | 9 +- .../bucketserver}/bucketclass_list.go | 2 +- .../bucketserver}/bucketclass_list_test.go | 2 +- .../bucketserver}/server.go | 11 +- .../bucketserver}/suite_test.go | 11 +- {pkg => internal}/ceph/auth.go | 0 {pkg => internal}/ceph/auth_test.go | 0 {pkg => internal}/ceph/commands.go | 0 {pkg => internal}/ceph/test.key | 0 {pkg => internal}/controllers/common.go | 0 .../controllers/image_controller.go | 70 +++++------ .../controllers/snapshot_controller.go | 31 ++--- {pkg => internal}/encryption/encryption.go | 0 {pkg => internal}/event/event.go | 4 +- {pkg => internal}/limits/calc.go | 2 +- {pkg => internal}/omap/config.go | 0 {pkg => internal}/omap/omap.go | 8 +- {pkg/utils => internal/rater}/rater.go | 2 +- {pkg => internal}/registry/registry.go | 0 {pkg => internal}/rook/config.go | 0 {pkg => internal}/round/size.go | 0 .../snapshotstrategy}/strategy.go | 4 +- {pkg => internal}/store/store.go | 2 +- {pkg => internal}/sync/sync.go | 0 {pkg => internal}/sync/sync_suite_test.go | 0 {pkg => internal}/sync/sync_test.go | 0 {pkg => internal}/utils/utils.go | 0 {pkg => internal}/vcr/registry.go | 3 +- .../volumeserver}/server.go | 18 +-- .../volumeserver}/status.go | 2 +- .../volumeserver}/volume.go | 11 +- .../volumeserver}/volume_create.go | 23 ++-- .../volumeserver}/volume_delete.go | 4 +- .../volumeserver}/volume_expand.go | 4 +- .../volumeserver}/volume_list.go | 10 +- iri/bucket/apiutils/constants.go | 12 -- iri/volume/apiutils/apiutils.go | 114 ------------------ .../integration}/integration_suite_test.go | 7 +- .../volume_create_integration_test.go | 9 +- .../volume_delete_integration_test.go | 4 +- .../volume_expand_integration_test.go | 9 +- .../volume_list_integration_test.go | 4 +- .../volume_status_integration_test.go | 7 +- 65 files changed, 314 insertions(+), 342 deletions(-) rename {pkg/api => api}/api.go (100%) rename {iri/volume/apiutils => api}/constants.go (88%) rename {pkg/api => api}/image.go (100%) rename {pkg/api => api}/snapshot.go (100%) rename iri/bucket/apiutils/apiutils.go => api/utils.go (53%) rename {iri/bucket/cmd/bucket => cmd/bucketprovider}/app/app.go (93%) rename {iri/volume/cmd/volume => cmd/bucketprovider}/main.go (84%) rename {iri/volume/cmd/volume => cmd/volumeprovider}/app/app.go (90%) rename {iri/bucket/cmd/bucket => cmd/volumeprovider}/main.go (84%) rename {pkg => internal}/bcr/registry.go (100%) rename {iri/bucket/server => internal/bucketserver}/bucket.go (94%) rename {iri/bucket/server => internal/bucketserver}/bucket_create.go (89%) rename {iri/bucket/server => internal/bucketserver}/bucket_create_test.go (99%) rename {iri/bucket/server => internal/bucketserver}/bucket_delete.go (97%) rename {iri/bucket/server => internal/bucketserver}/bucket_delete_test.go (99%) rename {iri/bucket/server => internal/bucketserver}/bucket_list.go (97%) rename {iri/bucket/server => internal/bucketserver}/bucket_list_test.go (99%) rename {iri/bucket/server => internal/bucketserver}/bucketclass_list.go (96%) rename {iri/bucket/server => internal/bucketserver}/bucketclass_list_test.go (97%) rename {iri/bucket/server => internal/bucketserver}/server.go (96%) rename {iri/bucket/server => internal/bucketserver}/suite_test.go (98%) rename {pkg => internal}/ceph/auth.go (100%) rename {pkg => internal}/ceph/auth_test.go (100%) rename {pkg => internal}/ceph/commands.go (100%) rename {pkg => internal}/ceph/test.key (100%) rename {pkg => internal}/controllers/common.go (100%) rename {pkg => internal}/controllers/image_controller.go (87%) rename {pkg => internal}/controllers/snapshot_controller.go (91%) rename {pkg => internal}/encryption/encryption.go (100%) rename {pkg => internal}/event/event.go (97%) rename {pkg => internal}/limits/calc.go (95%) rename {pkg => internal}/omap/config.go (100%) rename {pkg => internal}/omap/omap.go (97%) rename {pkg/utils => internal/rater}/rater.go (98%) rename {pkg => internal}/registry/registry.go (100%) rename {pkg => internal}/rook/config.go (100%) rename {pkg => internal}/round/size.go (100%) rename {pkg/utils => internal/snapshotstrategy}/strategy.go (91%) rename {pkg => internal}/store/store.go (96%) rename {pkg => internal}/sync/sync.go (100%) rename {pkg => internal}/sync/sync_suite_test.go (100%) rename {pkg => internal}/sync/sync_test.go (100%) rename {pkg => internal}/utils/utils.go (100%) rename {pkg => internal}/vcr/registry.go (99%) rename {iri/volume/server => internal/volumeserver}/server.go (79%) rename {iri/volume/server => internal/volumeserver}/status.go (98%) rename {iri/volume/server => internal/volumeserver}/volume.go (89%) rename {iri/volume/server => internal/volumeserver}/volume_create.go (80%) rename {iri/volume/server => internal/volumeserver}/volume_delete.go (91%) rename {iri/volume/server => internal/volumeserver}/volume_expand.go (95%) rename {iri/volume/server => internal/volumeserver}/volume_list.go (90%) delete mode 100644 iri/bucket/apiutils/constants.go delete mode 100644 iri/volume/apiutils/apiutils.go rename {integration => tests/integration}/integration_suite_test.go (98%) rename {integration => tests/integration}/volume_create_integration_test.go (96%) rename {integration => tests/integration}/volume_delete_integration_test.go (96%) rename {integration => tests/integration}/volume_expand_integration_test.go (95%) rename {integration => tests/integration}/volume_list_integration_test.go (97%) rename {integration => tests/integration}/volume_status_integration_test.go (92%) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 4fe37634..d7a7ffc5 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -18,5 +18,5 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v4 with: - version: v1.54.2 + version: v1.57.0 skip-pkg-cache: true diff --git a/.reuse/dep5 b/.reuse/dep5 index 44717559..ec4fa4fd 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -19,7 +19,7 @@ Files: CONTRIBUTING.md Dockerfile Makefile - pkg/ceph/test.key + internal/ceph/test.key mkdocs.yml hack/*.sh Copyright: 2023 SAP SE or an SAP affiliate company and IronCore contributors diff --git a/Dockerfile b/Dockerfile index b148e493..82852d04 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,8 +12,9 @@ RUN --mount=type=cache,target=/root/.cache/go-build \ go mod download # Copy the go source -COPY pkg/ pkg/ -COPY iri/ iri/ +COPY api/ api/ +COPY internal/ internal/ +COPY cmd/ cmd/ COPY hack/ hack/ ARG TARGETOS @@ -22,7 +23,7 @@ ARG TARGETARCH FROM builder as ceph-bucket-provider-builder RUN --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/go/pkg \ - CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/ceph-bucket-provider ./iri/bucket/cmd/bucket/main.go + CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/ceph-bucket-provider ./cmd/bucketprovider/main.go # Start from Kubernetes Debian base. @@ -34,7 +35,7 @@ RUN apt update && apt install -y libcephfs-dev librbd-dev librados-dev libc-bin # Build RUN --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/go/pkg \ - CGO_ENABLED=1 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/ceph-volume-provider ./iri/volume/cmd/volume/main.go + CGO_ENABLED=1 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/ceph-volume-provider ./cmd/volumeprovider/main.go # Use distroless as minimal base image to package the manager binary @@ -125,4 +126,4 @@ ENTRYPOINT ["/ceph-volume-provider"] FROM distroless-base as ceph-bucket-provider COPY --from=ceph-bucket-provider-builder /workspace/bin/ceph-bucket-provider /ceph-bucket-provider USER 65532:65532 -ENTRYPOINT ["/ceph-bucket-provider"] \ No newline at end of file +ENTRYPOINT ["/ceph-bucket-provider"] diff --git a/Makefile b/Makefile index 8a6ab523..4bc27f31 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ help: ## Display this help. .PHONY: manifests manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. # bucket - $(CONTROLLER_GEN) rbac:roleName=broker-role paths="./iri/bucket/..." output:rbac:artifacts:config=config/ceph-bucket-provider/ceph-provider-rbac + $(CONTROLLER_GEN) rbac:roleName=broker-role paths="./internal/bucketserver/..." output:rbac:artifacts:config=config/ceph-bucket-provider/ceph-provider-rbac .PHONY: generate generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. @@ -76,8 +76,9 @@ add-license: addlicense ## Add license headers to all go files. check-license: addlicense ## Check that every file has a license header present. find . -name '*.go' -exec $(ADDLICENSE) -check -c 'IronCore authors' {} + -lint: ## Run golangci-lint against code. - golangci-lint run ./... +.PHONY: lint +lint: golangci-lint ## Run golangci-lint on the code. + $(GOLANGCI_LINT) run ./... check: manifests generate check-license lint test @@ -96,19 +97,19 @@ clean-docs: ## Remove all local mkdocs Docker images (cleanup). .PHONY: build-volume build-volume: generate fmt vet ## Build manager binary. - CGO_ENABLED=1 GO111MODULE=on go build -ldflags="-s -w" -a -o bin/ceph-volume-provider ./iri/volume/cmd/volume/main.go + CGO_ENABLED=1 GO111MODULE=on go build -ldflags="-s -w" -a -o bin/ceph-volume-provider ./cmd/volumeprovider/main.go .PHONY: build-bucket build-bucket: generate fmt vet ## Build manager binary. - CGO_ENABLED=0 GO111MODULE=on go build -ldflags="-s -w" -a -o bin/ceph-bucket-provider ./iri/bucket/cmd/bucket/main.go + CGO_ENABLED=0 GO111MODULE=on go build -ldflags="-s -w" -a -o bin/ceph-bucket-provider ./cmd/bucketprovider/main.go .PHONY: run-volume run-volume: manifests generate fmt vet ## Run a controller from your host. - go run ./iri/bucket/cmd/volume/main.go + go run ./cmd/volumeprovider/main.go .PHONY: run-bucket run-bucket: manifests generate fmt vet ## Run a controller from your host. - go run ./iri/bucket/cmd/bucket/main.go + go run ./cmd/bucketprovider/main.go .PHONY: docker-build docker-build: test ## Build docker image with the manager. @@ -139,11 +140,13 @@ KUSTOMIZE ?= $(LOCALBIN)/kustomize CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest ADDLICENSE ?= $(LOCALBIN)/addlicense +GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint ## Tool Versions KUSTOMIZE_VERSION ?= v3.8.7 -CONTROLLER_TOOLS_VERSION ?= v0.13.0 +CONTROLLER_TOOLS_VERSION ?= v0.14.0 ADDLICENSE_VERSION ?= v1.1.1 +GOLANGCI_LINT_VERSION ?= v1.57.0 KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" .PHONY: kustomize @@ -165,3 +168,8 @@ $(ENVTEST): $(LOCALBIN) addlicense: $(ADDLICENSE) ## Download addlicense locally if necessary. $(ADDLICENSE): $(LOCALBIN) test -s $(LOCALBIN)/addlicense || GOBIN=$(LOCALBIN) go install github.com/google/addlicense@$(ADDLICENSE_VERSION) + +.PHONY: golangci-lint +golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. +$(GOLANGCI_LINT): $(LOCALBIN) + test -s $(LOCALBIN)/golangci-lint || GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) diff --git a/pkg/api/api.go b/api/api.go similarity index 100% rename from pkg/api/api.go rename to api/api.go diff --git a/iri/volume/apiutils/constants.go b/api/constants.go similarity index 88% rename from iri/volume/apiutils/constants.go rename to api/constants.go index b4ab7392..40f7971b 100644 --- a/iri/volume/apiutils/constants.go +++ b/api/constants.go @@ -1,12 +1,13 @@ // SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package apiutils +package api const ( LabelsAnnotation = "ceph-provider.ironcore.dev/labels" AnnotationsAnnotation = "ceph-provider.ironcore.dev/annotations" - ManagerLabel = "ceph-provider.ironcore.dev/manager" ClassLabel = "ceph-provider.ironcore.dev/class" + ManagerLabel = "ceph-provider.ironcore.dev/manager" + BucketManager = "ceph-bucket-provider" VolumeManager = "ceph-volume-provider" ) diff --git a/pkg/api/image.go b/api/image.go similarity index 100% rename from pkg/api/image.go rename to api/image.go diff --git a/pkg/api/snapshot.go b/api/snapshot.go similarity index 100% rename from pkg/api/snapshot.go rename to api/snapshot.go diff --git a/iri/bucket/apiutils/apiutils.go b/api/utils.go similarity index 53% rename from iri/bucket/apiutils/apiutils.go rename to api/utils.go index f31bc6a2..9a0d61ac 100644 --- a/iri/bucket/apiutils/apiutils.go +++ b/api/utils.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package apiutils +package api import ( "encoding/json" @@ -112,3 +112,104 @@ func IsManagedBy(o metav1.Object, manager string) bool { actual, ok := o.GetLabels()[ManagerLabel] return ok && actual == manager } + +func GetObjectMetadataFromObjectID(o Metadata) (*irimeta.ObjectMetadata, error) { + annotations, err := GetAnnotationsAnnotationForMetadata(o) + if err != nil { + return nil, err + } + + labels, err := GetLabelsAnnotationForMetadata(o) + if err != nil { + return nil, err + } + + var deletedAt int64 + if o.DeletedAt != nil && !o.DeletedAt.IsZero() { + deletedAt = o.DeletedAt.UnixNano() + } + + return &irimeta.ObjectMetadata{ + Id: o.ID, + Annotations: annotations, + Labels: labels, + Generation: o.GetGeneration(), + CreatedAt: o.CreatedAt.UnixNano(), + DeletedAt: deletedAt, + }, nil +} + +func GetAnnotationsAnnotationForMetadata(o Metadata) (map[string]string, error) { + data, ok := o.GetAnnotations()[AnnotationsAnnotation] + if !ok { + return nil, fmt.Errorf("object has no annotations at %s", AnnotationsAnnotation) + } + + var annotations map[string]string + if err := json.Unmarshal([]byte(data), &annotations); err != nil { + return nil, err + } + + return annotations, nil +} + +func GetLabelsAnnotationForMetadata(o Metadata) (map[string]string, error) { + data, ok := o.GetAnnotations()[LabelsAnnotation] + if !ok { + return nil, fmt.Errorf("object has no labels at %s", LabelsAnnotation) + } + + var labels map[string]string + if err := json.Unmarshal([]byte(data), &labels); err != nil { + return nil, err + } + + return labels, nil +} + +func GetClassLabelFromObject(o Object) (string, bool) { + class, found := o.GetLabels()[ClassLabel] + return class, found +} + +func SetObjectMetadataFromMetadata(o Object, metadata *irimeta.ObjectMetadata) error { + if err := SetAnnotationsAnnotationForObject(o, metadata.Annotations); err != nil { + return err + } + if err := SetLabelsAnnotationForOject(o, metadata.Labels); err != nil { + return err + } + return nil +} + +func SetLabelsAnnotationForOject(o Object, labels map[string]string) error { + data, err := json.Marshal(labels) + if err != nil { + return fmt.Errorf("error marshalling labels: %w", err) + } + metautils.SetAnnotation(o, LabelsAnnotation, string(data)) + return nil +} + +func SetAnnotationsAnnotationForObject(o Object, annotations map[string]string) error { + data, err := json.Marshal(annotations) + if err != nil { + return fmt.Errorf("error marshalling annotations: %w", err) + } + metautils.SetAnnotation(o, AnnotationsAnnotation, string(data)) + + return nil +} + +func SetClassLabelForObject(o Object, class string) { + metautils.SetLabel(o, ClassLabel, class) +} + +func IsObjectManagedBy(o Object, manager string) bool { + actual, ok := o.GetLabels()[ManagerLabel] + return ok && actual == manager +} + +func SetManagerLabel(o Object, manager string) { + metautils.SetLabel(o, ManagerLabel, manager) +} diff --git a/iri/bucket/cmd/bucket/app/app.go b/cmd/bucketprovider/app/app.go similarity index 93% rename from iri/bucket/cmd/bucket/app/app.go rename to cmd/bucketprovider/app/app.go index 84e99893..ffaec878 100644 --- a/iri/bucket/cmd/bucket/app/app.go +++ b/cmd/bucketprovider/app/app.go @@ -9,18 +9,16 @@ import ( "fmt" "net" + "github.com/ironcore-dev/ceph-provider/internal/bcr" + "github.com/ironcore-dev/ceph-provider/internal/bucketserver" + "github.com/ironcore-dev/controller-utils/configutils" + "github.com/ironcore-dev/ironcore/broker/common" + iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1" "github.com/spf13/cobra" "github.com/spf13/pflag" "google.golang.org/grpc" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/log/zap" - - "github.com/ironcore-dev/ceph-provider/pkg/bcr" - - "github.com/ironcore-dev/ceph-provider/iri/bucket/server" - "github.com/ironcore-dev/controller-utils/configutils" - "github.com/ironcore-dev/ironcore/broker/common" - iri "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1" ) type Options struct { @@ -99,7 +97,7 @@ func Run(ctx context.Context, opts Options) error { return fmt.Errorf("failed to initialize bucket class registry: %w", err) } - srv, err := server.New(cfg, classRegistry, server.Options{ + srv, err := bucketserver.New(cfg, classRegistry, bucketserver.Options{ Namespace: opts.Namespace, BucketPoolStorageClassName: opts.BucketPoolStorageClassName, BucketClassSelector: opts.BucketClassSelector, @@ -137,7 +135,7 @@ func Run(ctx context.Context, opts Options) error { return resp, err }), ) - iri.RegisterBucketRuntimeServer(grpcSrv, srv) + iriv1alpha1.RegisterBucketRuntimeServer(grpcSrv, srv) setupLog.Info("Starting server", "Address", l.Addr().String()) go func() { diff --git a/iri/volume/cmd/volume/main.go b/cmd/bucketprovider/main.go similarity index 84% rename from iri/volume/cmd/volume/main.go rename to cmd/bucketprovider/main.go index 140e920f..1fec5338 100644 --- a/iri/volume/cmd/volume/main.go +++ b/cmd/bucketprovider/main.go @@ -7,7 +7,7 @@ import ( "fmt" "os" - "github.com/ironcore-dev/ceph-provider/iri/volume/cmd/volume/app" + "github.com/ironcore-dev/ceph-provider/cmd/bucketprovider/app" ctrl "sigs.k8s.io/controller-runtime" ) diff --git a/iri/volume/cmd/volume/app/app.go b/cmd/volumeprovider/app/app.go similarity index 90% rename from iri/volume/cmd/volume/app/app.go rename to cmd/volumeprovider/app/app.go index 5226221e..6235bf8c 100644 --- a/iri/volume/cmd/volume/app/app.go +++ b/cmd/volumeprovider/app/app.go @@ -12,18 +12,18 @@ import ( "sync" "time" - "github.com/ironcore-dev/ceph-provider/iri/volume/server" - "github.com/ironcore-dev/ceph-provider/pkg/api" - "github.com/ironcore-dev/ceph-provider/pkg/ceph" - "github.com/ironcore-dev/ceph-provider/pkg/controllers" - "github.com/ironcore-dev/ceph-provider/pkg/encryption" - "github.com/ironcore-dev/ceph-provider/pkg/event" - "github.com/ironcore-dev/ceph-provider/pkg/omap" - "github.com/ironcore-dev/ceph-provider/pkg/utils" - "github.com/ironcore-dev/ceph-provider/pkg/vcr" + providerapi "github.com/ironcore-dev/ceph-provider/api" + "github.com/ironcore-dev/ceph-provider/internal/ceph" + "github.com/ironcore-dev/ceph-provider/internal/controllers" + "github.com/ironcore-dev/ceph-provider/internal/encryption" + "github.com/ironcore-dev/ceph-provider/internal/event" + "github.com/ironcore-dev/ceph-provider/internal/omap" + "github.com/ironcore-dev/ceph-provider/internal/snapshotstrategy" + "github.com/ironcore-dev/ceph-provider/internal/vcr" + "github.com/ironcore-dev/ceph-provider/internal/volumeserver" "github.com/ironcore-dev/ironcore-image/oci/remote" "github.com/ironcore-dev/ironcore/broker/common" - iri "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" + iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" "github.com/spf13/cobra" "github.com/spf13/pflag" "google.golang.org/grpc" @@ -192,16 +192,16 @@ func Run(ctx context.Context, opts Options) error { } setupLog.Info("Configuring image store", "OmapName", omap.OmapNameVolumes) - imageStore, err := omap.New(conn, opts.Ceph.Pool, omap.Options[*api.Image]{ + imageStore, err := omap.New(conn, opts.Ceph.Pool, omap.Options[*providerapi.Image]{ OmapName: omap.OmapNameVolumes, - NewFunc: func() *api.Image { return &api.Image{} }, - CreateStrategy: utils.ImageStrategy, + NewFunc: func() *providerapi.Image { return &providerapi.Image{} }, + CreateStrategy: snapshotstrategy.ImageStrategy, }) if err != nil { return fmt.Errorf("failed to initialize image store: %w", err) } - imageEvents, err := event.NewListWatchSource[*api.Image]( + imageEvents, err := event.NewListWatchSource[*providerapi.Image]( imageStore.List, imageStore.Watch, event.ListWatchSourceOptions{}, @@ -211,16 +211,16 @@ func Run(ctx context.Context, opts Options) error { } setupLog.Info("Configuring snapshot store", "OmapName", omap.OmapNameOsImages) - snapshotStore, err := omap.New(conn, opts.Ceph.Pool, omap.Options[*api.Snapshot]{ + snapshotStore, err := omap.New(conn, opts.Ceph.Pool, omap.Options[*providerapi.Snapshot]{ OmapName: omap.OmapNameOsImages, - NewFunc: func() *api.Snapshot { return &api.Snapshot{} }, - CreateStrategy: utils.SnapshotStrategy, + NewFunc: func() *providerapi.Snapshot { return &providerapi.Snapshot{} }, + CreateStrategy: snapshotstrategy.SnapshotStrategy, }) if err != nil { return fmt.Errorf("failed to initialize snapshot store: %w", err) } - snapshotEvents, err := event.NewListWatchSource[*api.Snapshot]( + snapshotEvents, err := event.NewListWatchSource[*providerapi.Snapshot]( snapshotStore.List, snapshotStore.Watch, event.ListWatchSourceOptions{}, @@ -319,13 +319,13 @@ func Run(ctx context.Context, opts Options) error { return fmt.Errorf("failed to initialize ceph command client: %w", err) } - srv, err := server.New( + srv, err := volumeserver.New( imageStore, snapshotStore, classRegistry, encryptor, cephCommandClient, - server.Options{ + volumeserver.Options{ BurstFactor: opts.Ceph.BurstFactor, BurstDurationInSeconds: opts.Ceph.BurstDurationInSeconds, }, @@ -362,7 +362,7 @@ func Run(ctx context.Context, opts Options) error { return resp, err }), ) - iri.RegisterVolumeRuntimeServer(grpcSrv, srv) + iriv1alpha1.RegisterVolumeRuntimeServer(grpcSrv, srv) setupLog.Info("Starting server", "Address", l.Addr().String()) go func() { diff --git a/iri/bucket/cmd/bucket/main.go b/cmd/volumeprovider/main.go similarity index 84% rename from iri/bucket/cmd/bucket/main.go rename to cmd/volumeprovider/main.go index 59ac2453..385d2e79 100644 --- a/iri/bucket/cmd/bucket/main.go +++ b/cmd/volumeprovider/main.go @@ -7,7 +7,7 @@ import ( "fmt" "os" - "github.com/ironcore-dev/ceph-provider/iri/bucket/cmd/bucket/app" + "github.com/ironcore-dev/ceph-provider/cmd/volumeprovider/app" ctrl "sigs.k8s.io/controller-runtime" ) diff --git a/docs/development/setup.md b/docs/development/setup.md index 9bef5475..c7b2fb1b 100644 --- a/docs/development/setup.md +++ b/docs/development/setup.md @@ -102,7 +102,7 @@ The required `ceph-provider` flags needs to be defined in order to connect to ce The following command starts a `ceph-volume-provider` and connects to a local `ceph` cluster. ```shell -go run ./iri/volume/cmd/volume/main.go \ +go run ./cmd/volumeprovider/main.go \ --address=./iri-volume.sock --supported-volume-classes=./classes.json --zap-log-level=2 @@ -140,7 +140,7 @@ The required `ceph-provider` flags needs to be defined in order to work with roo The following command starts a `ceph-bucket-provider`. The flag `bucket-pool-storage-class-name` defines the `StorageClass` and hereby implicit the `CephBlockPool` (see rook [docs](https://rook.io/docs/rook/v1.11/Storage-Configuration/Object-Storage-RGW/object-storage/)). ```shell -go run ./iri/bucket/cmd/bucket/main.go \ +go run ./cmd/bucketprovider/main.go \ --address=./iri-bucket.sock --bucket-pool-storage-class-name=rook-ceph-bucket ``` @@ -205,4 +205,4 @@ ID Class ```shell irictl-volume --address=unix:./iri-volume.sock delete volume 796264618065bb31024ec509d4ed8a87ed098ee8e89b370c06b0522ba4bf1e2 Volume 796264618065bb31024ec509d4ed8a87ed098ee8e89b370c06b0522ba4bf1e2 deleted -``` \ No newline at end of file +``` diff --git a/go.mod b/go.mod index d8abde10..c3d3ddf9 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/ironcore-dev/ceph-provider -go 1.21 +go 1.22 require ( github.com/ceph/go-ceph v0.26.0 diff --git a/pkg/bcr/registry.go b/internal/bcr/registry.go similarity index 100% rename from pkg/bcr/registry.go rename to internal/bcr/registry.go diff --git a/iri/bucket/server/bucket.go b/internal/bucketserver/bucket.go similarity index 94% rename from iri/bucket/server/bucket.go rename to internal/bucketserver/bucket.go index 37976f31..8bf6aba2 100644 --- a/iri/bucket/server/bucket.go +++ b/internal/bucketserver/bucket.go @@ -1,13 +1,13 @@ // SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server +package bucketserver import ( "context" "fmt" - "github.com/ironcore-dev/ceph-provider/iri/bucket/apiutils" + "github.com/ironcore-dev/ceph-provider/api" iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1" objectbucketv1alpha1 "github.com/kube-object-storage/lib-bucket-provisioner/pkg/apis/objectbucket.io/v1alpha1" "google.golang.org/grpc/codes" @@ -27,7 +27,7 @@ func (s *Server) convertBucketClaimAndAccessSecretToBucket( bucketClaim *objectbucketv1alpha1.ObjectBucketClaim, accessSecret *corev1.Secret, ) (*iriv1alpha1.Bucket, error) { - metadata, err := apiutils.GetObjectMetadata(bucketClaim) + metadata, err := api.GetObjectMetadata(bucketClaim) if err != nil { return nil, fmt.Errorf("failed to get bucket claim object metadata: %w", err) } @@ -37,7 +37,7 @@ func (s *Server) convertBucketClaimAndAccessSecretToBucket( return nil, fmt.Errorf("failed to convert bucket claim state to bucket state: %w", err) } - class, ok := apiutils.GetClassLabel(bucketClaim) + class, ok := api.GetClassLabel(bucketClaim) if !ok { return nil, fmt.Errorf("failed to get bucket class") } diff --git a/iri/bucket/server/bucket_create.go b/internal/bucketserver/bucket_create.go similarity index 89% rename from iri/bucket/server/bucket_create.go rename to internal/bucketserver/bucket_create.go index a2609d7b..142c3d72 100644 --- a/iri/bucket/server/bucket_create.go +++ b/internal/bucketserver/bucket_create.go @@ -1,14 +1,14 @@ // SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server +package bucketserver import ( "context" "fmt" "github.com/go-logr/logr" - "github.com/ironcore-dev/ceph-provider/iri/bucket/apiutils" + "github.com/ironcore-dev/ceph-provider/api" iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1" objectbucketv1alpha1 "github.com/kube-object-storage/lib-bucket-provisioner/pkg/apis/objectbucket.io/v1alpha1" corev1 "k8s.io/api/core/v1" @@ -36,11 +36,11 @@ func (s *Server) createBucketClaimAndAccessSecretFromBucket( }, } - if err := apiutils.SetObjectMetadata(bucketClaim, bucket.Metadata); err != nil { + if err := api.SetObjectMetadata(bucketClaim, bucket.Metadata); err != nil { return nil, nil, err } - apiutils.SetClassLabel(bucketClaim, bucket.Spec.Class) - apiutils.SetBucketManagerLabel(bucketClaim, apiutils.BucketManager) + api.SetClassLabel(bucketClaim, bucket.Spec.Class) + api.SetBucketManagerLabel(bucketClaim, api.BucketManager) log.V(2).Info("Creating bucket claim") if err := s.client.Create(ctx, bucketClaim); err != nil { diff --git a/iri/bucket/server/bucket_create_test.go b/internal/bucketserver/bucket_create_test.go similarity index 99% rename from iri/bucket/server/bucket_create_test.go rename to internal/bucketserver/bucket_create_test.go index 528c24f1..6c380ed5 100644 --- a/iri/bucket/server/bucket_create_test.go +++ b/internal/bucketserver/bucket_create_test.go @@ -1,11 +1,13 @@ // SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server_test +package bucketserver_test import ( "fmt" + iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1" + irimetav1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1" objectbucketv1alpha1 "github.com/kube-object-storage/lib-bucket-provisioner/pkg/apis/objectbucket.io/v1alpha1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -13,9 +15,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" . "sigs.k8s.io/controller-runtime/pkg/envtest/komega" - - iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1" - irimetav1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1" ) var _ = Describe("CreateBucket test", func() { diff --git a/iri/bucket/server/bucket_delete.go b/internal/bucketserver/bucket_delete.go similarity index 97% rename from iri/bucket/server/bucket_delete.go rename to internal/bucketserver/bucket_delete.go index b742a553..987d3f2f 100644 --- a/iri/bucket/server/bucket_delete.go +++ b/internal/bucketserver/bucket_delete.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server +package bucketserver import ( "context" diff --git a/iri/bucket/server/bucket_delete_test.go b/internal/bucketserver/bucket_delete_test.go similarity index 99% rename from iri/bucket/server/bucket_delete_test.go rename to internal/bucketserver/bucket_delete_test.go index 6c3af04a..9870bb67 100644 --- a/iri/bucket/server/bucket_delete_test.go +++ b/internal/bucketserver/bucket_delete_test.go @@ -1,11 +1,13 @@ // SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server_test +package bucketserver_test import ( "fmt" + iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1" + irimetav1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1" objectbucketv1alpha1 "github.com/kube-object-storage/lib-bucket-provisioner/pkg/apis/objectbucket.io/v1alpha1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -14,9 +16,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" . "sigs.k8s.io/controller-runtime/pkg/envtest/komega" - - iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1" - irimetav1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1" ) var _ = Describe("DeleteBucket test", func() { diff --git a/iri/bucket/server/bucket_list.go b/internal/bucketserver/bucket_list.go similarity index 97% rename from iri/bucket/server/bucket_list.go rename to internal/bucketserver/bucket_list.go index 6b60f5b0..094af129 100644 --- a/iri/bucket/server/bucket_list.go +++ b/internal/bucketserver/bucket_list.go @@ -1,13 +1,13 @@ // SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server +package bucketserver import ( "context" "fmt" - "github.com/ironcore-dev/ceph-provider/iri/bucket/apiutils" + "github.com/ironcore-dev/ceph-provider/api" "github.com/ironcore-dev/ironcore/broker/common" iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1" objectbucketv1alpha1 "github.com/kube-object-storage/lib-bucket-provisioner/pkg/apis/objectbucket.io/v1alpha1" @@ -23,7 +23,7 @@ func (s *Server) listManagedAndCreated(ctx context.Context, list client.ObjectLi return s.client.List(ctx, list, client.InNamespace(s.namespace), client.MatchingLabels{ - apiutils.ManagerLabel: apiutils.BucketManager, + api.ManagerLabel: api.BucketManager, }, ) } diff --git a/iri/bucket/server/bucket_list_test.go b/internal/bucketserver/bucket_list_test.go similarity index 99% rename from iri/bucket/server/bucket_list_test.go rename to internal/bucketserver/bucket_list_test.go index 97449188..02ae1d5d 100644 --- a/iri/bucket/server/bucket_list_test.go +++ b/internal/bucketserver/bucket_list_test.go @@ -1,21 +1,20 @@ // SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server_test +package bucketserver_test import ( "fmt" + iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1" + irimetav1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1" objectbucketv1alpha1 "github.com/kube-object-storage/lib-bucket-provisioner/pkg/apis/objectbucket.io/v1alpha1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" - . "sigs.k8s.io/controller-runtime/pkg/envtest/komega" - - iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1" - irimetav1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + . "sigs.k8s.io/controller-runtime/pkg/envtest/komega" ) var _ = Describe("ListBucket test", func() { diff --git a/iri/bucket/server/bucketclass_list.go b/internal/bucketserver/bucketclass_list.go similarity index 96% rename from iri/bucket/server/bucketclass_list.go rename to internal/bucketserver/bucketclass_list.go index 296cc1ba..8f8dd9be 100644 --- a/iri/bucket/server/bucketclass_list.go +++ b/internal/bucketserver/bucketclass_list.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server +package bucketserver import ( "context" diff --git a/iri/bucket/server/bucketclass_list_test.go b/internal/bucketserver/bucketclass_list_test.go similarity index 97% rename from iri/bucket/server/bucketclass_list_test.go rename to internal/bucketserver/bucketclass_list_test.go index 2c993013..81bfdeed 100644 --- a/iri/bucket/server/bucketclass_list_test.go +++ b/internal/bucketserver/bucketclass_list_test.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server_test +package bucketserver_test import ( . "github.com/onsi/ginkgo/v2" diff --git a/iri/bucket/server/server.go b/internal/bucketserver/server.go similarity index 96% rename from iri/bucket/server/server.go rename to internal/bucketserver/server.go index 7dea1f47..3c506970 100644 --- a/iri/bucket/server/server.go +++ b/internal/bucketserver/server.go @@ -1,13 +1,16 @@ // SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server +package bucketserver import ( "context" "fmt" "github.com/go-logr/logr" + "github.com/ironcore-dev/ceph-provider/api" + "github.com/ironcore-dev/ironcore/broker/common/idgen" + iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1" objectbucketv1alpha1 "github.com/kube-object-storage/lib-bucket-provisioner/pkg/apis/objectbucket.io/v1alpha1" rookv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" corev1 "k8s.io/api/core/v1" @@ -20,10 +23,6 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/apiutil" - - "github.com/ironcore-dev/ceph-provider/iri/bucket/apiutils" - "github.com/ironcore-dev/ironcore/broker/common/idgen" - iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1" ) var scheme = runtime.NewScheme() @@ -109,7 +108,7 @@ func (s *Server) getManagedAndCreated(ctx context.Context, name string, obj clie if err := s.client.Get(ctx, key, obj); err != nil { return err } - if !apiutils.IsManagedBy(obj, apiutils.BucketManager) { + if !api.IsManagedBy(obj, api.BucketManager) { gvk, err := apiutil.GVKForObject(obj, s.client.Scheme()) if err != nil { return err diff --git a/iri/bucket/server/suite_test.go b/internal/bucketserver/suite_test.go similarity index 98% rename from iri/bucket/server/suite_test.go rename to internal/bucketserver/suite_test.go index 4e8422c4..655e081c 100644 --- a/iri/bucket/server/suite_test.go +++ b/internal/bucketserver/suite_test.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server_test +package bucketserver_test import ( "context" @@ -12,6 +12,10 @@ import ( "testing" "time" + "github.com/ironcore-dev/ceph-provider/cmd/bucketprovider/app" + "github.com/ironcore-dev/controller-utils/modutils" + iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1" + "github.com/ironcore-dev/ironcore/iri/remote/bucket" bucketv1alpha1 "github.com/kube-object-storage/lib-bucket-provisioner/pkg/apis/objectbucket.io/v1alpha1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -26,11 +30,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/envtest" "sigs.k8s.io/controller-runtime/pkg/envtest/komega" logf "sigs.k8s.io/controller-runtime/pkg/log" - - "github.com/ironcore-dev/ceph-provider/iri/bucket/cmd/bucket/app" - "github.com/ironcore-dev/controller-utils/modutils" - iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/bucket/v1alpha1" - "github.com/ironcore-dev/ironcore/iri/remote/bucket" //+kubebuilder:scaffold:imports ) diff --git a/pkg/ceph/auth.go b/internal/ceph/auth.go similarity index 100% rename from pkg/ceph/auth.go rename to internal/ceph/auth.go diff --git a/pkg/ceph/auth_test.go b/internal/ceph/auth_test.go similarity index 100% rename from pkg/ceph/auth_test.go rename to internal/ceph/auth_test.go diff --git a/pkg/ceph/commands.go b/internal/ceph/commands.go similarity index 100% rename from pkg/ceph/commands.go rename to internal/ceph/commands.go diff --git a/pkg/ceph/test.key b/internal/ceph/test.key similarity index 100% rename from pkg/ceph/test.key rename to internal/ceph/test.key diff --git a/pkg/controllers/common.go b/internal/controllers/common.go similarity index 100% rename from pkg/controllers/common.go rename to internal/controllers/common.go diff --git a/pkg/controllers/image_controller.go b/internal/controllers/image_controller.go similarity index 87% rename from pkg/controllers/image_controller.go rename to internal/controllers/image_controller.go index b7f66e4c..b57d67c7 100644 --- a/pkg/controllers/image_controller.go +++ b/internal/controllers/image_controller.go @@ -16,12 +16,12 @@ import ( librbd "github.com/ceph/go-ceph/rbd" "github.com/containerd/containerd/reference" "github.com/go-logr/logr" - "github.com/ironcore-dev/ceph-provider/pkg/api" - "github.com/ironcore-dev/ceph-provider/pkg/encryption" - "github.com/ironcore-dev/ceph-provider/pkg/event" - "github.com/ironcore-dev/ceph-provider/pkg/round" - "github.com/ironcore-dev/ceph-provider/pkg/store" - "github.com/ironcore-dev/ceph-provider/pkg/utils" + providerapi "github.com/ironcore-dev/ceph-provider/api" + "github.com/ironcore-dev/ceph-provider/internal/encryption" + "github.com/ironcore-dev/ceph-provider/internal/event" + "github.com/ironcore-dev/ceph-provider/internal/round" + "github.com/ironcore-dev/ceph-provider/internal/store" + "github.com/ironcore-dev/ceph-provider/internal/utils" "github.com/ironcore-dev/ironcore-image/oci/image" "golang.org/x/exp/slices" "k8s.io/client-go/util/workqueue" @@ -44,10 +44,10 @@ func NewImageReconciler( log logr.Logger, conn *rados.Conn, registry image.Source, - images store.Store[*api.Image], - snapshots store.Store[*api.Snapshot], - imageEvents event.Source[*api.Image], - snapshotEvents event.Source[*api.Snapshot], + images store.Store[*providerapi.Image], + snapshots store.Store[*providerapi.Snapshot], + imageEvents event.Source[*providerapi.Image], + snapshotEvents event.Source[*providerapi.Snapshot], keyEncryption encryption.Encryptor, opts ImageReconcilerOptions, ) (*ImageReconciler, error) { @@ -114,11 +114,11 @@ type ImageReconciler struct { registry image.Source queue workqueue.RateLimitingInterface - images store.Store[*api.Image] - snapshots store.Store[*api.Snapshot] + images store.Store[*providerapi.Image] + snapshots store.Store[*providerapi.Snapshot] - imageEvents event.Source[*api.Image] - snapshotEvents event.Source[*api.Snapshot] + imageEvents event.Source[*providerapi.Image] + snapshotEvents event.Source[*providerapi.Snapshot] monitors string client string @@ -133,7 +133,7 @@ func (r *ImageReconciler) Start(ctx context.Context) error { //todo make configurable workerSize := 15 - imgEventReg, err := r.imageEvents.AddHandler(event.HandlerFunc[*api.Image](func(evt event.Event[*api.Image]) { + imgEventReg, err := r.imageEvents.AddHandler(event.HandlerFunc[*providerapi.Image](func(evt event.Event[*providerapi.Image]) { r.queue.Add(evt.Object.ID) })) if err != nil { @@ -143,8 +143,8 @@ func (r *ImageReconciler) Start(ctx context.Context) error { _ = r.imageEvents.RemoveHandler(imgEventReg) }() - snapEventReg, err := r.snapshotEvents.AddHandler(event.HandlerFunc[*api.Snapshot](func(evt event.Event[*api.Snapshot]) { - if evt.Type != event.TypeUpdated || evt.Object.Status.State != api.SnapshotStatePopulated { + snapEventReg, err := r.snapshotEvents.AddHandler(event.HandlerFunc[*providerapi.Snapshot](func(evt event.Event[*providerapi.Snapshot]) { + if evt.Type != event.TypeUpdated || evt.Object.Status.State != providerapi.SnapshotStatePopulated { return } @@ -211,7 +211,7 @@ const ( ImageFinalizer = "image" ) -func (r *ImageReconciler) deleteImage(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, image *api.Image) error { +func (r *ImageReconciler) deleteImage(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, image *providerapi.Image) error { if !slices.Contains(image.Finalizers, ImageFinalizer) { log.V(1).Info("image has no finalizer: done") return nil @@ -259,7 +259,7 @@ func (r *ImageReconciler) fetchAuth(ctx context.Context, log logr.Logger) (strin return strings.TrimPrefix(r.client, "client."), response.Key, nil } -func (r *ImageReconciler) reconcileSnapshot(ctx context.Context, log logr.Logger, img *api.Image) error { +func (r *ImageReconciler) reconcileSnapshot(ctx context.Context, log logr.Logger, img *providerapi.Image) error { if !(img.Spec.Image != "" && img.Spec.SnapshotRef == nil) { return nil } @@ -282,14 +282,14 @@ func (r *ImageReconciler) reconcileSnapshot(ctx context.Context, log logr.Logger if err != nil { switch { case errors.Is(err, store.ErrNotFound): - snap, err = r.snapshots.Create(ctx, &api.Snapshot{ - Metadata: api.Metadata{ + snap, err = r.snapshots.Create(ctx, &providerapi.Snapshot{ + Metadata: providerapi.Metadata{ ID: snapshotDigest, Labels: map[string]string{ imageDigestLabel: snapshotDigest, }, }, - Source: api.SnapshotSource{ + Source: providerapi.SnapshotSource{ IronCoreImage: resolvedImageName, }, }) @@ -310,7 +310,7 @@ func (r *ImageReconciler) reconcileSnapshot(ctx context.Context, log logr.Logger return nil } -func (r *ImageReconciler) isImageExisting(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, image *api.Image) (bool, error) { +func (r *ImageReconciler) isImageExisting(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, image *providerapi.Image) (bool, error) { images, err := librbd.GetImageNames(ioCtx) if err != nil { return false, fmt.Errorf("failed to list images: %w", err) @@ -325,7 +325,7 @@ func (r *ImageReconciler) isImageExisting(ctx context.Context, log logr.Logger, return false, nil } -func (r *ImageReconciler) updateImage(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, image *api.Image) (err error) { +func (r *ImageReconciler) updateImage(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, image *providerapi.Image) (err error) { log.V(2).Info("Updating image") img, err := librbd.OpenImage(ioCtx, ImageIDToRBDID(image.ID), librbd.NoSnapshot) if err != nil { @@ -403,7 +403,7 @@ func (r *ImageReconciler) reconcileImage(ctx context.Context, id string) error { log.V(1).Info("Checked image existence", "imageExists", imageExists) if imageExists { - if img.Status.State == api.ImageStateAvailable { + if img.Status.State == providerapi.ImageStateAvailable { if err := r.updateImage(ctx, log, ioCtx, img); err != nil { return fmt.Errorf("failed to update image: %w", err) } @@ -454,13 +454,13 @@ func (r *ImageReconciler) reconcileImage(ctx context.Context, id string) error { return fmt.Errorf("failed to fetch credentials: %w", err) } - img.Status.Access = &api.ImageAccess{ + img.Status.Access = &providerapi.ImageAccess{ Monitors: r.monitors, Handle: fmt.Sprintf("%s/%s", r.pool, ImageIDToRBDID(img.ID)), User: user, UserKey: key, } - img.Status.State = api.ImageStateAvailable + img.Status.State = providerapi.ImageStateAvailable if _, err = r.images.Update(ctx, img); err != nil { return fmt.Errorf("failed to update image metadate: %w", err) } @@ -470,7 +470,7 @@ func (r *ImageReconciler) reconcileImage(ctx context.Context, id string) error { return nil } -func (r *ImageReconciler) setImageLimits(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, image *api.Image) error { +func (r *ImageReconciler) setImageLimits(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, image *providerapi.Image) error { if len(image.Spec.Limits) <= 0 { return nil } @@ -498,7 +498,7 @@ func (r *ImageReconciler) setImageLimits(ctx context.Context, log logr.Logger, i return nil } -func (r *ImageReconciler) setWWN(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, image *api.Image) error { +func (r *ImageReconciler) setWWN(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, image *providerapi.Image) error { log.V(1).Info("Setting WWN") img, err := librbd.OpenImage(ioCtx, ImageIDToRBDID(image.ID), librbd.NoSnapshot) if err != nil { @@ -520,8 +520,8 @@ func (r *ImageReconciler) setWWN(ctx context.Context, log logr.Logger, ioCtx *ra return nil } -func (r *ImageReconciler) setEncryptionHeader(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, image *api.Image) error { - if image.Spec.Encryption.Type == "" || image.Spec.Encryption.Type == api.EncryptionTypeUnencrypted || image.Status.Encryption == api.EncryptionStateHeaderSet { +func (r *ImageReconciler) setEncryptionHeader(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, image *providerapi.Image) error { + if image.Spec.Encryption.Type == "" || image.Spec.Encryption.Type == providerapi.EncryptionTypeUnencrypted || image.Status.Encryption == providerapi.EncryptionStateHeaderSet { return nil } @@ -550,7 +550,7 @@ func (r *ImageReconciler) setEncryptionHeader(ctx context.Context, log logr.Logg return fmt.Errorf("failed to close rbd image: %w", err) } - image.Status.Encryption = api.EncryptionStateHeaderSet + image.Status.Encryption = providerapi.EncryptionStateHeaderSet if _, err = r.images.Update(ctx, image); err != nil { return fmt.Errorf("failed to update image encryption state: %w", err) } @@ -558,7 +558,7 @@ func (r *ImageReconciler) setEncryptionHeader(ctx context.Context, log logr.Logg return nil } -func (r *ImageReconciler) createEmptyImage(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, image *api.Image, options *librbd.ImageOptions) error { +func (r *ImageReconciler) createEmptyImage(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, image *providerapi.Image, options *librbd.ImageOptions) error { if err := librbd.CreateImage(ioCtx, ImageIDToRBDID(image.ID), round.OffBytes(image.Spec.Size), options); err != nil { return fmt.Errorf("failed to create rbd image: %w", err) } @@ -567,7 +567,7 @@ func (r *ImageReconciler) createEmptyImage(ctx context.Context, log logr.Logger, return nil } -func (r *ImageReconciler) createImageFromSnapshot(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, image *api.Image, snapshotRef string, options *librbd.ImageOptions) (bool, error) { +func (r *ImageReconciler) createImageFromSnapshot(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, image *providerapi.Image, snapshotRef string, options *librbd.ImageOptions) (bool, error) { snapshot, err := r.snapshots.Get(ctx, snapshotRef) if err != nil { if !errors.Is(err, store.ErrNotFound) { @@ -579,7 +579,7 @@ func (r *ImageReconciler) createImageFromSnapshot(ctx context.Context, log logr. return false, nil } - if snapshot.Status.State != api.SnapshotStatePopulated { + if snapshot.Status.State != providerapi.SnapshotStatePopulated { log.V(1).Info("snapshot is not populated", "state", snapshot.Status.State) return false, nil } diff --git a/pkg/controllers/snapshot_controller.go b/internal/controllers/snapshot_controller.go similarity index 91% rename from pkg/controllers/snapshot_controller.go rename to internal/controllers/snapshot_controller.go index 96e6c1fa..b5bebd9a 100644 --- a/pkg/controllers/snapshot_controller.go +++ b/internal/controllers/snapshot_controller.go @@ -14,11 +14,12 @@ import ( "github.com/ceph/go-ceph/rados" librbd "github.com/ceph/go-ceph/rbd" "github.com/go-logr/logr" - "github.com/ironcore-dev/ceph-provider/pkg/api" - "github.com/ironcore-dev/ceph-provider/pkg/event" - "github.com/ironcore-dev/ceph-provider/pkg/round" - "github.com/ironcore-dev/ceph-provider/pkg/store" - "github.com/ironcore-dev/ceph-provider/pkg/utils" + providerapi "github.com/ironcore-dev/ceph-provider/api" + "github.com/ironcore-dev/ceph-provider/internal/event" + "github.com/ironcore-dev/ceph-provider/internal/rater" + "github.com/ironcore-dev/ceph-provider/internal/round" + "github.com/ironcore-dev/ceph-provider/internal/store" + "github.com/ironcore-dev/ceph-provider/internal/utils" ironcoreimage "github.com/ironcore-dev/ironcore-image" "github.com/ironcore-dev/ironcore-image/oci/image" "golang.org/x/exp/slices" @@ -34,8 +35,8 @@ func NewSnapshotReconciler( log logr.Logger, conn *rados.Conn, registry image.Source, - store store.Store[*api.Snapshot], - events event.Source[*api.Snapshot], + store store.Store[*providerapi.Snapshot], + events event.Source[*providerapi.Snapshot], opts SnapshotReconcilerOptions, ) (*SnapshotReconciler, error) { if conn == nil { @@ -81,14 +82,14 @@ type SnapshotReconciler struct { registry image.Source queue workqueue.RateLimitingInterface - store store.Store[*api.Snapshot] - events event.Source[*api.Snapshot] + store store.Store[*providerapi.Snapshot] + events event.Source[*providerapi.Snapshot] pool string populatorBufferSize int64 } -func (r *SnapshotReconciler) openSnapshotSource(ctx context.Context, src api.SnapshotSource) (io.ReadCloser, uint64, string, error) { +func (r *SnapshotReconciler) openSnapshotSource(ctx context.Context, src providerapi.SnapshotSource) (io.ReadCloser, uint64, string, error) { switch { case src.IronCoreImage != "": @@ -124,7 +125,7 @@ func (r *SnapshotReconciler) Start(ctx context.Context) error { //todo make configurable workerSize := 15 - reg, err := r.events.AddHandler(event.HandlerFunc[*api.Snapshot](func(event event.Event[*api.Snapshot]) { + reg, err := r.events.AddHandler(event.HandlerFunc[*providerapi.Snapshot](func(event event.Event[*providerapi.Snapshot]) { r.queue.Add(event.Object.ID) })) if err != nil { @@ -218,7 +219,7 @@ func (r *SnapshotReconciler) cleanupSnapshotResources(log logr.Logger, img *libr return nil } -func (r *SnapshotReconciler) deleteSnapshot(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, snapshot *api.Snapshot) error { +func (r *SnapshotReconciler) deleteSnapshot(ctx context.Context, log logr.Logger, ioCtx *rados.IOContext, snapshot *providerapi.Snapshot) error { if !slices.Contains(snapshot.Finalizers, SnapshotFinalizer) { log.V(1).Info("snapshot has no finalizer: done") return nil @@ -289,7 +290,7 @@ func (r *SnapshotReconciler) reconcileSnapshot(ctx context.Context, id string) e } } - if snapshot.Status.State == api.SnapshotStatePopulated { + if snapshot.Status.State == providerapi.SnapshotStatePopulated { log.V(1).Info("Snapshot already populated") return nil } @@ -342,7 +343,7 @@ func (r *SnapshotReconciler) reconcileSnapshot(ctx context.Context, id string) e } snapshot.Status.Digest = digest - snapshot.Status.State = api.SnapshotStatePopulated + snapshot.Status.State = providerapi.SnapshotStatePopulated if _, err = r.store.Update(ctx, snapshot); err != nil { return fmt.Errorf("failed to update snapshot metadate: %w", err) @@ -370,7 +371,7 @@ func (r *SnapshotReconciler) prepareSnapshotContent(log logr.Logger, rbdImg *lib } func (r *SnapshotReconciler) populateImage(log logr.Logger, dst io.WriteCloser, src io.Reader) error { - rater := utils.NewRater(src) + rater := rater.NewRater(src) ticker := time.NewTicker(5 * time.Second) defer ticker.Stop() done := make(chan struct{}) diff --git a/pkg/encryption/encryption.go b/internal/encryption/encryption.go similarity index 100% rename from pkg/encryption/encryption.go rename to internal/encryption/encryption.go diff --git a/pkg/event/event.go b/internal/event/event.go similarity index 97% rename from pkg/event/event.go rename to internal/event/event.go index 304599c1..4c7fab1a 100644 --- a/pkg/event/event.go +++ b/internal/event/event.go @@ -10,8 +10,8 @@ import ( "time" "github.com/go-logr/logr" - "github.com/ironcore-dev/ceph-provider/pkg/api" - "github.com/ironcore-dev/ceph-provider/pkg/store" + "github.com/ironcore-dev/ceph-provider/api" + "github.com/ironcore-dev/ceph-provider/internal/store" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" ) diff --git a/pkg/limits/calc.go b/internal/limits/calc.go similarity index 95% rename from pkg/limits/calc.go rename to internal/limits/calc.go index f33d0428..09b84d83 100644 --- a/pkg/limits/calc.go +++ b/internal/limits/calc.go @@ -4,7 +4,7 @@ package limits import ( - "github.com/ironcore-dev/ceph-provider/pkg/api" + "github.com/ironcore-dev/ceph-provider/api" ) func Calculate(iops, tps int64, burstFactor, burstDurationInSeconds int64) api.Limits { diff --git a/pkg/omap/config.go b/internal/omap/config.go similarity index 100% rename from pkg/omap/config.go rename to internal/omap/config.go diff --git a/pkg/omap/omap.go b/internal/omap/omap.go similarity index 97% rename from pkg/omap/omap.go rename to internal/omap/omap.go index dd3028bc..194b6854 100644 --- a/pkg/omap/omap.go +++ b/internal/omap/omap.go @@ -12,10 +12,10 @@ import ( "time" "github.com/ceph/go-ceph/rados" - "github.com/ironcore-dev/ceph-provider/pkg/api" - "github.com/ironcore-dev/ceph-provider/pkg/store" - utilssync "github.com/ironcore-dev/ceph-provider/pkg/sync" - "github.com/ironcore-dev/ceph-provider/pkg/utils" + "github.com/ironcore-dev/ceph-provider/api" + "github.com/ironcore-dev/ceph-provider/internal/store" + utilssync "github.com/ironcore-dev/ceph-provider/internal/sync" + "github.com/ironcore-dev/ceph-provider/internal/utils" "k8s.io/apimachinery/pkg/util/sets" ) diff --git a/pkg/utils/rater.go b/internal/rater/rater.go similarity index 98% rename from pkg/utils/rater.go rename to internal/rater/rater.go index 9e7591c7..6f74853a 100644 --- a/pkg/utils/rater.go +++ b/internal/rater/rater.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package utils +package rater import ( "fmt" diff --git a/pkg/registry/registry.go b/internal/registry/registry.go similarity index 100% rename from pkg/registry/registry.go rename to internal/registry/registry.go diff --git a/pkg/rook/config.go b/internal/rook/config.go similarity index 100% rename from pkg/rook/config.go rename to internal/rook/config.go diff --git a/pkg/round/size.go b/internal/round/size.go similarity index 100% rename from pkg/round/size.go rename to internal/round/size.go diff --git a/pkg/utils/strategy.go b/internal/snapshotstrategy/strategy.go similarity index 91% rename from pkg/utils/strategy.go rename to internal/snapshotstrategy/strategy.go index 8f0950f6..571b402e 100644 --- a/pkg/utils/strategy.go +++ b/internal/snapshotstrategy/strategy.go @@ -1,12 +1,12 @@ // SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package utils +package snapshotstrategy import ( "crypto/rand" - "github.com/ironcore-dev/ceph-provider/pkg/api" + "github.com/ironcore-dev/ceph-provider/api" "github.com/ironcore-dev/ironcore/broker/common/idgen" ) diff --git a/pkg/store/store.go b/internal/store/store.go similarity index 96% rename from pkg/store/store.go rename to internal/store/store.go index 56cce6a3..e9f7fe45 100644 --- a/pkg/store/store.go +++ b/internal/store/store.go @@ -6,7 +6,7 @@ package store import ( "context" - "github.com/ironcore-dev/ceph-provider/pkg/api" + "github.com/ironcore-dev/ceph-provider/api" "github.com/pkg/errors" ) diff --git a/pkg/sync/sync.go b/internal/sync/sync.go similarity index 100% rename from pkg/sync/sync.go rename to internal/sync/sync.go diff --git a/pkg/sync/sync_suite_test.go b/internal/sync/sync_suite_test.go similarity index 100% rename from pkg/sync/sync_suite_test.go rename to internal/sync/sync_suite_test.go diff --git a/pkg/sync/sync_test.go b/internal/sync/sync_test.go similarity index 100% rename from pkg/sync/sync_test.go rename to internal/sync/sync_test.go diff --git a/pkg/utils/utils.go b/internal/utils/utils.go similarity index 100% rename from pkg/utils/utils.go rename to internal/utils/utils.go diff --git a/pkg/vcr/registry.go b/internal/vcr/registry.go similarity index 99% rename from pkg/vcr/registry.go rename to internal/vcr/registry.go index 15ffabeb..5a5f5edd 100644 --- a/pkg/vcr/registry.go +++ b/internal/vcr/registry.go @@ -8,9 +8,8 @@ import ( "io" "os" - "k8s.io/apimachinery/pkg/util/yaml" - iri "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" + "k8s.io/apimachinery/pkg/util/yaml" ) func LoadVolumeClasses(reader io.Reader) ([]iri.VolumeClass, error) { diff --git a/iri/volume/server/server.go b/internal/volumeserver/server.go similarity index 79% rename from iri/volume/server/server.go rename to internal/volumeserver/server.go index 3506d8b8..1ace74be 100644 --- a/iri/volume/server/server.go +++ b/internal/volumeserver/server.go @@ -1,16 +1,16 @@ // SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server +package volumeserver import ( "context" "github.com/go-logr/logr" - cephapi "github.com/ironcore-dev/ceph-provider/pkg/api" - "github.com/ironcore-dev/ceph-provider/pkg/ceph" - "github.com/ironcore-dev/ceph-provider/pkg/encryption" - "github.com/ironcore-dev/ceph-provider/pkg/store" + "github.com/ironcore-dev/ceph-provider/api" + "github.com/ironcore-dev/ceph-provider/internal/ceph" + "github.com/ironcore-dev/ceph-provider/internal/encryption" + "github.com/ironcore-dev/ceph-provider/internal/store" "github.com/ironcore-dev/ironcore/broker/common/idgen" iri "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" ctrl "sigs.k8s.io/controller-runtime" @@ -24,8 +24,8 @@ type VolumeClassRegistry interface { type Server struct { idGen idgen.IDGen - imageStore store.Store[*cephapi.Image] - snapshotStore store.Store[*cephapi.Snapshot] + imageStore store.Store[*api.Image] + snapshotStore store.Store[*api.Snapshot] volumeClasses VolumeClassRegistry cephCommandClient ceph.Command @@ -55,8 +55,8 @@ func setOptionsDefaults(o *Options) { var _ iri.VolumeRuntimeServer = (*Server)(nil) -func New(imageStore store.Store[*cephapi.Image], - snapshotStore store.Store[*cephapi.Snapshot], +func New(imageStore store.Store[*api.Image], + snapshotStore store.Store[*api.Snapshot], volumeClassRegistry VolumeClassRegistry, keyEncryption encryption.Encryptor, cephCommandClient ceph.Command, diff --git a/iri/volume/server/status.go b/internal/volumeserver/status.go similarity index 98% rename from iri/volume/server/status.go rename to internal/volumeserver/status.go index 17a1733b..cf6dfba1 100644 --- a/iri/volume/server/status.go +++ b/internal/volumeserver/status.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server +package volumeserver import ( "context" diff --git a/iri/volume/server/volume.go b/internal/volumeserver/volume.go similarity index 89% rename from iri/volume/server/volume.go rename to internal/volumeserver/volume.go index ca10345b..a9d352a9 100644 --- a/iri/volume/server/volume.go +++ b/internal/volumeserver/volume.go @@ -1,14 +1,13 @@ // SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server +package volumeserver import ( "fmt" - "github.com/ironcore-dev/ceph-provider/iri/volume/apiutils" - "github.com/ironcore-dev/ceph-provider/pkg/api" - "github.com/ironcore-dev/ceph-provider/pkg/utils" + "github.com/ironcore-dev/ceph-provider/api" + "github.com/ironcore-dev/ceph-provider/internal/utils" iri "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" ) @@ -21,7 +20,7 @@ const ( ) func (s *Server) convertImageToIriVolume(image *api.Image) (*iri.Volume, error) { - metadata, err := apiutils.GetObjectMetadata(image.Metadata) + metadata, err := api.GetObjectMetadataFromObjectID(image.Metadata) if err != nil { return nil, fmt.Errorf("error getting iri metadata: %w", err) } @@ -87,7 +86,7 @@ func (s *Server) getIriVolumeSpec(image *api.Image) (*iri.VolumeSpec, error) { }, } - class, ok := apiutils.GetClassLabel(image) + class, ok := api.GetClassLabelFromObject(image) if !ok { return nil, fmt.Errorf("failed to get volume class") } diff --git a/iri/volume/server/volume_create.go b/internal/volumeserver/volume_create.go similarity index 80% rename from iri/volume/server/volume_create.go rename to internal/volumeserver/volume_create.go index ffdee93a..aa31bba9 100644 --- a/iri/volume/server/volume_create.go +++ b/internal/volumeserver/volume_create.go @@ -1,25 +1,24 @@ // SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server +package volumeserver import ( "context" "fmt" "github.com/go-logr/logr" - "github.com/ironcore-dev/ceph-provider/iri/volume/apiutils" - "github.com/ironcore-dev/ceph-provider/pkg/api" - "github.com/ironcore-dev/ceph-provider/pkg/limits" - "github.com/ironcore-dev/ceph-provider/pkg/utils" - iri "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" + "github.com/ironcore-dev/ceph-provider/api" + "github.com/ironcore-dev/ceph-provider/internal/limits" + "github.com/ironcore-dev/ceph-provider/internal/utils" + iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" ) const ( EncryptionSecretDataPassphraseKey = "encryptionKey" ) -func (s *Server) createImageFromVolume(ctx context.Context, log logr.Logger, volume *iri.Volume) (*api.Image, error) { +func (s *Server) createImageFromVolume(ctx context.Context, log logr.Logger, volume *iriv1alpha1.Volume) (*api.Image, error) { if volume == nil { return nil, fmt.Errorf("got an empty volume") } @@ -71,11 +70,11 @@ func (s *Server) createImageFromVolume(ctx context.Context, log logr.Logger, vol } log.V(2).Info("Setting volume metadata to image") - if err := apiutils.SetObjectMetadata(image, volume.Metadata); err != nil { + if err := api.SetObjectMetadataFromMetadata(image, volume.Metadata); err != nil { return nil, fmt.Errorf("failed to set metadata: %w", err) } - apiutils.SetClassLabel(image, volume.Spec.Class) - apiutils.SetManagerLabel(image, apiutils.VolumeManager) + api.SetClassLabelForObject(image, volume.Spec.Class) + api.SetManagerLabel(image, api.VolumeManager) log.V(2).Info("Creating image in store") image, err = s.imageStore.Create(ctx, image) @@ -87,7 +86,7 @@ func (s *Server) createImageFromVolume(ctx context.Context, log logr.Logger, vol return image, nil } -func (s *Server) CreateVolume(ctx context.Context, req *iri.CreateVolumeRequest) (res *iri.CreateVolumeResponse, retErr error) { +func (s *Server) CreateVolume(ctx context.Context, req *iriv1alpha1.CreateVolumeRequest) (res *iriv1alpha1.CreateVolumeResponse, retErr error) { log := s.loggerFrom(ctx) log.V(1).Info("Creating volume") @@ -106,7 +105,7 @@ func (s *Server) CreateVolume(ctx context.Context, req *iri.CreateVolumeRequest) } log.V(1).Info("Volume created", "Volume", iriVolume.Metadata.Id, "State", iriVolume.Status.State) - return &iri.CreateVolumeResponse{ + return &iriv1alpha1.CreateVolumeResponse{ Volume: iriVolume, }, nil } diff --git a/iri/volume/server/volume_delete.go b/internal/volumeserver/volume_delete.go similarity index 91% rename from iri/volume/server/volume_delete.go rename to internal/volumeserver/volume_delete.go index 1920512c..34e32bce 100644 --- a/iri/volume/server/volume_delete.go +++ b/internal/volumeserver/volume_delete.go @@ -1,13 +1,13 @@ // SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server +package volumeserver import ( "context" "fmt" - "github.com/ironcore-dev/ceph-provider/pkg/store" + "github.com/ironcore-dev/ceph-provider/internal/store" iri "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" "github.com/pkg/errors" "google.golang.org/grpc/codes" diff --git a/iri/volume/server/volume_expand.go b/internal/volumeserver/volume_expand.go similarity index 95% rename from iri/volume/server/volume_expand.go rename to internal/volumeserver/volume_expand.go index 88b53b8d..695bc345 100644 --- a/iri/volume/server/volume_expand.go +++ b/internal/volumeserver/volume_expand.go @@ -1,14 +1,14 @@ // SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server +package volumeserver import ( "context" "fmt" "github.com/go-logr/logr" - "github.com/ironcore-dev/ceph-provider/pkg/utils" + "github.com/ironcore-dev/ceph-provider/internal/utils" iri "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" ) diff --git a/iri/volume/server/volume_list.go b/internal/volumeserver/volume_list.go similarity index 90% rename from iri/volume/server/volume_list.go rename to internal/volumeserver/volume_list.go index 12f74db9..e2820f33 100644 --- a/iri/volume/server/volume_list.go +++ b/internal/volumeserver/volume_list.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and IronCore contributors // SPDX-License-Identifier: Apache-2.0 -package server +package volumeserver import ( "context" @@ -9,8 +9,8 @@ import ( "fmt" "github.com/go-logr/logr" - "github.com/ironcore-dev/ceph-provider/iri/volume/apiutils" - "github.com/ironcore-dev/ceph-provider/pkg/store" + "github.com/ironcore-dev/ceph-provider/api" + "github.com/ironcore-dev/ceph-provider/internal/store" iri "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -26,7 +26,7 @@ func (s *Server) getIriVolume(ctx context.Context, log logr.Logger, imageId stri return nil, fmt.Errorf("failed to get image: %w", err) } - if !apiutils.IsManagedBy(cephImage, apiutils.VolumeManager) { + if !api.IsObjectManagedBy(cephImage, api.VolumeManager) { return nil, status.Errorf(codes.NotFound, "image %s not found", imageId) } @@ -60,7 +60,7 @@ func (s *Server) listVolumes(ctx context.Context, log logr.Logger) ([]*iri.Volum var res []*iri.Volume for _, cephImage := range cephImages { - if !apiutils.IsManagedBy(cephImage, apiutils.VolumeManager) { + if !api.IsObjectManagedBy(cephImage, api.VolumeManager) { continue } diff --git a/iri/bucket/apiutils/constants.go b/iri/bucket/apiutils/constants.go deleted file mode 100644 index f7d15586..00000000 --- a/iri/bucket/apiutils/constants.go +++ /dev/null @@ -1,12 +0,0 @@ -// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and IronCore contributors -// SPDX-License-Identifier: Apache-2.0 - -package apiutils - -const ( - LabelsAnnotation = "ceph-provider.ironcore.dev/labels" - AnnotationsAnnotation = "ceph-provider.ironcore.dev/annotations" - ClassLabel = "ceph-provider.ironcore.dev/class" - ManagerLabel = "ceph-provider.ironcore.dev/manager" - BucketManager = "ceph-bucket-provider" -) diff --git a/iri/volume/apiutils/apiutils.go b/iri/volume/apiutils/apiutils.go deleted file mode 100644 index a6115c63..00000000 --- a/iri/volume/apiutils/apiutils.go +++ /dev/null @@ -1,114 +0,0 @@ -// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and IronCore contributors -// SPDX-License-Identifier: Apache-2.0 - -package apiutils - -import ( - "encoding/json" - "fmt" - - "github.com/ironcore-dev/ceph-provider/pkg/api" - "github.com/ironcore-dev/controller-utils/metautils" - irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1" -) - -func GetObjectMetadata(o api.Metadata) (*irimeta.ObjectMetadata, error) { - annotations, err := GetAnnotationsAnnotation(o) - if err != nil { - return nil, err - } - - labels, err := GetLabelsAnnotation(o) - if err != nil { - return nil, err - } - - var deletedAt int64 - if o.DeletedAt != nil && !o.DeletedAt.IsZero() { - deletedAt = o.DeletedAt.UnixNano() - } - - return &irimeta.ObjectMetadata{ - Id: o.ID, - Annotations: annotations, - Labels: labels, - Generation: o.GetGeneration(), - CreatedAt: o.CreatedAt.UnixNano(), - DeletedAt: deletedAt, - }, nil -} - -func SetObjectMetadata(o api.Object, metadata *irimeta.ObjectMetadata) error { - if err := SetAnnotationsAnnotation(o, metadata.Annotations); err != nil { - return err - } - if err := SetLabelsAnnotation(o, metadata.Labels); err != nil { - return err - } - return nil -} - -func SetLabelsAnnotation(o api.Object, labels map[string]string) error { - data, err := json.Marshal(labels) - if err != nil { - return fmt.Errorf("error marshalling labels: %w", err) - } - metautils.SetAnnotation(o, LabelsAnnotation, string(data)) - return nil -} - -func GetLabelsAnnotation(o api.Metadata) (map[string]string, error) { - data, ok := o.GetAnnotations()[LabelsAnnotation] - if !ok { - return nil, fmt.Errorf("object has no labels at %s", LabelsAnnotation) - } - - var labels map[string]string - if err := json.Unmarshal([]byte(data), &labels); err != nil { - return nil, err - } - - return labels, nil -} - -func SetAnnotationsAnnotation(o api.Object, annotations map[string]string) error { - data, err := json.Marshal(annotations) - if err != nil { - return fmt.Errorf("error marshalling annotations: %w", err) - } - metautils.SetAnnotation(o, AnnotationsAnnotation, string(data)) - - return nil -} - -func GetAnnotationsAnnotation(o api.Metadata) (map[string]string, error) { - data, ok := o.GetAnnotations()[AnnotationsAnnotation] - if !ok { - return nil, fmt.Errorf("object has no annotations at %s", AnnotationsAnnotation) - } - - var annotations map[string]string - if err := json.Unmarshal([]byte(data), &annotations); err != nil { - return nil, err - } - - return annotations, nil -} - -func SetManagerLabel(o api.Object, manager string) { - metautils.SetLabel(o, ManagerLabel, manager) -} - -func SetClassLabel(o api.Object, class string) { - metautils.SetLabel(o, ClassLabel, class) -} - -func GetClassLabel(o api.Object) (string, bool) { - class, found := o.GetLabels()[ClassLabel] - return class, found -} - -func IsManagedBy(o api.Object, manager string) bool { - actual, ok := o.GetLabels()[ManagerLabel] - return ok && actual == manager -} diff --git a/integration/integration_suite_test.go b/tests/integration/integration_suite_test.go similarity index 98% rename from integration/integration_suite_test.go rename to tests/integration/integration_suite_test.go index 571a73fd..9683d3c3 100644 --- a/integration/integration_suite_test.go +++ b/tests/integration/integration_suite_test.go @@ -12,16 +12,15 @@ import ( "time" "github.com/ceph/go-ceph/rados" + "github.com/ironcore-dev/ceph-provider/cmd/volumeprovider/app" + iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" + "github.com/ironcore-dev/ironcore/iri/remote/volume" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" - - "github.com/ironcore-dev/ceph-provider/iri/volume/cmd/volume/app" - iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" - "github.com/ironcore-dev/ironcore/iri/remote/volume" ) const ( diff --git a/integration/volume_create_integration_test.go b/tests/integration/volume_create_integration_test.go similarity index 96% rename from integration/volume_create_integration_test.go rename to tests/integration/volume_create_integration_test.go index 3324da9a..739cc252 100644 --- a/integration/volume_create_integration_test.go +++ b/tests/integration/volume_create_integration_test.go @@ -8,9 +8,8 @@ import ( "fmt" "strings" - "github.com/ironcore-dev/ceph-provider/iri/volume/apiutils" - "github.com/ironcore-dev/ceph-provider/pkg/api" - "github.com/ironcore-dev/ceph-provider/pkg/omap" + "github.com/ironcore-dev/ceph-provider/api" + "github.com/ironcore-dev/ceph-provider/internal/omap" metav1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1" iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" . "github.com/onsi/ginkgo/v2" @@ -60,7 +59,7 @@ var _ = Describe("Create Volume", func() { return image }).Should(SatisfyAll( HaveField("Metadata.ID", Equal(createResp.Volume.Metadata.Id)), - HaveField("Metadata.Labels", HaveKeyWithValue(apiutils.ClassLabel, "foo")), + HaveField("Metadata.Labels", HaveKeyWithValue(api.ClassLabel, "foo")), HaveField("Spec.Image", Equal("")), HaveField("Spec.Size", Equal(uint64(1024*1024*1024))), HaveField("Spec.Limits", SatisfyAll( @@ -159,7 +158,7 @@ var _ = Describe("Create Volume", func() { return image }).Should(SatisfyAll( HaveField("Metadata.ID", Equal(createResp.Volume.Metadata.Id)), - HaveField("Metadata.Labels", HaveKeyWithValue(apiutils.ClassLabel, "foo")), + HaveField("Metadata.Labels", HaveKeyWithValue(api.ClassLabel, "foo")), HaveField("Spec.Image", Equal("")), HaveField("Spec.Size", Equal(uint64(1024*1024*1024))), HaveField("Spec.Limits", SatisfyAll( diff --git a/integration/volume_delete_integration_test.go b/tests/integration/volume_delete_integration_test.go similarity index 96% rename from integration/volume_delete_integration_test.go rename to tests/integration/volume_delete_integration_test.go index 9a8cc223..84a4740a 100644 --- a/integration/volume_delete_integration_test.go +++ b/tests/integration/volume_delete_integration_test.go @@ -8,8 +8,8 @@ import ( "fmt" "strings" - "github.com/ironcore-dev/ceph-provider/pkg/api" - "github.com/ironcore-dev/ceph-provider/pkg/omap" + "github.com/ironcore-dev/ceph-provider/api" + "github.com/ironcore-dev/ceph-provider/internal/omap" metav1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1" iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" . "github.com/onsi/ginkgo/v2" diff --git a/integration/volume_expand_integration_test.go b/tests/integration/volume_expand_integration_test.go similarity index 95% rename from integration/volume_expand_integration_test.go rename to tests/integration/volume_expand_integration_test.go index 9c4d5847..0f8a41ac 100644 --- a/integration/volume_expand_integration_test.go +++ b/tests/integration/volume_expand_integration_test.go @@ -8,9 +8,8 @@ import ( "fmt" "strings" - "github.com/ironcore-dev/ceph-provider/iri/volume/apiutils" - "github.com/ironcore-dev/ceph-provider/pkg/api" - "github.com/ironcore-dev/ceph-provider/pkg/omap" + "github.com/ironcore-dev/ceph-provider/api" + "github.com/ironcore-dev/ceph-provider/internal/omap" metav1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1" iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" . "github.com/onsi/ginkgo/v2" @@ -59,7 +58,7 @@ var _ = Describe("Expand Volume", func() { return image }).Should(SatisfyAll( HaveField("Metadata.ID", Equal(createResp.Volume.Metadata.Id)), - HaveField("Metadata.Labels", HaveKeyWithValue(apiutils.ClassLabel, "foo")), + HaveField("Metadata.Labels", HaveKeyWithValue(api.ClassLabel, "foo")), HaveField("Spec.Image", Equal("")), HaveField("Spec.Size", Equal(uint64(1024*1024*1024))), HaveField("Spec.Limits", SatisfyAll( @@ -130,7 +129,7 @@ var _ = Describe("Expand Volume", func() { return image }).Should(SatisfyAll( HaveField("Metadata.ID", Equal(createResp.Volume.Metadata.Id)), - HaveField("Metadata.Labels", HaveKeyWithValue(apiutils.ClassLabel, "foo")), + HaveField("Metadata.Labels", HaveKeyWithValue(api.ClassLabel, "foo")), HaveField("Spec.Image", Equal("")), HaveField("Spec.Size", Equal(uint64(2048*2048*2048))), HaveField("Spec.Limits", SatisfyAll( diff --git a/integration/volume_list_integration_test.go b/tests/integration/volume_list_integration_test.go similarity index 97% rename from integration/volume_list_integration_test.go rename to tests/integration/volume_list_integration_test.go index 23847aec..4bd01ff1 100644 --- a/integration/volume_list_integration_test.go +++ b/tests/integration/volume_list_integration_test.go @@ -8,8 +8,8 @@ import ( "fmt" "strings" - "github.com/ironcore-dev/ceph-provider/pkg/api" - "github.com/ironcore-dev/ceph-provider/pkg/omap" + "github.com/ironcore-dev/ceph-provider/api" + "github.com/ironcore-dev/ceph-provider/internal/omap" metav1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1" iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" . "github.com/onsi/ginkgo/v2" diff --git a/integration/volume_status_integration_test.go b/tests/integration/volume_status_integration_test.go similarity index 92% rename from integration/volume_status_integration_test.go rename to tests/integration/volume_status_integration_test.go index 3c1a4ea5..4e5c400e 100644 --- a/integration/volume_status_integration_test.go +++ b/tests/integration/volume_status_integration_test.go @@ -7,9 +7,8 @@ import ( "encoding/json" "strconv" - "github.com/ironcore-dev/ceph-provider/iri/volume/apiutils" - "github.com/ironcore-dev/ceph-provider/pkg/api" - "github.com/ironcore-dev/ceph-provider/pkg/omap" + "github.com/ironcore-dev/ceph-provider/api" + "github.com/ironcore-dev/ceph-provider/internal/omap" metav1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1" iriv1alpha1 "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" . "github.com/onsi/ginkgo/v2" @@ -72,7 +71,7 @@ var _ = Describe("Volume Status", func() { return image }).Should(SatisfyAll( HaveField("Metadata.ID", Equal(createResp.Volume.Metadata.Id)), - HaveField("Metadata.Labels", HaveKeyWithValue(apiutils.ClassLabel, "foo")), + HaveField("Metadata.Labels", HaveKeyWithValue(api.ClassLabel, "foo")), HaveField("Spec.Size", Equal(uint64(1*1024))), HaveField("Spec.Limits", SatisfyAll( HaveKeyWithValue(api.ReadBPSLimit, int64(100)),