-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add macvtap device plugin #2
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
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
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 |
---|---|---|
@@ -1 +1,11 @@ | ||
# Multi-stage dockerfile building a container image with both binaries included | ||
|
||
FROM golang:1.13 as builder | ||
ENV GOPATH=/go | ||
WORKDIR /go/src/github.com/kubevirt/macvtap-cni | ||
COPY . . | ||
RUN GOOS=linux CGO_ENABLED=0 go build -o /macvtap github.com/kubevirt/macvtap-cni/cmd/deviceplugin | ||
|
||
FROM registry.access.redhat.com/ubi8/ubi-minimal | ||
COPY --from=builder /macvtap /macvtap | ||
ENTRYPOINT [ "./macvtap", "-v", "3", "-logtostderr"] |
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,22 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
|
||
"github.com/golang/glog" | ||
"github.com/kubevirt/device-plugin-manager/pkg/dpm" | ||
macvtap "github.com/kubevirt/macvtap-cni/pkg/deviceplugin" | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
_, configDefined := os.LookupEnv(macvtap.ConfigEnvironmentVariable) | ||
if !configDefined { | ||
glog.Exitf("%s environment variable must be set", macvtap.ConfigEnvironmentVariable) | ||
} | ||
|
||
manager := dpm.NewManager(macvtap.MacvtapLister{}) | ||
manager.Run() | ||
} |
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,12 @@ | ||
kind: ConfigMap | ||
apiVersion: v1 | ||
metadata: | ||
name: macvtap-deviceplugin-config | ||
data: | ||
DP_MACVTAP_CONF: >- | ||
[ { | ||
"name" : "eth0", | ||
"master" : "eth0", | ||
"mode": "bridge", | ||
"capacity" : 50 | ||
} ] |
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
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
apiVersion: apps/v1 | ||
kind: DaemonSet | ||
metadata: | ||
name: macvtap-cni | ||
spec: | ||
selector: | ||
matchLabels: | ||
name: macvtap-cni | ||
template: | ||
metadata: | ||
labels: | ||
name: macvtap-cni | ||
spec: | ||
hostNetwork: true | ||
hostPID: true | ||
containers: | ||
- name: macvtap-cni | ||
image: quay.io/kubevirt/macvtap-cni:latest | ||
securityContext: | ||
privileged: true | ||
envFrom: | ||
- configMapRef: | ||
name: macvtap-deviceplugin-config | ||
volumeMounts: | ||
- name: deviceplugin | ||
mountPath: /var/lib/kubelet/device-plugins | ||
volumes: | ||
- name: deviceplugin | ||
hostPath: | ||
path: /var/lib/kubelet/device-plugins |
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,13 @@ | ||
package deviceplugin_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestDevicePlugin(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Deviceplugin Suite") | ||
} |
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,74 @@ | ||
package deviceplugin | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
|
||
"github.com/golang/glog" | ||
"github.com/kubevirt/device-plugin-manager/pkg/dpm" | ||
) | ||
|
||
const ( | ||
resourceNamespace = "macvtap.network.kubevirt.io" | ||
ConfigEnvironmentVariable = "DP_MACVTAP_CONF" | ||
) | ||
|
||
type MacvtapConfig struct { | ||
Name string `json:"name"` | ||
Master string `json:"master"` | ||
Mode string `json:"mode"` | ||
Capacity int `json:"capacity"` | ||
} | ||
|
||
type MacvtapLister struct { | ||
} | ||
|
||
func (ml MacvtapLister) GetResourceNamespace() string { | ||
return resourceNamespace | ||
} | ||
|
||
func readConfig() (map[string]MacvtapConfig, error) { | ||
var config []MacvtapConfig | ||
configMap := make(map[string]MacvtapConfig) | ||
|
||
configEnv := os.Getenv(ConfigEnvironmentVariable) | ||
err := json.Unmarshal([]byte(configEnv), &config) | ||
if err != nil { | ||
return configMap, err | ||
} | ||
|
||
for _, macvtapConfig := range config { | ||
configMap[macvtapConfig.Name] = macvtapConfig | ||
} | ||
|
||
return configMap, nil | ||
} | ||
|
||
func (ml MacvtapLister) Discover(pluginListCh chan dpm.PluginNameList) { | ||
var plugins = make(dpm.PluginNameList, 0) | ||
|
||
config, err := readConfig() | ||
if err != nil { | ||
glog.Errorf("Error reading config: %v", err) | ||
return | ||
} | ||
|
||
glog.V(3).Infof("Read configuration %+v", config) | ||
|
||
for _, macvtapConfig := range config { | ||
plugins = append(plugins, macvtapConfig.Name) | ||
} | ||
|
||
pluginListCh <- plugins | ||
} | ||
|
||
func (ml MacvtapLister) NewPlugin(name string) dpm.PluginInterface { | ||
config, _ := readConfig() | ||
glog.V(3).Infof("Creating device plugin with config %+v", config[name]) | ||
return NewMacvtapDevicePlugin( | ||
config[name].Name, | ||
config[name].Master, | ||
config[name].Mode, | ||
config[name].Capacity, | ||
) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So to apply new config, all DaemonSets need to be restarted? Could you document it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, ideally deleting the config map and creating a new one would take care of it. I was waiting for the cni to wire an encompassing readme to include this information.