Skip to content

Commit ba5e7fa

Browse files
committed
Drop support for v1beta1 ConversionReview requests
Signed-off-by: Leonardo Cecchi <[email protected]>
1 parent 6815d03 commit ba5e7fa

File tree

7 files changed

+17
-63
lines changed

7 files changed

+17
-63
lines changed

client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshotcontents.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ spec:
2020
conversion:
2121
strategy: Webhook
2222
webhook:
23-
conversionReviewVersions: ["v1","v1beta1"]
23+
conversionReviewVersions: ["v1"]
2424
clientConfig:
2525
service:
2626
namespace: default

deploy/kubernetes/webhook-example/create-cert.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ fi
5353

5454
csrName=${service}.${namespace}
5555
tmpdir=$(mktemp -d)
56+
trap 'rm -r -- "${tmpdir}"' EXIT
57+
5658
echo "creating certs in tmpdir ${tmpdir} "
5759

5860
cat <<EOF >> ${tmpdir}/csr.conf

deploy/kubernetes/webhook-example/patch-ca-bundle.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ set -o errexit
77
set -o nounset
88
set -o pipefail
99

10-
CA_BUNDLE=$(kubectl config view --raw -o json | jq -r '.clusters[0].cluster."certificate-authority-data"' | tr -d '"')
10+
CA_BUNDLE=$( kubectl get secret snapshot-conversion-webhook-secret -o json | jq -r '.data."tls.crt"' )
1111
JSON_PATCH="{\"spec\":{\"conversion\": {\"webhook\": {\"clientConfig\": {\"caBundle\": \"${CA_BUNDLE}\"}}}}}"
1212

13-
kubectl patch crd volumegroupsnapshotclasses.groupsnapshot.storage.k8s.io -p "${JSON_PATCH}"
1413
kubectl patch crd volumegroupsnapshotcontents.groupsnapshot.storage.k8s.io -p "${JSON_PATCH}"
15-
kubectl patch crd volumegroupsnapshots.groupsnapshot.storage.k8s.io -p "${JSON_PATCH}"

pkg/sidecar-controller/groupsnapshot_helper.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,9 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus(
603603
newStatus.VolumeSnapshotInfoList = append(newStatus.VolumeSnapshotInfoList, crdv1beta2.VolumeSnapshotInfo{
604604
VolumeHandle: snapshot.SourceVolumeId,
605605
SnapshotHandle: snapshot.SnapshotId,
606-
CreationTime: utils.CsiTimestampToKubernetes(snapshot.CreationTime),
606+
CreationTime: utils.CSITimestampToKubernetes(snapshot.CreationTime),
607607
ReadyToUse: &snapshot.ReadyToUse,
608-
RestoreSize: utils.CsiSizeToKubernetes(snapshot.SizeBytes),
608+
RestoreSize: utils.CSISizeToKubernetes(snapshot.SizeBytes),
609609
})
610610
}
611611

@@ -632,9 +632,9 @@ func (ctrl *csiSnapshotSideCarController) updateGroupSnapshotContentStatus(
632632
newStatus.VolumeSnapshotInfoList = append(newStatus.VolumeSnapshotInfoList, crdv1beta2.VolumeSnapshotInfo{
633633
VolumeHandle: snapshot.SourceVolumeId,
634634
SnapshotHandle: snapshot.SnapshotId,
635-
CreationTime: utils.CsiTimestampToKubernetes(snapshot.CreationTime),
635+
CreationTime: utils.CSITimestampToKubernetes(snapshot.CreationTime),
636636
ReadyToUse: &snapshot.ReadyToUse,
637-
RestoreSize: utils.CsiSizeToKubernetes(snapshot.SizeBytes),
637+
RestoreSize: utils.CSISizeToKubernetes(snapshot.SizeBytes),
638638
})
639639
}
640640
updated = true

pkg/utils/conversion.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ package utils
1818

1919
import "google.golang.org/protobuf/types/known/timestamppb"
2020

21-
// CsiTimestampToKubernetes converts a CSI timestamp in the format
21+
// CSITimestampToKubernetes converts a CSI timestamp in the format
2222
// used by the Snapshot API
23-
func CsiTimestampToKubernetes(creationTime *timestamppb.Timestamp) *int64 {
23+
func CSITimestampToKubernetes(creationTime *timestamppb.Timestamp) *int64 {
2424
if creationTime == nil {
2525
return nil
2626
}
@@ -29,9 +29,9 @@ func CsiTimestampToKubernetes(creationTime *timestamppb.Timestamp) *int64 {
2929
return &result
3030
}
3131

32-
// CsiSizeToKubernetes converts the size to the format used by
32+
// CSISizeToKubernetes converts the size to the format used by
3333
// the Snapshot API
34-
func CsiSizeToKubernetes(sizeBytes int64) *int64 {
34+
func CSISizeToKubernetes(sizeBytes int64) *int64 {
3535
if sizeBytes == 0 {
3636
return nil
3737
}

pkg/utils/conversion_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ import (
2323
)
2424

2525
func TestCsiSizeToKubernetes(t *testing.T) {
26-
if CsiSizeToKubernetes(0) != nil {
26+
if CSISizeToKubernetes(0) != nil {
2727
t.Error("Expected nil")
2828
}
2929

30-
if *CsiSizeToKubernetes(123) != 123 {
30+
if *CSISizeToKubernetes(123) != 123 {
3131
t.Error("Wrong size conversion")
3232
}
3333
}
3434

3535
func TestCsiTimestampToKubernetes(t *testing.T) {
36-
if CsiTimestampToKubernetes(nil) != nil {
36+
if CSITimestampToKubernetes(nil) != nil {
3737
t.Error("Expected nil")
3838
}
3939

4040
now := timestamppb.Now()
41-
if *CsiTimestampToKubernetes(now) != now.AsTime().UnixNano() {
41+
if *CSITimestampToKubernetes(now) != now.AsTime().UnixNano() {
4242
t.Error("Expected correct time conversion")
4343
}
4444
}

pkg/webhook/framework.go

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
)
4040

4141
// convertFunc is the user defined function for any conversion. The code in this file is a
42-
// template that can be use for any CR conversion given this function.
42+
// template that can be used for any CR conversion given this function.
4343
type convertFunc func(Object *unstructured.Unstructured, version string) (*unstructured.Unstructured, metav1.Status)
4444

4545
func statusErrorWithMessage(msg string, params ...interface{}) metav1.Status {
@@ -55,37 +55,6 @@ func statusSucceed() metav1.Status {
5555
}
5656
}
5757

58-
// doConversionV1beta1 converts the requested objects in the v1beta1 ConversionRequest using the given conversion function and
59-
// returns a conversion response. Failures are reported with the Reason in the conversion response.
60-
func doConversionV1beta1(convertRequest *v1beta1.ConversionRequest, convert convertFunc) *v1beta1.ConversionResponse {
61-
var convertedObjects []runtime.RawExtension
62-
for _, obj := range convertRequest.Objects {
63-
cr := unstructured.Unstructured{}
64-
if err := cr.UnmarshalJSON(obj.Raw); err != nil {
65-
klog.Error(err)
66-
return &v1beta1.ConversionResponse{
67-
Result: metav1.Status{
68-
Message: fmt.Sprintf("failed to unmarshall object (%v) with error: %v", string(obj.Raw), err),
69-
Status: metav1.StatusFailure,
70-
},
71-
}
72-
}
73-
convertedCR, status := convert(&cr, convertRequest.DesiredAPIVersion)
74-
if status.Status != metav1.StatusSuccess {
75-
klog.Error(status.String())
76-
return &v1beta1.ConversionResponse{
77-
Result: status,
78-
}
79-
}
80-
convertedCR.SetAPIVersion(convertRequest.DesiredAPIVersion)
81-
convertedObjects = append(convertedObjects, runtime.RawExtension{Object: convertedCR})
82-
}
83-
return &v1beta1.ConversionResponse{
84-
ConvertedObjects: convertedObjects,
85-
Result: statusSucceed(),
86-
}
87-
}
88-
8958
// doConversionV1 converts the requested objects in the v1 ConversionRequest using the given conversion function and
9059
// returns a conversion response. Failures are reported with the Reason in the conversion response.
9160
func doConversionV1(convertRequest *v1.ConversionRequest, convert convertFunc) *v1.ConversionResponse {
@@ -145,21 +114,6 @@ func serve(w http.ResponseWriter, r *http.Request, convert convertFunc) {
145114

146115
var responseObj runtime.Object
147116
switch *gvk {
148-
case v1beta1.SchemeGroupVersion.WithKind("ConversionReview"):
149-
convertReview, ok := obj.(*v1beta1.ConversionReview)
150-
if !ok {
151-
msg := fmt.Sprintf("Expected v1beta1.ConversionReview but got: %T", obj)
152-
klog.Errorf("%s", msg)
153-
http.Error(w, msg, http.StatusBadRequest)
154-
return
155-
}
156-
convertReview.Response = doConversionV1beta1(convertReview.Request, convert)
157-
convertReview.Response.UID = convertReview.Request.UID
158-
klog.V(2).Info(fmt.Sprintf("sending response: %v", convertReview.Response))
159-
160-
// reset the request, it is not needed in a response.
161-
convertReview.Request = &v1beta1.ConversionRequest{}
162-
responseObj = convertReview
163117
case v1.SchemeGroupVersion.WithKind("ConversionReview"):
164118
convertReview, ok := obj.(*v1.ConversionReview)
165119
if !ok {

0 commit comments

Comments
 (0)