Skip to content

Commit f13a3c2

Browse files
committed
Fix Volume resize
Signed-off-by: Lukas Frank <[email protected]>
1 parent 6ee8c5c commit f13a3c2

File tree

7 files changed

+6
-306
lines changed

7 files changed

+6
-306
lines changed

Dockerfile

Lines changed: 5 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
3030
&& update-ca-certificates \
3131
&& rm -rf /var/lib/apt/lists/*
3232

33-
# Install cross-compiler for ARM64 if building for arm64 on an amd64 host
34-
RUN if [ "$TARGETARCH" = "arm64" ] && [ "$BUILDARCH" = "amd64" ]; then \
35-
dpkg --add-architecture arm64 && \
36-
apt-get update && apt-get install -y --no-install-recommends \
37-
gcc-aarch64-linux-gnu librbd-dev:arm64 librados-dev:arm64 libc6-dev:arm64; \
38-
fi
39-
40-
# Install cross-compiler for AMD64 if building for amd64 on an arm64 host
41-
RUN if [ "$TARGETARCH" = "amd64" ] && [ "$BUILDARCH" = "arm64" ]; then \
42-
apt update && \
43-
apt-get install -y --no-install-recommends \
44-
gcc-x86-64-linux-gnu; \
45-
fi
4633

47-
# Set compiler and linker flags based on target architecture
48-
ENV CC=""
49-
ENV CGO_LDFLAGS=""
34+
RUN --mount=type=cache,target=/root/.cache/go-build \
35+
--mount=type=cache,target=/go/pkg \
36+
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o libvirt-provider ./cmd/libvirt-provider/main.go
5037

51-
RUN if [ "$TARGETARCH" != "$BUILDARCH" ] && [ "$TARGETARCH" = "arm64" ]; then \
52-
export CC="/usr/bin/aarch64-linux-gnu-gcc"; \
53-
export CGO_LDFLAGS="-L/usr/lib/aarch64-linux-gnu -Wl,-lrados -Wl,-lrbd"; \
54-
elif [ "$TARGETARCH" != "$BUILDARCH" ] && [ "$TARGETARCH" = "amd64" ]; then \
55-
export CC="/usr/bin/x86_64-linux-gnu-gcc"; \
56-
export CGO_LDFLAGS="-L/usr/lib/x86_64-linux-gnu -Wl,-lrados -Wl,-lrbd"; \
57-
else \
58-
export CC="/usr/bin/gcc"; \
59-
export CGO_LDFLAGS=""; \
60-
fi && \
61-
CGO_ENABLED=1 GOOS=$TARGETOS GOARCH=$TARGETARCH \
62-
CC="$CC" CGO_LDFLAGS="$CGO_LDFLAGS" \
63-
go build -ldflags="-s -w -linkmode=external" -o libvirt-provider ./cmd/libvirt-provider/main.go
6438

6539
# Install irictl-machine
6640
RUN --mount=type=cache,target=/root/.cache/go-build \
@@ -75,63 +49,8 @@ RUN if [ "$TARGETARCH" = "$BUILDARCH" ]; then \
7549
mv /go/bin/linux_$TARGETARCH/irictl-machine /workspace/irictl-machine; \
7650
fi
7751

78-
# Since we're leveraging apt to pull in dependencies, we use `gcr.io/distroless/base` because it includes glibc.
79-
FROM gcr.io/distroless/base-debian11 AS distroless-base
80-
81-
# The distroless amd64 image has a target triplet of x86_64
82-
FROM distroless-base AS distroless-amd64
83-
ENV LIB_DIR_PREFIX=x86_64
84-
ENV LIB_DIR_PREFIX_MINUS=x86-64
85-
ENV LIB_DIR_SUFFIX_NUMBER=2
86-
ENV LIB_DIR=lib64
87-
88-
# The distroless arm64 image has a target triplet of aarch64
89-
FROM distroless-base AS distroless-arm64
90-
ENV LIB_DIR_PREFIX=aarch64
91-
ENV LIB_DIR_PREFIX_MINUS=aarch64
92-
ENV LIB_DIR_SUFFIX_NUMBER=1
93-
ENV LIB_DIR=lib
94-
95-
FROM busybox:1.37.0-uclibc AS busybox
96-
FROM distroless-$TARGETARCH AS libvirt-provider
97-
WORKDIR /
98-
COPY --from=busybox /bin/sh /bin/sh
99-
COPY --from=busybox /bin/mkdir /bin/mkdir
100-
COPY --from=builder /lib/${LIB_DIR_PREFIX}-linux-gnu/librados.so.2 \
101-
/lib/${LIB_DIR_PREFIX}-linux-gnu/librbd.so.1 \
102-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libc.so.6 \
103-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libfmt.so.9 \
104-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libstdc++.so.6 \
105-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libgcc_s.so.1 \
106-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libssl.so.3 \
107-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libcryptsetup.so.12 \
108-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libcrypto.so.3 \
109-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libresolv.so.2 \
110-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libboost_thread.so.1.74.0 \
111-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libboost_iostreams.so.1.74.0 \
112-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libblkid.so.1 \
113-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libudev.so.1 \
114-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libibverbs.so.1 \
115-
/lib/${LIB_DIR_PREFIX}-linux-gnu/librdmacm.so.1 \
116-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libm.so.6 \
117-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libuuid.so.1 \
118-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libdevmapper.so.1.02.1 \
119-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libargon2.so.1 \
120-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libjson-c.so.5 \
121-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libz.so.1 \
122-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libbz2.so.1.0 \
123-
/lib/${LIB_DIR_PREFIX}-linux-gnu/liblzma.so.5 \
124-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libzstd.so.1 \
125-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libnl-route-3.so.200 \
126-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libnl-3.so.200 \
127-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libselinux.so.1 \
128-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libpthread.so.0 \
129-
/lib/${LIB_DIR_PREFIX}-linux-gnu/libpcre2-8.so.0 /lib/${LIB_DIR_PREFIX}-linux-gnu/
130-
RUN mkdir -p /${LIB_DIR}
131-
COPY --from=builder /${LIB_DIR}/ld-linux-${LIB_DIR_PREFIX_MINUS}.so.${LIB_DIR_SUFFIX_NUMBER} /${LIB_DIR}/
132-
RUN mkdir -p /usr/lib/${LIB_DIR_PREFIX}-linux-gnu/ceph/
133-
COPY --from=builder /usr/lib/${LIB_DIR_PREFIX}-linux-gnu/ceph/libceph-common.so.2 /usr/lib/${LIB_DIR_PREFIX}-linux-gnu/ceph
134-
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
52+
53+
13554

13655
COPY --from=builder /workspace/libvirt-provider /libvirt-provider
13756
COPY --from=builder /workspace/irictl-machine /irictl-machine

cmd/libvirt-provider/app/app.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ type Options struct {
6868
RootDir string
6969

7070
PathSupportedMachineClasses string
71-
ResyncIntervalVolumeSize time.Duration
7271

7372
EnableHugepages bool
7473

@@ -111,7 +110,6 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
111110
fs.StringVar(&o.RootDir, "libvirt-provider-dir", filepath.Join(homeDir, ".libvirt-provider"), "Path to the directory libvirt-provider manages its content at.")
112111

113112
fs.StringVar(&o.PathSupportedMachineClasses, "supported-machine-classes", o.PathSupportedMachineClasses, "File containing supported machine classes.")
114-
fs.DurationVar(&o.ResyncIntervalVolumeSize, "volume-size-resync-interval", 1*time.Minute, "Interval to determine volume size changes.")
115113

116114
fs.StringVar(&o.StreamingAddress, "streaming-address", ":20251", "Address to run the streaming server on")
117115
fs.StringVar(&o.BaseURL, "base-url", "", "The base url to construct urls for streaming from. If empty it will be "+
@@ -314,7 +312,6 @@ func Run(ctx context.Context, opts Options) error {
314312
Raw: rawInst,
315313
VolumePluginManager: volumePlugins,
316314
NetworkInterfacePlugin: nicPlugin,
317-
ResyncIntervalVolumeSize: opts.ResyncIntervalVolumeSize,
318315
ResyncIntervalGarbageCollector: opts.ResyncIntervalGarbageCollector,
319316
EnableHugepages: opts.EnableHugepages,
320317
GCVMGracefulShutdownTimeout: opts.GCVMGracefulShutdownTimeout,

internal/controllers/machine_controller.go

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ type MachineReconcilerOptions struct {
7373
VolumePluginManager *providervolume.PluginManager
7474
NetworkInterfacePlugin providernetworkinterface.Plugin
7575
VolumeEvents event.Source[*api.Machine]
76-
ResyncIntervalVolumeSize time.Duration
7776
ResyncIntervalGarbageCollector time.Duration
7877
EnableHugepages bool
7978
GCVMGracefulShutdownTimeout time.Duration
@@ -113,7 +112,6 @@ func NewMachineReconciler(
113112
raw: opts.Raw,
114113
volumePluginManager: opts.VolumePluginManager,
115114
networkInterfacePlugin: opts.NetworkInterfacePlugin,
116-
resyncIntervalVolumeSize: opts.ResyncIntervalVolumeSize,
117115
resyncIntervalGarbageCollector: opts.ResyncIntervalGarbageCollector,
118116
enableHugepages: opts.EnableHugepages,
119117
gcVMGracefulShutdownTimeout: opts.GCVMGracefulShutdownTimeout,
@@ -140,8 +138,6 @@ type MachineReconciler struct {
140138
machineEvents event.Source[*api.Machine]
141139
recorder.EventRecorder
142140

143-
resyncIntervalVolumeSize time.Duration
144-
145141
gcVMGracefulShutdownTimeout time.Duration
146142
resyncIntervalGarbageCollector time.Duration
147143

@@ -185,12 +181,6 @@ func (r *MachineReconciler) Start(ctx context.Context) error {
185181
}()
186182

187183
var wg sync.WaitGroup
188-
wg.Add(1)
189-
go func() {
190-
defer wg.Done()
191-
r.startCheckAndEnqueueVolumeResize(ctx, r.log.WithName("volume-size"))
192-
}()
193-
194184
wg.Add(1)
195185
go func() {
196186
defer wg.Done()
@@ -221,60 +211,6 @@ func (r *MachineReconciler) Start(ctx context.Context) error {
221211
return nil
222212
}
223213

224-
func (r *MachineReconciler) startCheckAndEnqueueVolumeResize(ctx context.Context, log logr.Logger) {
225-
if r.resyncIntervalVolumeSize == 0 {
226-
log.V(1).Info("volume resize trigger loop is disabled")
227-
return
228-
}
229-
230-
wait.UntilWithContext(ctx, func(ctx context.Context) {
231-
log.V(1).Info("starting volume resize trigger loop")
232-
machines, err := r.machines.List(ctx)
233-
if err != nil {
234-
log.Error(err, "failed to list machines")
235-
return
236-
}
237-
238-
for _, machine := range machines {
239-
if machine.DeletedAt != nil || !slices.Contains(machine.Finalizers, MachineFinalizer) {
240-
continue
241-
}
242-
243-
var shouldEnqueue bool
244-
for _, volume := range machine.Spec.Volumes {
245-
plugin, err := r.volumePluginManager.FindPluginBySpec(volume)
246-
if err != nil {
247-
log.Error(err, "failed to get volume plugin", "machineID", machine.ID, "volumeName", volume.Name)
248-
continue
249-
}
250-
251-
volumeID, err := plugin.GetBackingVolumeID(volume)
252-
if err != nil {
253-
log.Error(err, "failed to get volume id", "machineID", machine.ID, "volumeName", volume.Name)
254-
continue
255-
}
256-
257-
volumeSize, err := plugin.GetSize(ctx, volume)
258-
if err != nil {
259-
log.Error(err, "failed to get volume size", "machineID", machine.ID, "volumeName", volume.Name, "volumeID", volumeID)
260-
continue
261-
}
262-
263-
if lastVolumeSize := getLastVolumeSize(machine, GetUniqueVolumeName(plugin.Name(), volumeID)); volumeSize != lastVolumeSize {
264-
r.Eventf(machine.Metadata, corev1.EventTypeNormal, "SizeChangedVolume", "Volume size changed %s, lastVolumeSize: %d bytes, volumeSize: %d bytes", volume.Name, lastVolumeSize, volumeSize)
265-
log.V(1).Info("Volume size changed", "volumeName", volume.Name, "volumeID", volumeID, "machineID", machine.ID, "lastSize", lastVolumeSize, "volumeSize", volumeSize)
266-
shouldEnqueue = true
267-
break
268-
}
269-
}
270-
271-
if shouldEnqueue {
272-
r.queue.AddRateLimited(machine.ID)
273-
}
274-
}
275-
}, r.resyncIntervalVolumeSize)
276-
}
277-
278214
func (r *MachineReconciler) startEnqueueMachineByLibvirtEvent(ctx context.Context, log logr.Logger) {
279215
lifecycleEvents, err := r.host.Libvirt().LifecycleEvents(ctx)
280216
if err != nil {

internal/plugins/volume/ceph/ceph.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ func (p *plugin) Apply(ctx context.Context, spec *api.VolumeSpec, machine *api.M
138138
}
139139
}
140140

141-
volumeSize, err := p.GetSize(ctx, spec)
142-
if err != nil {
143-
return nil, fmt.Errorf("failed to get volume size: %w", err)
144-
}
145-
146141
return &volume.Volume{
147142
QCow2File: "",
148143
RawFile: "",
@@ -156,7 +151,6 @@ func (p *plugin) Apply(ctx context.Context, spec *api.VolumeSpec, machine *api.M
156151
Encryption: cephEncryption,
157152
},
158153
Handle: volumeData.handle,
159-
Size: volumeSize,
160154
}, nil
161155
}
162156

internal/plugins/volume/ceph/size.go

Lines changed: 0 additions & 138 deletions
This file was deleted.

0 commit comments

Comments
 (0)