diff --git a/images/agent/src/cmd/main.go b/images/agent/src/cmd/main.go index dfceb535..2ee15c72 100644 --- a/images/agent/src/cmd/main.go +++ b/images/agent/src/cmd/main.go @@ -32,18 +32,18 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/metrics/server" - "agent/config" - "agent/pkg/cache" - "agent/pkg/controller" - "agent/pkg/controller/bd" - "agent/pkg/controller/llv" - "agent/pkg/controller/llv_extender" - "agent/pkg/controller/lvg" - "agent/pkg/kubutils" - "agent/pkg/logger" - "agent/pkg/monitoring" - "agent/pkg/scanner" - "agent/pkg/utils" + "agent/internal/cache" + "agent/internal/config" + "agent/internal/controller" + "agent/internal/controller/bd" + "agent/internal/controller/llv" + "agent/internal/controller/llv_extender" + "agent/internal/controller/lvg" + "agent/internal/kubutils" + "agent/internal/logger" + "agent/internal/monitoring" + "agent/internal/scanner" + "agent/internal/utils" ) var ( diff --git a/images/agent/src/pkg/cache/cache.go b/images/agent/src/internal/cache/cache.go similarity index 99% rename from images/agent/src/pkg/cache/cache.go rename to images/agent/src/internal/cache/cache.go index e5bc9426..55229ce8 100644 --- a/images/agent/src/pkg/cache/cache.go +++ b/images/agent/src/internal/cache/cache.go @@ -7,7 +7,7 @@ import ( "sync" "agent/internal" - "agent/pkg/logger" + "agent/internal/logger" ) const ( diff --git a/images/agent/src/pkg/cache/cache_test.go b/images/agent/src/internal/cache/cache_test.go similarity index 100% rename from images/agent/src/pkg/cache/cache_test.go rename to images/agent/src/internal/cache/cache_test.go diff --git a/images/agent/src/config/config.go b/images/agent/src/internal/config/config.go similarity index 99% rename from images/agent/src/config/config.go rename to images/agent/src/internal/config/config.go index a657915d..3da615f0 100644 --- a/images/agent/src/config/config.go +++ b/images/agent/src/internal/config/config.go @@ -26,7 +26,7 @@ import ( "time" "agent/internal" - "agent/pkg/logger" + "agent/internal/logger" ) const ( diff --git a/images/agent/src/config/config_test.go b/images/agent/src/internal/config/config_test.go similarity index 100% rename from images/agent/src/config/config_test.go rename to images/agent/src/internal/config/config_test.go diff --git a/images/agent/src/internal/const.go b/images/agent/src/internal/const.go index 5796f36e..749dedf4 100644 --- a/images/agent/src/internal/const.go +++ b/images/agent/src/internal/const.go @@ -72,6 +72,23 @@ const ( BlockDeviceRotaLabelKey = BlockDeviceLabelPrefix + "/rota" BlockDeviceHotPlugLabelKey = BlockDeviceLabelPrefix + "/hotplug" BlockDeviceMachineIDLabelKey = BlockDeviceLabelPrefix + "/machineid" + + Thick = "Thick" + Thin = "Thin" + + LLVStatusPhaseCreated = "Created" + LLVStatusPhasePending = "Pending" + LLVStatusPhaseResizing = "Resizing" + LLVStatusPhaseFailed = "Failed" + + Local = "Local" + Shared = "Shared" + + NonOperational = "NonOperational" + + DeletionProtectionAnnotation = "storage.deckhouse.io/deletion-protection" + LVMVolumeGroupTag = "storage.deckhouse.io/lvmVolumeGroupName" + LVGMetadateNameLabelKey = "kubernetes.io/metadata.name" ) var ( @@ -81,3 +98,13 @@ var ( LVMTags = []string{"storage.deckhouse.io/enabled=true", "linstor-"} ResizeDelta = resource.MustParse(resizeDelta) ) + +const ( + CreateReconcile ReconcileType = "Create" + UpdateReconcile ReconcileType = "Update" + DeleteReconcile ReconcileType = "Delete" +) + +type ( + ReconcileType string +) diff --git a/images/agent/src/pkg/controller/bd/discoverer.go b/images/agent/src/internal/controller/bd/discoverer.go similarity index 98% rename from images/agent/src/pkg/controller/bd/discoverer.go rename to images/agent/src/internal/controller/bd/discoverer.go index d5bf1efe..97a69e10 100644 --- a/images/agent/src/pkg/controller/bd/discoverer.go +++ b/images/agent/src/internal/controller/bd/discoverer.go @@ -2,12 +2,11 @@ package bd import ( "agent/internal" - "agent/pkg/cache" - "agent/pkg/controller" - "agent/pkg/controller/clients" - "agent/pkg/controller/utils" - "agent/pkg/logger" - "agent/pkg/monitoring" + "agent/internal/cache" + "agent/internal/controller" + "agent/internal/logger" + "agent/internal/monitoring" + "agent/internal/utils" "context" "crypto/sha1" "fmt" @@ -30,7 +29,7 @@ const DiscovererName = "block-device-controller" type Discoverer struct { cl client.Client log logger.Logger - bdCl *clients.BDClient + bdCl *utils.BDClient metrics monitoring.Metrics sdsCache *cache.Cache opts Options @@ -52,7 +51,7 @@ func NewDiscoverer( return &Discoverer{ cl: cl, log: log, - bdCl: clients.NewBDClient(cl, metrics), + bdCl: utils.NewBDClient(cl, metrics), metrics: metrics, sdsCache: sdsCache, opts: opts, diff --git a/images/agent/src/pkg/controller/bd/discoverer_suite_test.go b/images/agent/src/internal/controller/bd/discoverer_suite_test.go similarity index 98% rename from images/agent/src/pkg/controller/bd/discoverer_suite_test.go rename to images/agent/src/internal/controller/bd/discoverer_suite_test.go index f5c3c104..330de6ad 100644 --- a/images/agent/src/pkg/controller/bd/discoverer_suite_test.go +++ b/images/agent/src/internal/controller/bd/discoverer_suite_test.go @@ -27,10 +27,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "agent/internal" - "agent/pkg/cache" - "agent/pkg/logger" - "agent/pkg/monitoring" - "agent/pkg/test_utils" + "agent/internal/cache" + "agent/internal/logger" + "agent/internal/monitoring" + "agent/internal/test_utils" ) var _ = Describe("Storage Controller", func() { diff --git a/images/agent/src/pkg/controller/bd/discoverer_test.go b/images/agent/src/internal/controller/bd/discoverer_test.go similarity index 98% rename from images/agent/src/pkg/controller/bd/discoverer_test.go rename to images/agent/src/internal/controller/bd/discoverer_test.go index 9b4d7cdd..879cd539 100644 --- a/images/agent/src/pkg/controller/bd/discoverer_test.go +++ b/images/agent/src/internal/controller/bd/discoverer_test.go @@ -32,12 +32,11 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "agent/internal" - "agent/pkg/cache" - cutils "agent/pkg/controller/utils" - "agent/pkg/logger" - "agent/pkg/monitoring" - "agent/pkg/test_utils" - "agent/pkg/utils" + "agent/internal/cache" + "agent/internal/logger" + "agent/internal/monitoring" + "agent/internal/test_utils" + "agent/internal/utils" ) //go:embed testdata/lsblk_output.json @@ -551,7 +550,7 @@ func TestBlockDeviceCtrl(t *testing.T) { expectedName := "testName" tags := fmt.Sprintf("storage.deckhouse.io/enabled=true,storage.deckhouse.io/lvmVolumeGroupName=%s", expectedName) - shouldBeTrue, actualName := cutils.CheckTag(tags) + shouldBeTrue, actualName := utils.CheckTag(tags) if assert.True(t, shouldBeTrue) { assert.Equal(t, expectedName, actualName) } @@ -560,7 +559,7 @@ func TestBlockDeviceCtrl(t *testing.T) { t.Run("Haven't tag_Returns false and empty", func(t *testing.T) { tags := "someWeirdTags=oMGwtFIsThis" - shouldBeFalse, actualName := cutils.CheckTag(tags) + shouldBeFalse, actualName := utils.CheckTag(tags) if assert.False(t, shouldBeFalse) { assert.Equal(t, "", actualName) } diff --git a/images/agent/src/pkg/controller/bd/testdata/lsblk_output.json b/images/agent/src/internal/controller/bd/testdata/lsblk_output.json similarity index 100% rename from images/agent/src/pkg/controller/bd/testdata/lsblk_output.json rename to images/agent/src/internal/controller/bd/testdata/lsblk_output.json diff --git a/images/agent/src/pkg/controller/controller.go b/images/agent/src/internal/controller/controller.go similarity index 98% rename from images/agent/src/pkg/controller/controller.go rename to images/agent/src/internal/controller/controller.go index dfb6b1d0..3fb13b12 100644 --- a/images/agent/src/pkg/controller/controller.go +++ b/images/agent/src/internal/controller/controller.go @@ -1,7 +1,7 @@ package controller import ( - "agent/pkg/logger" + "agent/internal/logger" "context" "fmt" "reflect" @@ -75,7 +75,7 @@ func AddReconciler[T client.Object]( } var obj T - err = c.Watch( + return c.Watch( source.Kind( mgrCache, obj, @@ -112,8 +112,6 @@ func AddReconciler[T client.Object]( }, ), ) - - return nil } func AddDiscoverer( @@ -169,7 +167,6 @@ func makeReconcileDispatcher[T client.Object]( return reconcile.Result{}, err } - // result, err := reconciler.Reconcile( ctx, ReconcileRequest[T]{ diff --git a/images/agent/src/pkg/controller/llv/reconciler.go b/images/agent/src/internal/controller/llv/reconciler.go similarity index 93% rename from images/agent/src/pkg/controller/llv/reconciler.go rename to images/agent/src/internal/controller/llv/reconciler.go index 55c29b0b..80a9c97a 100644 --- a/images/agent/src/pkg/controller/llv/reconciler.go +++ b/images/agent/src/internal/controller/llv/reconciler.go @@ -2,13 +2,11 @@ package llv import ( "agent/internal" - "agent/pkg/cache" - "agent/pkg/controller" - "agent/pkg/controller/clients" - cutils "agent/pkg/controller/utils" - "agent/pkg/logger" - "agent/pkg/monitoring" - "agent/pkg/utils" + "agent/internal/cache" + "agent/internal/controller" + "agent/internal/logger" + "agent/internal/monitoring" + "agent/internal/utils" "context" "errors" "fmt" @@ -27,22 +25,11 @@ import ( const ReconcilerName = "lvm-logical-volume-watcher-controller" -// TODO: remove -const ( - CreateReconcile reconcileType = "Create" - UpdateReconcile reconcileType = "Update" - DeleteReconcile reconcileType = "Delete" -) - -type ( - reconcileType string -) - type Reconciler struct { cl client.Client log logger.Logger - lvgCl *clients.LVGClient - llvCl *clients.LLVClient + lvgCl *utils.LVGClient + llvCl *utils.LLVClient metrics monitoring.Metrics sdsCache *cache.Cache opts ReconcilerOptions @@ -65,14 +52,14 @@ func NewReconciler( return &Reconciler{ cl: cl, log: log, - lvgCl: clients.NewLVGClient( + lvgCl: utils.NewLVGClient( cl, log, metrics, opts.NodeName, ReconcilerName, ), - llvCl: clients.NewLLVClient( + llvCl: utils.NewLLVClient( cl, log, ), metrics: metrics, @@ -124,7 +111,7 @@ func (r *Reconciler) Reconcile( err = r.llvCl.UpdatePhaseIfNeeded( ctx, llv, - cutils.LLVStatusPhaseFailed, + internal.LLVStatusPhaseFailed, fmt.Sprintf("LVMVolumeGroup %s not found", llv.Spec.LVMVolumeGroupName), ) if err != nil { @@ -140,7 +127,7 @@ func (r *Reconciler) Reconcile( err = r.llvCl.UpdatePhaseIfNeeded( ctx, llv, - cutils.LLVStatusPhaseFailed, + internal.LLVStatusPhaseFailed, fmt.Sprintf("Unable to get selected LVMVolumeGroup, err: %s", err.Error()), ) if err != nil { @@ -149,7 +136,7 @@ func (r *Reconciler) Reconcile( return controller.Result{}, err } - if !cutils.LVGBelongsToNode(lvg, r.opts.NodeName) { + if !utils.LVGBelongsToNode(lvg, r.opts.NodeName) { r.log.Info(fmt.Sprintf("[ReconcileLVMLogicalVolume] the LVMVolumeGroup %s of the LVMLogicalVolume %s does not belongs to the current node: %s. Reconciliation stopped", lvg.Name, llv.Name, r.opts.NodeName)) return controller.Result{}, nil } @@ -177,7 +164,7 @@ func (r *Reconciler) Reconcile( valid, reason := r.validateLVMLogicalVolume(llv, lvg) if !valid { r.log.Warning(fmt.Sprintf("[ReconcileLVMLogicalVolume] the LVMLogicalVolume %s is not valid, reason: %s", llv.Name, reason)) - err = r.llvCl.UpdatePhaseIfNeeded(ctx, llv, cutils.LLVStatusPhaseFailed, reason) + err = r.llvCl.UpdatePhaseIfNeeded(ctx, llv, internal.LLVStatusPhaseFailed, reason) if err != nil { r.log.Error(err, fmt.Sprintf("[ReconcileLVMLogicalVolume] unable to update the LVMLogicalVolume %s", llv.Name)) return controller.Result{}, err @@ -190,7 +177,7 @@ func (r *Reconciler) Reconcile( shouldRequeue, err := r.ReconcileLVMLogicalVolume(ctx, llv, lvg) if err != nil { r.log.Error(err, fmt.Sprintf("[RunLVMLogicalVolumeWatcherController] an error occurred while reconciling the LVMLogicalVolume: %s", llv.Name)) - updErr := r.llvCl.UpdatePhaseIfNeeded(ctx, llv, cutils.LLVStatusPhaseFailed, err.Error()) + updErr := r.llvCl.UpdatePhaseIfNeeded(ctx, llv, internal.LLVStatusPhaseFailed, err.Error()) if updErr != nil { r.log.Error(updErr, fmt.Sprintf("[RunLVMLogicalVolumeWatcherController] unable to update the LVMLogicalVolume %s", llv.Name)) return controller.Result{}, updErr @@ -212,17 +199,17 @@ func (r *Reconciler) ReconcileLVMLogicalVolume(ctx context.Context, llv *v1alpha r.log.Trace(fmt.Sprintf("[ReconcileLVMLogicalVolume] %+v", llv)) switch r.identifyReconcileFunc(lvg.Spec.ActualVGNameOnTheNode, llv) { - case CreateReconcile: + case internal.CreateReconcile: return r.reconcileLLVCreateFunc(ctx, llv, lvg) - case UpdateReconcile: + case internal.UpdateReconcile: return r.reconcileLLVUpdateFunc(ctx, llv, lvg) - case DeleteReconcile: + case internal.DeleteReconcile: return r.reconcileLLVDeleteFunc(ctx, llv, lvg) default: r.log.Info(fmt.Sprintf("[runEventReconcile] the LVMLogicalVolume %s has compeleted configuration and should not be reconciled", llv.Name)) - if llv.Status.Phase != cutils.LLVStatusPhaseCreated { - r.log.Warning(fmt.Sprintf("[runEventReconcile] the LVMLogicalVolume %s should not be reconciled but has an unexpected phase: %s. Setting the phase to %s", llv.Name, llv.Status.Phase, cutils.LLVStatusPhaseCreated)) - err := r.llvCl.UpdatePhaseIfNeeded(ctx, llv, cutils.LLVStatusPhaseCreated, "") + if llv.Status.Phase != internal.LLVStatusPhaseCreated { + r.log.Warning(fmt.Sprintf("[runEventReconcile] the LVMLogicalVolume %s should not be reconciled but has an unexpected phase: %s. Setting the phase to %s", llv.Name, llv.Status.Phase, internal.LLVStatusPhaseCreated)) + err := r.llvCl.UpdatePhaseIfNeeded(ctx, llv, internal.LLVStatusPhaseCreated, "") if err != nil { return true, err } @@ -241,19 +228,19 @@ func (r *Reconciler) reconcileLLVCreateFunc( // this check prevents infinite resource updating after retries if llv.Status == nil { - err := r.llvCl.UpdatePhaseIfNeeded(ctx, llv, cutils.LLVStatusPhasePending, "") + err := r.llvCl.UpdatePhaseIfNeeded(ctx, llv, internal.LLVStatusPhasePending, "") if err != nil { r.log.Error(err, fmt.Sprintf("[reconcileLLVCreateFunc] unable to update the LVMLogicalVolume %s", llv.Name)) return true, err } } - llvRequestSize, err := cutils.GetLLVRequestedSize(llv, lvg) + llvRequestSize, err := utils.GetLLVRequestedSize(llv, lvg) if err != nil { r.log.Error(err, fmt.Sprintf("[reconcileLLVCreateFunc] unable to get LVMLogicalVolume %s requested size", llv.Name)) return false, err } - freeSpace := cutils.GetFreeLVGSpaceForLLV(lvg, llv) + freeSpace := utils.GetFreeLVGSpaceForLLV(lvg, llv) r.log.Trace(fmt.Sprintf("[reconcileLLVCreateFunc] the LVMLogicalVolume %s, LV: %s, VG: %s type: %s requested size: %s, free space: %s", llv.Name, llv.Spec.ActualLVNameOnTheNode, lvg.Spec.ActualVGNameOnTheNode, llv.Spec.Type, llvRequestSize.String(), freeSpace.String())) if !utils.AreSizesEqualWithinDelta(llvRequestSize, freeSpace, internal.ResizeDelta) { @@ -268,10 +255,10 @@ func (r *Reconciler) reconcileLLVCreateFunc( var cmd string switch llv.Spec.Type { - case cutils.Thick: + case internal.Thick: r.log.Debug(fmt.Sprintf("[reconcileLLVCreateFunc] LV %s will be created in VG %s with size: %s", llv.Spec.ActualLVNameOnTheNode, lvg.Spec.ActualVGNameOnTheNode, llvRequestSize.String())) cmd, err = utils.CreateThickLogicalVolume(lvg.Spec.ActualVGNameOnTheNode, llv.Spec.ActualLVNameOnTheNode, llvRequestSize.Value(), isContiguous(llv)) - case cutils.Thin: + case internal.Thin: if llv.Spec.Source == nil { r.log.Debug(fmt.Sprintf("[reconcileLLVCreateFunc] LV %s of the LVMLogicalVolume %s will be created in Thin-pool %s with size %s", llv.Spec.ActualLVNameOnTheNode, llv.Name, llv.Spec.Thin.PoolName, llvRequestSize.String())) cmd, err = utils.CreateThinLogicalVolume(lvg.Spec.ActualVGNameOnTheNode, llv.Spec.Thin.PoolName, llv.Spec.ActualLVNameOnTheNode, llvRequestSize.Value()) @@ -343,7 +330,7 @@ func (r *Reconciler) reconcileLLVUpdateFunc( // status might be nil if a user creates the resource with LV name which matches existing LV on the node if llv.Status == nil { - err := r.llvCl.UpdatePhaseIfNeeded(ctx, llv, cutils.LLVStatusPhasePending, "") + err := r.llvCl.UpdatePhaseIfNeeded(ctx, llv, internal.LLVStatusPhasePending, "") if err != nil { r.log.Error(err, fmt.Sprintf("[reconcileLLVUpdateFunc] unable to update the LVMLogicalVolume %s", llv.Name)) return true, err @@ -360,7 +347,7 @@ func (r *Reconciler) reconcileLLVUpdateFunc( r.log.Debug(fmt.Sprintf("[reconcileLLVUpdateFunc] successfully got LVMLogicalVolume %s actual size %s before the extension", llv.Name, actualSize.String())) r.log.Debug(fmt.Sprintf("[reconcileLLVUpdateFunc] tries to count the LVMLogicalVolume %s requested size", llv.Name)) - llvRequestSize, err := cutils.GetLLVRequestedSize(llv, lvg) + llvRequestSize, err := utils.GetLLVRequestedSize(llv, lvg) if err != nil { r.log.Error(err, fmt.Sprintf("[reconcileLLVCreateFunc] unable to get LVMLogicalVolume %s requested size", llv.Name)) return false, err @@ -389,15 +376,15 @@ func (r *Reconciler) reconcileLLVUpdateFunc( r.log.Info(fmt.Sprintf("[reconcileLLVUpdateFunc] the LVMLogicalVolume %s should be resized", llv.Name)) // this check prevents infinite resource updates after retry - if llv.Status.Phase != cutils.LLVStatusPhaseFailed { - err := r.llvCl.UpdatePhaseIfNeeded(ctx, llv, cutils.LLVStatusPhaseResizing, "") + if llv.Status.Phase != internal.LLVStatusPhaseFailed { + err := r.llvCl.UpdatePhaseIfNeeded(ctx, llv, internal.LLVStatusPhaseResizing, "") if err != nil { r.log.Error(err, fmt.Sprintf("[reconcileLLVUpdateFunc] unable to update the LVMLogicalVolume %s", llv.Name)) return true, err } } - freeSpace := cutils.GetFreeLVGSpaceForLLV(lvg, llv) + freeSpace := utils.GetFreeLVGSpaceForLLV(lvg, llv) r.log.Trace(fmt.Sprintf("[reconcileLLVUpdateFunc] the LVMLogicalVolume %s, LV: %s, VG: %s, type: %s, extending size: %s, free space: %s", llv.Name, llv.Spec.ActualLVNameOnTheNode, lvg.Spec.ActualVGNameOnTheNode, llv.Spec.Type, extendingSize.String(), freeSpace.String())) if !utils.AreSizesEqualWithinDelta(freeSpace, extendingSize, internal.ResizeDelta) { @@ -475,20 +462,20 @@ func (r *Reconciler) reconcileLLVDeleteFunc( return false, nil } -func (r *Reconciler) identifyReconcileFunc(vgName string, llv *v1alpha1.LVMLogicalVolume) reconcileType { +func (r *Reconciler) identifyReconcileFunc(vgName string, llv *v1alpha1.LVMLogicalVolume) internal.ReconcileType { should := r.shouldReconcileByCreateFunc(vgName, llv) if should { - return CreateReconcile + return internal.CreateReconcile } should = r.shouldReconcileByUpdateFunc(vgName, llv) if should { - return UpdateReconcile + return internal.UpdateReconcile } should = shouldReconcileByDeleteFunc(llv) if should { - return DeleteReconcile + return internal.DeleteReconcile } return "" @@ -526,11 +513,11 @@ func (r *Reconciler) removeLLVFinalizersIfExist( func checkIfLVBelongsToLLV(llv *v1alpha1.LVMLogicalVolume, lv *internal.LVData) bool { switch llv.Spec.Type { - case cutils.Thin: + case internal.Thin: if lv.PoolName != llv.Spec.Thin.PoolName { return false } - case cutils.Thick: + case internal.Thick: contiguous := string(lv.LVAttr[2]) == "c" if string(lv.LVAttr[0]) != "-" || contiguous != isContiguous(llv) { @@ -621,7 +608,7 @@ func (r *Reconciler) validateLVMLogicalVolume(llv *v1alpha1.LVMLogicalVolume, lv reason.WriteString("No LV name specified. ") } - llvRequestedSize, err := cutils.GetLLVRequestedSize(llv, lvg) + llvRequestedSize, err := utils.GetLLVRequestedSize(llv, lvg) if err != nil { reason.WriteString(err.Error()) } @@ -637,7 +624,7 @@ func (r *Reconciler) validateLVMLogicalVolume(llv *v1alpha1.LVMLogicalVolume, lv } switch llv.Spec.Type { - case cutils.Thin: + case internal.Thin: if llv.Spec.Thin == nil { reason.WriteString("No thin pool specified. ") break @@ -654,7 +641,7 @@ func (r *Reconciler) validateLVMLogicalVolume(llv *v1alpha1.LVMLogicalVolume, lv if !exist { reason.WriteString("Selected thin pool does not exist in selected LVMVolumeGroup. ") } - case cutils.Thick: + case internal.Thick: if llv.Spec.Thin != nil { reason.WriteString("Thin pool specified for Thick LV. ") } diff --git a/images/agent/src/pkg/controller/llv/reconciler_test.go b/images/agent/src/internal/controller/llv/reconciler_test.go similarity index 91% rename from images/agent/src/pkg/controller/llv/reconciler_test.go rename to images/agent/src/internal/controller/llv/reconciler_test.go index c2fb5d31..51857b6e 100644 --- a/images/agent/src/pkg/controller/llv/reconciler_test.go +++ b/images/agent/src/internal/controller/llv/reconciler_test.go @@ -12,12 +12,11 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "agent/internal" - "agent/pkg/cache" - cutils "agent/pkg/controller/utils" - "agent/pkg/logger" - "agent/pkg/monitoring" - "agent/pkg/test_utils" - "agent/pkg/utils" + "agent/internal/cache" + "agent/internal/logger" + "agent/internal/monitoring" + "agent/internal/test_utils" + "agent/internal/utils" ) func TestLVMLogicaVolumeWatcher(t *testing.T) { @@ -41,7 +40,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { llv := &v1alpha1.LVMLogicalVolume{ ObjectMeta: v1.ObjectMeta{}, Spec: v1alpha1.LVMLogicalVolumeSpec{ - Type: cutils.Thin, + Type: internal.Thin, Thin: &v1alpha1.LVMLogicalVolumeThinSpec{PoolName: poolName}, }, } @@ -55,7 +54,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { llv := &v1alpha1.LVMLogicalVolume{ ObjectMeta: v1.ObjectMeta{}, Spec: v1alpha1.LVMLogicalVolumeSpec{ - Type: cutils.Thin, + Type: internal.Thin, Thin: &v1alpha1.LVMLogicalVolumeThinSpec{PoolName: poolName}, }, } @@ -68,7 +67,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { llv := &v1alpha1.LVMLogicalVolume{ ObjectMeta: v1.ObjectMeta{}, Spec: v1alpha1.LVMLogicalVolumeSpec{ - Type: cutils.Thick, + Type: internal.Thick, }, } lv := &internal.LVData{LVAttr: "-wi-a-----"} @@ -80,7 +79,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { llv := &v1alpha1.LVMLogicalVolume{ ObjectMeta: v1.ObjectMeta{}, Spec: v1alpha1.LVMLogicalVolumeSpec{ - Type: cutils.Thick, + Type: internal.Thick, }, } lv1 := &internal.LVData{LVAttr: "Vwi-a-----"} @@ -120,7 +119,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { llv := &v1alpha1.LVMLogicalVolume{ Spec: v1alpha1.LVMLogicalVolumeSpec{ ActualLVNameOnTheNode: "test-lv", - Type: cutils.Thick, + Type: internal.Thick, Size: "10M", LVMVolumeGroupName: lvgName, }, @@ -140,7 +139,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { llv := &v1alpha1.LVMLogicalVolume{ Spec: v1alpha1.LVMLogicalVolumeSpec{ ActualLVNameOnTheNode: lvName, - Type: cutils.Thick, + Type: internal.Thick, Size: "0M", LVMVolumeGroupName: "some-lvg", Thin: &v1alpha1.LVMLogicalVolumeThinSpec{PoolName: "some-lvg"}, @@ -184,7 +183,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { llv := &v1alpha1.LVMLogicalVolume{ Spec: v1alpha1.LVMLogicalVolumeSpec{ ActualLVNameOnTheNode: "test-lv", - Type: cutils.Thin, + Type: internal.Thin, Size: "10M", LVMVolumeGroupName: lvgName, Thin: &v1alpha1.LVMLogicalVolumeThinSpec{PoolName: tpName}, @@ -204,7 +203,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { llv := &v1alpha1.LVMLogicalVolume{ Spec: v1alpha1.LVMLogicalVolumeSpec{ ActualLVNameOnTheNode: "", - Type: cutils.Thin, + Type: internal.Thin, Size: "0M", LVMVolumeGroupName: "some-lvg", }, @@ -224,7 +223,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { }) t.Run("getThinPoolAvailableSpace", func(t *testing.T) { - free, err := cutils.GetThinPoolAvailableSpace( + free, err := utils.GetThinPoolAvailableSpace( resource.MustParse("10Gi"), resource.MustParse("5Gi"), internal.AllocationLimitDefaultValue, @@ -252,12 +251,12 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { } t.Run("returns_true", func(t *testing.T) { - belongs := cutils.LVGBelongsToNode(lvg, nodeName) + belongs := utils.LVGBelongsToNode(lvg, nodeName) assert.True(t, belongs) }) t.Run("returns_false", func(t *testing.T) { - belongs := cutils.LVGBelongsToNode(lvg, "other_node") + belongs := utils.LVGBelongsToNode(lvg, "other_node") assert.False(t, belongs) }) }) @@ -269,7 +268,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { actual := r.identifyReconcileFunc(vgName, llv) - assert.Equal(t, CreateReconcile, actual) + assert.Equal(t, internal.CreateReconcile, actual) }) t.Run("returns_update", func(t *testing.T) { @@ -281,7 +280,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { ActualLVNameOnTheNode: lvName, }, Status: &v1alpha1.LVMLogicalVolumeStatus{ - Phase: cutils.LLVStatusPhaseCreated, + Phase: internal.LLVStatusPhaseCreated, }, } r.sdsCache.StoreLVs([]internal.LVData{ @@ -293,7 +292,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { actual := r.identifyReconcileFunc(vgName, llv) - assert.Equal(t, UpdateReconcile, actual) + assert.Equal(t, internal.UpdateReconcile, actual) }) t.Run("returns_delete", func(t *testing.T) { @@ -302,13 +301,13 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { llv := &v1alpha1.LVMLogicalVolume{ ObjectMeta: v1.ObjectMeta{DeletionTimestamp: &v1.Time{}}, Status: &v1alpha1.LVMLogicalVolumeStatus{ - Phase: cutils.LLVStatusPhaseCreated, + Phase: internal.LLVStatusPhaseCreated, }, } actual := r.identifyReconcileFunc(vgName, llv) - assert.Equal(t, DeleteReconcile, actual) + assert.Equal(t, internal.DeleteReconcile, actual) }) }) @@ -322,7 +321,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { ActualLVNameOnTheNode: lvName, }, Status: &v1alpha1.LVMLogicalVolumeStatus{ - Phase: cutils.LLVStatusPhaseCreated, + Phase: internal.LLVStatusPhaseCreated, }, } @@ -338,7 +337,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { ActualLVNameOnTheNode: lvName, }, Status: &v1alpha1.LVMLogicalVolumeStatus{ - Phase: cutils.LLVStatusPhaseCreated, + Phase: internal.LLVStatusPhaseCreated, }, } r.sdsCache.StoreLVs([]internal.LVData{ @@ -360,7 +359,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { ActualLVNameOnTheNode: lvName, }, Status: &v1alpha1.LVMLogicalVolumeStatus{ - Phase: cutils.LLVStatusPhaseCreated, + Phase: internal.LLVStatusPhaseCreated, }, } should := r.shouldReconcileByCreateFunc(vgName, llv) @@ -389,7 +388,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { ActualLVNameOnTheNode: lvName, }, Status: &v1alpha1.LVMLogicalVolumeStatus{ - Phase: cutils.LLVStatusPhaseCreated, + Phase: internal.LLVStatusPhaseCreated, }, } r.sdsCache.StoreLVs([]internal.LVData{ @@ -410,7 +409,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { ActualLVNameOnTheNode: lvName, }, Status: &v1alpha1.LVMLogicalVolumeStatus{ - Phase: cutils.LLVStatusPhaseCreated, + Phase: internal.LLVStatusPhaseCreated, }, } should := r.shouldReconcileByUpdateFunc(vgName, llv) @@ -446,7 +445,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { Name: "test", }, Status: &v1alpha1.LVMLogicalVolumeStatus{ - Phase: cutils.LLVStatusPhaseCreated, + Phase: internal.LLVStatusPhaseCreated, Reason: "", }, } @@ -464,7 +463,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { } }() - err = r.llvCl.UpdatePhaseIfNeeded(ctx, llv, cutils.LLVStatusPhaseFailed, reason) + err = r.llvCl.UpdatePhaseIfNeeded(ctx, llv, internal.LLVStatusPhaseFailed, reason) if assert.NoError(t, err) { newLLV := &v1alpha1.LVMLogicalVolume{} err = r.cl.Get(ctx, client.ObjectKey{ @@ -472,7 +471,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { Namespace: "", }, newLLV) - assert.Equal(t, newLLV.Status.Phase, cutils.LLVStatusPhaseFailed) + assert.Equal(t, newLLV.Status.Phase, internal.LLVStatusPhaseFailed) assert.Equal(t, newLLV.Status.Reason, reason) } }) @@ -576,7 +575,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { Size: oldSize.String(), }, Status: &v1alpha1.LVMLogicalVolumeStatus{ - Phase: cutils.LLVStatusPhasePending, + Phase: internal.LLVStatusPhasePending, Reason: "", ActualSize: *oldSize, }, @@ -605,12 +604,12 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { } if assert.NotNil(t, oldLLV) { - assert.Equal(t, cutils.LLVStatusPhasePending, oldLLV.Status.Phase) + assert.Equal(t, internal.LLVStatusPhasePending, oldLLV.Status.Phase) assert.Equal(t, oldSize.Value(), oldLLV.Status.ActualSize.Value()) } oldLLV.Spec.Size = newSize.String() - oldLLV.Status.Phase = cutils.LLVStatusPhaseCreated + oldLLV.Status.Phase = internal.LLVStatusPhaseCreated oldLLV.Status.ActualSize = *newSize err = r.updateLVMLogicalVolumeSpec(ctx, oldLLV) @@ -624,7 +623,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { return } - assert.Equal(t, cutils.LLVStatusPhasePending, newLLV.Status.Phase) + assert.Equal(t, internal.LLVStatusPhasePending, newLLV.Status.Phase) assert.Equal(t, oldSize.Value(), newLLV.Status.ActualSize.Value()) } }) @@ -648,7 +647,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { Size: oldSize.String(), }, Status: &v1alpha1.LVMLogicalVolumeStatus{ - Phase: cutils.LLVStatusPhasePending, + Phase: internal.LLVStatusPhasePending, Reason: "", ActualSize: *oldSize, }, @@ -677,7 +676,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { } if assert.NotNil(t, oldLLV) { - assert.Equal(t, cutils.LLVStatusPhasePending, oldLLV.Status.Phase) + assert.Equal(t, internal.LLVStatusPhasePending, oldLLV.Status.Phase) assert.Equal(t, oldSize.Value(), oldLLV.Status.ActualSize.Value()) } @@ -695,7 +694,7 @@ func TestLVMLogicaVolumeWatcher(t *testing.T) { } assert.Equal(t, oldSize.String(), newLLV.Spec.Size) - assert.Equal(t, cutils.LLVStatusPhaseCreated, newLLV.Status.Phase) + assert.Equal(t, internal.LLVStatusPhaseCreated, newLLV.Status.Phase) assert.Equal(t, newSize.Value(), newLLV.Status.ActualSize.Value()) } }) diff --git a/images/agent/src/pkg/controller/llv_extender/reconciler.go b/images/agent/src/internal/controller/llv_extender/reconciler.go similarity index 88% rename from images/agent/src/pkg/controller/llv_extender/reconciler.go rename to images/agent/src/internal/controller/llv_extender/reconciler.go index 4c0d3e3d..1eb130f2 100644 --- a/images/agent/src/pkg/controller/llv_extender/reconciler.go +++ b/images/agent/src/internal/controller/llv_extender/reconciler.go @@ -2,13 +2,11 @@ package llv_extender import ( "agent/internal" - "agent/pkg/cache" - "agent/pkg/controller" - "agent/pkg/controller/clients" - cutils "agent/pkg/controller/utils" - "agent/pkg/logger" - "agent/pkg/monitoring" - "agent/pkg/utils" + "agent/internal/cache" + "agent/internal/controller" + "agent/internal/logger" + "agent/internal/monitoring" + "agent/internal/utils" "context" "errors" "fmt" @@ -24,8 +22,8 @@ const ReconcilerName = "lvm-logical-volume-extender-controller" type Reconciler struct { cl client.Client log logger.Logger - lvgCl *clients.LVGClient - llvCl *clients.LLVClient + lvgCl *utils.LVGClient + llvCl *utils.LLVClient metrics monitoring.Metrics sdsCache *cache.Cache opts ReconcilerOptions @@ -46,14 +44,14 @@ func NewReconciler( return &Reconciler{ cl: cl, log: log, - lvgCl: clients.NewLVGClient( + lvgCl: utils.NewLVGClient( cl, log, metrics, opts.NodeName, ReconcilerName, ), - llvCl: clients.NewLLVClient(cl, log), + llvCl: utils.NewLLVClient(cl, log), metrics: metrics, sdsCache: sdsCache, opts: opts, @@ -108,7 +106,7 @@ func (r *Reconciler) shouldLLVExtenderReconcileEvent(newLVG *v1alpha1.LVMVolumeG return false } - if !cutils.LVGBelongsToNode(newLVG, r.opts.NodeName) { + if !utils.LVGBelongsToNode(newLVG, r.opts.NodeName) { r.log.Debug(fmt.Sprintf("[RunLVMLogicalVolumeExtenderWatcherController] the LVMVolumeGroup %s should not be reconciled as it does not belong to the node %s", newLVG.Name, r.opts.NodeName)) return false } @@ -141,7 +139,7 @@ func (r *Reconciler) ReconcileLVMLogicalVolumeExtension( shouldRetry := false for _, llv := range llvs { r.log.Info(fmt.Sprintf("[ReconcileLVMLogicalVolumeExtension] starts to reconcile the LVMLogicalVolume %s", llv.Name)) - llvRequestedSize, err := cutils.GetLLVRequestedSize(&llv, lvg) + llvRequestedSize, err := utils.GetLLVRequestedSize(&llv, lvg) if err != nil { r.log.Error(err, fmt.Sprintf("[ReconcileLVMLogicalVolumeExtension] unable to get requested size of the LVMLogicalVolume %s", llv.Name)) shouldRetry = true @@ -153,7 +151,7 @@ func (r *Reconciler) ReconcileLVMLogicalVolumeExtension( if lv == nil { err = fmt.Errorf("lv %s not found", llv.Spec.ActualLVNameOnTheNode) r.log.Error(err, fmt.Sprintf("[ReconcileLVMLogicalVolumeExtension] unable to find LV %s of the LVMLogicalVolume %s", llv.Spec.ActualLVNameOnTheNode, llv.Name)) - err = r.llvCl.UpdatePhaseIfNeeded(ctx, &llv, cutils.LLVStatusPhaseFailed, err.Error()) + err = r.llvCl.UpdatePhaseIfNeeded(ctx, &llv, internal.LLVStatusPhaseFailed, err.Error()) if err != nil { r.log.Error(err, fmt.Sprintf("[ReconcileLVMLogicalVolumeExtension] unable to update the LVMLogicalVolume %s", llv.Name)) } @@ -171,11 +169,11 @@ func (r *Reconciler) ReconcileLVMLogicalVolumeExtension( continue } - freeSpace := cutils.GetFreeLVGSpaceForLLV(lvg, &llv) + freeSpace := utils.GetFreeLVGSpaceForLLV(lvg, &llv) if llvRequestedSize.Value()+internal.ResizeDelta.Value() > freeSpace.Value() { err = errors.New("not enough space") r.log.Error(err, fmt.Sprintf("[ReconcileLVMLogicalVolumeExtension] unable to extend the LV %s of the LVMLogicalVolume %s", llv.Spec.ActualLVNameOnTheNode, llv.Name)) - err = r.llvCl.UpdatePhaseIfNeeded(ctx, &llv, cutils.LLVStatusPhaseFailed, fmt.Sprintf("unable to extend LV, err: %s", err.Error())) + err = r.llvCl.UpdatePhaseIfNeeded(ctx, &llv, internal.LLVStatusPhaseFailed, fmt.Sprintf("unable to extend LV, err: %s", err.Error())) if err != nil { r.log.Error(err, fmt.Sprintf("[ReconcileLVMLogicalVolumeExtension] unable to update the LVMLogicalVolume %s", llv.Name)) shouldRetry = true @@ -184,7 +182,7 @@ func (r *Reconciler) ReconcileLVMLogicalVolumeExtension( } r.log.Info(fmt.Sprintf("[ReconcileLVMLogicalVolumeExtension] the LVMLogicalVolume %s should be extended from %s to %s size", llv.Name, llv.Status.ActualSize.String(), llvRequestedSize.String())) - err = r.llvCl.UpdatePhaseIfNeeded(ctx, &llv, cutils.LLVStatusPhaseResizing, "") + err = r.llvCl.UpdatePhaseIfNeeded(ctx, &llv, internal.LLVStatusPhaseResizing, "") if err != nil { r.log.Error(err, fmt.Sprintf("[ReconcileLVMLogicalVolumeExtension] unable to update the LVMLogicalVolume %s", llv.Name)) shouldRetry = true @@ -194,7 +192,7 @@ func (r *Reconciler) ReconcileLVMLogicalVolumeExtension( cmd, err := utils.ExtendLV(llvRequestedSize.Value(), lvg.Spec.ActualVGNameOnTheNode, llv.Spec.ActualLVNameOnTheNode) if err != nil { r.log.Error(err, fmt.Sprintf("[ReconcileLVMLogicalVolumeExtension] unable to extend LV %s of the LVMLogicalVolume %s, cmd: %s", llv.Spec.ActualLVNameOnTheNode, llv.Name, cmd)) - err = r.llvCl.UpdatePhaseIfNeeded(ctx, &llv, cutils.LLVStatusPhaseFailed, fmt.Sprintf("unable to extend LV, err: %s", err.Error())) + err = r.llvCl.UpdatePhaseIfNeeded(ctx, &llv, internal.LLVStatusPhaseFailed, fmt.Sprintf("unable to extend LV, err: %s", err.Error())) if err != nil { r.log.Error(err, fmt.Sprintf("[ReconcileLVMLogicalVolumeExtension] unable to update the LVMLogicalVolume %s", llv.Name)) } @@ -224,7 +222,7 @@ func (r *Reconciler) ReconcileLVMLogicalVolumeExtension( r.log.Error(err, fmt.Sprintf("[ReconcileLVMLogicalVolumeExtension] unable to resize the LVMLogicalVolume %s", llv.Name)) shouldRetry = true - if err = r.llvCl.UpdatePhaseIfNeeded(ctx, &llv, cutils.LLVStatusPhaseFailed, err.Error()); err != nil { + if err = r.llvCl.UpdatePhaseIfNeeded(ctx, &llv, internal.LLVStatusPhaseFailed, err.Error()); err != nil { r.log.Error(err, fmt.Sprintf("[ReconcileLVMLogicalVolumeExtension] unable to update the LVMLogicalVolume %s", llv.Name)) } continue @@ -247,7 +245,7 @@ func (r *Reconciler) getAllLLVsWithPercentSize(ctx context.Context, lvgName stri result := make([]v1alpha1.LVMLogicalVolume, 0, len(llvList.Items)) for _, llv := range llvList.Items { - if llv.Spec.LVMVolumeGroupName == lvgName && cutils.IsPercentSize(llv.Spec.Size) { + if llv.Spec.LVMVolumeGroupName == lvgName && utils.IsPercentSize(llv.Spec.Size) { result = append(result, llv) } } diff --git a/images/agent/src/pkg/controller/lvg/discoverer.go b/images/agent/src/internal/controller/lvg/discoverer.go similarity index 98% rename from images/agent/src/pkg/controller/lvg/discoverer.go rename to images/agent/src/internal/controller/lvg/discoverer.go index 01287003..0b16d64b 100644 --- a/images/agent/src/pkg/controller/lvg/discoverer.go +++ b/images/agent/src/internal/controller/lvg/discoverer.go @@ -2,13 +2,11 @@ package lvg import ( "agent/internal" - "agent/pkg/cache" - "agent/pkg/controller" - "agent/pkg/controller/clients" - cutils "agent/pkg/controller/utils" - "agent/pkg/logger" - "agent/pkg/monitoring" - "agent/pkg/utils" + "agent/internal/cache" + "agent/internal/controller" + "agent/internal/logger" + "agent/internal/monitoring" + "agent/internal/utils" "context" "errors" "fmt" @@ -29,8 +27,8 @@ const DiscovererName = "lvm-volume-group-discover-controller" type Discoverer struct { cl client.Client log logger.Logger - lvgCl *clients.LVGClient - bdCl *clients.BDClient + lvgCl *utils.LVGClient + bdCl *utils.BDClient metrics monitoring.Metrics sdsCache *cache.Cache opts DiscovererOptions @@ -51,8 +49,8 @@ func NewDiscoverer( return &Discoverer{ cl: cl, log: log, - lvgCl: clients.NewLVGClient(cl, log, metrics, opts.NodeName, DiscovererName), - bdCl: clients.NewBDClient(cl, metrics), + lvgCl: utils.NewLVGClient(cl, log, metrics, opts.NodeName, DiscovererName), + bdCl: utils.NewBDClient(cl, metrics), metrics: metrics, sdsCache: sdsCache, opts: opts, @@ -432,7 +430,7 @@ func (d *Discoverer) UpdateLVMVolumeGroupByCandidate( candidate internal.LVMVolumeGroupCandidate, ) error { // Check if VG has some problems - if candidate.Health == NonOperational { + if candidate.Health == internal.NonOperational { d.log.Warning(fmt.Sprintf("[UpdateLVMVolumeGroupByCandidate] candidate for LVMVolumeGroup %s has NonOperational health, message %s. Update the VGReady condition to False", lvg.Name, candidate.Message)) updErr := d.lvgCl.UpdateLVGConditionIfNeeded(ctx, lvg, metav1.ConditionFalse, internal.TypeVGReady, internal.ReasonScanFailed, candidate.Message) if updErr != nil { @@ -945,7 +943,7 @@ func convertStatusThinPools(lvg v1alpha1.LVMVolumeGroup, thinPools []internal.LV limit = internal.AllocationLimitDefaultValue } - freeSpace, err := cutils.GetThinPoolAvailableSpace(tp.ActualSize, tp.AllocatedSize, limit) + freeSpace, err := utils.GetThinPoolAvailableSpace(tp.ActualSize, tp.AllocatedSize, limit) if err != nil { return nil, err } diff --git a/images/agent/src/pkg/controller/lvg/discoverer_test.go b/images/agent/src/internal/controller/lvg/discoverer_test.go similarity index 98% rename from images/agent/src/pkg/controller/lvg/discoverer_test.go rename to images/agent/src/internal/controller/lvg/discoverer_test.go index b1f6bdb5..fa783887 100644 --- a/images/agent/src/pkg/controller/lvg/discoverer_test.go +++ b/images/agent/src/internal/controller/lvg/discoverer_test.go @@ -27,10 +27,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "agent/internal" - "agent/pkg/cache" - "agent/pkg/logger" - "agent/pkg/monitoring" - "agent/pkg/test_utils" + "agent/internal/cache" + "agent/internal/logger" + "agent/internal/monitoring" + "agent/internal/test_utils" ) func TestLVMVolumeGroupDiscover(t *testing.T) { @@ -616,7 +616,7 @@ func TestLVMVolumeGroupDiscover(t *testing.T) { firstLVName: { ObjectMeta: metav1.ObjectMeta{Name: firstLVName}, Spec: v1alpha1.LVMVolumeGroupSpec{ - Type: Local, + Type: internal.Local, ActualVGNameOnTheNode: vgName, Local: v1alpha1.LVMVolumeGroupLocalSpec{ NodeName: "other-node", @@ -626,7 +626,7 @@ func TestLVMVolumeGroupDiscover(t *testing.T) { secondLVName: { ObjectMeta: metav1.ObjectMeta{Name: secondLVName}, Spec: v1alpha1.LVMVolumeGroupSpec{ - Type: Local, + Type: internal.Local, ActualVGNameOnTheNode: vgName, Local: v1alpha1.LVMVolumeGroupLocalSpec{ NodeName: currentNode, @@ -640,7 +640,7 @@ func TestLVMVolumeGroupDiscover(t *testing.T) { vgName: { ObjectMeta: metav1.ObjectMeta{Name: secondLVName}, Spec: v1alpha1.LVMVolumeGroupSpec{ - Type: Local, + Type: internal.Local, ActualVGNameOnTheNode: vgName, Local: v1alpha1.LVMVolumeGroupLocalSpec{ NodeName: currentNode, @@ -665,7 +665,7 @@ func TestLVMVolumeGroupDiscover(t *testing.T) { firstLVName: { ObjectMeta: metav1.ObjectMeta{Name: firstLVName}, Spec: v1alpha1.LVMVolumeGroupSpec{ - Type: Local, + Type: internal.Local, Local: v1alpha1.LVMVolumeGroupLocalSpec{ NodeName: anotherNode, }, @@ -674,7 +674,7 @@ func TestLVMVolumeGroupDiscover(t *testing.T) { secondLVName: { ObjectMeta: metav1.ObjectMeta{Name: secondLVName}, Spec: v1alpha1.LVMVolumeGroupSpec{ - Type: Local, + Type: internal.Local, Local: v1alpha1.LVMVolumeGroupLocalSpec{ NodeName: anotherNode, }, diff --git a/images/agent/src/pkg/controller/lvg/reconciler.go b/images/agent/src/internal/controller/lvg/reconciler.go similarity index 96% rename from images/agent/src/pkg/controller/lvg/reconciler.go rename to images/agent/src/internal/controller/lvg/reconciler.go index 49070fc6..45d62854 100644 --- a/images/agent/src/pkg/controller/lvg/reconciler.go +++ b/images/agent/src/internal/controller/lvg/reconciler.go @@ -2,13 +2,11 @@ package lvg import ( "agent/internal" - "agent/pkg/cache" - "agent/pkg/controller" - "agent/pkg/controller/clients" - cutils "agent/pkg/controller/utils" - "agent/pkg/logger" - "agent/pkg/monitoring" - "agent/pkg/utils" + "agent/internal/cache" + "agent/internal/controller" + "agent/internal/logger" + "agent/internal/monitoring" + "agent/internal/utils" "context" "errors" "fmt" @@ -24,37 +22,12 @@ import ( ) const ReconcilerName = "lvm-volume-group-watcher-controller" -const LVGMetadateNameLabelKey = "kubernetes.io/metadata.name" - -const ( - Local = "Local" - Shared = "Shared" - - Failed = "Failed" - - NonOperational = "NonOperational" - - deletionProtectionAnnotation = "storage.deckhouse.io/deletion-protection" - - LVMVolumeGroupTag = "storage.deckhouse.io/lvmVolumeGroupName" -) - -// TODO: remove -const ( - CreateReconcile reconcileType = "Create" - UpdateReconcile reconcileType = "Update" - DeleteReconcile reconcileType = "Delete" -) - -type ( - reconcileType string -) type Reconciler struct { cl client.Client log logger.Logger - lvgCl *clients.LVGClient - bdCl *clients.BDClient + lvgCl *utils.LVGClient + bdCl *utils.BDClient metrics monitoring.Metrics sdsCache *cache.Cache opts ReconcilerOptions @@ -76,14 +49,14 @@ func NewReconciler( return &Reconciler{ cl: cl, log: log, - lvgCl: clients.NewLVGClient( + lvgCl: utils.NewLVGClient( cl, log, metrics, opts.NodeName, ReconcilerName, ), - bdCl: clients.NewBDClient(cl, metrics), + bdCl: utils.NewBDClient(cl, metrics), metrics: metrics, sdsCache: sdsCache, opts: opts, @@ -190,17 +163,17 @@ func (r *Reconciler) Reconcile(ctx context.Context, request controller.Reconcile } r.log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] successfully validated BlockDevices of the LVMVolumeGroup %s", lvg.Name)) - r.log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] tries to add label %s to the LVMVolumeGroup %s", LVGMetadateNameLabelKey, r.opts.NodeName)) - added, err = r.addLVGLabelIfNeeded(ctx, lvg, LVGMetadateNameLabelKey, lvg.Name) + r.log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] tries to add label %s to the LVMVolumeGroup %s", internal.LVGMetadateNameLabelKey, r.opts.NodeName)) + added, err = r.addLVGLabelIfNeeded(ctx, lvg, internal.LVGMetadateNameLabelKey, lvg.Name) if err != nil { - r.log.Error(err, fmt.Sprintf("[RunLVMVolumeGroupWatcherController] unable to add label %s to the LVMVolumeGroup %s", LVGMetadateNameLabelKey, lvg.Name)) + r.log.Error(err, fmt.Sprintf("[RunLVMVolumeGroupWatcherController] unable to add label %s to the LVMVolumeGroup %s", internal.LVGMetadateNameLabelKey, lvg.Name)) return controller.Result{}, err } if added { - r.log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] successfully added label %s to the LVMVolumeGroup %s", LVGMetadateNameLabelKey, lvg.Name)) + r.log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] successfully added label %s to the LVMVolumeGroup %s", internal.LVGMetadateNameLabelKey, lvg.Name)) } else { - r.log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] no need to add label %s to the LVMVolumeGroup %s", LVGMetadateNameLabelKey, lvg.Name)) + r.log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] no need to add label %s to the LVMVolumeGroup %s", internal.LVGMetadateNameLabelKey, lvg.Name)) } // We do this after BlockDevices validation and node belonging check to prevent multiple updates by all agents pods @@ -255,13 +228,13 @@ func (r *Reconciler) runEventReconcile( recType := r.identifyLVGReconcileFunc(lvg) switch recType { - case CreateReconcile: + case internal.CreateReconcile: r.log.Info(fmt.Sprintf("[runEventReconcile] CreateReconcile starts the reconciliation for the LVMVolumeGroup %s", lvg.Name)) return r.reconcileLVGCreateFunc(ctx, lvg, blockDevices) - case UpdateReconcile: + case internal.UpdateReconcile: r.log.Info(fmt.Sprintf("[runEventReconcile] UpdateReconcile starts the reconciliation for the LVMVolumeGroup %s", lvg.Name)) return r.reconcileLVGUpdateFunc(ctx, lvg, blockDevices) - case DeleteReconcile: + case internal.DeleteReconcile: r.log.Info(fmt.Sprintf("[runEventReconcile] DeleteReconcile starts the reconciliation for the LVMVolumeGroup %s", lvg.Name)) return r.reconcileLVGDeleteFunc(ctx, lvg) default: @@ -286,16 +259,16 @@ func (r *Reconciler) reconcileLVGDeleteFunc(ctx context.Context, lvg *v1alpha1.L } } - _, exist := lvg.Annotations[deletionProtectionAnnotation] + _, exist := lvg.Annotations[internal.DeletionProtectionAnnotation] if exist { - r.log.Debug(fmt.Sprintf("[reconcileLVGDeleteFunc] the LVMVolumeGroup %s has a deletion timestamp but also has a deletion protection annotation %s. Remove it to proceed the delete operation", lvg.Name, deletionProtectionAnnotation)) + r.log.Debug(fmt.Sprintf("[reconcileLVGDeleteFunc] the LVMVolumeGroup %s has a deletion timestamp but also has a deletion protection annotation %s. Remove it to proceed the delete operation", lvg.Name, internal.DeletionProtectionAnnotation)) err := r.lvgCl.UpdateLVGConditionIfNeeded( ctx, lvg, v1.ConditionFalse, internal.TypeVGConfigurationApplied, internal.ReasonTerminating, - fmt.Sprintf("to delete the LVG remove the annotation %s", deletionProtectionAnnotation), + fmt.Sprintf("to delete the LVG remove the annotation %s", internal.DeletionProtectionAnnotation), ) if err != nil { r.log.Error(err, fmt.Sprintf("[reconcileLVGDeleteFunc] unable to add the condition %s to the LVMVolumeGroup %s", internal.TypeVGConfigurationApplied, lvg.Name)) @@ -518,7 +491,7 @@ func (r *Reconciler) reconcileLVGCreateFunc( for _, tp := range lvg.Spec.ThinPools { vgSize := countVGSizeByBlockDevices(blockDevices) - tpRequestedSize, err := cutils.GetRequestedSizeFromString(tp.Size, vgSize) + tpRequestedSize, err := utils.GetRequestedSizeFromString(tp.Size, vgSize) if err != nil { r.log.Error(err, fmt.Sprintf("[reconcileLVGCreateFunc] unable to get thin-pool %s requested size of the LVMVolumeGroup %s", tp.Name, lvg.Name)) return false, err @@ -585,7 +558,7 @@ func (r *Reconciler) shouldLVGWatcherReconcileUpdateEvent(oldLVG, newLVG *v1alph return true } - if r.shouldUpdateLVGLabels(newLVG, LVGMetadateNameLabelKey, newLVG.Name) { + if r.shouldUpdateLVGLabels(newLVG, internal.LVGMetadateNameLabelKey, newLVG.Name) { r.log.Debug(fmt.Sprintf("[shouldLVGWatcherReconcileUpdateEvent] update event should be reconciled as the LVMVolumeGroup's %s labels have been changed", newLVG.Name)) return true } @@ -649,7 +622,7 @@ func (r *Reconciler) syncThinPoolsAllocationLimit(ctx context.Context, lvg *v1al updated = true lvg.Status.ThinPools[i].AllocationLimit = specLimits - space, err = cutils.GetThinPoolAvailableSpace(lvg.Status.ThinPools[i].ActualSize, lvg.Status.ThinPools[i].AllocatedSize, specLimits) + space, err = utils.GetThinPoolAvailableSpace(lvg.Status.ThinPools[i].ActualSize, lvg.Status.ThinPools[i].AllocatedSize, specLimits) if err != nil { r.log.Error(err, fmt.Sprintf("[syncThinPoolsAllocationLimit] unable to get thin pool %s available space", lvg.Status.ThinPools[i].Name)) return err @@ -736,7 +709,7 @@ func (r *Reconciler) validateLVGForCreateFunc( var totalThinPoolSize int64 for _, tp := range lvg.Spec.ThinPools { - tpRequestedSize, err := cutils.GetRequestedSizeFromString(tp.Size, totalVGSize) + tpRequestedSize, err := utils.GetRequestedSizeFromString(tp.Size, totalVGSize) if err != nil { reason.WriteString(err.Error()) continue @@ -851,7 +824,7 @@ func (r *Reconciler) validateLVGForUpdateFunc( newTotalVGSize := resource.NewQuantity(vg.VGSize.Value()+additionBlockDeviceSpace, resource.BinarySI) for _, specTp := range lvg.Spec.ThinPools { // might be a case when Thin-pool is already created, but is not shown in status - tpRequestedSize, err := cutils.GetRequestedSizeFromString(specTp.Size, *newTotalVGSize) + tpRequestedSize, err := utils.GetRequestedSizeFromString(specTp.Size, *newTotalVGSize) if err != nil { reason.WriteString(err.Error()) continue @@ -909,17 +882,17 @@ func (r *Reconciler) validateLVGForUpdateFunc( return true, "" } -func (r *Reconciler) identifyLVGReconcileFunc(lvg *v1alpha1.LVMVolumeGroup) reconcileType { +func (r *Reconciler) identifyLVGReconcileFunc(lvg *v1alpha1.LVMVolumeGroup) internal.ReconcileType { if r.shouldReconcileLVGByCreateFunc(lvg) { - return CreateReconcile + return internal.CreateReconcile } if r.shouldReconcileLVGByUpdateFunc(lvg) { - return UpdateReconcile + return internal.UpdateReconcile } if r.shouldReconcileLVGByDeleteFunc(lvg) { - return DeleteReconcile + return internal.DeleteReconcile } return "none" @@ -962,7 +935,7 @@ func (r *Reconciler) reconcileThinPoolsIfNeeded( errs := strings.Builder{} for _, specTp := range lvg.Spec.ThinPools { - tpRequestedSize, err := cutils.GetRequestedSizeFromString(specTp.Size, lvg.Status.VGSize) + tpRequestedSize, err := utils.GetRequestedSizeFromString(specTp.Size, lvg.Status.VGSize) if err != nil { r.log.Error(err, fmt.Sprintf("[ReconcileThinPoolsIfNeeded] unable to get requested thin-pool %s size of the LVMVolumeGroup %s", specTp.Name, lvg.Name)) return err @@ -1261,7 +1234,7 @@ func (r *Reconciler) createVGComplex(lvg *v1alpha1.LVMVolumeGroup, blockDevices r.log.Debug(fmt.Sprintf("[CreateVGComplex] successfully created all PVs for the LVMVolumeGroup %s", lvg.Name)) r.log.Debug(fmt.Sprintf("[CreateVGComplex] the LVMVolumeGroup %s type is %s", lvg.Name, lvg.Spec.Type)) switch lvg.Spec.Type { - case Local: + case internal.Local: start := time.Now() cmd, err := utils.CreateVGLocal(lvg.Spec.ActualVGNameOnTheNode, lvg.Name, paths) r.metrics.UtilsCommandsDuration(ReconcilerName, "vgcreate").Observe(r.metrics.GetEstimatedTimeInSeconds(start)) @@ -1272,7 +1245,7 @@ func (r *Reconciler) createVGComplex(lvg *v1alpha1.LVMVolumeGroup, blockDevices r.log.Error(err, "error CreateVGLocal") return err } - case Shared: + case internal.Shared: start := time.Now() cmd, err := utils.CreateVGShared(lvg.Spec.ActualVGNameOnTheNode, lvg.Name, paths) r.metrics.UtilsCommandsDuration(ReconcilerName, "vgcreate").Observe(r.metrics.GetEstimatedTimeInSeconds(start)) @@ -1295,7 +1268,7 @@ func (r *Reconciler) updateVGTagIfNeeded( lvg *v1alpha1.LVMVolumeGroup, vg internal.VGData, ) (bool, error) { - found, tagName := cutils.CheckTag(vg.VGTags) + found, tagName := utils.CheckTag(vg.VGTags) if found && lvg.Name != tagName { if checkIfConditionIsTrue(lvg, internal.TypeVGConfigurationApplied) { err := r.lvgCl.UpdateLVGConditionIfNeeded(ctx, lvg, v1.ConditionFalse, internal.TypeVGConfigurationApplied, internal.ReasonUpdating, "trying to apply the configuration") @@ -1306,23 +1279,23 @@ func (r *Reconciler) updateVGTagIfNeeded( } start := time.Now() - cmd, err := utils.VGChangeDelTag(vg.VGName, fmt.Sprintf("%s=%s", LVMVolumeGroupTag, tagName)) + cmd, err := utils.VGChangeDelTag(vg.VGName, fmt.Sprintf("%s=%s", internal.LVMVolumeGroupTag, tagName)) r.metrics.UtilsCommandsDuration(ReconcilerName, "vgchange").Observe(r.metrics.GetEstimatedTimeInSeconds(start)) r.metrics.UtilsCommandsExecutionCount(ReconcilerName, "vgchange").Inc() r.log.Debug(fmt.Sprintf("[UpdateVGTagIfNeeded] exec cmd: %s", cmd)) if err != nil { - r.log.Error(err, fmt.Sprintf("[UpdateVGTagIfNeeded] unable to delete LVMVolumeGroupTag: %s=%s, vg: %s", LVMVolumeGroupTag, tagName, vg.VGName)) + r.log.Error(err, fmt.Sprintf("[UpdateVGTagIfNeeded] unable to delete LVMVolumeGroupTag: %s=%s, vg: %s", internal.LVMVolumeGroupTag, tagName, vg.VGName)) r.metrics.UtilsCommandsErrorsCount(ReconcilerName, "vgchange").Inc() return false, err } start = time.Now() - cmd, err = utils.VGChangeAddTag(vg.VGName, fmt.Sprintf("%s=%s", LVMVolumeGroupTag, lvg.Name)) + cmd, err = utils.VGChangeAddTag(vg.VGName, fmt.Sprintf("%s=%s", internal.LVMVolumeGroupTag, lvg.Name)) r.metrics.UtilsCommandsDuration(ReconcilerName, "vgchange").Observe(r.metrics.GetEstimatedTimeInSeconds(start)) r.metrics.UtilsCommandsExecutionCount(ReconcilerName, "vgchange").Inc() r.log.Debug(fmt.Sprintf("[UpdateVGTagIfNeeded] exec cmd: %s", cmd)) if err != nil { - r.log.Error(err, fmt.Sprintf("[UpdateVGTagIfNeeded] unable to add LVMVolumeGroupTag: %s=%s, vg: %s", LVMVolumeGroupTag, lvg.Name, vg.VGName)) + r.log.Error(err, fmt.Sprintf("[UpdateVGTagIfNeeded] unable to add LVMVolumeGroupTag: %s=%s, vg: %s", internal.LVMVolumeGroupTag, lvg.Name, vg.VGName)) r.metrics.UtilsCommandsErrorsCount(ReconcilerName, "vgchange").Inc() return false, err } @@ -1335,7 +1308,7 @@ func (r *Reconciler) updateVGTagIfNeeded( func (r *Reconciler) extendThinPool(lvg *v1alpha1.LVMVolumeGroup, specThinPool v1alpha1.LVMVolumeGroupThinPoolSpec) error { volumeGroupFreeSpaceBytes := lvg.Status.VGSize.Value() - lvg.Status.AllocatedSize.Value() - tpRequestedSize, err := cutils.GetRequestedSizeFromString(specThinPool.Size, lvg.Status.VGSize) + tpRequestedSize, err := utils.GetRequestedSizeFromString(specThinPool.Size, lvg.Status.VGSize) if err != nil { return err } diff --git a/images/agent/src/pkg/controller/lvg/reconciler_test.go b/images/agent/src/internal/controller/lvg/reconciler_test.go similarity index 97% rename from images/agent/src/pkg/controller/lvg/reconciler_test.go rename to images/agent/src/internal/controller/lvg/reconciler_test.go index 95dbed00..42bbb383 100644 --- a/images/agent/src/pkg/controller/lvg/reconciler_test.go +++ b/images/agent/src/internal/controller/lvg/reconciler_test.go @@ -15,21 +15,12 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "agent/internal" - "agent/pkg/cache" - cutils "agent/pkg/controller/utils" - "agent/pkg/logger" - "agent/pkg/monitoring" - "agent/pkg/test_utils" + "agent/internal/cache" + "agent/internal/utils" ) func TestLVMVolumeGroupWatcherCtrl(t *testing.T) { - cl := test_utils.NewFakeClient() ctx := context.Background() - log := logger.Logger{} - metrics := monitoring.GetMetrics("") - ch := cache.New() - - r := NewReconciler(cl, log, metrics, ch, ReconcilerOptions{}) t.Run("validateLVGForUpdateFunc", func(t *testing.T) { t.Run("without_thin_pools_returns_true", func(t *testing.T) { @@ -81,7 +72,7 @@ func TestLVMVolumeGroupWatcherCtrl(t *testing.T) { }, } - ch.StorePVs(pvs, bytes.Buffer{}) + r.ch.StorePVs(pvs, bytes.Buffer{}) valid, reason := r.validateLVGForUpdateFunc(lvg, bds) if assert.True(t, valid) { @@ -434,7 +425,7 @@ func TestLVMVolumeGroupWatcherCtrl(t *testing.T) { } actual := r.identifyLVGReconcileFunc(lvg) - assert.Equal(t, CreateReconcile, actual) + assert.Equal(t, internal.CreateReconcile, actual) }) t.Run("returns_update", func(t *testing.T) { @@ -453,7 +444,7 @@ func TestLVMVolumeGroupWatcherCtrl(t *testing.T) { r.sdsCache.StoreVGs(vgs, bytes.Buffer{}) actual := r.identifyLVGReconcileFunc(lvg) - assert.Equal(t, UpdateReconcile, actual) + assert.Equal(t, internal.UpdateReconcile, actual) }) t.Run("returns_delete", func(t *testing.T) { @@ -473,7 +464,7 @@ func TestLVMVolumeGroupWatcherCtrl(t *testing.T) { r.sdsCache.StoreVGs(vgs, bytes.Buffer{}) actual := r.identifyLVGReconcileFunc(lvg) - assert.Equal(t, DeleteReconcile, actual) + assert.Equal(t, internal.DeleteReconcile, actual) }) }) @@ -584,7 +575,7 @@ func TestLVMVolumeGroupWatcherCtrl(t *testing.T) { t.Run("getRequestedSizeFromString", func(t *testing.T) { t.Run("for_percent_size", func(t *testing.T) { - actual, err := cutils.GetRequestedSizeFromString("50%", resource.MustParse("10G")) + actual, err := utils.GetRequestedSizeFromString("50%", resource.MustParse("10G")) if err != nil { t.Error(err) } @@ -594,7 +585,7 @@ func TestLVMVolumeGroupWatcherCtrl(t *testing.T) { }) t.Run("for_number_size", func(t *testing.T) { - actual, err := cutils.GetRequestedSizeFromString("5G", resource.MustParse("10G")) + actual, err := utils.GetRequestedSizeFromString("5G", resource.MustParse("10G")) if err != nil { t.Error(err) } @@ -1097,7 +1088,7 @@ func TestLVMVolumeGroupWatcherCtrl(t *testing.T) { oldLVG := &v1alpha1.LVMVolumeGroup{} newLVG := &v1alpha1.LVMVolumeGroup{} newLVG.Name = "test-name" - newLVG.Labels = map[string]string{LVGMetadateNameLabelKey: "test-name"} + newLVG.Labels = map[string]string{internal.LVGMetadateNameLabelKey: "test-name"} newLVG.Status.Conditions = []v1.Condition{ { Type: internal.TypeVGConfigurationApplied, @@ -1117,7 +1108,7 @@ func TestLVMVolumeGroupWatcherCtrl(t *testing.T) { Reason: internal.ReasonCreating, }, } - newLVG.Labels = map[string]string{LVGMetadateNameLabelKey: newLVG.Name} + newLVG.Labels = map[string]string{internal.LVGMetadateNameLabelKey: newLVG.Name} assert.False(t, r.shouldLVGWatcherReconcileUpdateEvent(oldLVG, newLVG)) }) @@ -1131,7 +1122,7 @@ func TestLVMVolumeGroupWatcherCtrl(t *testing.T) { Reason: internal.ReasonCreating, }, } - newLVG.Labels = map[string]string{LVGMetadateNameLabelKey: "some-other-name"} + newLVG.Labels = map[string]string{internal.LVGMetadateNameLabelKey: "some-other-name"} assert.True(t, r.shouldLVGWatcherReconcileUpdateEvent(oldLVG, newLVG)) }) diff --git a/images/agent/src/pkg/controller/lvg/utils.go b/images/agent/src/internal/controller/lvg/utils.go similarity index 100% rename from images/agent/src/pkg/controller/lvg/utils.go rename to images/agent/src/internal/controller/lvg/utils.go diff --git a/images/agent/src/pkg/kubutils/kubernetes.go b/images/agent/src/internal/kubutils/kubernetes.go similarity index 100% rename from images/agent/src/pkg/kubutils/kubernetes.go rename to images/agent/src/internal/kubutils/kubernetes.go diff --git a/images/agent/src/pkg/logger/logger.go b/images/agent/src/internal/logger/logger.go similarity index 100% rename from images/agent/src/pkg/logger/logger.go rename to images/agent/src/internal/logger/logger.go diff --git a/images/agent/src/pkg/monitoring/monitoring.go b/images/agent/src/internal/monitoring/monitoring.go similarity index 100% rename from images/agent/src/pkg/monitoring/monitoring.go rename to images/agent/src/internal/monitoring/monitoring.go diff --git a/images/agent/src/pkg/scanner/scanner.go b/images/agent/src/internal/scanner/scanner.go similarity index 97% rename from images/agent/src/pkg/scanner/scanner.go rename to images/agent/src/internal/scanner/scanner.go index 0a9f9bca..5f4a1df0 100644 --- a/images/agent/src/pkg/scanner/scanner.go +++ b/images/agent/src/internal/scanner/scanner.go @@ -10,15 +10,15 @@ import ( "github.com/pilebones/go-udev/netlink" "k8s.io/utils/clock" - "agent/config" "agent/internal" - "agent/pkg/cache" - "agent/pkg/controller" - "agent/pkg/controller/bd" - "agent/pkg/controller/lvg" - "agent/pkg/logger" - "agent/pkg/throttler" - "agent/pkg/utils" + "agent/internal/cache" + "agent/internal/config" + "agent/internal/controller" + "agent/internal/controller/bd" + "agent/internal/controller/lvg" + "agent/internal/logger" + "agent/internal/throttler" + "agent/internal/utils" ) func RunScanner( diff --git a/images/agent/src/pkg/test_utils/fake_client.go b/images/agent/src/internal/test_utils/fake_client.go similarity index 100% rename from images/agent/src/pkg/test_utils/fake_client.go rename to images/agent/src/internal/test_utils/fake_client.go diff --git a/images/agent/src/pkg/throttler/throttler.go b/images/agent/src/internal/throttler/throttler.go similarity index 100% rename from images/agent/src/pkg/throttler/throttler.go rename to images/agent/src/internal/throttler/throttler.go diff --git a/images/agent/src/pkg/controller/clients/bd_client.go b/images/agent/src/internal/utils/client_bd.go similarity index 97% rename from images/agent/src/pkg/controller/clients/bd_client.go rename to images/agent/src/internal/utils/client_bd.go index bbcd360b..2736688e 100644 --- a/images/agent/src/pkg/controller/clients/bd_client.go +++ b/images/agent/src/internal/utils/client_bd.go @@ -1,7 +1,7 @@ -package clients +package utils import ( - "agent/pkg/monitoring" + "agent/internal/monitoring" "context" "time" diff --git a/images/agent/src/pkg/controller/clients/llv_client.go b/images/agent/src/internal/utils/client_llv.go similarity index 92% rename from images/agent/src/pkg/controller/clients/llv_client.go rename to images/agent/src/internal/utils/client_llv.go index 6672eff3..bac2fb94 100644 --- a/images/agent/src/pkg/controller/clients/llv_client.go +++ b/images/agent/src/internal/utils/client_llv.go @@ -1,8 +1,8 @@ -package clients +package utils import ( - cutils "agent/pkg/controller/utils" - "agent/pkg/logger" + "agent/internal" + "agent/internal/logger" "context" "fmt" @@ -68,7 +68,7 @@ func (llvCl *LLVClient) UpdatePhaseToCreatedIfNeeded( } } - updateNeeded := llv.Status.Phase != cutils.LLVStatusPhaseCreated || + updateNeeded := llv.Status.Phase != internal.LLVStatusPhaseCreated || llv.Status.ActualSize.Value() != actualSize.Value() || llv.Status.Reason != "" || llv.Status.Contiguous != contiguous @@ -78,7 +78,7 @@ func (llvCl *LLVClient) UpdatePhaseToCreatedIfNeeded( return nil } - llv.Status.Phase = cutils.LLVStatusPhaseCreated + llv.Status.Phase = internal.LLVStatusPhaseCreated llv.Status.Reason = "" llv.Status.ActualSize = actualSize llv.Status.Contiguous = contiguous diff --git a/images/agent/src/pkg/controller/clients/lvg_client.go b/images/agent/src/internal/utils/client_lvg.go similarity index 98% rename from images/agent/src/pkg/controller/clients/lvg_client.go rename to images/agent/src/internal/utils/client_lvg.go index eef57dda..1e2fa750 100644 --- a/images/agent/src/pkg/controller/clients/lvg_client.go +++ b/images/agent/src/internal/utils/client_lvg.go @@ -1,8 +1,8 @@ -package clients +package utils import ( - "agent/pkg/logger" - "agent/pkg/monitoring" + "agent/internal/logger" + "agent/internal/monitoring" "context" "fmt" "time" diff --git a/images/agent/src/pkg/utils/commands.go b/images/agent/src/internal/utils/commands.go similarity index 99% rename from images/agent/src/pkg/utils/commands.go rename to images/agent/src/internal/utils/commands.go index 86c8c006..a9691aa7 100644 --- a/images/agent/src/pkg/utils/commands.go +++ b/images/agent/src/internal/utils/commands.go @@ -29,8 +29,8 @@ import ( "time" "agent/internal" - "agent/pkg/logger" - "agent/pkg/monitoring" + "agent/internal/logger" + "agent/internal/monitoring" ) func GetBlockDevices(ctx context.Context) ([]internal.Device, string, bytes.Buffer, error) { diff --git a/images/agent/src/pkg/utils/commands_test.go b/images/agent/src/internal/utils/commands_test.go similarity index 100% rename from images/agent/src/pkg/utils/commands_test.go rename to images/agent/src/internal/utils/commands_test.go diff --git a/images/agent/src/pkg/utils/units.go b/images/agent/src/internal/utils/units.go similarity index 100% rename from images/agent/src/pkg/utils/units.go rename to images/agent/src/internal/utils/units.go diff --git a/images/agent/src/pkg/controller/utils/utils.go b/images/agent/src/internal/utils/utils.go similarity index 92% rename from images/agent/src/pkg/controller/utils/utils.go rename to images/agent/src/internal/utils/utils.go index ae256a8a..2d6176fa 100644 --- a/images/agent/src/pkg/controller/utils/utils.go +++ b/images/agent/src/internal/utils/utils.go @@ -9,16 +9,6 @@ import ( "k8s.io/apimachinery/pkg/api/resource" ) -const ( - Thick = "Thick" - Thin = "Thin" - - LLVStatusPhaseCreated = "Created" - LLVStatusPhasePending = "Pending" - LLVStatusPhaseResizing = "Resizing" - LLVStatusPhaseFailed = "Failed" -) - func IsPercentSize(size string) bool { return strings.Contains(size, "%") } @@ -77,9 +67,9 @@ func GetThinPoolSpaceWithAllocationLimit(actualSize resource.Quantity, allocatio func GetLLVRequestedSize(llv *v1alpha1.LVMLogicalVolume, lvg *v1alpha1.LVMVolumeGroup) (resource.Quantity, error) { switch llv.Spec.Type { - case Thick: + case internal.Thick: return GetRequestedSizeFromString(llv.Spec.Size, lvg.Status.VGSize) - case Thin: + case internal.Thin: for _, tp := range lvg.Status.ThinPools { if tp.Name == llv.Spec.Thin.PoolName { totalSize, err := GetThinPoolSpaceWithAllocationLimit(tp.ActualSize, tp.AllocationLimit) @@ -108,9 +98,9 @@ func LVGBelongsToNode(lvg *v1alpha1.LVMVolumeGroup, nodeName string) bool { func GetFreeLVGSpaceForLLV(lvg *v1alpha1.LVMVolumeGroup, llv *v1alpha1.LVMLogicalVolume) resource.Quantity { switch llv.Spec.Type { - case Thick: + case internal.Thick: return lvg.Status.VGFree - case Thin: + case internal.Thin: for _, tp := range lvg.Status.ThinPools { if tp.Name == llv.Spec.Thin.PoolName { return tp.AvailableSpace diff --git a/images/agent/src/pkg/controller/bd/doc.go b/images/agent/src/pkg/controller/bd/doc.go deleted file mode 100644 index 6c5ac0e2..00000000 --- a/images/agent/src/pkg/controller/bd/doc.go +++ /dev/null @@ -1,7 +0,0 @@ -package bd - -/* -BlockDevice reconciler -TODO - -*/