Skip to content

Commit

Permalink
object: add check specific to name and namespace for ceph cosi driver
Browse files Browse the repository at this point in the history
The name for cephcosi driver should be ceph-cosi-driver and namespace
should same as the rook operator. Otherwise request need to be failed.

Fixes: #13025
Signed-off-by: Jiffin Tony Thottan <thottanjiffin@gmail.com>
  • Loading branch information
thotz committed Jan 30, 2024
1 parent 3b1a428 commit 6d57324
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pkg/operator/ceph/object/cosi/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,18 @@ func (r *ReconcileCephCOSIDriver) Reconcile(context context.Context, request rec
func (r *ReconcileCephCOSIDriver) reconcile(request reconcile.Request) (reconcile.Result, cephv1.CephCOSIDriver, error) {
cephCOSIDriver := &cephv1.CephCOSIDriver{}

// Check No of instances of CephCOSIDriver
cephCOSIDriverList := &cephv1.CephCOSIDriverList{}
err := r.client.List(r.opManagerContext, cephCOSIDriverList)
if err != nil {
return reconcile.Result{}, *cephCOSIDriver, errors.Wrap(err, "failed to list CephCOSIDriver")
}
if len(cephCOSIDriverList.Items) > 1 {
return reconcile.Result{}, *cephCOSIDriver, errors.New("more than one instance of CephCOSIDriver found")
}

// Fetch the CephCOSIDriver instance
err := r.client.Get(r.opManagerContext, request.NamespacedName, cephCOSIDriver)
cephCOSIDriver := cephCOSIDriverList.Items[0]

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / docs-check

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / docs-check

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / govulncheck

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / govulncheck

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / unittests

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / unittests

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / macos-build

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / macos-build

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / linux-build-all (1.21)

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / linux-build-all (1.21)

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephObjectSuite (v1.23.17)

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephObjectSuite (v1.23.17)

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephHelmSuite (v1.23.17)

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephHelmSuite (v1.23.17)

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephHelmSuite (v1.29.0)

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephHelmSuite (v1.29.0)

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephObjectSuite (v1.29.0)

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephObjectSuite (v1.29.0)

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephSmokeSuite (v1.23.17)

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephSmokeSuite (v1.23.17)

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephSmokeSuite (v1.29.0)

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephSmokeSuite (v1.29.0)

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephMultiClusterDeploySuite (v1.29.0)

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephMultiClusterDeploySuite (v1.29.0)

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestHelmUpgradeSuite (v1.23.17)

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestHelmUpgradeSuite (v1.23.17)

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestHelmUpgradeSuite (v1.23.17)

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestHelmUpgradeSuite (v1.23.17)

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephUpgradeSuite (v1.23.17)

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephUpgradeSuite (v1.23.17)

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestHelmUpgradeSuite (v1.29.0)

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestHelmUpgradeSuite (v1.29.0)

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephUpgradeSuite (v1.29.0)

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / TestCephUpgradeSuite (v1.29.0)

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / csi-hostnetwork-disabled

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / csi-hostnetwork-disabled

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / canary

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / canary

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / encryption

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / encryption

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / encryption-pvc

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / encryption-pvc

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / encryption-pvc-db

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / encryption-pvc-db

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / encryption-pvc-db-wal

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / encryption-pvc-db-wal

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / encryption-pvc-kms-vault-k8s-auth

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / encryption-pvc-kms-vault-k8s-auth

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / encryption-pvc-kms-vault-token-auth

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / encryption-pvc-kms-vault-token-auth

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / lvm

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / lvm

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / lvm-pvc

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / lvm-pvc

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / multi-cluster-mirroring

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / multi-cluster-mirroring

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / multus-cluster-network

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / multus-cluster-network

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / osd-with-metadata-device

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / osd-with-metadata-device

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / pvc

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / pvc

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / pvc-db

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / pvc-db

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / pvc-db-wal

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / pvc-db-wal

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / raw-disk

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / raw-disk

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / rgw-multisite-testing

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / rgw-multisite-testing

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / two-osds-in-device

no new variables on left side of :=

Check failure on line 132 in pkg/operator/ceph/object/cosi/controller.go

View workflow job for this annotation

GitHub Actions / two-osds-in-device

cannot use cephCOSIDriverList.Items[0] (variable of type "github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver) as *"github.com/rook/rook/pkg/apis/ceph.rook.io/v1".CephCOSIDriver value in assignment
logger.Debugf("CephCOSIDriver: %+v", cephCOSIDriver)
if err != nil && client.IgnoreNotFound(err) != nil {
return reconcile.Result{}, *cephCOSIDriver, errors.Wrapf(err, "failed to get Ceph COSI Driver %s", request.NamespacedName)
Expand Down Expand Up @@ -157,9 +167,9 @@ func (r *ReconcileCephCOSIDriver) reconcile(request reconcile.Request) (reconcil
cephCOSIDriver.Name = CephCOSIDriverName
}

// Set the default CephCOSIDriver namespace if not already set
if cephCOSIDriver.Namespace == "" {
cephCOSIDriver.Namespace = os.Getenv(k8sutil.PodNamespaceEnvVar)
// The ceph-cosi-driver CRD should be same namespace as the operator
if cephCOSIDriver.Namespace != os.Getenv(k8sutil.PodNamespaceEnvVar) {
return reconcile.Result{}, *cephCOSIDriver, errors.New("Ceph COSI Driver namespace must be same as operator")
}

// Check whether object store is running
Expand Down
56 changes: 56 additions & 0 deletions pkg/operator/ceph/object/cosi/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,60 @@ func TestCephCOSIDriverController(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "quay.io/ceph/cosi:custom", cephCOSIDriverDeployment.Spec.Template.Spec.Containers[0].Image)
})

t.Run("ceph cosi driver CRD with custom namespace", func(t *testing.T) {
cephCOSIDriver := &cephv1.CephCOSIDriver{
ObjectMeta: metav1.ObjectMeta{
Name: CephCOSIDriverName,
Namespace: "custom-namespace",
},
Spec: cephv1.CephCOSIDriverSpec{
Image: "quay.io/ceph/cosi:custom",
DeploymentStrategy: cephv1.COSIDeploymentStrategyAuto,
},
}
r := setupNewEnvironment(cephCOSIDriver)
req := reconcile.Request{
NamespacedName: types.NamespacedName{
Name: CephCOSIDriverName,
Namespace: "custom-namespace",
},
}
res, err := r.Reconcile(ctx, req)
assert.Error(t, err)
assert.Equal(t, false, res.Requeue)
})

t.Run("multiple ceph cosi driver CRDs", func(t *testing.T) {
cephCOSIDriver1 := &cephv1.CephCOSIDriver{
ObjectMeta: metav1.ObjectMeta{
Name: "ceph-cosi-driver-1",
Namespace: namespace,
},
Spec: cephv1.CephCOSIDriverSpec{
Image: "quay.io/ceph/cosi:custom",
DeploymentStrategy: cephv1.COSIDeploymentStrategyAuto,
},
}
cephCOSIDriver2 := &cephv1.CephCOSIDriver{
ObjectMeta: metav1.ObjectMeta{
Name: "ceph-cosi-driver-2",
Namespace: namespace,
},
Spec: cephv1.CephCOSIDriverSpec{
Image: "quay.io/ceph/cosi:custom",
DeploymentStrategy: cephv1.COSIDeploymentStrategyAuto,
},
}
r := setupNewEnvironment(cephCOSIDriver1, cephCOSIDriver2)
req := reconcile.Request{
NamespacedName: types.NamespacedName{
Name: "ceph-cosi-driver-1",
Namespace: namespace,
},
}
res, err := r.Reconcile(ctx, req)
assert.Error(t, err)
assert.Equal(t, false, res.Requeue)
})
}

0 comments on commit 6d57324

Please sign in to comment.