-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more nil pointer check for CSI related code in backup controller. (…
…#5388) Add some corner cases checking for CSI snapshot in backup controller. Signed-off-by: Xun Jiang <[email protected]>
- Loading branch information
1 parent
11a7c79
commit 5027aae
Showing
6 changed files
with
279 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add some corner cases checking for CSI snapshot in backup controller. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
Copyright the Velero contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package builder | ||
|
||
import ( | ||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// VolumeSnapshotBuilder builds VolumeSnapshot objects. | ||
type VolumeSnapshotBuilder struct { | ||
object *snapshotv1api.VolumeSnapshot | ||
} | ||
|
||
// ForVolumeSnapshot is the constructor for VolumeSnapshotBuilder. | ||
func ForVolumeSnapshot(ns, name string) *VolumeSnapshotBuilder { | ||
return &VolumeSnapshotBuilder{ | ||
object: &snapshotv1api.VolumeSnapshot{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: snapshotv1api.SchemeGroupVersion.String(), | ||
Kind: "VolumeSnapshot", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: name, | ||
Namespace: ns, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// ObjectMeta applies functional options to the VolumeSnapshot's ObjectMeta. | ||
func (v *VolumeSnapshotBuilder) ObjectMeta(opts ...ObjectMetaOpt) *VolumeSnapshotBuilder { | ||
for _, opt := range opts { | ||
opt(v.object) | ||
} | ||
|
||
return v | ||
} | ||
|
||
// Result return the built VolumeSnapshot. | ||
func (v *VolumeSnapshotBuilder) Result() *snapshotv1api.VolumeSnapshot { | ||
return v.object | ||
} | ||
|
||
// Status init the built VolumeSnapshot's status. | ||
func (v *VolumeSnapshotBuilder) Status() *VolumeSnapshotBuilder { | ||
v.object.Status = &snapshotv1api.VolumeSnapshotStatus{} | ||
return v | ||
} | ||
|
||
// BoundVolumeSnapshotContentName set built VolumeSnapshot's status BoundVolumeSnapshotContentName field. | ||
func (v *VolumeSnapshotBuilder) BoundVolumeSnapshotContentName(vscName string) *VolumeSnapshotBuilder { | ||
v.object.Status.BoundVolumeSnapshotContentName = &vscName | ||
return v | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
Copyright the Velero contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package builder | ||
|
||
import ( | ||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// VolumeSnapshotContentBuilder builds VolumeSnapshotContent object. | ||
type VolumeSnapshotContentBuilder struct { | ||
object *snapshotv1api.VolumeSnapshotContent | ||
} | ||
|
||
// ForVolumeSnapshotContent is the constructor of VolumeSnapshotContentBuilder. | ||
func ForVolumeSnapshotContent(name string) *VolumeSnapshotContentBuilder { | ||
return &VolumeSnapshotContentBuilder{ | ||
object: &snapshotv1api.VolumeSnapshotContent{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: snapshotv1api.SchemeGroupVersion.String(), | ||
Kind: "VolumeSnapshotContent", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: name, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// Result returns the built VolumeSnapshotContent. | ||
func (v *VolumeSnapshotContentBuilder) Result() *snapshotv1api.VolumeSnapshotContent { | ||
return v.object | ||
} | ||
|
||
// Status initiates VolumeSnapshotContent's status. | ||
func (v *VolumeSnapshotContentBuilder) Status() *VolumeSnapshotContentBuilder { | ||
v.object.Status = &snapshotv1api.VolumeSnapshotContentStatus{} | ||
return v | ||
} | ||
|
||
// DeletionPolicy sets built VolumeSnapshotContent's spec.DeletionPolicy value. | ||
func (v *VolumeSnapshotContentBuilder) DeletionPolicy(policy snapshotv1api.DeletionPolicy) *VolumeSnapshotContentBuilder { | ||
v.object.Spec.DeletionPolicy = policy | ||
return v | ||
} | ||
|
||
func (v *VolumeSnapshotContentBuilder) VolumeSnapshotRef(namespace, name string) *VolumeSnapshotContentBuilder { | ||
v.object.Spec.VolumeSnapshotRef = v1.ObjectReference{ | ||
APIVersion: "snapshot.storage.k8s.io/v1", | ||
Kind: "VolumeSnapshot", | ||
Namespace: namespace, | ||
Name: name, | ||
} | ||
return v | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters