Skip to content

Commit

Permalink
new scheme for env variable names
Browse files Browse the repository at this point in the history
Based on discussions on env variable now the plugin will export
them in following format:
   PCIDEVICE_INTEL_COM_NET_A=0000:87:10.0;0000:87:11.6

Change-Id: I60cf0ded245f041a1842cc541a584eb1de2f7dbc
  • Loading branch information
ahalimx86 committed Nov 22, 2018
1 parent 9e0654f commit abfdd2e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/resources/genericPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (rp *genericResourcePool) GetEnvs(deviceIDs []string) map[string]string {
if i == lastIndex {
break
}
values += " "
values += ","
}
envs[rp.config.ResourceName] = values
return envs
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/netDevicePool.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (rp *netDevicePool) GetEnvs(deviceIDs []string) map[string]string {
if i == lastIndex {
break
}
values += " "
values += ","
}
envs[rp.config.ResourceName] = values
return envs
Expand Down
18 changes: 17 additions & 1 deletion pkg/resources/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"net"
"os"
"path/filepath"
"strings"
"time"

"github.com/golang/glog"
Expand Down Expand Up @@ -86,7 +87,7 @@ func (rs *resourceServer) Allocate(ctx context.Context, rqt *pluginapi.AllocateR
for _, container := range rqt.ContainerRequests {
containerResp := new(pluginapi.ContainerAllocateResponse)
containerResp.Devices = rs.resourcePool.GetDeviceSpecs(rs.resourcePool.GetDeviceFiles(), container.DevicesIDs)
containerResp.Envs = rs.resourcePool.GetEnvs(container.DevicesIDs)
containerResp.Envs = rs.getEnvs(container.DevicesIDs)
containerResp.Mounts = rs.resourcePool.GetMounts()
resp.ContainerResponses = append(resp.ContainerResponses, containerResp)
}
Expand Down Expand Up @@ -281,3 +282,18 @@ func (rs *resourceServer) triggerUpdate() {
}()
}
}

func (rs *resourceServer) getEnvs(deviceIDs []string) map[string]string {

varPrefix := "PCIDEVICE"
resourceNamePrefix := strings.Replace(rs.resourceNamePrefix, ".", "_", -1)

envs := rs.resourcePool.GetEnvs(deviceIDs)

newEnvs := make(map[string]string)
for k, v := range envs {
exportedVar := strings.ToUpper(fmt.Sprintf("%s_%s_%s", varPrefix, resourceNamePrefix, k))
newEnvs[exportedVar] = v
}
return newEnvs
}
2 changes: 1 addition & 1 deletion pkg/resources/uioPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (rp *uioResourcePool) GetEnvs(deviceIDs []string) map[string]string {
if i == lastIndex {
break
}
values += " "
values += ","
}
envs[rp.config.ResourceName] = values
return envs
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/vfioPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (rp *vfioResourcePool) GetEnvs(deviceIDs []string) map[string]string {
if i == lastIndex {
break
}
values += " "
values += ","
}
envs[rp.config.ResourceName] = values
return envs
Expand Down

0 comments on commit abfdd2e

Please sign in to comment.