Skip to content

Commit ab228b6

Browse files
robinschneiderDuciwuci
authored andcommitted
Cherrypick SKE changes
1 parent 259ed77 commit ab228b6

File tree

5 files changed

+123
-49
lines changed

5 files changed

+123
-49
lines changed

Dockerfile

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -102,49 +102,6 @@ LABEL name="barbican-kms-plugin" \
102102

103103
CMD ["sh", "-c", "/bin/barbican-kms-plugin --socketpath ${socketpath} --cloud-config ${cloudconfig}"]
104104

105-
##
106-
## cinder-csi-plugin
107-
##
108-
109-
# step 1: copy all necessary files from Debian distro to /dest folder
110-
# all magic happens in tools/csi-deps.sh
111-
FROM ${DEBIAN_IMAGE} AS cinder-csi-plugin-utils
112-
113-
RUN clean-install bash rsync mount udev btrfs-progs e2fsprogs xfsprogs util-linux
114-
COPY tools/csi-deps.sh /tools/csi-deps.sh
115-
RUN /tools/csi-deps.sh
116-
117-
# step 2: check if all necessary files are copied and work properly
118-
# the build have to finish without errors, but the result image will not be used
119-
FROM ${DISTROLESS_IMAGE} AS cinder-csi-plugin-utils-check
120-
121-
COPY --from=cinder-csi-plugin-utils /dest /
122-
COPY --from=cinder-csi-plugin-utils /bin/sh /bin/sh
123-
COPY tools/csi-deps-check.sh /tools/csi-deps-check.sh
124-
125-
SHELL ["/bin/sh"]
126-
RUN /tools/csi-deps-check.sh
127-
128-
# step 3: build tiny cinder-csi-plugin image with only necessary files
129-
FROM ${DISTROLESS_IMAGE} AS cinder-csi-plugin
130-
131-
# Copying csi-deps-check.sh simply ensures that the resulting image has a dependency
132-
# on cinder-csi-plugin-utils-check and therefore that the check has passed
133-
COPY --from=cinder-csi-plugin-utils-check /tools/csi-deps-check.sh /bin/csi-deps-check.sh
134-
COPY --from=cinder-csi-plugin-utils /dest /
135-
COPY --from=builder /build/cinder-csi-plugin /bin/cinder-csi-plugin
136-
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
137-
138-
LABEL name="cinder-csi-plugin" \
139-
license="Apache Version 2.0" \
140-
maintainers="Kubernetes Authors" \
141-
description="Cinder CSI Plugin" \
142-
distribution-scope="public" \
143-
summary="Cinder CSI Plugin" \
144-
help="none"
145-
146-
CMD ["/bin/cinder-csi-plugin"]
147-
148105
##
149106
## k8s-keystone-auth
150107
##
@@ -221,3 +178,47 @@ LABEL name="octavia-ingress-controller" \
221178
help="none"
222179

223180
CMD ["/bin/octavia-ingress-controller"]
181+
182+
## SKE: Concourse only pushes the last built image. Therefore we have to move this to the bottom.
183+
##
184+
## cinder-csi-plugin
185+
##
186+
187+
# step 1: copy all necessary files from Debian distro to /dest folder
188+
# all magic happens in tools/csi-deps.sh
189+
FROM ${DEBIAN_IMAGE} AS cinder-csi-plugin-utils
190+
191+
RUN clean-install bash rsync mount udev btrfs-progs e2fsprogs xfsprogs util-linux
192+
COPY tools/csi-deps.sh /tools/csi-deps.sh
193+
RUN /tools/csi-deps.sh
194+
195+
# step 2: check if all necessary files are copied and work properly
196+
# the build have to finish without errors, but the result image will not be used
197+
FROM ${DISTROLESS_IMAGE} AS cinder-csi-plugin-utils-check
198+
199+
COPY --from=cinder-csi-plugin-utils /dest /
200+
COPY --from=cinder-csi-plugin-utils /bin/sh /bin/sh
201+
COPY tools/csi-deps-check.sh /tools/csi-deps-check.sh
202+
203+
SHELL ["/bin/sh"]
204+
RUN /tools/csi-deps-check.sh
205+
206+
# step 3: build tiny cinder-csi-plugin image with only necessary files
207+
FROM ${DISTROLESS_IMAGE} AS cinder-csi-plugin
208+
209+
# Copying csi-deps-check.sh simply ensures that the resulting image has a dependency
210+
# on cinder-csi-plugin-utils-check and therefore that the check has passed
211+
COPY --from=cinder-csi-plugin-utils-check /tools/csi-deps-check.sh /bin/csi-deps-check.sh
212+
COPY --from=cinder-csi-plugin-utils /dest /
213+
COPY --from=builder /build/cinder-csi-plugin /bin/cinder-csi-plugin
214+
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
215+
216+
LABEL name="cinder-csi-plugin" \
217+
license="Apache Version 2.0" \
218+
maintainers="Kubernetes Authors" \
219+
description="Cinder CSI Plugin" \
220+
distribution-scope="public" \
221+
summary="Cinder CSI Plugin" \
222+
help="none"
223+
224+
CMD ["/bin/cinder-csi-plugin"]

pkg/csi/cinder/controllerserver.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"slices"
2323
"sort"
2424
"strconv"
25+
"time"
2526

2627
"github.com/container-storage-interface/spec/lib/go/csi"
2728
"github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/backups"
@@ -32,6 +33,7 @@ import (
3233
"google.golang.org/grpc/codes"
3334
"google.golang.org/grpc/status"
3435
"google.golang.org/protobuf/types/known/timestamppb"
36+
"k8s.io/apimachinery/pkg/util/wait"
3537

3638
sharedcsi "k8s.io/cloud-provider-openstack/pkg/csi"
3739
"k8s.io/cloud-provider-openstack/pkg/csi/cinder/openstack"
@@ -118,6 +120,10 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
118120
if volSizeGB != vols[0].Size {
119121
return nil, status.Error(codes.AlreadyExists, "Volume Already exists with same name and different capacity")
120122
}
123+
124+
if volumes[0].Status != openstack.VolumeAvailableStatus {
125+
return nil, status.Error(codes.Internal, fmt.Sprintf("Volume %s is not in available state", volumes[0].ID))
126+
}
121127
klog.V(4).Infof("Volume %s already exists in Availability Zone: %s of size %d GiB", vols[0].ID, vols[0].AvailabilityZone, vols[0].Size)
122128
return getCreateVolumeResponse(&vols[0], nil, ignoreVolumeAZ, req.GetAccessibilityRequirements()), nil
123129
} else if len(vols) > 1 {
@@ -241,6 +247,23 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
241247
vol.BackupID = &sourceBackupID
242248
}
243249

250+
if err != nil {
251+
klog.Errorf("Failed to CreateVolume: %v", err)
252+
return nil, status.Errorf(codes.Internal, "CreateVolume failed with error %v", err)
253+
}
254+
255+
targetStatus := []string{openstack.VolumeAvailableStatus}
256+
err = cloud.WaitVolumeTargetStatusWithCustomBackoff(vol.ID, targetStatus,
257+
&wait.Backoff{
258+
Duration: 20 * time.Second,
259+
Steps: 5,
260+
Factor: 1.28,
261+
})
262+
if err != nil {
263+
klog.Errorf("Failed to WaitVolumeTargetStatus of volume %s: %v", vol.ID, err)
264+
return nil, status.Error(codes.Internal, fmt.Sprintf("CreateVolume Volume %s failed getting available in time: %v", vol.ID, err))
265+
}
266+
244267
klog.V(4).Infof("CreateVolume: Successfully created volume %s in Availability Zone: %s of size %d GiB", vol.ID, vol.AvailabilityZone, vol.Size)
245268

246269
return getCreateVolumeResponse(vol, volCtx, ignoreVolumeAZ, req.GetAccessibilityRequirements()), nil

pkg/csi/cinder/openstack/openstack.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers"
3131
"github.com/spf13/pflag"
3232
gcfg "gopkg.in/gcfg.v1"
33+
"k8s.io/apimachinery/pkg/util/wait"
3334
"k8s.io/cloud-provider-openstack/pkg/client"
3435
"k8s.io/cloud-provider-openstack/pkg/metrics"
3536
"k8s.io/cloud-provider-openstack/pkg/util/metadata"
@@ -54,6 +55,7 @@ type IOpenStack interface {
5455
DetachVolume(ctx context.Context, instanceID, volumeID string) error
5556
WaitDiskDetached(ctx context.Context, instanceID string, volumeID string) error
5657
WaitVolumeTargetStatus(ctx context.Context, volumeID string, tStatus []string) error
58+
WaitVolumeTargetStatusWithCustomBackoff(volumeID string, tStatus []string, backoff *wait.Backoff) error
5759
GetAttachmentDiskPath(ctx context.Context, instanceID, volumeID string) (string, error)
5860
GetVolume(ctx context.Context, volumeID string) (*volumes.Volume, error)
5961
GetVolumesByName(ctx context.Context, name string) ([]volumes.Volume, error)

pkg/csi/cinder/openstack/openstack_mock.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/volumes"
2626
"github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers"
2727
"github.com/stretchr/testify/mock"
28+
"k8s.io/apimachinery/pkg/util/wait"
2829
"k8s.io/cloud-provider-openstack/pkg/util/errors"
2930
"k8s.io/cloud-provider-openstack/pkg/util/metadata"
3031
)
@@ -200,6 +201,20 @@ func (_m *OpenStackMock) WaitVolumeTargetStatus(ctx context.Context, volumeID st
200201
return r0
201202
}
202203

204+
// WaitVolumeTargetStatusWithCustomBackoff provides a mock function with given fields: volumeID, tStatus, backoff
205+
func (_m *OpenStackMock) WaitVolumeTargetStatusWithCustomBackoff(volumeID string, tStatus []string, backoff *wait.Backoff) error {
206+
ret := _m.Called(volumeID, tStatus, backoff)
207+
208+
var r0 error
209+
if rf, ok := ret.Get(0).(func(string, []string, *wait.Backoff) error); ok {
210+
r0 = rf(volumeID, tStatus, backoff)
211+
} else {
212+
r0 = ret.Error(0)
213+
}
214+
215+
return r0
216+
}
217+
203218
// WaitDiskDetached provides a mock function with given fields: instanceID, volumeID
204219
func (_m *OpenStackMock) WaitDiskDetached(ctx context.Context, instanceID string, volumeID string) error {
205220
ret := _m.Called(instanceID, volumeID)

pkg/csi/cinder/openstack/openstack_volumes.go

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ const (
4343
operationFinishInitDelay = 1 * time.Second
4444
operationFinishFactor = 1.1
4545
operationFinishSteps = 10
46-
diskAttachInitDelay = 1 * time.Second
47-
diskAttachFactor = 1.2
48-
diskAttachSteps = 15
49-
diskDetachInitDelay = 1 * time.Second
50-
diskDetachFactor = 1.2
51-
diskDetachSteps = 13
46+
diskAttachInitDelay = 7 * time.Second
47+
diskAttachFactor = 1.4
48+
diskAttachSteps = 10
49+
diskDetachInitDelay = 7 * time.Second
50+
diskDetachFactor = 1.4
51+
diskDetachSteps = 10
5252
volumeDescription = "Created by OpenStack Cinder CSI driver"
5353
)
5454

@@ -230,6 +230,12 @@ func (os *OpenStack) AttachVolume(ctx context.Context, instanceID, volumeID stri
230230
return "", fmt.Errorf("failed to attach %s volume to %s compute: %v", volumeID, instanceID, err)
231231
}
232232

233+
//redundant waitDiskAttached, workaround for raise condition in backend
234+
err = os.WaitDiskAttached(instanceID, volumeID)
235+
if err != nil {
236+
return "", err
237+
}
238+
233239
return volume.ID, nil
234240
}
235241

@@ -291,6 +297,33 @@ func (os *OpenStack) WaitVolumeTargetStatus(ctx context.Context, volumeID string
291297
return waitErr
292298
}
293299

300+
// WaitVolumeTargetStatusWithCustomBackoff waits for volume to be in target state with custom backoff
301+
func (os *OpenStack) WaitVolumeTargetStatusWithCustomBackoff(volumeID string, tStatus []string, backoff *wait.Backoff) error {
302+
waitErr := wait.ExponentialBackoff(*backoff, func() (bool, error) {
303+
vol, err := os.GetVolume(volumeID)
304+
if err != nil {
305+
return false, err
306+
}
307+
for _, t := range tStatus {
308+
if vol.Status == t {
309+
return true, nil
310+
}
311+
}
312+
for _, eState := range volumeErrorStates {
313+
if vol.Status == eState {
314+
return false, fmt.Errorf("Volume is in Error State : %s", vol.Status)
315+
}
316+
}
317+
return false, nil
318+
})
319+
320+
if waitErr == wait.ErrWaitTimeout {
321+
waitErr = fmt.Errorf("Timeout on waiting for volume %s status to be in %v", volumeID, tStatus)
322+
}
323+
324+
return waitErr
325+
}
326+
294327
// DetachVolume detaches given cinder volume from the compute
295328
func (os *OpenStack) DetachVolume(ctx context.Context, instanceID, volumeID string) error {
296329
volume, err := os.GetVolume(ctx, volumeID)

0 commit comments

Comments
 (0)