func NewNitroEnclavesCPUDevicePlugin()

in pkg/nitro_enclaves_cpu_plugin/device_plugin.go [269:309]


func NewNitroEnclavesCPUDevicePlugin(config *config.PluginConfig) *NitroEnclavesCPUDevicePlugin {

	if err := config.Validate(); err != nil {
		glog.Errorf("invalid CPU plugin config: %v", err)
	}

	glog.V(0).Infof("Initializing Nitro Enclaves CPU device plugin with following params: %v", config)

	// create a virtual device for each 'offline' cpu on the kubernetes worker. An offline CPU can be considered a
	// CPU that is not in use by the host OS and has thus been allocated by the AWS Nitro Enclave allocation service.
	var devs []*pluginapi.Device
	if config.EnclaveCPUAdvertisement {

		data, err := os.ReadFile(deviceOfflineCPUsPath)
		if err != nil {
			glog.V(0).Infof("Error reading offline CPU file: %v", err)
			// if error was thrown in read CPU file step, set data to empty string to have
			// determineAdvisableCPUs set availableCPUsOnInstance to 0
			data = []byte("")
		}

		availableCPUsOnInstance, err := determineAdvisableCPUs(string(data))
		if err != nil {
			glog.V(0).Infof("Error while determining advisable CPUs on the instance: %v", err)
			availableCPUsOnInstance = 0
		}

		for i := 0; i < availableCPUsOnInstance; i++ {
			devs = append(devs, &pluginapi.Device{
				ID:     generateEnclaveCPUID(deviceName),
				Health: pluginapi.Healthy,
			})
		}
		glog.V(0).Infof("Reserved CPUs for encalves added: %v", availableCPUsOnInstance)
	}

	return &NitroEnclavesCPUDevicePlugin{
		devices: devs,
		stop:    make(chan interface{}),
	}
}