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:
1 parent
ffc029f6fe
commit
b6a8a094ce
1 file changed
+15
-3
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user