From 159fd054f66bbe67e3d491aa0c8239efbf4682ce Mon Sep 17 00:00:00 2001 From: Rom Date: Tue, 16 Nov 2021 15:13:02 -0800 Subject: [PATCH 1/5] FEAT: load kernel modules for ubuntu based node image --- Dockerfile.ubuntu1804 | 28 +++++++++++ Dockerfile.ubuntu2004 | 28 +++++++++++ Makefile | 5 ++ daemonset-ubuntu1804.yaml | 98 ++++++++++++++++++++++++++++++++++++ daemonset-ubuntu2004.yaml | 98 ++++++++++++++++++++++++++++++++++++ scripts/01-lio/enable-lio.sh | 6 +++ 6 files changed, 263 insertions(+) create mode 100644 Dockerfile.ubuntu1804 create mode 100644 Dockerfile.ubuntu2004 create mode 100644 daemonset-ubuntu1804.yaml create mode 100644 daemonset-ubuntu2004.yaml diff --git a/Dockerfile.ubuntu1804 b/Dockerfile.ubuntu1804 new file mode 100644 index 0000000..2bb4edf --- /dev/null +++ b/Dockerfile.ubuntu1804 @@ -0,0 +1,28 @@ +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="support@storageos.com" \ + 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 + +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 diff --git a/Dockerfile.ubuntu2004 b/Dockerfile.ubuntu2004 new file mode 100644 index 0000000..2736add --- /dev/null +++ b/Dockerfile.ubuntu2004 @@ -0,0 +1,28 @@ +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="support@storageos.com" \ + 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 + +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 diff --git a/Makefile b/Makefile index f7b17a3..0151363 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,11 @@ tidy: docker-build: docker build --no-cache . -f Dockerfile -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/init:ubuntu1804 + docker build --no-cache . -f Dockerfile.ubuntu2004 -t storageos/init:ubuntu2004 + # Push the docker image docker-push: docker push ${IMAGE} diff --git a/daemonset-ubuntu1804.yaml b/daemonset-ubuntu1804.yaml new file mode 100644 index 0000000..6e967f9 --- /dev/null +++ b/daemonset-ubuntu1804.yaml @@ -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 \ No newline at end of file diff --git a/daemonset-ubuntu2004.yaml b/daemonset-ubuntu2004.yaml new file mode 100644 index 0000000..0a3a068 --- /dev/null +++ b/daemonset-ubuntu2004.yaml @@ -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 \ No newline at end of file diff --git a/scripts/01-lio/enable-lio.sh b/scripts/01-lio/enable-lio.sh index 65e727a..26f9149 100755 --- a/scripts/01-lio/enable-lio.sh +++ b/scripts/01-lio/enable-lio.sh @@ -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 From ee1ca4694f6ceaf981bd44e28f9d7cdeeaaba9b1 Mon Sep 17 00:00:00 2001 From: Rom Date: Tue, 16 Nov 2021 15:22:37 -0800 Subject: [PATCH 2/5] FEAT: load kernel modules for ubuntu based node image --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0151363..d9cc57e 100644 --- a/Makefile +++ b/Makefile @@ -25,8 +25,8 @@ docker-build: # Build the docker image with the extra kernel modules installation for Ubuntu docker-build-ubuntu: - docker build --no-cache . -f Dockerfile.ubuntu1804 -t storageos/init:ubuntu1804 - docker build --no-cache . -f Dockerfile.ubuntu2004 -t storageos/init:ubuntu2004 + 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: From 29866f4c3d6205e96e2958f611dbe7e059109e30 Mon Sep 17 00:00:00 2001 From: Rom Date: Tue, 16 Nov 2021 15:36:53 -0800 Subject: [PATCH 3/5] FEAT: load kernel modules for ubuntu based node image --- Dockerfile.ubuntu1804 | 3 ++- Dockerfile.ubuntu2004 | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile.ubuntu1804 b/Dockerfile.ubuntu1804 index 2bb4edf..218d882 100644 --- a/Dockerfile.ubuntu1804 +++ b/Dockerfile.ubuntu1804 @@ -20,7 +20,8 @@ LABEL name="StorageOS Custom Init for Ubuntu Node Image" \ 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 install kmod apt && \ + apt -y clean COPY scripts/ /scripts COPY --from=build /go/src/github.com/storageos/init/LICENSE /licenses/ diff --git a/Dockerfile.ubuntu2004 b/Dockerfile.ubuntu2004 index 2736add..7e8832d 100644 --- a/Dockerfile.ubuntu2004 +++ b/Dockerfile.ubuntu2004 @@ -20,7 +20,8 @@ LABEL name="StorageOS Custom Init for Ubuntu Node Image" \ 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 install kmod apt && \ + apt -y clean COPY scripts/ /scripts COPY --from=build /go/src/github.com/storageos/init/LICENSE /licenses/ From 3b57e99244a6fe97c207e973e832d6e4b19f7c55 Mon Sep 17 00:00:00 2001 From: Rom Date: Tue, 16 Nov 2021 15:52:15 -0800 Subject: [PATCH 4/5] FEAT: load kernel modules for ubuntu based node image --- Dockerfile => Dockerfile.ubi8 | 0 Makefile | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename Dockerfile => Dockerfile.ubi8 (100%) diff --git a/Dockerfile b/Dockerfile.ubi8 similarity index 100% rename from Dockerfile rename to Dockerfile.ubi8 diff --git a/Makefile b/Makefile index d9cc57e..865155c 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ 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: From 70f9d796fcc64810d3ab64628c13458fbb6cbb1e Mon Sep 17 00:00:00 2001 From: Rom Date: Wed, 17 Nov 2021 09:24:54 -0800 Subject: [PATCH 5/5] fix typo in enable-lio.sh --- scripts/01-lio/enable-lio.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/01-lio/enable-lio.sh b/scripts/01-lio/enable-lio.sh index 26f9149..33b8d83 100755 --- a/scripts/01-lio/enable-lio.sh +++ b/scripts/01-lio/enable-lio.sh @@ -10,7 +10,7 @@ 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 +#install packages for the modinstall daemonset if [ $MOD_INSTALL ] then apt update && apt -y --no-install-recommends install linux-modules-extra-$(uname -r)