Skip to content

Commit 39630d6

Browse files
Initial commit with support for static provisioning
1 parent b5713fd commit 39630d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2540
-9
lines changed

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM --platform=$BUILDPLATFORM golang:1.19.0-bullseye as builder
2+
WORKDIR /go/src/github.com/kubernetes-sigs/aws-file-cache-csi-driver
3+
ADD . .
4+
RUN make
5+
6+
FROM amazonlinux:2 AS linux-amazon
7+
RUN yum update -y
8+
RUN yum install util-linux libyaml -y \
9+
&& amazon-linux-extras install -y lustre
10+
11+
COPY --from=builder /go/src/github.com/kubernetes-sigs/aws-file-cache-csi-driver/bin/aws-file-cache-csi-driver /bin/aws-file-cache-csi-driver
12+
13+
ENTRYPOINT ["/bin/aws-file-cache-csi-driver"]

Makefile

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
VERSION=0.1.0
2+
3+
PKG=github.com/kubernetes-sigs/aws-file-cache-csi-driver
4+
GIT_COMMIT?=$(shell git rev-parse HEAD)
5+
BUILD_DATE?=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
6+
7+
LDFLAGS?="-X ${PKG}/pkg/driver.driverVersion=${VERSION} -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE}"
8+
9+
GO111MODULE=on
10+
GOPROXY=direct
11+
GOPATH=$(shell go env GOPATH)
12+
GOOS=$(shell go env GOOS)
13+
GOBIN=$(shell pwd)/bin
14+
15+
IMAGE?=648284600874.dkr.ecr.us-east-1.amazonaws.com/aws-file-cache-csi-driver
16+
TAG?=$(GIT_COMMIT)
17+
18+
OUTPUT_TYPE?=docker
19+
20+
ARCH=amd64
21+
OS=linux
22+
OSVERSION=amazon
23+
24+
ALL_OS?=linux
25+
ALL_ARCH_linux?=amd64 arm64
26+
ALL_OSVERSION_linux?=amazon
27+
ALL_OS_ARCH_OSVERSION_linux=$(foreach arch, $(ALL_ARCH_linux), $(foreach osversion, ${ALL_OSVERSION_linux}, linux-$(arch)-${osversion}))
28+
29+
ALL_OS_ARCH_OSVERSION=$(foreach os, $(ALL_OS), ${ALL_OS_ARCH_OSVERSION_${os}})
30+
31+
PLATFORM?=linux/amd64,linux/arm64
32+
33+
# split words on hyphen, access by 1-index
34+
word-hyphen = $(word $2,$(subst -, ,$1))
35+
36+
.EXPORT_ALL_VARIABLES:
37+
38+
.PHONY: aws-file-cache-csi-driver
39+
aws-file-cache-csi-driver:
40+
mkdir -p bin
41+
CGO_ENABLED=0 GOOS=linux go build -ldflags ${LDFLAGS} -o bin/aws-file-cache-csi-driver ./cmd/
42+
43+
.PHONY: all
44+
all: all-image-docker
45+
46+
.PHONY: all-push
47+
all-push:
48+
docker buildx build \
49+
--no-cache-filter=linux-amazon \
50+
--platform=$(PLATFORM) \
51+
--progress=plain \
52+
--target=$(OS)-$(OSVERSION) \
53+
--output=type=registry \
54+
-t=$(IMAGE):$(TAG) \
55+
.
56+
touch $@
57+
58+
.PHONY: all-image-docker
59+
all-image-docker: $(addprefix sub-image-docker-,$(ALL_OS_ARCH_OSVERSION_linux))
60+
61+
sub-image-%:
62+
$(MAKE) OUTPUT_TYPE=$(call word-hyphen,$*,1) OS=$(call word-hyphen,$*,2) ARCH=$(call word-hyphen,$*,3) OSVERSION=$(call word-hyphen,$*,4) image
63+
64+
.PHONY: test
65+
test:
66+
go test -v -race ./pkg/...
67+
68+
.PHONY: clean
69+
clean:
70+
rm -rf .*image-* bin/

README.md

Lines changed: 99 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,106 @@
1-
# aws-file-cache-csi-driver
1+
[![Build Status](https://travis-ci.org/aws/aws-fsx-csi-driver.svg?branch=master)](https://travis-ci.org/aws/aws-fsx-csi-driver)
22

3-
Amazon File Cache Cloud Container Storage Interface(CSI) Driver
3+
**WARNING**: This driver is in pre ALPHA currently. This means that there may potentially be backwards compatible breaking changes moving forward. Do NOT use this driver in a production environment in its current state.
44

5-
## Community, discussion, contribution, and support
5+
**DISCLAIMER**: This is not an officially supported Amazon product
66

7-
Learn how to engage with the Kubernetes community on the [community page](http://kubernetes.io/community/).
7+
## Amazon File Cache CSI Driver
8+
### Overview
89

9-
You can reach the maintainers of this project at:
10+
The [Amazon File Cache]() Container Storage Interface (CSI) Driver provides a [CSI]() interface used by container orchestrators to manage the lifecycle of Amazon file cache volumes.
1011

11-
- [Slack](https://kubernetes.slack.com/messages/sig-cloud-provider)
12-
- [Mailing List](https://groups.google.com/forum/#!forum/kubernetes-sig-cloud-provider)
12+
This driver is in alpha stage. Basic volume operations that are functional include NodePublishVolume/NodeUnpublishVolume.
1313

14-
### Code of conduct
14+
### CSI Specification Compability Matrix
15+
| AWS File Cache CSI Driver \ CSI Version | v1.0.0|
16+
|---------------------------------------------------|-------|
17+
| master branch | yes |
18+
19+
### Kubernetes Version Compability Matrix
20+
| AWS File Cache CSI Driver \ Kubernetes Version | v1.17+ |
21+
|---------------------------------------------------|--------|
22+
| master branch | yes |
23+
24+
## Features
25+
Currently only static provisioning is supported. With static provisioning, a file cache should be created manually, then it could be mounted inside container as a persistence volume (PV) using File Cache CSI Driver.
26+
27+
The following CSI interfaces are implemented:
28+
* Controller Service:
29+
* Node Service: NodePublishVolume, NodeUnpublishVolume, NodeGetCapabilities, NodeGetInfo, NodeGetId
30+
* Identity Service: GetPluginInfo, GetPluginCapabilities, Probe
31+
32+
## Examples
33+
This example shows how to make an Amazon File Cache availble inside container for the application to consume. Before this, get yourself familiar with how to setup kubernetes on AWS and [create an Amazon file cache](https://docs.aws.amazon.com/fsx/latest/FileCacheGuide/getting-started.html). And when creating an Amazon File Cache, make sure it is created inside the same VPC as kuberentes cluster or it is accessible through VPC peering.
34+
35+
Once kubernetes cluster and an Amazon File Cache is created, create secret manifest file using [secret.yaml](../deploy/kubernetes/secret.yaml).
36+
37+
Then create the secret object:
38+
```sh
39+
kubectl apply -f deploy/kubernetes/secret.yaml
40+
```
41+
42+
Deploy the Amazon file cache CSI driver:
43+
44+
```sh
45+
kubectl apply -k deploy/kubernetes/base/
46+
```
47+
48+
Edit the [persistence volume manifest file](../examples/kubernetes/static_provisioning/specs/pv.yaml):
49+
```sh
50+
apiVersion: v1
51+
kind: PersistentVolume
52+
metadata:
53+
name: fc-pv
54+
spec:
55+
capacity:
56+
storage: 1200Gi
57+
volumeMode: FileCache
58+
accessModes:
59+
- ReadWriteOnce
60+
persistentVolumeReclaimPolicy: Recycle
61+
storageClassName: fc-sc
62+
csi:
63+
driver: file.cache.csi.aws.com
64+
volumeHandle: [FileCacheId]
65+
volumeAttributes:
66+
dnsname: [DNSName]
67+
```
68+
Replace `volumeHandle` with `FileCacheId` and `dnsname` with `DNSName`. You can get both `FileCacheId` and `DNSName` using AWS CLI:
69+
70+
```sh
71+
aws fsx describe-file-caches
72+
```
73+
74+
Then create PV, persistence volume claim (PVC) and storage class:
75+
```sh
76+
kubectl apply -f examples/kubernetes/dynamic_provisioning/specs/storageclass.yaml
77+
kubectl apply -f examples/kubernetes/dynamic_provisioning/specs/pv.yaml
78+
kubectl apply -f examples/kubernetes/dynamic_provisioning/specs/claim.yaml
79+
kubectl apply -f examples/kubernetes/dynamic_provisioning/specs/pod.yaml
80+
```
81+
82+
After objects are created, verify that pod is running:
83+
84+
```sh
85+
kubectl get pods
86+
```
87+
88+
Make sure data is written onto Amazon File Cache:
89+
90+
```sh
91+
kubectl exec -ti fc-app -- df -h
92+
kubectl exec -it fc-app -- ls /data
93+
```
94+
95+
## Development
96+
Please go through [CSI Spec](https://github.com/container-storage-interface/spec/blob/master/spec.md) and [General CSI driver development guideline](https://kubernetes-csi.github.io/docs/Development.html) to get some basic understanding of CSI driver before you start.
97+
98+
### Requirements
99+
* Golang 1.9+
100+
101+
### Testing
102+
To execute all unit tests, run: `make test`
103+
104+
## License
105+
This library is licensed under the Apache 2.0 License.
15106

16-
Participation in the Kubernetes community is governed by the [Kubernetes Code of Conduct](code-of-conduct.md).

cmd/main.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"os"
7+
8+
"k8s.io/klog/v2"
9+
"sigs.k8s.io/aws-file-cache-csi-driver/pkg/driver"
10+
)
11+
12+
func main() {
13+
var (
14+
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI Endpoint")
15+
version = flag.Bool("version", false, "Print the version and exit")
16+
)
17+
klog.InitFlags(nil)
18+
flag.Parse()
19+
20+
if *version {
21+
info, err := driver.GetVersionJSON()
22+
if err != nil {
23+
klog.Fatalln(err)
24+
}
25+
fmt.Println(info)
26+
os.Exit(0)
27+
}
28+
29+
drv := driver.NewDriver(*endpoint)
30+
if err := drv.Run(); err != nil {
31+
klog.Fatalln(err)
32+
}
33+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: file-cache-csi-controller
6+
labels:
7+
app.kubernetes.io/name: aws-file-cache-csi-driver
8+
spec:
9+
replicas: 2
10+
selector:
11+
matchLabels:
12+
app: file-cache-csi-controller
13+
app.kubernetes.io/name: aws-file-cache-csi-driver
14+
template:
15+
metadata:
16+
labels:
17+
app: file-cache-csi-controller
18+
app.kubernetes.io/name: aws-file-cache-csi-driver
19+
spec:
20+
nodeSelector:
21+
kubernetes.io/os: linux
22+
hostNetwork: true
23+
serviceAccountName: file-cache-csi-controller-sa
24+
priorityClassName: system-cluster-critical
25+
tolerations:
26+
- key: CriticalAddonsOnly
27+
operator: Exists
28+
- operator: Exists
29+
effect: NoExecute
30+
tolerationSeconds: 300
31+
containers:
32+
- name: file-cache-plugin
33+
image: 648284600874.dkr.ecr.us-east-1.amazonaws.com/aws-file-cache-csi-driver:v0.0.1
34+
args :
35+
- --endpoint=$(CSI_ENDPOINT)
36+
- --v=5
37+
env:
38+
- name: CSI_ENDPOINT
39+
value: unix:///var/lib/csi/sockets/pluginproxy/csi.sock
40+
- name: AWS_ACCESS_KEY_ID
41+
valueFrom:
42+
secretKeyRef:
43+
name: aws-secret
44+
key: key_id
45+
optional: true
46+
- name: AWS_SECRET_ACCESS_KEY
47+
valueFrom:
48+
secretKeyRef:
49+
name: aws-secret
50+
key: access_key
51+
optional: true
52+
volumeMounts:
53+
- name: socket-dir
54+
mountPath: /var/lib/csi/sockets/pluginproxy/
55+
ports:
56+
- name: healthz
57+
containerPort: 9910
58+
protocol: TCP
59+
livenessProbe:
60+
httpGet:
61+
path: /healthz
62+
port: healthz
63+
initialDelaySeconds: 10
64+
timeoutSeconds: 3
65+
periodSeconds: 2
66+
failureThreshold: 5
67+
- name: csi-provisioner
68+
image: public.ecr.aws/eks-distro/kubernetes-csi/external-provisioner:v3.4.0-eks-1-23-13
69+
args:
70+
- --csi-address=$(ADDRESS)
71+
- --timeout=5m
72+
- --extra-create-metadata
73+
- --leader-election=true
74+
env:
75+
- name: ADDRESS
76+
value: /var/lib/csi/sockets/pluginproxy/csi.sock
77+
volumeMounts:
78+
- name: socket-dir
79+
mountPath: /var/lib/csi/sockets/pluginproxy/
80+
- name: liveness-probe
81+
image: public.ecr.aws/eks-distro/kubernetes-csi/livenessprobe:v2.9.0-eks-1-23-13
82+
args:
83+
- --csi-address=/csi/csi.sock
84+
- --health-port=9910
85+
volumeMounts:
86+
- name: socket-dir
87+
mountPath: /csi
88+
volumes:
89+
- name: socket-dir
90+
emptyDir: {}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
3+
apiVersion: v1
4+
kind: ServiceAccount
5+
metadata:
6+
name: file-cache-csi-controller-sa
7+
labels:
8+
app.kubernetes.io/name: aws-file-cache-csi-driver
9+
---
10+
11+
kind: ClusterRole
12+
apiVersion: rbac.authorization.k8s.io/v1
13+
metadata:
14+
name: file-cache-csi-external-provisioner-role
15+
labels:
16+
app.kubernetes.io/name: aws-file-cache-csi-driver
17+
rules:
18+
- apiGroups: [""]
19+
resources: ["persistentvolumes"]
20+
verbs: ["get", "list", "watch", "create", "delete"]
21+
- apiGroups: [""]
22+
resources: ["persistentvolumeclaims"]
23+
verbs: ["get", "list", "watch", "update"]
24+
- apiGroups: ["storage.k8s.io"]
25+
resources: ["storageclasses"]
26+
verbs: ["get", "list", "watch"]
27+
- apiGroups: [""]
28+
resources: ["events"]
29+
verbs: ["list", "watch", "create", "update", "patch"]
30+
- apiGroups: ["storage.k8s.io"]
31+
resources: ["csinodes"]
32+
verbs: ["get", "list", "watch"]
33+
- apiGroups: [""]
34+
resources: ["nodes"]
35+
verbs: ["get", "list", "watch"]
36+
- apiGroups: ["coordination.k8s.io"]
37+
resources: ["leases"]
38+
verbs: ["get", "watch", "list", "delete", "update", "create"]
39+
40+
---
41+
42+
kind: ClusterRoleBinding
43+
apiVersion: rbac.authorization.k8s.io/v1
44+
metadata:
45+
name: file-cache-csi-external-provisioner-binding
46+
labels:
47+
app.kubernetes.io/name: aws-file-cache-csi-driver
48+
subjects:
49+
- kind: ServiceAccount
50+
name: file-cache-csi-controller-sa
51+
namespace: default
52+
roleRef:
53+
kind: ClusterRole
54+
name: file-cache-csi-external-provisioner-role
55+
apiGroup: rbac.authorization.k8s.io
56+
---
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
3+
apiVersion: storage.k8s.io/v1
4+
kind: CSIDriver
5+
metadata:
6+
name: file.cache.csi.aws.com
7+
spec:
8+
attachRequired: false

0 commit comments

Comments
 (0)