Skip to content

Commit

Permalink
Add rancher storage provisioner
Browse files Browse the repository at this point in the history
  • Loading branch information
presztak committed Sep 23, 2023
1 parent 53fd558 commit bd86e95
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 0 deletions.
4 changes: 4 additions & 0 deletions deploy/addons/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ var (
//go:embed storage-provisioner-gluster/*.tmpl
StorageProvisionerGlusterAssets embed.FS

// StorageProvisionerRancherAssets assets for storage-provisioner-rancher addon
//go:embed storage-provisioner-rancher/*.tmpl
StorageProvisionerRancherAssets embed.FS

// EfkAssets assets for efk addon
//go:embed efk/*.tmpl
EfkAssets embed.FS
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
apiVersion: v1
kind: Namespace
metadata:
name: local-path-storage

---
apiVersion: v1
kind: ServiceAccount
metadata:
name: local-path-provisioner-service-account
namespace: local-path-storage

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: local-path-provisioner-role
rules:
- apiGroups: [ "" ]
resources: [ "nodes", "persistentvolumeclaims", "configmaps" ]
verbs: [ "get", "list", "watch" ]
- apiGroups: [ "" ]
resources: [ "endpoints", "persistentvolumes", "pods" ]
verbs: [ "*" ]
- apiGroups: [ "" ]
resources: [ "events" ]
verbs: [ "create", "patch" ]
- apiGroups: [ "storage.k8s.io" ]
resources: [ "storageclasses" ]
verbs: [ "get", "list", "watch" ]

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: local-path-provisioner-bind
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: local-path-provisioner-role
subjects:
- kind: ServiceAccount
name: local-path-provisioner-service-account
namespace: local-path-storage

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: local-path-provisioner
namespace: local-path-storage
spec:
replicas: 1
selector:
matchLabels:
app: local-path-provisioner
template:
metadata:
labels:
app: local-path-provisioner
spec:
serviceAccountName: local-path-provisioner-service-account
containers:
- name: local-path-provisioner
image: {{.CustomRegistries.LocalPathProvisioner | default .ImageRepository | default .Registries.LocalPathProvisioner }}{{ .Images.LocalPathProvisioner }}
imagePullPolicy: IfNotPresent
command:
- local-path-provisioner
- --debug
- start
- --config
- /etc/config/config.json
volumeMounts:
- name: config-volume
mountPath: /etc/config/
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
volumes:
- name: config-volume
configMap:
name: local-path-config

---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: local-path
provisioner: rancher.io/local-path
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete

---
kind: ConfigMap
apiVersion: v1
metadata:
name: local-path-config
namespace: local-path-storage
data:
config.json: |-
{
"nodePathMap":[
{
"node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
"paths":["/opt/local-path-provisioner"]
}
]
}
setup: |-
#!/bin/sh
set -eu
mkdir -m 0777 -p "$VOL_DIR"
teardown: |-
#!/bin/sh
set -eu
rm -rf "$VOL_DIR"
helperPod.yaml: |-
apiVersion: v1
kind: Pod
metadata:
name: helper-pod
spec:
containers:
- name: helper-pod
image: {{.CustomRegistries.Helper | default .ImageRepository | default .Registries.Helper }}{{ .Images.Helper }}
imagePullPolicy: IfNotPresent



2 changes: 2 additions & 0 deletions pkg/addons/addons_storage_classes.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func enableOrDisableStorageClasses(cc *config.ClusterConfig, name string, val st
class := defaultStorageClassProvisioner
if name == "storage-provisioner-gluster" {
class = "glusterfile"
} else if name == "storage-provisioner-rancher" {
class = "local-path"
}

api, err := machine.NewAPIClient()
Expand Down
5 changes: 5 additions & 0 deletions pkg/addons/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ var Addons = []*Addon{
set: SetBool,
callbacks: []setFn{enableOrDisableStorageClasses},
},
{
name: "storage-provisioner-rancher",
set: SetBool,
callbacks: []setFn{enableOrDisableStorageClasses},
},
{
name: "metallb",
set: SetBool,
Expand Down
13 changes: 13 additions & 0 deletions pkg/minikube/assets/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,19 @@ var Addons = map[string]*Addon{
"GlusterfsServer": "docker.io",
"GlusterfileProvisioner": "docker.io",
}),
"storage-provisioner-rancher": NewAddon([]*BinAsset{
MustBinAsset(addons.StorageProvisionerRancherAssets,
"storage-provisioner-rancher/storage-provisioner-rancher.yaml.tmpl",
vmpath.GuestAddonsDir,
"storage-provisioner-rancher.yaml",
"0640"),
}, false, "storage-provisioner-rancher", "3rd party (Rancher)", "", "", map[string]string{
"LocalPathProvisioner": "rancher/local-path-provisioner:v0.0.22@sha256:e34c88ae0affb1cdefbb874140d6339d4a27ec4ee420ae8199cd839997b05246",
"Helper": "busybox:stable@sha256:3fbc632167424a6d997e74f52b878d7cc478225cffac6bc977eedfe51c7f4e79",
}, map[string]string{
"LocalPathProvisioner": "docker.io",
"Helper": "docker.io",
}),
"efk": NewAddon([]*BinAsset{
MustBinAsset(addons.EfkAssets,
"efk/elasticsearch-rc.yaml.tmpl",
Expand Down

0 comments on commit bd86e95

Please sign in to comment.