Skip to content

Commit

Permalink
test: revamp vgmanager unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobmoellerdev committed Sep 22, 2023
1 parent a518d55 commit e9ba448
Show file tree
Hide file tree
Showing 5 changed files with 312 additions and 341 deletions.
3 changes: 1 addition & 2 deletions cmd/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ func run(cmd *cobra.Command, _ []string, opts *Options) error {
return fmt.Errorf("unable to create LVMCluster webhook: %w", err)
}
if err = (&lvmv1alpha1.LVMVolumeGroup{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "LVMVolumeGroup ")
os.Exit(1)
return fmt.Errorf("unable to create LVMVolumeGroup webhoook: %w", err)
}

pvController := persistent_volume.NewPersistentVolumeReconciler(mgr.GetClient(), mgr.GetAPIReader(), mgr.GetEventRecorderFor("lvms-pv-controller"))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
go.uber.org/zap v1.26.0
gotest.tools/v3 v3.5.1
k8s.io/api v0.28.2
k8s.io/apiextensions-apiserver v0.28.2
k8s.io/apimachinery v0.28.2
k8s.io/client-go v0.28.2
k8s.io/component-helpers v0.28.2
Expand Down Expand Up @@ -99,7 +100,6 @@ require (
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.28.2 // indirect
k8s.io/component-base v0.28.2 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand Down
196 changes: 0 additions & 196 deletions pkg/vgmanager/suite_test.go

This file was deleted.

14 changes: 10 additions & 4 deletions pkg/vgmanager/vgmanager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,10 @@ func (r *VGReconciler) reconcile(
}
return ctrl.Result{}, err
}

lvmdConfigWasMissing := false
if lvmdConfig == nil {
// The lvmdconfig file does not exist and will be created.
msg := "lvmd config file doesn't exist, will attempt to create a fresh config"
logger.Info(msg)
r.NormalEvent(ctx, volumeGroup, EventReasonLVMDConfigMissing, msg)
lvmdConfigWasMissing = true
lvmdConfig = &lvmd.Config{
SocketName: controllers.DefaultLVMdSocket,
}
Expand Down Expand Up @@ -296,6 +295,13 @@ func (r *VGReconciler) reconcile(

// Apply and save lvmd config
if !cmp.Equal(existingLvmdConfig, lvmdConfig) {
if lvmdConfigWasMissing {
// The lvmdconfig file does not exist and will be created.
msg := "lvmd config file doesn't exist, will attempt to create a fresh config"
logger.Info(msg)
r.NormalEvent(ctx, volumeGroup, EventReasonLVMDConfigMissing, msg)
}

if err := r.LVMD.Save(lvmdConfig); err != nil {
err := fmt.Errorf("failed to update lvmd config file to update volume group %s: %w", volumeGroup.GetName(), err)
if _, err := r.setVolumeGroupFailedStatus(ctx, volumeGroup, devices, err); err != nil {
Expand Down
Loading

0 comments on commit e9ba448

Please sign in to comment.