diff --git a/Dockerfile b/Dockerfile.ubi8 similarity index 100% rename from Dockerfile rename to Dockerfile.ubi8 diff --git a/Dockerfile.ubuntu1804 b/Dockerfile.ubuntu1804 new file mode 100644 index 0000000..218d882 --- /dev/null +++ b/Dockerfile.ubuntu1804 @@ -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="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 && \ + 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 diff --git a/Dockerfile.ubuntu2004 b/Dockerfile.ubuntu2004 new file mode 100644 index 0000000..7e8832d --- /dev/null +++ b/Dockerfile.ubuntu2004 @@ -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="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 && \ + 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 diff --git a/Makefile b/Makefile index f7b17a3..865155c 100644 --- a/Makefile +++ b/Makefile @@ -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: 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..33b8d83 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