Skip to content

Commit e4a0146

Browse files
robinschneiderDuciwuci
authored andcommitted
Cherrypick SKE changes
1 parent 63ec67a commit e4a0146

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
@@ -23,6 +23,7 @@ import (
2323
"slices"
2424
"sort"
2525
"strconv"
26+
"time"
2627

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

3739
sharedcsi "k8s.io/cloud-provider-openstack/pkg/csi"
3840
"k8s.io/cloud-provider-openstack/pkg/csi/cinder/openstack"
@@ -117,6 +119,10 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
117119
if volSizeGB != vols[0].Size {
118120
return nil, status.Error(codes.AlreadyExists, "Volume Already exists with same name and different capacity")
119121
}
122+
123+
if volumes[0].Status != openstack.VolumeAvailableStatus {
124+
return nil, status.Error(codes.Internal, fmt.Sprintf("Volume %s is not in available state", volumes[0].ID))
125+
}
120126
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)
121127
accessibleTopology := getTopology(&vols[0], accessibleTopologyReq, cs.Driver.withTopology, ignoreVolumeAZ)
122128
return getCreateVolumeResponse(&vols[0], nil, accessibleTopology), nil
@@ -247,6 +253,23 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
247253
vol.BackupID = &sourceBackupID
248254
}
249255

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

252275
accessibleTopology := getTopology(vol, accessibleTopologyReq, cs.Driver.withTopology, ignoreVolumeAZ)

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
@@ -47,12 +47,12 @@ const (
4747
operationFinishInitDelay = 1 * time.Second
4848
operationFinishFactor = 1.1
4949
operationFinishSteps = 10
50-
diskAttachInitDelay = 1 * time.Second
51-
diskAttachFactor = 1.2
52-
diskAttachSteps = 15
53-
diskDetachInitDelay = 1 * time.Second
54-
diskDetachFactor = 1.2
55-
diskDetachSteps = 13
50+
diskAttachInitDelay = 7 * time.Second
51+
diskAttachFactor = 1.4
52+
diskAttachSteps = 10
53+
diskDetachInitDelay = 7 * time.Second
54+
diskDetachFactor = 1.4
55+
diskDetachSteps = 10
5656
volumeDescription = "Created by OpenStack Cinder CSI driver"
5757
)
5858

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

240+
//redundant waitDiskAttached, workaround for raise condition in backend
241+
err = os.WaitDiskAttached(instanceID, volumeID)
242+
if err != nil {
243+
return "", err
244+
}
245+
240246
return volume.ID, nil
241247
}
242248

@@ -298,6 +304,33 @@ func (os *OpenStack) WaitVolumeTargetStatus(ctx context.Context, volumeID string
298304
return waitErr
299305
}
300306

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

0 commit comments

Comments
 (0)