diff --git a/Dockerfile b/Dockerfile index 885ebec96..4e76569b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build --ldflags "-s -w" -a -o vgman RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build --ldflags "-s -w" -a -o metricsexporter cmd/metricsexporter/exporter.go # vgmanager needs 'nsenter' and other basic linux utils to correctly function -FROM registry.access.redhat.com/ubi8/ubi-minimal:8.7 +FROM registry.access.redhat.com/ubi9/ubi-minimal:9.2 # Update the image to get the latest CVE updates RUN microdnf update -y && \ diff --git a/pkg/internal/block_device.go b/pkg/internal/block_device.go index 327521c2f..73c514121 100644 --- a/pkg/internal/block_device.go +++ b/pkg/internal/block_device.go @@ -57,8 +57,8 @@ type BlockDevice struct { FSType string `json:"fstype"` Size string `json:"size"` Children []BlockDevice `json:"children,omitempty"` - Rotational string `json:"rota"` - ReadOnly string `json:"ro,omitempty"` + Rotational bool `json:"rota"` + ReadOnly bool `json:"ro,omitempty"` Serial string `json:"serial,omitempty"` PartLabel string `json:"partLabel,omitempty"` @@ -118,11 +118,6 @@ func (b BlockDevice) IsUsableLoopDev(exec Executor) (bool, error) { return usable, nil } -// IsReadOnly checks is disk is read only -func (b BlockDevice) IsReadOnly() (bool, error) { - return parseBitBool(b.ReadOnly) -} - // HasChildren checks if the disk has partitions func (b BlockDevice) HasChildren() bool { return len(b.Children) > 0 @@ -151,13 +146,3 @@ func (b BlockDevice) HasBindMounts() (bool, string, error) { return false, "", nil } - -func parseBitBool(s string) (bool, error) { - switch s { - case "0", "false", "": - return false, nil - case "1", "true": - return true, nil - } - return false, fmt.Errorf("invalid value: %q", s) -} diff --git a/pkg/vgmanager/devices_test.go b/pkg/vgmanager/devices_test.go index aecd2fee9..52506e10b 100644 --- a/pkg/vgmanager/devices_test.go +++ b/pkg/vgmanager/devices_test.go @@ -55,7 +55,7 @@ func TestAvailableDevicesForVG(t *testing.T) { Name: "/dev/nvme1n1", Type: "disk", Size: "279.4G", - ReadOnly: "false", + ReadOnly: false, State: "live", KName: "/dev/nvme1n1", }, @@ -74,7 +74,7 @@ func TestAvailableDevicesForVG(t *testing.T) { Name: "/dev/nvme1n1", Type: "disk", Size: "279.4G", - ReadOnly: "true", + ReadOnly: true, State: "live", KName: "/dev/nvme1n1", }, @@ -93,7 +93,7 @@ func TestAvailableDevicesForVG(t *testing.T) { Name: "/dev/nvme1n1", Type: "disk", Size: "279.4G", - ReadOnly: "false", + ReadOnly: false, State: "suspended", KName: "/dev/nvme1n1", }, @@ -112,7 +112,7 @@ func TestAvailableDevicesForVG(t *testing.T) { Name: "/dev/nvme1n1", Type: "disk", Size: "279.4G", - ReadOnly: "false", + ReadOnly: false, State: "live", KName: "/dev/nvme1n1", PartLabel: "BIOS-BOOT", @@ -132,7 +132,7 @@ func TestAvailableDevicesForVG(t *testing.T) { Name: "/dev/nvme1n1", Type: "disk", Size: "279.4G", - ReadOnly: "false", + ReadOnly: false, State: "live", KName: "/dev/nvme1n1", PartLabel: "reserved", @@ -152,7 +152,7 @@ func TestAvailableDevicesForVG(t *testing.T) { Name: "/dev/nvme1n1", Type: "disk", Size: "279.4G", - ReadOnly: "false", + ReadOnly: false, State: "live", KName: "/dev/nvme1n1", FSType: "ext4", @@ -172,13 +172,13 @@ func TestAvailableDevicesForVG(t *testing.T) { Name: "/dev/nvme1n1", Type: "disk", Size: "279.4G", - ReadOnly: "false", + ReadOnly: false, State: "live", KName: "/dev/nvme1n1", Children: []internal.BlockDevice{ { Name: "/dev/nvme1n1p1", - ReadOnly: "true", + ReadOnly: true, }, }, }, @@ -197,7 +197,7 @@ func TestAvailableDevicesForVG(t *testing.T) { Name: "/dev/nvme1n1", Type: "disk", Size: "279.4G", - ReadOnly: "false", + ReadOnly: false, State: "live", KName: "/dev/nvme1n1", Children: []internal.BlockDevice{ @@ -205,7 +205,7 @@ func TestAvailableDevicesForVG(t *testing.T) { Name: "/dev/nvme1n1p1", Type: "disk", Size: "50G", - ReadOnly: "false", + ReadOnly: false, State: "live", KName: "/dev/nvme1n1p1", }, @@ -213,7 +213,7 @@ func TestAvailableDevicesForVG(t *testing.T) { Name: "/dev/nvme1n1p2", Type: "disk", Size: "50G", - ReadOnly: "false", + ReadOnly: false, State: "live", KName: "/dev/nvme1n1p2", }, @@ -242,7 +242,7 @@ func TestAvailableDevicesForVG(t *testing.T) { KName: calculateDevicePath(t, "nvme1n1p1"), Type: "disk", Size: "279.4G", - ReadOnly: "false", + ReadOnly: false, State: "live", }, }, @@ -286,7 +286,7 @@ func TestAvailableDevicesForVG(t *testing.T) { KName: calculateDevicePath(t, "nvme1n1p1"), Type: "disk", Size: "279.4G", - ReadOnly: "true", + ReadOnly: true, State: "live", }, }, @@ -320,7 +320,7 @@ func TestAvailableDevicesForVG(t *testing.T) { KName: calculateDevicePath(t, "nvme1n1p1"), Type: "disk", Size: "279.4G", - ReadOnly: "false", + ReadOnly: false, State: "live", }, }, @@ -352,7 +352,7 @@ func TestAvailableDevicesForVG(t *testing.T) { KName: calculateDevicePath(t, "nvme1n1p1"), Type: "disk", Size: "279.4G", - ReadOnly: "false", + ReadOnly: false, State: "live", }, }, @@ -384,7 +384,7 @@ func TestAvailableDevicesForVG(t *testing.T) { KName: calculateDevicePath(t, "nvme1n1p1"), Type: "disk", Size: "279.4G", - ReadOnly: "false", + ReadOnly: false, State: "live", Children: []internal.BlockDevice{ { @@ -392,7 +392,7 @@ func TestAvailableDevicesForVG(t *testing.T) { KName: calculateDevicePath(t, "nvme1n1p2"), Type: "disk", Size: "4G", - ReadOnly: "false", + ReadOnly: false, State: "live", }, }, diff --git a/pkg/vgmanager/filter.go b/pkg/vgmanager/filter.go index 0d93add55..c0991f79a 100644 --- a/pkg/vgmanager/filter.go +++ b/pkg/vgmanager/filter.go @@ -40,8 +40,7 @@ const ( // they verify that the device itself is good to use var FilterMap = map[string]func(internal.BlockDevice, internal.Executor) (bool, error){ notReadOnly: func(dev internal.BlockDevice, _ internal.Executor) (bool, error) { - readOnly, err := dev.IsReadOnly() - return !readOnly, err + return !dev.ReadOnly, nil }, notSuspended: func(dev internal.BlockDevice, _ internal.Executor) (bool, error) { diff --git a/pkg/vgmanager/filter_test.go b/pkg/vgmanager/filter_test.go index df6d10553..f6af872d2 100644 --- a/pkg/vgmanager/filter_test.go +++ b/pkg/vgmanager/filter_test.go @@ -16,12 +16,8 @@ type filterTestCase struct { func TestNotReadOnly(t *testing.T) { testcases := []filterTestCase{ - {label: "tc empty string", device: internal.BlockDevice{ReadOnly: ""}, expected: true, expectErr: false}, - {label: "tc false", device: internal.BlockDevice{ReadOnly: "false"}, expected: true, expectErr: false}, - {label: "tc true", device: internal.BlockDevice{ReadOnly: "true"}, expected: false, expectErr: false}, - {label: "tc 0", device: internal.BlockDevice{ReadOnly: "0"}, expected: true, expectErr: false}, - {label: "tc 1", device: internal.BlockDevice{ReadOnly: "1"}, expected: false, expectErr: false}, - {label: "tc invalid string", device: internal.BlockDevice{ReadOnly: "test"}, expected: true, expectErr: true}, + {label: "tc false", device: internal.BlockDevice{ReadOnly: false}, expected: true, expectErr: false}, + {label: "tc true", device: internal.BlockDevice{ReadOnly: true}, expected: false, expectErr: false}, } for _, tc := range testcases { result, err := FilterMap[notReadOnly](tc.device, nil)