Skip to content

Commit 1f76335

Browse files
Merge pull request #12995 from eliaskoromilas/fpga-operator
InAccel FPGA Operator addon
2 parents 1a72b45 + 6364518 commit 1f76335

File tree

10 files changed

+168
-1
lines changed

10 files changed

+168
-1
lines changed

cmd/minikube/cmd/config/addons_list_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestAddonsList(t *testing.T) {
7777
Ambassador *interface{} `json:"ambassador"`
7878
}
7979

80-
b := make([]byte, 544)
80+
b := make([]byte, 557)
8181
r, w, err := os.Pipe()
8282
if err != nil {
8383
t.Fatalf("failed to create pipe: %v", err)

deploy/addons/assets.go

+4
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,8 @@ var (
143143
// AliyunMirror assets for aliyun_mirror.json
144144
//go:embed aliyun_mirror.json
145145
AliyunMirror embed.FS
146+
147+
// InAccelAssets assets for inaccel addon
148+
//go:embed inaccel/fpga-operator.yaml.tmpl
149+
InAccelAssets embed.FS
146150
)

deploy/addons/inaccel/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### Documentation
2+
3+
For detailed usage instructions visit: [docs.inaccel.com](https://docs.inaccel.com)
4+
5+
### Support
6+
7+
For more product information contact: [email protected]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
labels:
6+
addonmanager.kubernetes.io/mode: Reconcile
7+
kubernetes.io/minikube-addons: inaccel
8+
name: inaccel-addon
9+
namespace: kube-system
10+
data:
11+
disable.sh: |
12+
#!/bin/sh -e
13+
exec >/proc/1/fd/1
14+
echo "Disabling InAccel FPGA Operator"
15+
helm uninstall inaccel --namespace kube-system
16+
echo "InAccel is disabled"
17+
enable.sh: |
18+
#!/bin/sh -e
19+
exec >/proc/1/fd/1
20+
echo "Enabling InAccel FPGA Operator"
21+
helm install inaccel fpga-operator --namespace kube-system --repo https://setup.inaccel.com/helm
22+
echo "InAccel is enabled"
23+
---
24+
apiVersion: v1
25+
kind: Pod
26+
metadata:
27+
labels:
28+
addonmanager.kubernetes.io/mode: Reconcile
29+
kubernetes.io/minikube-addons: inaccel
30+
name: inaccel-addon
31+
namespace: kube-system
32+
spec:
33+
containers:
34+
- command:
35+
- sleep
36+
- infinity
37+
image: {{ .CustomRegistries.Helm3 | default .ImageRepository | default .Registries.Helm3 }}{{ .Images.Helm3 }}
38+
lifecycle:
39+
postStart:
40+
exec:
41+
command:
42+
- /inaccel/enable.sh
43+
preStop:
44+
exec:
45+
command:
46+
- /inaccel/disable.sh
47+
name: helm3
48+
volumeMounts:
49+
- mountPath: /inaccel
50+
name: inaccel-addon
51+
readOnly: true
52+
volumes:
53+
- configMap:
54+
defaultMode: 0777
55+
name: inaccel-addon
56+
name: inaccel-addon

pkg/addons/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,9 @@ var Addons = []*Addon{
197197
set: SetBool,
198198
callbacks: []setFn{EnableOrDisableAddon},
199199
},
200+
{
201+
name: "inaccel",
202+
set: SetBool,
203+
callbacks: []setFn{EnableOrDisableAddon},
204+
},
200205
}

pkg/minikube/assets/addons.go

+11
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,17 @@ var Addons = map[string]*Addon{
690690
}, false, "portainer", "Portainer.io", "", map[string]string{
691691
"Portainer": "portainer/portainer-ce:latest@sha256:4f126c5114b63e9d1bceb4b368944d14323329a9a0d4e7bb7eb53c9b7435d498",
692692
}, nil),
693+
"inaccel": NewAddon([]*BinAsset{
694+
MustBinAsset(addons.InAccelAssets,
695+
"inaccel/fpga-operator.yaml.tmpl",
696+
vmpath.GuestAddonsDir,
697+
"fpga-operator.yaml",
698+
"0640"),
699+
}, false, "inaccel", "InAccel <[email protected]>", map[string]string{
700+
"Helm3": "alpine/helm:3.9.0@sha256:9f4bf4d24241f983910550b1fe8688571cd684046500abe58cef14308f9cb19e",
701+
}, map[string]string{
702+
"Helm3": "docker.io",
703+
}),
693704
}
694705

695706
// parseMapString creates a map based on `str` which is encoded as <key1>=<value1>,<key2>=<value2>,...

pkg/minikube/detect/detect.go

+22
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package detect
1818

1919
import (
20+
"io"
2021
"net/http"
2122
"os"
2223
"os/exec"
@@ -67,6 +68,27 @@ func IsOnGCE() bool {
6768
return resp.Header.Get("Metadata-Flavor") == "Google"
6869
}
6970

71+
// IsOnAmazonEC2 determines whether minikube is currently running on Amazon EC2
72+
// and, if yes, on which instance type.
73+
func IsOnAmazonEC2() (bool, string) {
74+
resp, err := http.Get("http://instance-data.ec2.internal/latest/meta-data/instance-type")
75+
if err != nil {
76+
return false, ""
77+
}
78+
defer resp.Body.Close()
79+
80+
if resp.StatusCode != http.StatusOK {
81+
return true, ""
82+
}
83+
84+
instanceType, err := io.ReadAll(resp.Body)
85+
if err != nil {
86+
return true, ""
87+
}
88+
89+
return true, string(instanceType)
90+
}
91+
7092
// IsCloudShell determines whether minikube is running inside CloudShell
7193
func IsCloudShell() bool {
7294
e := os.Getenv("CLOUD_SHELL")

site/content/en/docs/contrib/tests.en.md

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ tests the csi hostpath driver by creating a persistent volume, snapshotting it a
4242
#### validateGCPAuthAddon
4343
tests the GCP Auth addon with either phony or real credentials and makes sure the files are mounted into pods correctly
4444

45+
#### validateInAccelAddon
46+
tests the InAccel addon by trying a vadd
47+
4548
## TestCertOptions
4649
makes sure minikube certs respect the --apiserver-ips and --apiserver-names parameters
4750

test/integration/addons_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ func TestAddons(t *testing.T) {
6868
args := append([]string{"start", "-p", profile, "--wait=true", "--memory=4000", "--alsologtostderr", "--addons=registry", "--addons=metrics-server", "--addons=volumesnapshots", "--addons=csi-hostpath-driver", "--addons=gcp-auth"}, StartArgs()...)
6969
if !NoneDriver() { // none driver does not support ingress
7070
args = append(args, "--addons=ingress", "--addons=ingress-dns")
71+
} else if isOnAmazonEC2, instanceType := detect.IsOnAmazonEC2(); isOnAmazonEC2 && strings.HasPrefix(instanceType, "f1.") {
72+
args = append(args, "--addons=inaccel") // inaccel supports only none driver
7173
}
7274
if !arm64Platform() {
7375
args = append(args, "--addons=helm-tiller")
@@ -95,6 +97,7 @@ func TestAddons(t *testing.T) {
9597
{"HelmTiller", validateHelmTillerAddon},
9698
{"Olm", validateOlmAddon},
9799
{"CSI", validateCSIDriverAndSnapshots},
100+
{"InAccel", validateInAccelAddon},
98101
}
99102
for _, tc := range tests {
100103
tc := tc
@@ -708,3 +711,40 @@ func validateGCPAuthAddon(ctx context.Context, t *testing.T, profile string) {
708711
}
709712
}
710713
}
714+
715+
// validateInAccelAddon tests the inaccel addon by trying a vadd
716+
func validateInAccelAddon(ctx context.Context, t *testing.T, profile string) {
717+
defer PostMortemLogs(t, profile)
718+
719+
if !NoneDriver() {
720+
t.Skipf("skipping: inaccel not supported")
721+
}
722+
723+
if isOnAmazonEC2, instanceType := detect.IsOnAmazonEC2(); !(isOnAmazonEC2 && strings.HasPrefix(instanceType, "f1.")) {
724+
t.Skipf("skipping: not running on an Amazon EC2 f1 instance")
725+
}
726+
727+
// create sample pod
728+
rr, err := Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "create", "--filename", filepath.Join(*testdataDir, "inaccel.yaml")))
729+
if err != nil {
730+
t.Fatalf("creating pod with %s failed: %v", rr.Command(), err)
731+
}
732+
733+
if _, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "wait", "--for", "condition=ready", "--timeout", "-1s", "pod/inaccel-vadd")); err != nil {
734+
t.Fatalf("failed waiting for inaccel-vadd pod: %v", err)
735+
}
736+
737+
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "logs", "--follow", "pod/inaccel-vadd"))
738+
if err != nil {
739+
t.Fatalf("%q failed: %v", rr.Command(), err)
740+
}
741+
if !strings.Contains(rr.Stdout.String(), "Test PASSED") {
742+
t.Fatalf("expected inaccel-vadd logs to include: %q but got: %s", "Test PASSED", rr.Output())
743+
}
744+
745+
// delete pod
746+
rr, err = Run(t, exec.CommandContext(ctx, "kubectl", "--context", profile, "delete", "pod/inaccel-vadd"))
747+
if err != nil {
748+
t.Fatalf("deleting pod with %s failed: %v", rr.Command(), err)
749+
}
750+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
annotations:
5+
inaccel/cli: |
6+
bitstream install https://store.inaccel.com/artifactory/bitstreams/xilinx/aws-vu9p-f1/dynamic-shell/aws/vector/1/1addition
7+
labels:
8+
inaccel/fpga: enabled
9+
name: inaccel-vadd
10+
spec:
11+
containers:
12+
- image: inaccel/vadd
13+
name: inaccel-vadd
14+
resources:
15+
limits:
16+
xilinx/aws-vu9p-f1: 1
17+
nodeSelector:
18+
xilinx/aws-vu9p-f1: dynamic-shell
19+
restartPolicy: Never

0 commit comments

Comments
 (0)