Cockroachdb: fixes unhandled type assertions

unhandled type assertions can lead to runtime panic. using
the boolean 'ok' flag to handle failure to assert type.

Issue: #4566
Signed-off-by: Umanga Chapagain <chapagainumanga@gmail.com>
This commit is contained in:
Umanga Chapagain committed 2020-04-04 14:00:42 +05:30
1 parent ffc029f6fe
commit b6a8a094ce
1 file changed
+15 -3
+15 -3
View File
@@ -123,7 +123,11 @@ func (c *ClusterController) StartWatch(namespace string, stopCh chan struct{}) {
}
func (c *ClusterController) onAdd(obj interface{}) {
clusterObj := obj.(*cockroachdbv1alpha1.Cluster).DeepCopy()
clusterObj, ok := obj.(*cockroachdbv1alpha1.Cluster)
if !ok {
return
}
clusterObj = clusterObj.DeepCopy()
logger.Infof("new cluster %s added to namespace %s", clusterObj.Name, clusterObj.Namespace)
cluster := newCluster(clusterObj, c.context)
@@ -176,8 +180,16 @@ func (c *ClusterController) onAdd(obj interface{}) {
}
func (c *ClusterController) onUpdate(oldObj, newObj interface{}) {
_ = oldObj.(*cockroachdbv1alpha1.Cluster).DeepCopy()
newCluster := newObj.(*cockroachdbv1alpha1.Cluster).DeepCopy()
oldCluster, ok := oldObj.(*cockroachdbv1alpha1.Cluster)
if !ok {
return
}
_ = oldCluster.DeepCopy()
newCluster, ok := newObj.(*cockroachdbv1alpha1.Cluster)
if !ok {
return
}
newCluster = newCluster.DeepCopy()
logger.Infof("cluster %s updated in namespace %s", newCluster.Name, newCluster.Namespace)
}