Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCPVE-380: feat: rhel 9 and accompanying changes #361

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
19 changes: 2 additions & 17 deletions pkg/internal/block_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
jeff-roche marked this conversation as resolved.
Show resolved Hide resolved
ReadOnly bool `json:"ro,omitempty"`
Serial string `json:"serial,omitempty"`
PartLabel string `json:"partLabel,omitempty"`

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
34 changes: 17 additions & 17 deletions pkg/vgmanager/devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand All @@ -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",
},
Expand All @@ -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",
},
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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,
},
},
},
Expand All @@ -197,23 +197,23 @@ 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",
Type: "disk",
Size: "50G",
ReadOnly: "false",
ReadOnly: false,
State: "live",
KName: "/dev/nvme1n1p1",
},
{
Name: "/dev/nvme1n1p2",
Type: "disk",
Size: "50G",
ReadOnly: "false",
ReadOnly: false,
State: "live",
KName: "/dev/nvme1n1p2",
},
Expand Down Expand Up @@ -242,7 +242,7 @@ func TestAvailableDevicesForVG(t *testing.T) {
KName: calculateDevicePath(t, "nvme1n1p1"),
Type: "disk",
Size: "279.4G",
ReadOnly: "false",
ReadOnly: false,
State: "live",
},
},
Expand Down Expand Up @@ -286,7 +286,7 @@ func TestAvailableDevicesForVG(t *testing.T) {
KName: calculateDevicePath(t, "nvme1n1p1"),
Type: "disk",
Size: "279.4G",
ReadOnly: "true",
ReadOnly: true,
State: "live",
},
},
Expand Down Expand Up @@ -320,7 +320,7 @@ func TestAvailableDevicesForVG(t *testing.T) {
KName: calculateDevicePath(t, "nvme1n1p1"),
Type: "disk",
Size: "279.4G",
ReadOnly: "false",
ReadOnly: false,
State: "live",
},
},
Expand Down Expand Up @@ -352,7 +352,7 @@ func TestAvailableDevicesForVG(t *testing.T) {
KName: calculateDevicePath(t, "nvme1n1p1"),
Type: "disk",
Size: "279.4G",
ReadOnly: "false",
ReadOnly: false,
State: "live",
},
},
Expand Down Expand Up @@ -384,15 +384,15 @@ func TestAvailableDevicesForVG(t *testing.T) {
KName: calculateDevicePath(t, "nvme1n1p1"),
Type: "disk",
Size: "279.4G",
ReadOnly: "false",
ReadOnly: false,
State: "live",
Children: []internal.BlockDevice{
{
Name: "nvme1n1p2",
KName: calculateDevicePath(t, "nvme1n1p2"),
Type: "disk",
Size: "4G",
ReadOnly: "false",
ReadOnly: false,
State: "live",
},
},
Expand Down
3 changes: 1 addition & 2 deletions pkg/vgmanager/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 2 additions & 6 deletions pkg/vgmanager/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down