Skip to content

Commit

Permalink
fix: add kubernetes node_name in json
Browse files Browse the repository at this point in the history
  • Loading branch information
alisterd51 committed May 31, 2024
1 parent c5c21ae commit 90da789
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions bs/bs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ type BlockStorageInfos struct {
Type string `json:"type"`
BlockDev string `json:"block_dev"`
Status string `json:"status"`
NodeName string `json:"node_name"`
Metadata map[string]string `json:"metadata"`
}
3 changes: 3 additions & 0 deletions bs/fs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ func ExtractBsInfos(m *machine.MachineInfos) map[uuid.UUID]*BlockStorageInfos {

// Add machine UUID
i.MachineId = m.Uuid

// Add machine node name
i.NodeName = m.KubeNodeName
infos[i.Uuid] = i
}

Expand Down
5 changes: 5 additions & 0 deletions bs/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func openstackVolumesServiceAuth() (*gophercloud.ServiceClient, error) {
}

type MultiAttachments struct {
NodeName string `json:"node_name"`
MultiAttach MultiAttach `json:"multi-attach"`
}

Expand All @@ -64,6 +65,7 @@ type OpenstackAttach struct {
HostName string `json:"host_name"`
ServerId string `json:"server_id"`
VolumeId string `json:"volume_id"`
NodeName string `json:"node_name"`
}

func openstackAllVolumes() ([]volumes.Volume, error) {
Expand Down Expand Up @@ -121,6 +123,7 @@ func OpenstackGetMultiAttachments(machineInfos *machine.MachineInfos) (*MultiAtt
HostName: attachment.HostName,
ServerId: attachment.ServerID,
VolumeId: attachment.VolumeID,
NodeName: machineInfos.KubeNodeName,
}
attachments = append(attachments, openstack_attach)
}
Expand All @@ -129,6 +132,7 @@ func OpenstackGetMultiAttachments(machineInfos *machine.MachineInfos) (*MultiAtt
}

multiAttachments := MultiAttachments{
NodeName: machineInfos.KubeNodeName,
MultiAttach: MultiAttach{
Count: len(attachments),
Data: attachments,
Expand Down Expand Up @@ -214,6 +218,7 @@ func OpenstackGetBlockStorage(machineInfos *machine.MachineInfos) (map[uuid.UUID
Type: machine.BsUnknown,
BlockDev: "unknown",
Status: vol.Status,
NodeName: machineInfos.KubeNodeName,
Metadata: vol.Metadata,
}
}
Expand Down
11 changes: 7 additions & 4 deletions cmd/koherence/check/bs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ type bsTuple struct {
type IncoherenceError struct{}

type All struct {
Merged Merged `json:"merged"`
Diff Diff `json:"diff"`
NodeName string `json:"node_name"`
Merged Merged `json:"merged"`
Diff Diff `json:"diff"`
}

type Merged struct {
Expand Down Expand Up @@ -60,7 +61,7 @@ func GetBsProvider(machineInfos *machine.MachineInfos) (map[uuid.UUID]*bs.BlockS
}
}

func BsMerge(bsFs map[uuid.UUID]*bs.BlockStorageInfos, bsProvider map[uuid.UUID]*bs.BlockStorageInfos) ([]byte, error) {
func BsMerge(machineInfos *machine.MachineInfos, bsFs map[uuid.UUID]*bs.BlockStorageInfos, bsProvider map[uuid.UUID]*bs.BlockStorageInfos) ([]byte, error) {
var b []byte
var err error

Expand Down Expand Up @@ -104,6 +105,7 @@ func BsMerge(bsFs map[uuid.UUID]*bs.BlockStorageInfos, bsProvider map[uuid.UUID]
Type: v.Type,
BlockDev: v.BlockDev,
Status: p.Status,
NodeName: v.NodeName,
Metadata: p.Metadata,
}
}
Expand All @@ -119,6 +121,7 @@ func BsMerge(bsFs map[uuid.UUID]*bs.BlockStorageInfos, bsProvider map[uuid.UUID]
}

all := All{
NodeName: machineInfos.KubeNodeName,
Merged: Merged{
Count: len(BsMerged),
Data: merged,
Expand Down Expand Up @@ -157,7 +160,7 @@ func bsCheckerCommand(clicontext *cli.Context) error {
return err
}

b, err := BsMerge(bsFs, bsProvider)
b, err := BsMerge(machineInfos, bsFs, bsProvider)

if b != nil {
fmt.Fprintln(os.Stdout, string(b))
Expand Down
2 changes: 1 addition & 1 deletion cmd/koherence/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func checkBsHandler(w http.ResponseWriter, req *http.Request) {
return
}

b, _ := check.BsMerge(bsFs, bsProvider)
b, _ := check.BsMerge(machineInfos, bsFs, bsProvider)

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
Expand Down
1 change: 1 addition & 0 deletions machine/fs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,6 @@ func ReadFsInfos() (*MachineInfos, error) {
SysVendor: string(sysVendor),
ChassisVendor: string(chassisVendor),
BlockStorageType: getBSType(),
KubeNodeName: os.Getenv("KUBE_NODE_NAME"),
}, nil
}
1 change: 1 addition & 0 deletions machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ type MachineInfos struct {
SysVendor string `json:"sys_vendor"`
ChassisVendor string `json:"chassis_vendor"`
BlockStorageType string `json:"block_storage_type"`
KubeNodeName string `json:"node_name"`
}
2 changes: 2 additions & 0 deletions machine/openstack_linklocal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"log/slog"
"net/http"
"os"
"time"

"github.com/google/uuid"
Expand Down Expand Up @@ -103,5 +104,6 @@ func ReadOpenstackInfos() (*MachineInfos, error) {
SysVendor: ProviderOpenstack,
ChassisVendor: "QEMU",
BlockStorageType: "None",
KubeNodeName: os.Getenv("KUBE_NODE_NAME"),
}, nil
}

0 comments on commit 90da789

Please sign in to comment.