Skip to content

Commit

Permalink
Handle status conversion for CronJob/VolumeSnapshot (#1477)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
tamalsaha committed Sep 18, 2022
1 parent fb80667 commit 7c055ae
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ require (
k8s.io/klog/v2 v2.80.1
k8s.io/kube-aggregator v0.25.1
k8s.io/kubernetes v0.0.0-00010101000000-000000000000
kmodules.xyz/client-go v0.25.2
kmodules.xyz/client-go v0.25.3
kmodules.xyz/constants v0.0.0-20220317041001-545c1e31a70a
kmodules.xyz/csi-utils v0.25.0
kmodules.xyz/csi-utils v0.25.1
kmodules.xyz/custom-resources v0.25.0
kmodules.xyz/objectstore-api v0.25.0
kmodules.xyz/offshoot-api v0.25.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1353,12 +1353,12 @@ k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1/go.mod h1:C/N6wCaBHeBHkHU
k8s.io/utils v0.0.0-20200729134348-d5654de09c73/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20220823124924-e9cbc92d1a73 h1:H9TCJUUx+2VA0ZiD9lvtaX8fthFsMoD+Izn93E/hm8U=
k8s.io/utils v0.0.0-20220823124924-e9cbc92d1a73/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
kmodules.xyz/client-go v0.25.2 h1:Uav3RB85b3Pz2dhWI3VQR4XYjSSklpw8EFb88HHpMjI=
kmodules.xyz/client-go v0.25.2/go.mod h1:PQAVWlXoHmk/OXqIuUz3xEW5H04uidiLwVyGX0yYnBQ=
kmodules.xyz/client-go v0.25.3 h1:k/Ua12o/SKqpNsHo9oMbdJWlUBJpfSnHgmewHt9ZINI=
kmodules.xyz/client-go v0.25.3/go.mod h1:PQAVWlXoHmk/OXqIuUz3xEW5H04uidiLwVyGX0yYnBQ=
kmodules.xyz/constants v0.0.0-20220317041001-545c1e31a70a h1:wo6TxmquRJwXXX/HejI6NRyfx13UzuHGjndTumlutbc=
kmodules.xyz/constants v0.0.0-20220317041001-545c1e31a70a/go.mod h1:3C5i73Z7fcMVyu5TXtPuizGD8vWAbesXFVp1ESbIa1k=
kmodules.xyz/csi-utils v0.25.0 h1:7G9n8hd8IfPX/B3JW+/y6pxo0Two/VS0xPK58WA7C9I=
kmodules.xyz/csi-utils v0.25.0/go.mod h1:OapLAHRlPZL2cMy0CsyJ/9aMkR6tno11eP/qBFnUqC0=
kmodules.xyz/csi-utils v0.25.1 h1:nawNvZHflavV7ARDZu7CH0KNUmx5hKtbWKp6ORGrtC8=
kmodules.xyz/csi-utils v0.25.1/go.mod h1:GL/DCW8gkFiyzwYJ82uMRqQY+O2tWyskZsgzIAxyk80=
kmodules.xyz/custom-resources v0.25.0 h1:5JQTEuiv6lC/+VVFNKqzfX4YtJCmN5E7mcNtGnHGVQM=
kmodules.xyz/custom-resources v0.25.0/go.mod h1:ULwzvLmOqZJcPSXKI7iLclYL5eYRlKx8Nbex28Ht19E=
kmodules.xyz/objectstore-api v0.25.0 h1:xT7+SXBqAMtVkfOdp4espHAfZ6MYUC4G1OgzTkURNnU=
Expand Down
46 changes: 42 additions & 4 deletions vendor/kmodules.xyz/csi-utils/volumesnapshot/volumesnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func CreateOrPatchVolumeSnapshot(ctx context.Context, c cs.Interface, meta metav
c,
meta,
func(in *apiv1beta1.VolumeSnapshot) *apiv1beta1.VolumeSnapshot {
out := convert_v1_to_v1beta1(transform(convert_v1beta1_to_v1(in)))
out := convert_spec_v1_to_v1beta1(transform(convert_spec_v1beta1_to_v1(in)))
out.Status = in.Status
return out
},
Expand All @@ -45,7 +45,7 @@ func CreateVolumeSnapshot(ctx context.Context, c cs.Interface, in *apiv1.VolumeS
if discovery.ExistsGroupVersionKind(c.Discovery(), apiv1.SchemeGroupVersion.String(), kindVolumeSnapshot) {
return c.SnapshotV1().VolumeSnapshots(in.Namespace).Create(ctx, in, metav1.CreateOptions{})
}
result, err := c.SnapshotV1beta1().VolumeSnapshots(in.Namespace).Create(ctx, convert_v1_to_v1beta1(in), metav1.CreateOptions{})
result, err := c.SnapshotV1beta1().VolumeSnapshots(in.Namespace).Create(ctx, convert_spec_v1_to_v1beta1(in), metav1.CreateOptions{})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -107,7 +107,7 @@ func WaitUntilVolumeSnapshotReady(c cs.Interface, meta types.NamespacedName) err
})
}

func convert_v1beta1_to_v1(in *apiv1beta1.VolumeSnapshot) *apiv1.VolumeSnapshot {
func convert_spec_v1beta1_to_v1(in *apiv1beta1.VolumeSnapshot) *apiv1.VolumeSnapshot {
return &apiv1.VolumeSnapshot{
TypeMeta: metav1.TypeMeta{
Kind: in.Kind,
Expand All @@ -124,7 +124,26 @@ func convert_v1beta1_to_v1(in *apiv1beta1.VolumeSnapshot) *apiv1.VolumeSnapshot
}
}

func convert_v1_to_v1beta1(in *apiv1.VolumeSnapshot) *apiv1beta1.VolumeSnapshot {
func convert_v1beta1_to_v1(in *apiv1beta1.VolumeSnapshot) *apiv1.VolumeSnapshot {
out := convert_spec_v1beta1_to_v1(in)
if in.Status != nil {
out.Status = &apiv1.VolumeSnapshotStatus{
BoundVolumeSnapshotContentName: in.Status.BoundVolumeSnapshotContentName,
CreationTime: in.Status.CreationTime,
ReadyToUse: in.Status.ReadyToUse,
RestoreSize: in.Status.RestoreSize,
}
if in.Status.Error != nil {
out.Status.Error = &apiv1.VolumeSnapshotError{
Time: in.Status.Error.Time,
Message: in.Status.Error.Message,
}
}
}
return out
}

func convert_spec_v1_to_v1beta1(in *apiv1.VolumeSnapshot) *apiv1beta1.VolumeSnapshot {
return &apiv1beta1.VolumeSnapshot{
TypeMeta: metav1.TypeMeta{
Kind: in.Kind,
Expand All @@ -140,3 +159,22 @@ func convert_v1_to_v1beta1(in *apiv1.VolumeSnapshot) *apiv1beta1.VolumeSnapshot
},
}
}

func convert_v1_to_v1beta1(in *apiv1.VolumeSnapshot) *apiv1beta1.VolumeSnapshot {
out := convert_spec_v1_to_v1beta1(in)
if in.Status != nil {
out.Status = &apiv1beta1.VolumeSnapshotStatus{
BoundVolumeSnapshotContentName: in.Status.BoundVolumeSnapshotContentName,
CreationTime: in.Status.CreationTime,
ReadyToUse: in.Status.ReadyToUse,
RestoreSize: in.Status.RestoreSize,
}
if in.Status.Error != nil {
out.Status.Error = &apiv1beta1.VolumeSnapshotError{
Time: in.Status.Error.Time,
Message: in.Status.Error.Message,
}
}
}
return out
}
4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ k8s.io/utils/path
k8s.io/utils/pointer
k8s.io/utils/strings/slices
k8s.io/utils/trace
# kmodules.xyz/client-go v0.25.2
# kmodules.xyz/client-go v0.25.3
## explicit; go 1.18
kmodules.xyz/client-go
kmodules.xyz/client-go/admissionregistration
Expand Down Expand Up @@ -1576,7 +1576,7 @@ kmodules.xyz/constants/aws
kmodules.xyz/constants/azure
kmodules.xyz/constants/google
kmodules.xyz/constants/openstack
# kmodules.xyz/csi-utils v0.25.0
# kmodules.xyz/csi-utils v0.25.1
## explicit; go 1.18
kmodules.xyz/csi-utils/volumesnapshot
kmodules.xyz/csi-utils/volumesnapshot/v1
Expand Down

0 comments on commit 7c055ae

Please sign in to comment.