Skip to content

Commit 7d4f284

Browse files
Cherrypick SKE changes
1 parent 64b8130 commit 7d4f284

File tree

5 files changed

+119
-49
lines changed

5 files changed

+119
-49
lines changed

Dockerfile

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

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

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

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

pkg/csi/cinder/controllerserver.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ limitations under the License.
1717
package cinder
1818

1919
import (
20+
"fmt"
2021
"strconv"
22+
"time"
2123

2224
"github.com/container-storage-interface/spec/lib/go/csi"
2325
"github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots"
@@ -27,6 +29,7 @@ import (
2729
"google.golang.org/grpc/codes"
2830
"google.golang.org/grpc/status"
2931
"google.golang.org/protobuf/types/known/timestamppb"
32+
"k8s.io/apimachinery/pkg/util/wait"
3033

3134
"k8s.io/cloud-provider-openstack/pkg/csi/cinder/openstack"
3235
"k8s.io/cloud-provider-openstack/pkg/util"
@@ -92,6 +95,10 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
9295
if volSizeGB != volumes[0].Size {
9396
return nil, status.Error(codes.AlreadyExists, "Volume Already exists with same name and different capacity")
9497
}
98+
99+
if volumes[0].Status != openstack.VolumeAvailableStatus {
100+
return nil, status.Error(codes.Internal, fmt.Sprintf("Volume %s is not in available state", volumes[0].ID))
101+
}
95102
klog.V(4).Infof("Volume %s already exists in Availability Zone: %s of size %d GiB", volumes[0].ID, volumes[0].AvailabilityZone, volumes[0].Size)
96103
return getCreateVolumeResponse(&volumes[0], ignoreVolumeAZ, req.GetAccessibilityRequirements()), nil
97104
} else if len(volumes) > 1 {
@@ -142,6 +149,18 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
142149

143150
}
144151

152+
targetStatus := []string{openstack.VolumeAvailableStatus}
153+
err = cloud.WaitVolumeTargetStatusWithCustomBackoff(vol.ID, targetStatus,
154+
&wait.Backoff{
155+
Duration: 20 * time.Second,
156+
Steps: 5,
157+
Factor: 1.28,
158+
})
159+
if err != nil {
160+
klog.Errorf("Failed to WaitVolumeTargetStatus of volume %s: %v", vol.ID, err)
161+
return nil, status.Error(codes.Internal, fmt.Sprintf("CreateVolume Volume %s failed getting available in time: %v", vol.ID, err))
162+
}
163+
145164
klog.V(4).Infof("CreateVolume: Successfully created volume %s in Availability Zone: %s of size %d GiB", vol.ID, vol.AvailabilityZone, vol.Size)
146165

147166
return getCreateVolumeResponse(vol, ignoreVolumeAZ, req.GetAccessibilityRequirements()), nil

pkg/csi/cinder/openstack/openstack.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
2929
"github.com/spf13/pflag"
3030
gcfg "gopkg.in/gcfg.v1"
31+
"k8s.io/apimachinery/pkg/util/wait"
3132
"k8s.io/cloud-provider-openstack/pkg/client"
3233
"k8s.io/cloud-provider-openstack/pkg/metrics"
3334
"k8s.io/cloud-provider-openstack/pkg/util/metadata"
@@ -52,6 +53,7 @@ type IOpenStack interface {
5253
DetachVolume(instanceID, volumeID string) error
5354
WaitDiskDetached(instanceID string, volumeID string) error
5455
WaitVolumeTargetStatus(volumeID string, tStatus []string) error
56+
WaitVolumeTargetStatusWithCustomBackoff(volumeID string, tStatus []string, backoff *wait.Backoff) error
5557
GetAttachmentDiskPath(instanceID, volumeID string) (string, error)
5658
GetVolume(volumeID string) (*volumes.Volume, error)
5759
GetVolumesByName(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
@@ -21,6 +21,7 @@ import (
2121
"github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes"
2222
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
2323
"github.com/stretchr/testify/mock"
24+
"k8s.io/apimachinery/pkg/util/wait"
2425
"k8s.io/cloud-provider-openstack/pkg/util/metadata"
2526
)
2627

@@ -174,6 +175,20 @@ func (_m *OpenStackMock) WaitVolumeTargetStatus(volumeID string, tStatus []strin
174175
return r0
175176
}
176177

178+
// WaitVolumeTargetStatusWithCustomBackoff provides a mock function with given fields: volumeID, tStatus, backoff
179+
func (_m *OpenStackMock) WaitVolumeTargetStatusWithCustomBackoff(volumeID string, tStatus []string, backoff *wait.Backoff) error {
180+
ret := _m.Called(volumeID, tStatus, backoff)
181+
182+
var r0 error
183+
if rf, ok := ret.Get(0).(func(string, []string, *wait.Backoff) error); ok {
184+
r0 = rf(volumeID, tStatus, backoff)
185+
} else {
186+
r0 = ret.Error(0)
187+
}
188+
189+
return r0
190+
}
191+
177192
// WaitDiskDetached provides a mock function with given fields: instanceID, volumeID
178193
func (_m *OpenStackMock) WaitDiskDetached(instanceID string, volumeID string) error {
179194
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
@@ -39,12 +39,12 @@ const (
3939
operationFinishInitDelay = 1 * time.Second
4040
operationFinishFactor = 1.1
4141
operationFinishSteps = 10
42-
diskAttachInitDelay = 1 * time.Second
43-
diskAttachFactor = 1.2
44-
diskAttachSteps = 15
45-
diskDetachInitDelay = 1 * time.Second
46-
diskDetachFactor = 1.2
47-
diskDetachSteps = 13
42+
diskAttachInitDelay = 7 * time.Second
43+
diskAttachFactor = 1.4
44+
diskAttachSteps = 10
45+
diskDetachInitDelay = 7 * time.Second
46+
diskDetachFactor = 1.4
47+
diskDetachSteps = 10
4848
volumeDescription = "Created by OpenStack Cinder CSI driver"
4949
)
5050

@@ -203,6 +203,12 @@ func (os *OpenStack) AttachVolume(instanceID, volumeID string) (string, error) {
203203
return "", fmt.Errorf("failed to attach %s volume to %s compute: %v", volumeID, instanceID, err)
204204
}
205205

206+
//redundant waitDiskAttached, workaround for raise condition in backend
207+
err = os.WaitDiskAttached(instanceID, volumeID)
208+
if err != nil {
209+
return "", err
210+
}
211+
206212
return volume.ID, nil
207213
}
208214

@@ -264,6 +270,33 @@ func (os *OpenStack) WaitVolumeTargetStatus(volumeID string, tStatus []string) e
264270
return waitErr
265271
}
266272

273+
// WaitVolumeTargetStatusWithCustomBackoff waits for volume to be in target state with custom backoff
274+
func (os *OpenStack) WaitVolumeTargetStatusWithCustomBackoff(volumeID string, tStatus []string, backoff *wait.Backoff) error {
275+
waitErr := wait.ExponentialBackoff(*backoff, func() (bool, error) {
276+
vol, err := os.GetVolume(volumeID)
277+
if err != nil {
278+
return false, err
279+
}
280+
for _, t := range tStatus {
281+
if vol.Status == t {
282+
return true, nil
283+
}
284+
}
285+
for _, eState := range volumeErrorStates {
286+
if vol.Status == eState {
287+
return false, fmt.Errorf("Volume is in Error State : %s", vol.Status)
288+
}
289+
}
290+
return false, nil
291+
})
292+
293+
if waitErr == wait.ErrWaitTimeout {
294+
waitErr = fmt.Errorf("Timeout on waiting for volume %s status to be in %v", volumeID, tStatus)
295+
}
296+
297+
return waitErr
298+
}
299+
267300
// DetachVolume detaches given cinder volume from the compute
268301
func (os *OpenStack) DetachVolume(instanceID, volumeID string) error {
269302
volume, err := os.GetVolume(volumeID)

0 commit comments

Comments
 (0)