Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue-1657: resize pvc with nbd-lightweight and minikube #1846

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 59 additions & 12 deletions cloud/blockstore/libs/service_local/service_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cloud/blockstore/libs/service/storage.h>
#include <cloud/blockstore/libs/service/storage_provider.h>
#include <cloud/storage/core/libs/common/error.h>
#include <cloud/storage/core/libs/common/timer.h>

#include <library/cpp/protobuf/util/pb_io.h>

Expand Down Expand Up @@ -62,17 +63,23 @@ struct TMountSession
{
const TString SessionId;
const TString ClientId;
const IStoragePtr Storage;
const TStorageAdapter StorageAdapter;
const NProto::EVolumeAccessMode AccessMode;
IStoragePtr Storage;
std::unique_ptr<TStorageAdapter> StorageAdapter;

TMountSession(TString clientId, IStoragePtr storage, ui32 blockSize)
TMountSession(
TString clientId,
antonmyagkov marked this conversation as resolved.
Show resolved Hide resolved
NProto::EVolumeAccessMode accessMode,
IStoragePtr storage,
ui32 blockSize)
: SessionId(CreateGuidAsString())
, ClientId(std::move(clientId))
, AccessMode(accessMode)
, Storage(storage)
, StorageAdapter(
std::move(storage),
blockSize,
true)
, StorageAdapter(std::make_unique<TStorageAdapter>(
std::move(storage),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а тут какие-то 2 лишних пробела добавилось в отступ

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Потому что теперь это параметры std::make_unique

blockSize,
true))
{}
};

Expand All @@ -83,7 +90,7 @@ using TMountSessionMap = THashMap<TString, TMountSessionPtr>;

struct TMountedVolume
{
const NProto::TVolume Volume;
NProto::TVolume Volume;

TMountSessionMap Sessions;
TMutex SessionLock;
Expand All @@ -92,11 +99,15 @@ struct TMountedVolume
: Volume(std::move(volume))
{}

TMountSessionPtr CreateSession(TString clientId, IStoragePtr storage)
TMountSessionPtr CreateSession(
TString clientId,
NProto::EVolumeAccessMode accessMode,
IStoragePtr storage)
{
with_lock (SessionLock) {
auto session = std::make_shared<TMountSession>(
std::move(clientId),
accessMode,
std::move(storage),
Volume.GetBlockSize());

Expand Down Expand Up @@ -201,6 +212,29 @@ class TVolumeManager

TFile fileData(MakeDataPath(diskId), EOpenModeFlag::OpenExisting);
fileData.Resize(volume.GetBlockSize() * blocksCount);

auto mountedVolume = FindMountedVolume(diskId);
if (!mountedVolume) {
return;
}
with_lock (mountedVolume->SessionLock) {
mountedVolume->Volume = volume;
for (auto& session: mountedVolume->Sessions) {
auto dataPath = MakeDataPath(volume.GetDiskId());
volume.SetDiskId(dataPath);
session.second->Storage = StorageProvider
qkrorlqr marked this conversation as resolved.
Show resolved Hide resolved
->CreateStorage(
volume,
session.second->ClientId,
session.second->AccessMode)
.GetValueSync();
session.second->StorageAdapter =
std::make_unique<TStorageAdapter>(
session.second->Storage,
volume.GetBlockSize(),
true);
}
}
}

void DestroyVolume(const TString& diskId)
Expand Down Expand Up @@ -266,6 +300,7 @@ class TVolumeManager

auto session = mountedVolume->CreateSession(
clientId,
accessMode,
std::move(storage));

NProto::TMountVolumeResponse response;
Expand Down Expand Up @@ -666,7 +701,11 @@ TFuture<NProto::TReadBlocksResponse> TLocalService::ReadBlocks(
<< "Out of bounds read request";
}

return session->StorageAdapter.ReadBlocks(
if (!session->StorageAdapter) {
ythrow TServiceError(E_FAIL) << "Invalid storage adapter";
}

return session->StorageAdapter->ReadBlocks(
Now(),
std::move(ctx),
std::move(request),
Expand Down Expand Up @@ -725,7 +764,11 @@ TFuture<NProto::TWriteBlocksResponse> TLocalService::WriteBlocks(
<< "Out of bounds write request";
}

return session->StorageAdapter.WriteBlocks(
if (!session->StorageAdapter) {
ythrow TServiceError(E_FAIL) << "Invalid storage adapter";
}

return session->StorageAdapter->WriteBlocks(
Now(),
std::move(ctx),
std::move(request),
Expand Down Expand Up @@ -776,7 +819,11 @@ TFuture<NProto::TZeroBlocksResponse> TLocalService::ZeroBlocks(
<< "Out of bounds write request";
}

return session->StorageAdapter.ZeroBlocks(
if (!session->StorageAdapter) {
ythrow TServiceError(E_FAIL) << "Invalid storage adapter";
}

return session->StorageAdapter->ZeroBlocks(
Now(),
std::move(ctx),
std::move(request),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ spec:
requests:
storage: 1Gi
limits:
storage: 1Gi
storage: 10Gi
storageClassName: nbs-csi-sc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ metadata:
name: nbs-csi-sc
provisioner: nbs.csi.nebius.ai
volumeBindingMode: Immediate
allowVolumeExpansion: true
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,33 @@ spec:
volumeMounts:
- name: socket-dir
mountPath: /csi
- name: csi-resizer
image: registry.k8s.io/sig-storage/csi-resizer:v1.11.2
imagePullPolicy: IfNotPresent
args:
- "--v=5"
- "--csi-address=/csi/csi.sock"
- "--leader-election"
- "--http-endpoint=:8081"
env:
- name: KUBE_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
resources:
requests:
memory: "64Mi"
cpu: "100m"
limits:
memory: "128Mi"
cpu: "250m"
ports:
- containerPort: 8081
name: http-endpoint
protocol: TCP
volumeMounts:
- name: socket-dir
mountPath: /csi
- name: csi-nbs-driver
image: nbs-csi-driver:latest
imagePullPolicy: IfNotPresent
Expand Down
Loading