-
Notifications
You must be signed in to change notification settings - Fork 575
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
218 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package checkpoint | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
|
||
"github.com/intel/multus-cni/types" | ||
) | ||
|
||
const ( | ||
checkPointfile = "/var/lib/kubelet/device-plugins/kubelet_internal_checkpoint" | ||
) | ||
|
||
type PodDevicesEntry struct { | ||
PodUID string | ||
ContainerName string | ||
ResourceName string | ||
DeviceIDs []string | ||
AllocResp []byte | ||
} | ||
|
||
type checkpointData struct { | ||
PodDeviceEntries []PodDevicesEntry | ||
RegisteredDevices map[string][]string | ||
} | ||
|
||
type Data struct { | ||
Data checkpointData | ||
Checksum uint64 | ||
} | ||
|
||
// getPodEntries gets all Pod device allocation entries from checkpoint file | ||
func getPodEntries() ([]PodDevicesEntry, error) { | ||
|
||
podEntries := []PodDevicesEntry{} | ||
|
||
cpd := &Data{} | ||
rawBytes, err := ioutil.ReadFile(checkPointfile) | ||
if err != nil { | ||
return podEntries, fmt.Errorf("getPodEntries(): error reading file %s\n%v\n", checkPointfile, err) | ||
|
||
} | ||
|
||
if err = json.Unmarshal(rawBytes, cpd); err != nil { | ||
return podEntries, fmt.Errorf("getPodEntries(): error unmarshalling raw bytes %v", err) | ||
} | ||
|
||
return cpd.Data.PodDeviceEntries, nil | ||
} | ||
|
||
// GetComputeDeviceMap returns a map of resourceName to list of device IDs | ||
func GetComputeDeviceMap(podID string) (map[string]*types.ResourceInfo, error) { | ||
|
||
resourceMap := make(map[string]*types.ResourceInfo) | ||
podEntires, err := getPodEntries() | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, pod := range podEntires { | ||
if pod.PodUID == podID { | ||
entry, ok := resourceMap[pod.ResourceName] | ||
if ok { | ||
// already exists; append to it | ||
entry.DeviceIDs = append(entry.DeviceIDs, pod.DeviceIDs...) | ||
} else { | ||
// new entry | ||
resourceMap[pod.ResourceName] = &types.ResourceInfo{DeviceIDs: pod.DeviceIDs} | ||
} | ||
} | ||
} | ||
|
||
return resourceMap, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: testpod1 | ||
labels: | ||
env: test | ||
annotations: | ||
k8s.v1.cni.cncf.io/networks: sriov-net-a | ||
spec: | ||
containers: | ||
- name: appcntr1 | ||
image: centos/tools | ||
imagePullPolicy: IfNotPresent | ||
command: [ "/bin/bash", "-c", "--" ] | ||
args: [ "while true; do sleep 300000; done;" ] | ||
resources: | ||
requests: | ||
intel.com/sriov: '1' | ||
limits: | ||
intel.com/sriov: '1' | ||
restartPolicy: "Never" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: "k8s.cni.cncf.io/v1" | ||
kind: NetworkAttachmentDefinition | ||
metadata: | ||
name: sriov-net-a | ||
annotations: | ||
k8s.v1.cni.cncf.io/resourceName: intel.com/sriov | ||
spec: | ||
config: '{ | ||
"type": "sriov", | ||
"vlan": 1000, | ||
"ipam": { | ||
"type": "host-local", | ||
"subnet": "10.56.217.0/24", | ||
"rangeStart": "10.56.217.171", | ||
"rangeEnd": "10.56.217.181", | ||
"routes": [{ | ||
"dst": "0.0.0.0/0" | ||
}], | ||
"gateway": "10.56.217.1" | ||
} | ||
}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters