Skip to content

Commit

Permalink
fix: add CSI Node verification to avoid race
Browse files Browse the repository at this point in the history
Signed-off-by: Jakob Möller <jmoller@redhat.com>
  • Loading branch information
jakobmoellerdev committed Jun 25, 2024
1 parent 93f17e9 commit a3d9770
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/vgmanager/vgmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func run(cmd *cobra.Command, _ []string, opts *Options) error {
return fmt.Errorf("unable to create controller VGManager: %w", err)
}

if err := mgr.AddReadyzCheck("readyz", readyCheck(mgr, lvmdConfig)); err != nil {
if err := mgr.AddReadyzCheck("readyz", readyCheck(mgr)); err != nil {
return fmt.Errorf("unable to set up ready check: %w", err)
}

Expand Down Expand Up @@ -334,7 +334,7 @@ func pluginRegistrationSocketPath() string {
}

// readyCheck returns a healthz.Checker that verifies the operator is ready
func readyCheck(mgr manager.Manager, config *lvmd.Config) healthz.Checker {
func readyCheck(mgr manager.Manager) healthz.Checker {
return func(req *http.Request) error {
// Perform various checks here to determine if the operator is ready
if !mgr.GetCache().WaitForCacheSync(req.Context()) {
Expand Down
1 change: 1 addition & 0 deletions test/e2e/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func VerifyLVMSSetup(ctx context.Context, cluster *v1alpha1.LVMCluster) {
GinkgoHelper()
validateLVMCluster(ctx, cluster)
validateCSIDriver(ctx)
validateCSINodeInfo(ctx, cluster, true)
validateVGManager(ctx)
validateLVMVolumeGroup(ctx)
validateStorageClass(ctx)
Expand Down
1 change: 1 addition & 0 deletions test/e2e/lvm_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func lvmClusterTest() {
return
}
DeleteResource(ctx, cluster)
validateCSINodeInfo(ctx, cluster, false)
})

Describe("Filesystem Type", Serial, func() {
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/lvm_pvc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func pvcTestThinProvisioning() {
return
}
DeleteResource(ctx, cluster)
validateCSINodeInfo(ctx, cluster, false)
})
})

Expand Down Expand Up @@ -125,6 +126,7 @@ func pvcTestThickProvisioning() {
return
}
DeleteResource(ctx, cluster)
validateCSINodeInfo(ctx, cluster, false)
})
})

Expand Down
45 changes: 45 additions & 0 deletions test/e2e/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
. "github.com/onsi/gomega"
"github.com/openshift/lvm-operator/api/v1alpha1"
"github.com/openshift/lvm-operator/internal/controllers/lvmcluster/resource"
"github.com/openshift/lvm-operator/internal/controllers/lvmcluster/selector"
topolvmv1 "github.com/topolvm/topolvm/api/v1"
appsv1 "k8s.io/api/apps/v1"
k8sv1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -174,6 +175,50 @@ func validatePodData(ctx context.Context, pod *k8sv1.Pod, expectedData string, c
return Expect(actualData).To(Equal(expectedData))
}

func validateCSINodeInfo(ctx context.Context, lvmCluster *v1alpha1.LVMCluster, shouldBePresent bool) bool {
GinkgoHelper()
By("validating the CSINode(s) for the Cluster to have the driver registered")
return Eventually(func(ctx context.Context) error {
cluster := lvmCluster
if err := crClient.Get(ctx, client.ObjectKeyFromObject(cluster), cluster); err != nil {
return fmt.Errorf("failed to get LVMCluster: %v", err)
}

nodeList := &k8sv1.NodeList{}
if err := crClient.List(ctx, nodeList); err != nil {
return fmt.Errorf("failed to list Nodes: %v", err)
}

nodes, err := selector.ValidNodes(cluster, nodeList)
if err != nil {
return fmt.Errorf("failed to get valid nodes: %v", err)
}

for _, node := range nodes {
var csiNode storagev1.CSINode
if err := crClient.Get(ctx, client.ObjectKey{Name: node.Name}, &csiNode); err != nil {
return fmt.Errorf("failed to get CSINode %q: %v", node.Name, err)
}
exists := false
for _, d := range csiNode.Spec.Drivers {
if d.Name == csiDriverName {
exists = true
break
}
}
if exists != shouldBePresent {
return fmt.Errorf("CSINode %q should %scontain the driver %q",
node.Name,
map[bool]string{true: "", false: "not "}[shouldBePresent],
csiDriverName,
)
}
}

return nil
}, timeout, interval).WithContext(ctx).Should(Succeed())
}

func SummaryOnFailure(ctx context.Context) {
if !CurrentSpecReport().Failed() {
GinkgoLogr.Info("skipping test namespace summary due to successful test run")
Expand Down

0 comments on commit a3d9770

Please sign in to comment.