Skip to content

Commit

Permalink
fix(vd): add phase collector
Browse files Browse the repository at this point in the history
Add phase collector for virtual disk

Signed-off-by: Isteb4k <[email protected]>
  • Loading branch information
Isteb4k authored Jul 9, 2024
1 parent f2eb4ba commit e336c82
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions images/virtualization-artifact/pkg/controller/vd/vd_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)},
}
Expand Down

0 comments on commit e336c82

Please sign in to comment.