-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
118 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package controllers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
lvmv1alpha1 "github.com/red-hat-storage/lvm-operator/api/v1alpha1" | ||
v1 "k8s.io/api/apps/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
var _ = Describe("LVMCluster controller", func() { | ||
|
||
const ( | ||
timeout = time.Second * 10 | ||
interval = time.Millisecond * 250 | ||
) | ||
|
||
ctx := context.Background() | ||
|
||
// LVMCluster CR details | ||
lvmClusterName := types.NamespacedName{Name: "test-lvmcluster-node", Namespace: testLvmClusterNamespace} | ||
lvmClusterOut := &lvmv1alpha1.LVMCluster{} | ||
lvmClusterIn := &lvmv1alpha1.LVMCluster{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-lvmcluster-node", | ||
Namespace: testLvmClusterNamespace, | ||
}, | ||
Spec: lvmv1alpha1.LVMClusterSpec{ | ||
DeviceClasses: []lvmv1alpha1.DeviceClass{{Name: "test"}}, | ||
}, | ||
} | ||
|
||
csiNodeName := types.NamespacedName{Name: TopolvmNodeDaemonsetName, Namespace: testLvmClusterNamespace} | ||
csiNodeOut := &v1.DaemonSet{} | ||
|
||
Context("LVMCluster reconciliation on installing CR", func() { | ||
It("should reconcile LVMCluster CR creation, ", func() { | ||
By("verifying CR status.Ready is set to true on reconciliation") | ||
Expect(k8sClient.Create(ctx, lvmClusterIn)).Should(Succeed()) | ||
|
||
// placeholder to check CR status.Ready field to be true | ||
Eventually(func() bool { | ||
err := k8sClient.Get(ctx, lvmClusterName, lvmClusterOut) | ||
if err != nil { | ||
return false | ||
} | ||
return lvmClusterOut.Status.Ready | ||
}, timeout, interval).Should(Equal(true)) | ||
|
||
// presence of Node Daemonset | ||
By("Confirming CSI Node daemonSet exists") | ||
Eventually(func() bool { | ||
|
||
dsl := &v1.DaemonSetList{} | ||
err := k8sClient.List(ctx, dsl, client.InNamespace(testLvmClusterNamespace)) | ||
fmt.Printf("JMO ------------------> %v", dsl) | ||
|
||
err = k8sClient.Get(ctx, csiNodeName, csiNodeOut) | ||
return err == nil | ||
|
||
}, timeout, interval).Should(BeTrue()) | ||
|
||
}) | ||
}) | ||
|
||
Context("LVMCluster reconciliation on uninstalling CR", func() { | ||
It("should reconcile LVMCluster CR deletion ", func() { | ||
By("confirming absence of lvm cluster CR and deletion of operator created resources") | ||
Eventually(func() bool { | ||
err := k8sClient.Delete(ctx, lvmClusterOut) | ||
|
||
// deletion of LVM Cluster CR | ||
return err != nil | ||
}, timeout, interval).Should(BeTrue()) | ||
}) | ||
}) | ||
|
||
}) |