From 41c567beafa7ad35024eabe2dbcd4803aacc9a17 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Tue, 13 Apr 2021 02:02:09 -0700 Subject: [PATCH] ceph: fix multiple imports This fixes additional double-imports. Signed-off-by: Lars Lehtonen --- pkg/operator/ceph/client/controller.go | 9 ++++---- .../ceph/config/keyring/store_test.go | 7 +++--- pkg/operator/ceph/controller/spec_test.go | 22 +++++++++---------- .../ceph/disruption/clusterdisruption/osd.go | 10 ++++----- .../disruption/clusterdisruption/osd_test.go | 3 +-- pkg/operator/ceph/nfs/nfs.go | 3 +-- pkg/operator/ceph/nfs/spec_test.go | 3 +-- pkg/operator/ceph/pool/validate.go | 3 +-- pkg/operator/ceph/provisioner/provisioner.go | 7 +++--- 9 files changed, 28 insertions(+), 39 deletions(-) diff --git a/pkg/operator/ceph/client/controller.go b/pkg/operator/ceph/client/controller.go index 691ad07de..39bd0a95e 100644 --- a/pkg/operator/ceph/client/controller.go +++ b/pkg/operator/ceph/client/controller.go @@ -36,7 +36,6 @@ import ( "github.com/coreos/pkg/capnslog" cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" "github.com/rook/rook/pkg/clusterd" - ceph "github.com/rook/rook/pkg/daemon/ceph/client" cephclient "github.com/rook/rook/pkg/daemon/ceph/client" "github.com/rook/rook/pkg/operator/ceph/cluster/mon" opcontroller "github.com/rook/rook/pkg/operator/ceph/controller" @@ -235,14 +234,14 @@ func (r *ReconcileCephClient) createOrUpdateClient(cephClient *cephv1.CephClient clientEntity, caps := genClientEntity(cephClient) // Check if client was created manually, create if necessary or update caps and create secret - key, err := ceph.AuthGetKey(r.context, r.clusterInfo, clientEntity) + key, err := cephclient.AuthGetKey(r.context, r.clusterInfo, clientEntity) if err != nil { - key, err = ceph.AuthGetOrCreateKey(r.context, r.clusterInfo, clientEntity, caps) + key, err = cephclient.AuthGetOrCreateKey(r.context, r.clusterInfo, clientEntity, caps) if err != nil { return errors.Wrapf(err, "failed to create client %q", cephClient.Name) } } else { - err = ceph.AuthUpdateCaps(r.context, r.clusterInfo, clientEntity, caps) + err = cephclient.AuthUpdateCaps(r.context, r.clusterInfo, clientEntity, caps) if err != nil { return errors.Wrapf(err, "client %q exists, failed to update client caps", cephClient.Name) } @@ -292,7 +291,7 @@ func (r *ReconcileCephClient) createOrUpdateClient(cephClient *cephv1.CephClient // Delete the client func (r *ReconcileCephClient) deleteClient(cephClient *cephv1.CephClient) error { logger.Infof("deleting client object %q", cephClient.Name) - if err := ceph.AuthDelete(r.context, r.clusterInfo, generateClientName(cephClient.Name)); err != nil { + if err := cephclient.AuthDelete(r.context, r.clusterInfo, generateClientName(cephClient.Name)); err != nil { return errors.Wrapf(err, "failed to delete client %q", cephClient.Name) } diff --git a/pkg/operator/ceph/config/keyring/store_test.go b/pkg/operator/ceph/config/keyring/store_test.go index 4d2d288e8..176256821 100644 --- a/pkg/operator/ceph/config/keyring/store_test.go +++ b/pkg/operator/ceph/config/keyring/store_test.go @@ -23,7 +23,6 @@ import ( "github.com/pkg/errors" "github.com/rook/rook/pkg/clusterd" - "github.com/rook/rook/pkg/daemon/ceph/client" cephclient "github.com/rook/rook/pkg/daemon/ceph/client" "github.com/rook/rook/pkg/operator/k8sutil" testop "github.com/rook/rook/pkg/operator/test" @@ -51,7 +50,7 @@ func TestGenerateKey(t *testing.T) { } ns := "rook-ceph" ownerInfo := k8sutil.OwnerInfo{} - s := GetSecretStore(ctx, &client.ClusterInfo{Namespace: ns}, &ownerInfo) + s := GetSecretStore(ctx, &cephclient.ClusterInfo{Namespace: ns}, &ownerInfo) generateKey = "generatedsecretkey" failGenerateKey = false @@ -80,7 +79,7 @@ func TestKeyringStore(t *testing.T) { } ownerInfo := cephclient.NewMinimumOwnerInfoWithOwnerRef() ns := "rook-ceph" - k := GetSecretStore(ctx, &client.ClusterInfo{Namespace: ns}, ownerInfo) + k := GetSecretStore(ctx, &cephclient.ClusterInfo{Namespace: ns}, ownerInfo) assertKeyringData := func(keyringName, expectedKeyring string) { s, e := clientset.CoreV1().Secrets(ns).Get(ctxt, keyringName, metav1.GetOptions{}) @@ -125,7 +124,7 @@ func TestResourceVolumeAndMount(t *testing.T) { Clientset: clientset, } ownerInfo := cephclient.NewMinimumOwnerInfoWithOwnerRef() - k := GetSecretStore(ctx, &client.ClusterInfo{Namespace: "ns"}, ownerInfo) + k := GetSecretStore(ctx, &cephclient.ClusterInfo{Namespace: "ns"}, ownerInfo) err := k.CreateOrUpdate("test-resource", "qwertyuiop") assert.NoError(t, err) err = k.CreateOrUpdate("second-resource", "asdfgyhujkl") diff --git a/pkg/operator/ceph/controller/spec_test.go b/pkg/operator/ceph/controller/spec_test.go index 3c76461e4..ba69558d4 100644 --- a/pkg/operator/ceph/controller/spec_test.go +++ b/pkg/operator/ceph/controller/spec_test.go @@ -22,9 +22,7 @@ import ( "testing" cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" - "github.com/rook/rook/pkg/daemon/ceph/client" cephclient "github.com/rook/rook/pkg/daemon/ceph/client" - "github.com/rook/rook/pkg/operator/ceph/config" opconfig "github.com/rook/rook/pkg/operator/ceph/config" "github.com/rook/rook/pkg/operator/ceph/version" "github.com/rook/rook/pkg/operator/k8sutil" @@ -110,24 +108,24 @@ func TestCheckPodMemory(t *testing.T) { } func TestBuildAdminSocketCommand(t *testing.T) { - c := getDaemonConfig(config.OsdType, "") + c := getDaemonConfig(opconfig.OsdType, "") command := c.buildAdminSocketCommand() assert.Equal(t, "status", command) - c.daemonType = config.MonType + c.daemonType = opconfig.MonType command = c.buildAdminSocketCommand() assert.Equal(t, "mon_status", command) } func TestBuildSocketName(t *testing.T) { daemonID := "0" - c := getDaemonConfig(config.OsdType, daemonID) + c := getDaemonConfig(opconfig.OsdType, daemonID) socketName := c.buildSocketName() assert.Equal(t, "ceph-osd.0.asok", socketName) - c.daemonType = config.MonType + c.daemonType = opconfig.MonType c.daemonID = "a" socketName = c.buildSocketName() assert.Equal(t, "ceph-mon.a.asok", socketName) @@ -135,7 +133,7 @@ func TestBuildSocketName(t *testing.T) { func TestBuildSocketPath(t *testing.T) { daemonID := "0" - c := getDaemonConfig(config.OsdType, daemonID) + c := getDaemonConfig(opconfig.OsdType, daemonID) socketPath := c.buildSocketPath() assert.Equal(t, "/run/ceph/ceph-osd.0.asok", socketPath) @@ -143,7 +141,7 @@ func TestBuildSocketPath(t *testing.T) { func TestGenerateLivenessProbeExecDaemon(t *testing.T) { daemonID := "0" - probe := GenerateLivenessProbeExecDaemon(config.OsdType, daemonID) + probe := GenerateLivenessProbeExecDaemon(opconfig.OsdType, daemonID) expectedCommand := []string{"env", "-i", "sh", @@ -156,21 +154,21 @@ func TestGenerateLivenessProbeExecDaemon(t *testing.T) { assert.Equal(t, initialDelaySecondsOSDDaemon, probe.InitialDelaySeconds) // test with a mon so the delay should be 10 - probe = GenerateLivenessProbeExecDaemon(config.MonType, "a") + probe = GenerateLivenessProbeExecDaemon(opconfig.MonType, "a") assert.Equal(t, initialDelaySecondsNonOSDDaemon, probe.InitialDelaySeconds) } func TestDaemonFlags(t *testing.T) { testcases := []struct { label string - clusterInfo *client.ClusterInfo + clusterInfo *cephclient.ClusterInfo clusterSpec *cephv1.ClusterSpec daemonID string expected []string }{ { label: "case 1: IPv6 enabled", - clusterInfo: &client.ClusterInfo{ + clusterInfo: &cephclient.ClusterInfo{ FSID: "id", }, clusterSpec: &cephv1.ClusterSpec{ @@ -186,7 +184,7 @@ func TestDaemonFlags(t *testing.T) { }, { label: "case 2: IPv6 disabled", - clusterInfo: &client.ClusterInfo{ + clusterInfo: &cephclient.ClusterInfo{ FSID: "id", }, clusterSpec: &cephv1.ClusterSpec{}, diff --git a/pkg/operator/ceph/disruption/clusterdisruption/osd.go b/pkg/operator/ceph/disruption/clusterdisruption/osd.go index a31026281..23fc3dba9 100644 --- a/pkg/operator/ceph/disruption/clusterdisruption/osd.go +++ b/pkg/operator/ceph/disruption/clusterdisruption/osd.go @@ -23,13 +23,11 @@ import ( "time" "github.com/pkg/errors" - cephClient "github.com/rook/rook/pkg/daemon/ceph/client" cephclient "github.com/rook/rook/pkg/daemon/ceph/client" "github.com/rook/rook/pkg/operator/ceph/cluster/osd" opcontroller "github.com/rook/rook/pkg/operator/ceph/controller" "github.com/rook/rook/pkg/operator/k8sutil" apierrors "k8s.io/apimachinery/pkg/api/errors" - kerrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -56,7 +54,7 @@ const ( func (r *ReconcileClusterDisruption) createPDB(pdb *policyv1beta1.PodDisruptionBudget) error { err := r.client.Create(context.TODO(), pdb) - if err != nil && !kerrors.IsAlreadyExists(err) { + if err != nil && !apierrors.IsAlreadyExists(err) { return errors.Wrapf(err, "failed to create pdb %q", pdb.Name) } return nil @@ -64,7 +62,7 @@ func (r *ReconcileClusterDisruption) createPDB(pdb *policyv1beta1.PodDisruptionB func (r *ReconcileClusterDisruption) deletePDB(pdb *policyv1beta1.PodDisruptionBudget) error { err := r.client.Delete(context.TODO(), pdb) - if err != nil && !kerrors.IsNotFound(err) { + if err != nil && !apierrors.IsNotFound(err) { return errors.Wrapf(err, "failed to delete pdb %q", pdb.Name) } return nil @@ -198,7 +196,7 @@ func (r *ReconcileClusterDisruption) initializePDBState(request reconcile.Reques } err := r.client.Get(context.TODO(), pdbStateMapRequest, pdbStateMap) - if kerrors.IsNotFound(err) { + if apierrors.IsNotFound(err) { // create configmap to track the draining failure domain pdbStateMap.Data = map[string]string{drainingFailureDomainKey: ""} err := r.client.Create(context.TODO(), pdbStateMap) @@ -377,7 +375,7 @@ func (r *ReconcileClusterDisruption) updateNoout(clusterInfo *cephclient.Cluster return nil } -func (r *ReconcileClusterDisruption) getOSDFailureDomains(clusterInfo *cephClient.ClusterInfo, request reconcile.Request, poolFailureDomain string) ([]string, []string, error) { +func (r *ReconcileClusterDisruption) getOSDFailureDomains(clusterInfo *cephclient.ClusterInfo, request reconcile.Request, poolFailureDomain string) ([]string, []string, error) { osdDeploymentList := &appsv1.DeploymentList{} namespaceListOpts := client.InNamespace(request.Namespace) topologyLocationLabel := fmt.Sprintf(osd.TopologyLocationLabel, poolFailureDomain) diff --git a/pkg/operator/ceph/disruption/clusterdisruption/osd_test.go b/pkg/operator/ceph/disruption/clusterdisruption/osd_test.go index bc197ac4b..53703bfed 100644 --- a/pkg/operator/ceph/disruption/clusterdisruption/osd_test.go +++ b/pkg/operator/ceph/disruption/clusterdisruption/osd_test.go @@ -32,7 +32,6 @@ import ( "github.com/stretchr/testify/assert" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" - v1 "k8s.io/api/core/v1" policyv1beta1 "k8s.io/api/policy/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -64,7 +63,7 @@ func fakeOSDDeployment(id, readyReplicas int) appsv1.Deployment { }, }, Spec: appsv1.DeploymentSpec{ - Template: v1.PodTemplateSpec{ + Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "topology-location-zone": fmt.Sprintf("zone-%d", id), diff --git a/pkg/operator/ceph/nfs/nfs.go b/pkg/operator/ceph/nfs/nfs.go index db67c34b5..eb4f594c5 100644 --- a/pkg/operator/ceph/nfs/nfs.go +++ b/pkg/operator/ceph/nfs/nfs.go @@ -25,7 +25,6 @@ import ( "github.com/pkg/errors" cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" "github.com/rook/rook/pkg/clusterd" - "github.com/rook/rook/pkg/daemon/ceph/client" cephclient "github.com/rook/rook/pkg/daemon/ceph/client" opmon "github.com/rook/rook/pkg/operator/ceph/cluster/mon" "github.com/rook/rook/pkg/operator/ceph/config" @@ -275,7 +274,7 @@ func validateGanesha(context *clusterd.Context, clusterInfo *cephclient.ClusterI } // The existence of the pool provided in n.Spec.RADOS.Pool is necessary otherwise addRADOSConfigFile() will fail - _, err := client.GetPoolDetails(context, clusterInfo, n.Spec.RADOS.Pool) + _, err := cephclient.GetPoolDetails(context, clusterInfo, n.Spec.RADOS.Pool) if err != nil { return errors.Wrapf(err, "pool %q not found", n.Spec.RADOS.Pool) } diff --git a/pkg/operator/ceph/nfs/spec_test.go b/pkg/operator/ceph/nfs/spec_test.go index 8144863e6..1974ccff2 100644 --- a/pkg/operator/ceph/nfs/spec_test.go +++ b/pkg/operator/ceph/nfs/spec_test.go @@ -26,7 +26,6 @@ import ( cephclient "github.com/rook/rook/pkg/daemon/ceph/client" "github.com/rook/rook/pkg/operator/ceph/config" cephver "github.com/rook/rook/pkg/operator/ceph/version" - "github.com/rook/rook/pkg/operator/test" optest "github.com/rook/rook/pkg/operator/test" exectest "github.com/rook/rook/pkg/util/exec/test" "github.com/stretchr/testify/assert" @@ -65,7 +64,7 @@ func TestDeploymentSpec(t *testing.T) { }, } - clientset := test.New(t, 1) + clientset := optest.New(t, 1) c := &clusterd.Context{ Executor: &exectest.MockExecutor{}, RookClientset: rookclient.NewSimpleClientset(), diff --git a/pkg/operator/ceph/pool/validate.go b/pkg/operator/ceph/pool/validate.go index 24e38731a..c7fa293f3 100644 --- a/pkg/operator/ceph/pool/validate.go +++ b/pkg/operator/ceph/pool/validate.go @@ -18,7 +18,6 @@ limitations under the License. package pool import ( - "github.com/rook/rook/pkg/daemon/ceph/client" cephclient "github.com/rook/rook/pkg/daemon/ceph/client" "github.com/pkg/errors" @@ -41,7 +40,7 @@ func ValidatePool(context *clusterd.Context, clusterInfo *cephclient.ClusterInfo } // ValidatePoolSpec validates the Ceph block pool spec CR -func ValidatePoolSpec(context *clusterd.Context, clusterInfo *client.ClusterInfo, clusterSpec *cephv1.ClusterSpec, p *cephv1.PoolSpec) error { +func ValidatePoolSpec(context *clusterd.Context, clusterInfo *cephclient.ClusterInfo, clusterSpec *cephv1.ClusterSpec, p *cephv1.PoolSpec) error { if p.IsReplicated() && p.IsErasureCoded() { return errors.New("both replication and erasure code settings cannot be specified") } diff --git a/pkg/operator/ceph/provisioner/provisioner.go b/pkg/operator/ceph/provisioner/provisioner.go index 3112cce51..3caac0a69 100644 --- a/pkg/operator/ceph/provisioner/provisioner.go +++ b/pkg/operator/ceph/provisioner/provisioner.go @@ -26,7 +26,6 @@ import ( "github.com/pkg/errors" "github.com/rook/rook/pkg/clusterd" "github.com/rook/rook/pkg/daemon/ceph/agent/flexvolume" - "github.com/rook/rook/pkg/daemon/ceph/client" ceph "github.com/rook/rook/pkg/daemon/ceph/client" "github.com/rook/rook/pkg/operator/ceph/cluster" v1 "k8s.io/api/core/v1" @@ -97,7 +96,7 @@ func (p *RookVolumeProvisioner) Provision(_ context.Context, options controller. return nil, controller.ProvisioningFinished, err } - clusterInfo := client.AdminClusterInfo(cfg.clusterNamespace) + clusterInfo := ceph.AdminClusterInfo(cfg.clusterNamespace) blockImage, err := p.createVolume(clusterInfo, imageName, cfg.blockPool, cfg.dataBlockPool, requestBytes) if err != nil { return nil, controller.ProvisioningFinished, err @@ -159,7 +158,7 @@ func (p *RookVolumeProvisioner) Provision(_ context.Context, options controller. } // createVolume creates a rook block volume. -func (p *RookVolumeProvisioner) createVolume(clusterInfo *client.ClusterInfo, image, pool, dataPool string, size int64) (*ceph.CephBlockImage, error) { +func (p *RookVolumeProvisioner) createVolume(clusterInfo *ceph.ClusterInfo, image, pool, dataPool string, size int64) (*ceph.CephBlockImage, error) { if image == "" || pool == "" || clusterInfo.Namespace == "" || size == 0 { return nil, errors.Errorf("image missing required fields (image=%s, pool=%s, clusterNamespace=%s, size=%d)", image, pool, clusterInfo.Namespace, size) } @@ -196,7 +195,7 @@ func (p *RookVolumeProvisioner) Delete(_ context.Context, volume *v1.PersistentV if clusterns == "" { return errors.Errorf("failed to delete rook block image %s/%s: no clusterNamespace or (deprecated) clusterName option given", pool, volume.Name) } - clusterInfo := client.AdminClusterInfo(clusterns) + clusterInfo := ceph.AdminClusterInfo(clusterns) err := ceph.DeleteImage(p.context, clusterInfo, name, pool) if err != nil { return errors.Wrapf(err, "failed to delete rook block image %s/%s", pool, volume.Name)