Skip to content

Commit

Permalink
Add size and make information to InitConfigv1
Browse files Browse the repository at this point in the history
Signed-off-by: Bala.FA <bala@minio.io>
  • Loading branch information
balamurugana committed Jan 4, 2023
1 parent cf3bd74 commit 4193021
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 33 deletions.
9 changes: 5 additions & 4 deletions cmd/kubectl-directpv/discover.go
Expand Up @@ -105,10 +105,11 @@ func toInitConfig(resultMap map[directpvtypes.NodeID][]types.Device) InitConfig
continue
}
driveInfo = append(driveInfo, DriveInfo{
ID: device.ID,
Name: device.Name,
MajorMinor: device.MajorMinor,
FS: device.FSType,
ID: device.ID,
Name: device.Name,
Size: device.Size,
Make: device.Make,
FS: device.FSType,
})
}
nodeInfo = append(nodeInfo, NodeInfo{
Expand Down
7 changes: 3 additions & 4 deletions cmd/kubectl-directpv/init.go
Expand Up @@ -94,10 +94,9 @@ func toInitRequestObjects(config *InitConfig, requestID string) (initRequests []
initDevices := []types.InitDevice{}
for _, device := range node.Drives {
initDevices = append(initDevices, types.InitDevice{
ID: device.ID,
Name: device.Name,
MajorMinor: device.MajorMinor,
Force: device.FS != "",
ID: device.ID,
Name: device.Name,
Force: device.FS != "",
})
}
if len(initDevices) > 0 {
Expand Down
9 changes: 5 additions & 4 deletions cmd/kubectl-directpv/init_config_v1.go
Expand Up @@ -32,8 +32,9 @@ type NodeInfoV1 struct {

// DriveInfoV1 represents the drives that are to be initialized
type DriveInfoV1 struct {
ID string `yaml:"id"`
Name string `yaml:"name"`
MajorMinor string `yaml:"majorMinor"`
FS string `yaml:"fs,omitempty"`
ID string `yaml:"id"`
Name string `yaml:"name"`
Size uint64 `yaml:"size"`
Make string `yaml:"make"`
FS string `yaml:"fs,omitempty"`
}
7 changes: 3 additions & 4 deletions pkg/apis/directpv.min.io/v1beta1/init_request.go
Expand Up @@ -98,10 +98,9 @@ type InitRequestSpec struct {

// InitDevice represents the device requested for initialization.
type InitDevice struct {
ID string `json:"id"`
Name string `json:"name"`
MajorMinor string `json:"majorMinor"`
Force bool `json:"force"`
ID string `json:"id"`
Name string `json:"name"`
Force bool `json:"force"`
}

// InitRequestStatus represents the status of the InitRequest.
Expand Down
9 changes: 1 addition & 8 deletions pkg/apis/directpv.min.io/v1beta1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/device/probe.go
Expand Up @@ -75,7 +75,7 @@ func (d Device) ID(nodeID directpvtypes.NodeID) string {

stringToHash := strings.Join(toSlice(deviceMap, ":"), "\n")
h := sha256.Sum256([]byte(stringToHash))
return base64.StdEncoding.EncodeToString(h[:])
return d.MajorMinor + "$" + base64.StdEncoding.EncodeToString(h[:])
}

// Make returns device make information.
Expand Down
6 changes: 3 additions & 3 deletions pkg/device/probe_test.go
Expand Up @@ -64,7 +64,7 @@ func TestID(t *testing.T) {
"E:ID_PART_ENTRY_DISK": "259",
},
},
expectedID: "0sd/C9q7zmRagIcJaw6M7gmW2HftkINuent6OUtTQdc=",
expectedID: "259:0$0sd/C9q7zmRagIcJaw6M7gmW2HftkINuent6OUtTQdc=",
},
// with mountpoints disordered
{
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestID(t *testing.T) {
"E:ID_PART_ENTRY_DISK": "259",
},
},
expectedID: "0sd/C9q7zmRagIcJaw6M7gmW2HftkINuent6OUtTQdc=",
expectedID: "259:0$0sd/C9q7zmRagIcJaw6M7gmW2HftkINuent6OUtTQdc=",
},
// with udevdata disordered
{
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestID(t *testing.T) {
"E:ID_REVISION": "2.8.8341",
},
},
expectedID: "0sd/C9q7zmRagIcJaw6M7gmW2HftkINuent6OUtTQdc=",
expectedID: "259:0$0sd/C9q7zmRagIcJaw6M7gmW2HftkINuent6OUtTQdc=",
},
}

Expand Down
11 changes: 9 additions & 2 deletions pkg/initrequest/event.go
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"os"
"strings"
"sync"

"github.com/google/uuid"
Expand Down Expand Up @@ -160,7 +161,12 @@ func (handler *initRequestEventHandler) initDevices(ctx context.Context, req *ty

var majorMinorList []string
for i := range req.Spec.Devices {
majorMinorList = append(majorMinorList, req.Spec.Devices[i].MajorMinor)
tokens := strings.SplitN(req.Spec.Devices[i].ID, "$", 2)
if len(tokens) != 2 {
client.Eventf(req, client.EventTypeWarning, client.EventReasonInitError, "invalid device ID %v", req.Spec.Devices[i])
return updateInitRequest(ctx, req.Name, req.Status.Results, directpvtypes.InitStatusError)
}
majorMinorList = append(majorMinorList, tokens[0])
}

devices, err := handler.getDevices(majorMinorList...)
Expand All @@ -177,7 +183,8 @@ func (handler *initRequestEventHandler) initDevices(ctx context.Context, req *ty
var wg sync.WaitGroup
for i := range req.Spec.Devices {
results[i].Name = req.Spec.Devices[i].Name
device, found := probedDevices[req.Spec.Devices[i].MajorMinor]
majorMinor := strings.SplitN(req.Spec.Devices[i].ID, "$", 2)[0]
device, found := probedDevices[majorMinor]
switch {
case !found:
results[i].Error = "device not found"
Expand Down
3 changes: 0 additions & 3 deletions pkg/installer/directpv.min.io_directpvinitrequests.yaml
Expand Up @@ -43,14 +43,11 @@ spec:
type: boolean
id:
type: string
majorMinor:
type: string
name:
type: string
required:
- force
- id
- majorMinor
- name
type: object
type: array
Expand Down

0 comments on commit 4193021

Please sign in to comment.