ceph: nits from https://github.com/rook/rook/pull/4679
- Use %q when possible - don't use fmt.Errorf - use the right type when returning errors Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
1 parent
6a5d958236
commit
2e9ee105ed
2 files changed
+17
-17
No files matched your search
@@ -44,7 +44,7 @@ func (r *ReconcileClusterDisruption) processPools(request reconcile.Request) (*c
|
||||
cephBlockPoolList := &cephv1.CephBlockPoolList{}
|
||||
err := r.client.List(context.TODO(), cephBlockPoolList, namespaceListOpt)
|
||||
if err != nil {
|
||||
return nil, nil, "", poolCount, errors.Wrapf(err, "could not list the CephBlockpools %s", request.NamespacedName)
|
||||
return nil, nil, "", poolCount, errors.Wrapf(err, "could not list the CephBlockpools %v", request.NamespacedName)
|
||||
}
|
||||
poolCount += len(cephBlockPoolList.Items)
|
||||
for _, cephBlockPool := range cephBlockPoolList.Items {
|
||||
@@ -54,7 +54,7 @@ func (r *ReconcileClusterDisruption) processPools(request reconcile.Request) (*c
|
||||
cephFilesystemList := &cephv1.CephFilesystemList{}
|
||||
err = r.client.List(context.TODO(), cephFilesystemList, namespaceListOpt)
|
||||
if err != nil {
|
||||
return nil, nil, "", poolCount, errors.Wrapf(err, "could not list the CephFilesystems %s", request.NamespacedName)
|
||||
return nil, nil, "", poolCount, errors.Wrapf(err, "could not list the CephFilesystems %v", request.NamespacedName)
|
||||
}
|
||||
poolCount += len(cephFilesystemList.Items)
|
||||
for _, cephFilesystem := range cephFilesystemList.Items {
|
||||
@@ -66,7 +66,7 @@ func (r *ReconcileClusterDisruption) processPools(request reconcile.Request) (*c
|
||||
cephObjectStoreList := &cephv1.CephObjectStoreList{}
|
||||
err = r.client.List(context.TODO(), cephObjectStoreList, namespaceListOpt)
|
||||
if err != nil {
|
||||
return nil, nil, "", poolCount, errors.Wrapf(err, "could not list the CephObjectStores %s", request.NamespacedName)
|
||||
return nil, nil, "", poolCount, errors.Wrapf(err, "could not list the CephObjectStores %v", request.NamespacedName)
|
||||
}
|
||||
poolCount += len(cephObjectStoreList.Items)
|
||||
for _, cephObjectStore := range cephObjectStoreList.Items {
|
||||
@@ -115,7 +115,7 @@ func (r *ReconcileClusterDisruption) getOngoingDrains(request reconcile.Request)
|
||||
operatorNameSpaceListOpts := client.InNamespace(request.Namespace)
|
||||
err := r.client.List(context.TODO(), canaryDeploymentList, client.MatchingLabels{k8sutil.AppAttr: nodedrain.CanaryAppName}, operatorNameSpaceListOpts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "could not list canary deployments")
|
||||
return nil, errors.Wrap(err, "could not list canary deployments")
|
||||
}
|
||||
|
||||
ongoingDrains := make([]*corev1.Node, 0)
|
||||
@@ -132,10 +132,10 @@ func (r *ReconcileClusterDisruption) getOngoingDrains(request reconcile.Request)
|
||||
if err != nil {
|
||||
return nil, errors.Errorf("could not get node: %s ", nodeHostname)
|
||||
} else if len(nodeList.Items) < 1 {
|
||||
logger.Infof("node %s does not exist, deleting corresponding drain-canary", nodeHostname)
|
||||
logger.Infof("node %q does not exist, deleting corresponding drain-canary", nodeHostname)
|
||||
err = r.client.DeleteAllOf(context.TODO(), &appsv1.Deployment{}, client.MatchingLabels{corev1.LabelHostname: nodeHostname, k8sutil.AppAttr: nodedrain.CanaryAppName})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not delete drain-canary for host %s: %+v", nodeHostname, err)
|
||||
return nil, errors.Wrapf(err, "could not delete drain-canary for host %q", nodeHostname)
|
||||
}
|
||||
} else if len(nodeList.Items) > 1 {
|
||||
logger.Warningf("found more than one node with %s=%s", corev1.LabelHostname, nodeHostname)
|
||||
@@ -185,7 +185,7 @@ func (r *ReconcileClusterDisruption) reconcileCephObjectStore(cephObjectStoreLis
|
||||
request := types.NamespacedName{Name: pdbName, Namespace: namespace}
|
||||
err := r.reconcileStaticPDB(request, pdb)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not reconcile cephobjectstore pdb %s", request)
|
||||
return errors.Wrapf(err, "could not reconcile cephobjectstore pdb %v", request)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -234,7 +234,7 @@ func (r *ReconcileClusterDisruption) reconcileCephFilesystem(cephFilesystemList
|
||||
request := types.NamespacedName{Name: pdbName, Namespace: namespace}
|
||||
err := r.reconcileStaticPDB(request, pdb)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not reconcile cephfs pdb %s", request)
|
||||
return errors.Wrapf(err, "could not reconcile cephfs pdb %v", request)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -75,7 +75,7 @@ func (r *ReconcileNode) reconcile(request reconcile.Request) (reconcile.Result,
|
||||
return reconcile.Result{}, nil
|
||||
}
|
||||
|
||||
logger.Debugf("reconciling node: %s", request.Name)
|
||||
logger.Debugf("reconciling node: %q", request.Name)
|
||||
|
||||
// Create or Update the deployment default/foo
|
||||
deploy := &appsv1.Deployment{
|
||||
@@ -90,10 +90,10 @@ func (r *ReconcileNode) reconcile(request reconcile.Request) (reconcile.Result,
|
||||
err := r.client.Get(context.TODO(), request.NamespacedName, node)
|
||||
if kerrors.IsNotFound(err) {
|
||||
// delete any canary deployments if the node doesn't exist
|
||||
logger.Infof("deleting drain-canary deployment for deleted node %s", request.Name)
|
||||
logger.Infof("deleting drain-canary deployment for deleted node %q", request.Name)
|
||||
err = r.client.Delete(context.TODO(), deploy)
|
||||
if err != nil {
|
||||
return reconcile.Result{}, fmt.Errorf("could not delete drain-canary deployment for deleted node %s: %+v", request.Name, err)
|
||||
return reconcile.Result{}, errors.Wrapf(err, "could not delete drain-canary deployment for deleted node %q", request.Name)
|
||||
}
|
||||
return reconcile.Result{}, nil
|
||||
} else if err != nil {
|
||||
@@ -102,13 +102,13 @@ func (r *ReconcileNode) reconcile(request reconcile.Request) (reconcile.Result,
|
||||
|
||||
nodeHostnameLabel, ok := node.ObjectMeta.Labels[corev1.LabelHostname]
|
||||
if !ok {
|
||||
return reconcile.Result{}, errors.Errorf("Label key %s does not exist on node %s", corev1.LabelHostname, request.NamespacedName)
|
||||
return reconcile.Result{}, errors.Errorf("Label key %q does not exist on node %q", corev1.LabelHostname, request.NamespacedName)
|
||||
}
|
||||
|
||||
osdPodList := &corev1.PodList{}
|
||||
err = r.client.List(context.TODO(), osdPodList, client.MatchingLabels{k8sutil.AppAttr: osd.AppName})
|
||||
if err != nil {
|
||||
return reconcile.Result{}, errors.Wrapf(err, "could not list the osd pods")
|
||||
return reconcile.Result{}, errors.Wrap(err, "could not list the osd pods")
|
||||
}
|
||||
|
||||
// map with tolerations as keys and empty struct as values for uniqueness
|
||||
@@ -212,16 +212,16 @@ func (r *ReconcileNode) reconcile(request reconcile.Request) (reconcile.Result,
|
||||
if occupiedByOSD {
|
||||
op, err := controllerutil.CreateOrUpdate(context.TODO(), r.client, deploy, mutateFunc)
|
||||
if err != nil {
|
||||
return reconcile.Result{}, errors.Wrapf(err, "node reconcile failed on op %s", op)
|
||||
return reconcile.Result{}, errors.Wrapf(err, "node reconcile failed on op %q", op)
|
||||
}
|
||||
msg := fmt.Sprintf("deployment successfully reconciled for node %s. operation: %s", request.Name, op)
|
||||
msg := fmt.Sprintf("deployment successfully reconciled for node %q. operation: %q", request.Name, op)
|
||||
if op == controllerutil.OperationResultCreated {
|
||||
logger.Info(msg)
|
||||
} else {
|
||||
logger.Debug(msg)
|
||||
}
|
||||
} else {
|
||||
logger.Debugf("not watching for drains on node %s as there are no osds running there.", request.Name)
|
||||
logger.Debugf("not watching for drains on node %q as there are no osds running there.", request.Name)
|
||||
|
||||
// get the canary deployment
|
||||
canarayDeployment := &appsv1.Deployment{}
|
||||
@@ -236,7 +236,7 @@ func (r *ReconcileNode) reconcile(request reconcile.Request) (reconcile.Result,
|
||||
// delete the canary deployments that aren't triggered by drains, but are on nodes that aren't occupied by OSDs
|
||||
// if it's on a draining node, we don't want to kill the canary.
|
||||
if canarayDeployment.Status.ReadyReplicas > 0 {
|
||||
logger.Infof("deleting drain-canary deployment on node %s as OSDs are no longer scheduled here", request.Name)
|
||||
logger.Infof("deleting drain-canary deployment on node %q as OSDs are no longer scheduled here", request.Name)
|
||||
err := r.client.Delete(context.TODO(), canarayDeployment)
|
||||
if err != nil {
|
||||
return reconcile.Result{}, errors.Wrapf(err, "could not delete deployment %q", key)
|
||||
|
||||
Reference in new issue
Block a user