Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

init-ubuntu: init container to deploy extra kernel modules for ubuntu 18.04/20.04 #20

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
29 changes: 29 additions & 0 deletions Dockerfile.ubuntu1804
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM golang:1.15.0 AS build

WORKDIR /go/src/github.com/storageos/init/
COPY . /go/src/github.com/storageos/init/
RUN make build

FROM ubuntu:18.04
LABEL name="StorageOS Custom Init for Ubuntu Node Image" \
maintainer="[email protected]" \
vendor="StorageOS" \
version="v2.1.0-ubuntu1804" \
release="1" \
distribution-scope="public" \
architecture="x86_64" \
url="https://docs.ondat.io" \
io.k8s.description="The StorageOS custom Init container prepares a node for running StorageOS by installing the required extra kernel module packages." \
io.k8s.display-name="StorageOS Init" \
io.openshift.tags="storageos,storage,operator,pv,pvc,storageclass,persistent,csi" \
summary="Highly-available persistent block storage for containerized applications." \
description="StorageOS transforms commodity server or cloud based disk capacity into enterprise-class storage to run persistent workloads such as databases in containers. Provides high availability, low latency persistent block storage. No other hardware or software is required."

RUN apt -y update && \
apt -y install kmod apt && \
apt -y clean

COPY scripts/ /scripts
COPY --from=build /go/src/github.com/storageos/init/LICENSE /licenses/
COPY --from=build /go/src/github.com/storageos/init/build/_output/bin/init /init
CMD /init -scripts=/scripts
29 changes: 29 additions & 0 deletions Dockerfile.ubuntu2004
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM golang:1.15.0 AS build

WORKDIR /go/src/github.com/storageos/init/
COPY . /go/src/github.com/storageos/init/
RUN make build

FROM ubuntu:20.04
LABEL name="StorageOS Custom Init for Ubuntu Node Image" \
maintainer="[email protected]" \
vendor="StorageOS" \
version="v2.1.0-ubuntu2004" \
release="1" \
distribution-scope="public" \
architecture="x86_64" \
url="https://docs.ondat.io" \
io.k8s.description="The StorageOS custom Init container prepares a node for running StorageOS by installing the required extra kernel module packages." \
io.k8s.display-name="StorageOS Init" \
io.openshift.tags="storageos,storage,operator,pv,pvc,storageclass,persistent,csi" \
summary="Highly-available persistent block storage for containerized applications." \
description="StorageOS transforms commodity server or cloud based disk capacity into enterprise-class storage to run persistent workloads such as databases in containers. Provides high availability, low latency persistent block storage. No other hardware or software is required."

RUN apt -y update && \
apt -y install kmod apt && \
apt -y clean

COPY scripts/ /scripts
COPY --from=build /go/src/github.com/storageos/init/LICENSE /licenses/
COPY --from=build /go/src/github.com/storageos/init/build/_output/bin/init /init
CMD /init -scripts=/scripts
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ tidy:

# Build the docker image
docker-build:
docker build --no-cache . -f Dockerfile -t $(IMAGE)
docker build --no-cache . -f Dockerfile.ubi8 -t $(IMAGE)

# Build the docker image with the extra kernel modules installation for Ubuntu
docker-build-ubuntu:
docker build --no-cache . -f Dockerfile.ubuntu1804 -t storageos/modinstall:ubuntu1804
docker build --no-cache . -f Dockerfile.ubuntu2004 -t storageos/modinstall:ubuntu2004

# Push the docker image
docker-push:
Expand Down
98 changes: 98 additions & 0 deletions daemonset-ubuntu1804.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# ServiceAccount for DaemonSet.
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: modinstall-daemonset-sa
namespace: default
# ClusterRole for init container.
---
a​piVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: init-container
rules:
- apiGroups:
- apps
resources:
- daemonsets
verbs:
- get
- apiGroups:
- ""
resources:
- secrets
verbs:
- create
- get
- list
- delete
# Bind DaemonSet ServiceAccount with init-container ClusterRole.
---
​kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: init-container
subjects:
- kind: ServiceAccount
name: modinstall-daemonset-sa
namespace: default
roleRef:
kind: ClusterRole
name: init-container
apiGroup: rbac.authorization.k8s.io
# call for the custom init container to install extra kernel modules package
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: modinstall-daemonset
labels:
app: modinstall-daemonset
spec:
selector:
matchLabels:
name: modinstall-daemonset
template:
metadata:
labels:
name: modinstall-daemonset
spec:
serviceAccountName: modinstall-daemonset-sa
initContainers:
- name: init-ubuntu
image: storageos/init:ubuntu2004
env:
- name: MOD_INSTALL
value: INSTALL
command: [ 'bash']
args: [ 'scripts/01-lio/enable-lio.sh' ]
volumeMounts:
- name: kernel-modules
mountPath: /lib/modules
mountPropagation: Bidirectional
- name: sys
mountPath: /sys
mountPropagation: Bidirectional
securityContext:
privileged: true
capabilities:
add:
- SYS_ADMIN
containers:
- name: wait
image: storageos/init:ubuntu2004
command: [ 'sleep']
args: [ '5256000' ]
volumes:
- name: kernel-modules
hostPath:
path: /lib/modules
- name: sys
hostPath:
path: /sys
updateStrategy:
type: OnDelete
98 changes: 98 additions & 0 deletions daemonset-ubuntu2004.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# ServiceAccount for DaemonSet.
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: modinstall-daemonset-sa
namespace: default
# ClusterRole for init container.
---
a​piVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: init-container
rules:
- apiGroups:
- apps
resources:
- daemonsets
verbs:
- get
- apiGroups:
- ""
resources:
- secrets
verbs:
- create
- get
- list
- delete
# Bind DaemonSet ServiceAccount with init-container ClusterRole.
---
​kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: init-container
subjects:
- kind: ServiceAccount
name: modinstall-daemonset-sa
namespace: default
roleRef:
kind: ClusterRole
name: init-container
apiGroup: rbac.authorization.k8s.io
# call for the custom init container to install extra kernel modules package
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: modinstall-daemonset
labels:
app: modinstall-daemonset
spec:
selector:
matchLabels:
name: modinstall-daemonset
template:
metadata:
labels:
name: modinstall-daemonset
spec:
serviceAccountName: modinstall-daemonset-sa
initContainers:
- name: init-ubuntu
image: storageos/init:ubuntu1804
env:
- name: MOD_INSTALL
value: INSTALL
command: [ 'bash']
args: [ 'scripts/01-lio/enable-lio.sh' ]
volumeMounts:
- name: kernel-modules
mountPath: /lib/modules
mountPropagation: Bidirectional
- name: sys
mountPath: /sys
mountPropagation: Bidirectional
securityContext:
privileged: true
capabilities:
add:
- SYS_ADMIN
containers:
- name: wait
image: storageos/init:ubuntu1804
command: [ 'sleep']
args: [ '5256000' ]
volumes:
- name: kernel-modules
hostPath:
path: /lib/modules
- name: sys
hostPath:
path: /sys
updateStrategy:
type: OnDelete
6 changes: 6 additions & 0 deletions scripts/01-lio/enable-lio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ function module_error_log() {
echo -e "${RE}ERROR: The kernel module $mod couldn't load properly. Please try to run${NC} modprobe $mod ${RE}. Once loaded, the directory $mod_dir should be accessible. Otherwise the module has not been loaded as expected.${NC}"
}

#install packages for the modinstall daemonset
if [ $MOD_INSTALL ]
then
apt update && apt -y --no-install-recommends install linux-modules-extra-$(uname -r)
fi

# Configfs can be built in the kernel, hence the module
# initstate file will not exist. Even though, the mount
# is present and working
Expand Down