diff --git a/images/virtualization-artifact/pkg/controller/vd/vd_controller.go b/images/virtualization-artifact/pkg/controller/vd/vd_controller.go index 7a4565f03..c4e6b07cb 100644 --- a/images/virtualization-artifact/pkg/controller/vd/vd_controller.go +++ b/images/virtualization-artifact/pkg/controller/vd/vd_controller.go @@ -23,13 +23,16 @@ import ( "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/builder" + "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/metrics" "github.com/deckhouse/virtualization-controller/pkg/controller/service" "github.com/deckhouse/virtualization-controller/pkg/controller/vd/internal" "github.com/deckhouse/virtualization-controller/pkg/controller/vd/internal/source" "github.com/deckhouse/virtualization-controller/pkg/dvcr" + vdcolelctor "github.com/deckhouse/virtualization-controller/pkg/monitoring/metrics/vd" virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2" ) @@ -96,7 +99,22 @@ func NewController( return nil, err } + vdcolelctor.SetupCollector(&lister{cache: mgr.GetCache()}, metrics.Registry) + log.Info("Initialized VirtualDisk controller", "image", importerImage) return vdController, nil } + +type lister struct { + cache cache.Cache +} + +func (l lister) List() ([]virtv2.VirtualDisk, error) { + disks := virtv2.VirtualDiskList{} + err := l.cache.List(context.Background(), &disks) + if err != nil { + return nil, err + } + return disks.Items, nil +} diff --git a/images/virtualization-artifact/pkg/monitoring/metrics/virtualdisk/collector.go b/images/virtualization-artifact/pkg/monitoring/metrics/vd/collector.go similarity index 99% rename from images/virtualization-artifact/pkg/monitoring/metrics/virtualdisk/collector.go rename to images/virtualization-artifact/pkg/monitoring/metrics/vd/collector.go index c23cbcf19..33e581789 100644 --- a/images/virtualization-artifact/pkg/monitoring/metrics/virtualdisk/collector.go +++ b/images/virtualization-artifact/pkg/monitoring/metrics/vd/collector.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package virtualdisk +package vd import ( "github.com/prometheus/client_golang/prometheus" @@ -98,9 +98,9 @@ func (s *scraper) updateDiskStatusPhaseMetrics(disk virtv2.VirtualDisk) { {phase == virtv2.DiskPending, string(virtv2.DiskPending)}, {phase == virtv2.DiskWaitForUserUpload, string(virtv2.DiskWaitForUserUpload)}, {phase == virtv2.DiskProvisioning, string(virtv2.DiskProvisioning)}, - {phase == virtv2.DiskReady, string(virtv2.DiskReady)}, {phase == virtv2.DiskFailed, string(virtv2.DiskFailed)}, {phase == virtv2.DiskLost, string(virtv2.DiskLost)}, + {phase == virtv2.DiskReady, string(virtv2.DiskReady)}, {phase == virtv2.DiskResizing, string(virtv2.DiskResizing)}, {phase == virtv2.DiskTerminating, string(virtv2.DiskTerminating)}, }