From 84afed1819d6edc1dd3fbcc4d9f371531b493a61 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Sat, 1 Oct 2022 13:11:55 +0200 Subject: [PATCH 01/90] Initial commit --- LICENSE | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 + 2 files changed, 203 insertions(+) create mode 100644 LICENSE create mode 100644 README.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..be1dbe0 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# kwasm-node-installer +Installs KWasm on Kubernetes nodes. From eea85844f02f98f2995e61dcba88584b56222bbf Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Sat, 1 Oct 2022 12:57:01 +0200 Subject: [PATCH 02/90] PoC with KinD Signed-off-by: Sven Pfennig --- .dockerignore | 2 ++ .github/workflows/docker-build.yaml | 50 +++++++++++++++++++++++++++++ README.md | 20 ++++++++++++ example/daemonset.yaml | 41 +++++++++++++++++++++++ example/test-job.yaml | 19 +++++++++++ images/installer/Dockerfile | 18 +++++++++++ script/installer.sh | 19 +++++++++++ 7 files changed, 169 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker-build.yaml create mode 100644 example/daemonset.yaml create mode 100644 example/test-job.yaml create mode 100644 images/installer/Dockerfile create mode 100755 script/installer.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d7a1655 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +example +images \ No newline at end of file diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml new file mode 100644 index 0000000..b6cbd4c --- /dev/null +++ b/.github/workflows/docker-build.yaml @@ -0,0 +1,50 @@ +name: Docker Image CI + +on: + push: + branches: [ main ] + tags: [ '*' ] + pull_request: + branches: [ main ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + buildx: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - + name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + - + name: Log in to the Container registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - + name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + file: images/installer/Dockerfile + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/README.md b/README.md index be1dbe0..aa5ccdd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,22 @@ # kwasm-node-installer Installs KWasm on Kubernetes nodes. + +## How to build +```bash +docker build . -f images/installer/Dockerfile -t kwasm/kwasm-installer +``` + +## Quickstart +```bash +kind create cluster + +kubectl apply -f https://raw.githubusercontent.com/KWasm/kwasm-node-installer/main/example/daemonset.yaml + +echo 'apiVersion: node.k8s.io/v1 +kind: RuntimeClass +metadata: + name: crun +handler: crun' |kubectl apply -f - + +kubectl apply -f https://raw.githubusercontent.com/KWasm/kwasm-node-installer/main/example/test-job.yaml +``` diff --git a/example/daemonset.yaml b/example/daemonset.yaml new file mode 100644 index 0000000..5ef261e --- /dev/null +++ b/example/daemonset.yaml @@ -0,0 +1,41 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: kwasm-initializer + labels: + app: default-init +spec: + selector: + matchLabels: + app: default-init + updateStrategy: + type: RollingUpdate + template: + metadata: + labels: + name: kwasm-initializer + app: default-init + spec: + hostPID: true + volumes: + - name: node-root + hostPath: + path: / + - name: entrypoint + configMap: + name: entrypoint + defaultMode: 0744 + initContainers: + - image: ghcr.io/kwasm/kwasm-node-installer:main + name: kwasm-initializer + env: + - name: NODE_ROOT + value: /mnt/node-root/ + securityContext: + privileged: true + volumeMounts: + - name: node-root + mountPath: /mnt/node-root/ + containers: + - image: k8s.gcr.io/pause:3.1 + name: pause diff --git a/example/test-job.yaml b/example/test-job.yaml new file mode 100644 index 0000000..c8c8b8a --- /dev/null +++ b/example/test-job.yaml @@ -0,0 +1,19 @@ +apiVersion: batch/v1 +kind: Job +metadata: + creationTimestamp: null + name: wasm-test +spec: + template: + metadata: + annotations: + module.wasm.image/variant: compat-smart + creationTimestamp: null + spec: + containers: + - image: wasmedge/example-wasi:latest + name: wasm-test + resources: {} + restartPolicy: Never + runtimeClassName: crun + backoffLimit: 1 diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile new file mode 100644 index 0000000..9de7e69 --- /dev/null +++ b/images/installer/Dockerfile @@ -0,0 +1,18 @@ +FROM ubuntu:22.04 as builder-wasmedge + +RUN DEBIAN_FRONTEND=noninteractive apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt install -y curl make git gcc build-essential pkgconf libtool libsystemd-dev libprotobuf-c-dev libcap-dev libseccomp-dev libyajl-dev go-md2man libtool autoconf python3 automake \ + && curl https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -p /usr/local --version=0.11.0 \ + && git clone --depth 1 --branch 1.6 https://github.com/containers/crun.git \ + && cd crun \ + && ./autogen.sh \ + && ./configure --with-wasmedge --enable-embedded-yajl\ + && make + +FROM busybox + +COPY --from=builder-wasmedge /crun/crun /assets/crun +COPY --from=builder-wasmedge /usr/local/lib/libwasmedge.so /assets/libwasmedge.so +COPY script/installer.sh /script/installer.sh + +CMD sh /script/installer.sh \ No newline at end of file diff --git a/script/installer.sh b/script/installer.sh new file mode 100755 index 0000000..f56f3e6 --- /dev/null +++ b/script/installer.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env sh +set -euo pipefail + +cp /assets/crun $NODE_ROOT/usr/local/bin/crun +cp /assets/libwasmedge.so $NODE_ROOT/usr/local/lib/libwasmedge.so +ln -s /usr/local/lib/libwasmedge.so $NODE_ROOT/usr/local/lib/libwasmedge.so.0 && \ +ln -s /usr/local/lib/libwasmedge.so $NODE_ROOT/usr/local/lib/libwasmedge.so.0.0.0 + +if ! grep -q crun $NODE_ROOT/etc/containerd/config.toml; then + echo '[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun] + runtime_type = "io.containerd.runc.v2" + pod_annotations = ["module.wasm.image/variant", "run.oci.handler"] +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun.options] + BinaryName = "crun"' >> $NODE_ROOT/etc/containerd/config.toml +fi + +nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- ldconfig +nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- /bin/systemctl restart containerd +sleep 10 \ No newline at end of file From 2ce757d963037dbab6ef0577275e4e39c6a30049 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Sat, 1 Oct 2022 22:07:50 +0200 Subject: [PATCH 03/90] add installer for crun with wasmtime Signed-off-by: Sven Pfennig --- .github/workflows/docker-build.yaml | 31 ++++++++++++++++++++++++- example/daemonset.yaml | 2 +- images/installer/Dockerfile | 36 ++++++++++++++++++++++++----- script/installer.sh | 18 +++++++++++---- 4 files changed, 75 insertions(+), 12 deletions(-) diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index b6cbd4c..66f0cf5 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -25,6 +25,14 @@ jobs: name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v1 + - + name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- - name: Log in to the Container registry uses: docker/login-action@v1 @@ -38,6 +46,17 @@ jobs: uses: docker/metadata-action@v3 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - + name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: ghcr.io/kwasm/kwasm-node-installer:crun-wasmtime + target: crun-wasmtime + file: images/installer/Dockerfile + labels: ${{ steps.meta.outputs.labels }} - name: Build and push Docker image uses: docker/build-push-action@v2 @@ -47,4 +66,14 @@ jobs: platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }} file: images/installer/Dockerfile - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file + labels: ${{ steps.meta.outputs.labels }} +# - + # This ugly bit is necessary if you don't want your cache to grow forever + # until it hits GitHub's limit of 5GB. + # Temp fix + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 +# name: Move cache +# run: | +# rm -rf /tmp/.buildx-cache +# mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/example/daemonset.yaml b/example/daemonset.yaml index 5ef261e..b5124a5 100644 --- a/example/daemonset.yaml +++ b/example/daemonset.yaml @@ -26,7 +26,7 @@ spec: name: entrypoint defaultMode: 0744 initContainers: - - image: ghcr.io/kwasm/kwasm-node-installer:main + - image: ghcr.io/kwasm/kwasm-node-installer:crun-wasmedge name: kwasm-initializer env: - name: NODE_ROOT diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 9de7e69..6ee7710 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -1,18 +1,42 @@ -FROM ubuntu:22.04 as builder-wasmedge +FROM ubuntu:22.04 as builder-crun RUN DEBIAN_FRONTEND=noninteractive apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt install -y curl make git gcc build-essential pkgconf libtool libsystemd-dev libprotobuf-c-dev libcap-dev libseccomp-dev libyajl-dev go-md2man libtool autoconf python3 automake \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y curl make git gcc build-essential pkgconf libtool libsystemd-dev libprotobuf-c-dev libcap-dev libseccomp-dev libyajl-dev go-md2man libtool autoconf python3 automake xz-utils \ && curl https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -p /usr/local --version=0.11.0 \ && git clone --depth 1 --branch 1.6 https://github.com/containers/crun.git \ && cd crun \ && ./autogen.sh \ && ./configure --with-wasmedge --enable-embedded-yajl\ - && make + && make \ + && mv crun crun-wasmedge +RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v1.0.1/wasmtime-v1.0.1-$(uname -m)-linux-c-api.tar.xz | tar xJf - -C / \ + && cp -R /wasmtime-v1.0.1-$(uname -m)-linux-c-api/* /usr/local/ \ + && cd /crun \ + && ./configure --with-wasmtime --enable-embedded-yajl \ + && make \ + && mv crun crun-wasmtime + +FROM busybox as crun-wasmtime + +COPY --from=builder-crun /crun/crun-wasmtime /assets/crun-wasmtime +COPY --from=builder-crun /usr/local/lib/libwasmtime.so /assets/libwasmtime.so +COPY script/installer.sh /script/installer.sh + +CMD sh /script/installer.sh wasmtime + +FROM busybox as crun-wasmedge + +COPY --from=builder-crun /crun/crun-wasmedge /assets/crun-wasmedge +COPY --from=builder-crun /usr/local/lib/libwasmedge.so /assets/libwasmedge.so +COPY script/installer.sh /script/installer.sh + +CMD sh /script/installer.sh wasmedge FROM busybox -COPY --from=builder-wasmedge /crun/crun /assets/crun -COPY --from=builder-wasmedge /usr/local/lib/libwasmedge.so /assets/libwasmedge.so +COPY --from=builder-crun /crun/crun-* /assets/ +COPY --from=builder-crun /usr/local/lib/libwasmedge.so /assets/libwasmedge.so +COPY --from=builder-crun /usr/local/lib/libwasmtime.so /assets/libwasmtime.so COPY script/installer.sh /script/installer.sh -CMD sh /script/installer.sh \ No newline at end of file +CMD sh /script/installer.sh wasmedge \ No newline at end of file diff --git a/script/installer.sh b/script/installer.sh index f56f3e6..35fc407 100755 --- a/script/installer.sh +++ b/script/installer.sh @@ -1,10 +1,20 @@ #!/usr/bin/env sh set -euo pipefail -cp /assets/crun $NODE_ROOT/usr/local/bin/crun -cp /assets/libwasmedge.so $NODE_ROOT/usr/local/lib/libwasmedge.so -ln -s /usr/local/lib/libwasmedge.so $NODE_ROOT/usr/local/lib/libwasmedge.so.0 && \ -ln -s /usr/local/lib/libwasmedge.so $NODE_ROOT/usr/local/lib/libwasmedge.so.0.0.0 +case $1 in + wasmtime) + cp /assets/crun-wasmtime $NODE_ROOT/usr/local/bin/crun + cp /assets/libwasmtime.so $NODE_ROOT/usr/local/lib/libwasmtime.so + ;; + *) + #wasmedge) + cp /assets/crun-wasmedge $NODE_ROOT/usr/local/bin/crun + cp /assets/libwasmedge.so $NODE_ROOT/usr/local/lib/libwasmedge.so + ln -s /usr/local/lib/libwasmedge.so $NODE_ROOT/usr/local/lib/libwasmedge.so.0 && \ + ln -s /usr/local/lib/libwasmedge.so $NODE_ROOT/usr/local/lib/libwasmedge.so.0.0.0 + ;; + +esac if ! grep -q crun $NODE_ROOT/etc/containerd/config.toml; then echo '[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun] From 029403b120ae4a592903ee520a3767e401da6f18 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Sun, 2 Oct 2022 07:22:21 +0200 Subject: [PATCH 04/90] enable docker layer caching Signed-off-by: Sven Pfennig --- .github/workflows/docker-build.yaml | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index 66f0cf5..3fe8132 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -25,14 +25,6 @@ jobs: name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v1 - - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - name: Log in to the Container registry uses: docker/login-action@v1 @@ -57,6 +49,8 @@ jobs: target: crun-wasmtime file: images/installer/Dockerfile labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max - name: Build and push Docker image uses: docker/build-push-action@v2 @@ -67,13 +61,5 @@ jobs: tags: ${{ steps.meta.outputs.tags }} file: images/installer/Dockerfile labels: ${{ steps.meta.outputs.labels }} -# - - # This ugly bit is necessary if you don't want your cache to grow forever - # until it hits GitHub's limit of 5GB. - # Temp fix - # https://github.com/docker/build-push-action/issues/252 - # https://github.com/moby/buildkit/issues/1896 -# name: Move cache -# run: | -# rm -rf /tmp/.buildx-cache -# mv /tmp/.buildx-cache-new /tmp/.buildx-cache + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file From 4fbe76d632b658367afa96736a9a314ea92d106b Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Wed, 12 Oct 2022 23:27:39 +0200 Subject: [PATCH 05/90] add minikube support Signed-off-by: Sven Pfennig --- example/daemonset.yaml | 2 +- images/installer/Dockerfile | 2 +- script/installer.sh | 28 ++++++++++++++++++---------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/example/daemonset.yaml b/example/daemonset.yaml index b5124a5..bbf2a6d 100644 --- a/example/daemonset.yaml +++ b/example/daemonset.yaml @@ -30,7 +30,7 @@ spec: name: kwasm-initializer env: - name: NODE_ROOT - value: /mnt/node-root/ + value: /mnt/node-root securityContext: privileged: true volumeMounts: diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 6ee7710..33de889 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:22.04 as builder-crun +FROM ubuntu:20.04 as builder-crun RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y curl make git gcc build-essential pkgconf libtool libsystemd-dev libprotobuf-c-dev libcap-dev libseccomp-dev libyajl-dev go-md2man libtool autoconf python3 automake xz-utils \ diff --git a/script/installer.sh b/script/installer.sh index 35fc407..9502e50 100755 --- a/script/installer.sh +++ b/script/installer.sh @@ -1,17 +1,21 @@ #!/usr/bin/env sh set -euo pipefail +mkdir -p $NODE_ROOT/opt/kwasm/bin/ +mkdir -p $NODE_ROOT/opt/kwasm/lib/ case $1 in wasmtime) - cp /assets/crun-wasmtime $NODE_ROOT/usr/local/bin/crun - cp /assets/libwasmtime.so $NODE_ROOT/usr/local/lib/libwasmtime.so + cp /assets/crun-wasmtime $NODE_ROOT/opt/kwasm/bin/crun && \ + cp /assets/libwasmtime.so $NODE_ROOT/opt/kwasm/lib/libwasmtime.so && \ + ln -sf /opt/kwasm/lib/libwasmtime.so $NODE_ROOT/lib/libwasmtime.so ;; *) #wasmedge) - cp /assets/crun-wasmedge $NODE_ROOT/usr/local/bin/crun - cp /assets/libwasmedge.so $NODE_ROOT/usr/local/lib/libwasmedge.so - ln -s /usr/local/lib/libwasmedge.so $NODE_ROOT/usr/local/lib/libwasmedge.so.0 && \ - ln -s /usr/local/lib/libwasmedge.so $NODE_ROOT/usr/local/lib/libwasmedge.so.0.0.0 + cp /assets/crun-wasmedge $NODE_ROOT/opt/kwasm/bin/crun && \ + cp /assets/libwasmedge.so $NODE_ROOT/opt/kwasm/lib/libwasmedge.so && \ + ln -sf /opt/kwasm/lib/libwasmedge.so $NODE_ROOT/lib/libwasmedge.so && \ + ln -sf /opt/kwasm/lib/libwasmedge.so $NODE_ROOT/lib/libwasmedge.so.0 && \ + ln -sf /opt/kwasm/lib/libwasmedge.so $NODE_ROOT/lib/libwasmedge.so.0.0.0 ;; esac @@ -21,9 +25,13 @@ if ! grep -q crun $NODE_ROOT/etc/containerd/config.toml; then runtime_type = "io.containerd.runc.v2" pod_annotations = ["module.wasm.image/variant", "run.oci.handler"] [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun.options] - BinaryName = "crun"' >> $NODE_ROOT/etc/containerd/config.toml + BinaryName = "/opt/kwasm/bin/crun"' >> $NODE_ROOT/etc/containerd/config.toml + rm -Rf $NODE_ROOT/opt/kwasm/active fi -nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- ldconfig -nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- /bin/systemctl restart containerd -sleep 10 \ No newline at end of file +if [ ! -f $NODE_ROOT/opt/kwasm/active ]; then + nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- /bin/systemctl restart containerd + touch $NODE_ROOT/opt/kwasm/active +else + echo "No change in containerd/config.toml" +fi From 62ef61c57d32b32e046c7017117d4fec2163392d Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Fri, 14 Oct 2022 20:33:38 +0200 Subject: [PATCH 06/90] change build image to ubuntu 18.04 Signed-off-by: Sven Pfennig --- images/installer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 33de889..6fde11d 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:20.04 as builder-crun +FROM ubuntu:18.04 as builder-crun RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y curl make git gcc build-essential pkgconf libtool libsystemd-dev libprotobuf-c-dev libcap-dev libseccomp-dev libyajl-dev go-md2man libtool autoconf python3 automake xz-utils \ From 24d56dcdb2bf19c68c70d1c55bc941fabe41fb39 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Mon, 17 Oct 2022 17:15:10 +0200 Subject: [PATCH 07/90] add microk8s support Signed-off-by: Sven Pfennig --- script/installer.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/script/installer.sh b/script/installer.sh index 9502e50..f41a895 100755 --- a/script/installer.sh +++ b/script/installer.sh @@ -20,17 +20,28 @@ case $1 in esac -if ! grep -q crun $NODE_ROOT/etc/containerd/config.toml; then +CONTAINERD_CONF=/etc/containerd/config.toml +IS_MICROK8S=false +if ps aux | grep kubelet | grep -q snap/microk8s; then + CONTAINERD_CONF=/var/snap/microk8s/current/args/containerd-template.toml + IS_MICROK8S=true +fi + +if ! grep -q crun $NODE_ROOT$CONTAINERD_CONF; then echo '[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun] runtime_type = "io.containerd.runc.v2" pod_annotations = ["module.wasm.image/variant", "run.oci.handler"] [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun.options] - BinaryName = "/opt/kwasm/bin/crun"' >> $NODE_ROOT/etc/containerd/config.toml + BinaryName = "/opt/kwasm/bin/crun"' >> $NODE_ROOT$CONTAINERD_CONF rm -Rf $NODE_ROOT/opt/kwasm/active fi if [ ! -f $NODE_ROOT/opt/kwasm/active ]; then - nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- /bin/systemctl restart containerd + if $IS_MICROK8S; then + nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- systemctl restart snap.microk8s.daemon-containerd + else + nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- /bin/systemctl restart containerd + fi touch $NODE_ROOT/opt/kwasm/active else echo "No change in containerd/config.toml" From cecaae82acb91728e22f1584190e82ab038f4ec2 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Mon, 17 Oct 2022 19:44:07 +0200 Subject: [PATCH 08/90] update readme and manifests Signed-off-by: Sven Pfennig --- README.md | 44 +++++++++++++++++++++++++++++---------- example/daemonset.yaml | 2 +- example/debug.yaml | 42 +++++++++++++++++++++++++++++++++++++ example/runtimeclass.yaml | 5 +++++ example/test-job.yaml | 6 ++++++ 5 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 example/debug.yaml create mode 100644 example/runtimeclass.yaml diff --git a/README.md b/README.md index aa5ccdd..897efed 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,44 @@ -# kwasm-node-installer -Installs KWasm on Kubernetes nodes. +# KWasm-node-installer -## How to build -```bash -docker build . -f images/installer/Dockerfile -t kwasm/kwasm-installer -``` +The KWasm Node Installer is a container image that contains binaries and configuration to enable a Kubernetes node to run pure webassembly images. + +> WARNING: Not meant to be used in production! + +Since this installer changes the configuration of the node it can make a node unusable. We recommend using a fresh KinD/MiniKube/MicroK8s or a managed cloud service like AKS/GKE/EKS. + +## Supported Kubernetes distributions +- KinD +- MiniKube +- MicroK8s +- Azure AKS +- GCP GKE (Ubuntu Nodes) +- AWS EKS (Ubuntu Nodes) +- Digital Ocean Kubernetes + +## Currently not supported Kubernetes distributions +- K3d +- AWS EKS +- OCI OKE ## Quickstart +### KinD +Prerequisites: +- Docker +- KinD +- kubectl + ```bash kind create cluster +# As default crun-wasmedge is used for installation. kubectl apply -f https://raw.githubusercontent.com/KWasm/kwasm-node-installer/main/example/daemonset.yaml -echo 'apiVersion: node.k8s.io/v1 -kind: RuntimeClass -metadata: - name: crun -handler: crun' |kubectl apply -f - kubectl apply -f https://raw.githubusercontent.com/KWasm/kwasm-node-installer/main/example/test-job.yaml ``` + +## How to build +The dockerfile `images/installer/Dockerfile` has multiple stages by building it you create an image that contains a crun version built with WasmEdge support and one with WasmTime. If you only need one of them you can use a different stage with the target parameter `--target crun-wasmedge` or `--target crun-wasmtime`. +```bash +docker build . -f images/installer/Dockerfile -t kwasm/kwasm-installer +``` diff --git a/example/daemonset.yaml b/example/daemonset.yaml index bbf2a6d..e762e67 100644 --- a/example/daemonset.yaml +++ b/example/daemonset.yaml @@ -26,7 +26,7 @@ spec: name: entrypoint defaultMode: 0744 initContainers: - - image: ghcr.io/kwasm/kwasm-node-installer:crun-wasmedge + - image: ghcr.io/kwasm/kwasm-node-installer:main name: kwasm-initializer env: - name: NODE_ROOT diff --git a/example/debug.yaml b/example/debug.yaml new file mode 100644 index 0000000..59f0656 --- /dev/null +++ b/example/debug.yaml @@ -0,0 +1,42 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: kwasm-debug + labels: + app: default +spec: + selector: + matchLabels: + app: default + updateStrategy: + type: RollingUpdate + template: + metadata: + labels: + name: kwasm-debug + app: default + spec: + hostPID: true + volumes: + - name: node-root + hostPath: + path: / + - name: entrypoint + configMap: + name: entrypoint + defaultMode: 0744 + containers: + - image: ubuntu + name: kwasm-debug + command: + - sh + - -c + - "tail -f /dev/null" + env: + - name: NODE_ROOT + value: /mnt/node-root + securityContext: + privileged: true + volumeMounts: + - name: node-root + mountPath: /mnt/node-root/ diff --git a/example/runtimeclass.yaml b/example/runtimeclass.yaml new file mode 100644 index 0000000..f83293e --- /dev/null +++ b/example/runtimeclass.yaml @@ -0,0 +1,5 @@ +apiVersion: node.k8s.io/v1 +kind: RuntimeClass +metadata: + name: crun +handler: crun diff --git a/example/test-job.yaml b/example/test-job.yaml index c8c8b8a..4002968 100644 --- a/example/test-job.yaml +++ b/example/test-job.yaml @@ -1,3 +1,9 @@ +apiVersion: node.k8s.io/v1 +kind: RuntimeClass +metadata: + name: crun +handler: crun +--- apiVersion: batch/v1 kind: Job metadata: From a035aaa519bda6f56e302f8a9b95cf7795fb1c27 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Mon, 24 Oct 2022 20:02:50 +0200 Subject: [PATCH 09/90] add containerd-shim-spin Signed-off-by: Sven Pfennig --- example/install-job.yaml | 34 ++++++++++++++++++++++++++++++++++ images/installer/Dockerfile | 3 +++ script/installer.sh | 10 ++++++++-- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 example/install-job.yaml diff --git a/example/install-job.yaml b/example/install-job.yaml new file mode 100644 index 0000000..0b81f87 --- /dev/null +++ b/example/install-job.yaml @@ -0,0 +1,34 @@ +apiVersion: batch/v1 +kind: Job +metadata: + creationTimestamp: null + name: default-init +spec: + template: + metadata: + labels: + name: kwasm-initializer + app: default-init + spec: + restartPolicy: Never + hostPID: true + volumes: + - name: node-root + hostPath: + path: / + - name: entrypoint + configMap: + name: entrypoint + defaultMode: 0744 + containers: + - image: docker.io/0xe282b0/kwasm-installer:0.1.0 + name: kwasm-initializer + env: + - name: NODE_ROOT + value: /mnt/node-root + securityContext: + privileged: true + volumeMounts: + - name: node-root + mountPath: /mnt/node-root/ + backoffLimit: 1 diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 6fde11d..b17121c 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -15,6 +15,7 @@ RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v1.0. && ./configure --with-wasmtime --enable-embedded-yajl \ && make \ && mv crun crun-wasmtime +RUN curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.3.3/containerd-wasm-shims-v1-linux-$(uname -m|sed s/amd64/aarch64/g).tar.gz | tar -xzf - FROM busybox as crun-wasmtime @@ -37,6 +38,8 @@ FROM busybox COPY --from=builder-crun /crun/crun-* /assets/ COPY --from=builder-crun /usr/local/lib/libwasmedge.so /assets/libwasmedge.so COPY --from=builder-crun /usr/local/lib/libwasmtime.so /assets/libwasmtime.so +COPY --from=builder-crun /containerd-shim-slight-v1 /assets/containerd-shim-slight-v1 +COPY --from=builder-crun /containerd-shim-spin-v1 /assets/containerd-shim-spin-v1 COPY script/installer.sh /script/installer.sh CMD sh /script/installer.sh wasmedge \ No newline at end of file diff --git a/script/installer.sh b/script/installer.sh index f41a895..426a114 100755 --- a/script/installer.sh +++ b/script/installer.sh @@ -17,9 +17,11 @@ case $1 in ln -sf /opt/kwasm/lib/libwasmedge.so $NODE_ROOT/lib/libwasmedge.so.0 && \ ln -sf /opt/kwasm/lib/libwasmedge.so $NODE_ROOT/lib/libwasmedge.so.0.0.0 ;; - esac +cp /assets/containerd-shim-spin-v1 $NODE_ROOT/opt/kwasm/bin/containerd-shim-spin-v1 +ln -s /opt/kwasm/bin/containerd-shim-spin-v1 $NODE_ROOT/bin/ + CONTAINERD_CONF=/etc/containerd/config.toml IS_MICROK8S=false if ps aux | grep kubelet | grep -q snap/microk8s; then @@ -32,7 +34,11 @@ if ! grep -q crun $NODE_ROOT$CONTAINERD_CONF; then runtime_type = "io.containerd.runc.v2" pod_annotations = ["module.wasm.image/variant", "run.oci.handler"] [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun.options] - BinaryName = "/opt/kwasm/bin/crun"' >> $NODE_ROOT$CONTAINERD_CONF + BinaryName = "/opt/kwasm/bin/crun" +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.spin] + runtime_type = "io.containerd.spin.v1" +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.spin.options] + BinaryName = "/opt/kwasm/bin/containerd-shim-spin-v1"' >> $NODE_ROOT$CONTAINERD_CONF rm -Rf $NODE_ROOT/opt/kwasm/active fi From f8899ebde12b9cb06220b3256ec47ccdf033483e Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Sun, 30 Oct 2022 21:10:52 +0100 Subject: [PATCH 10/90] add containerd-shim-wasmedge Signed-off-by: Sven Pfennig --- images/installer/Dockerfile | 13 ++++++++++--- script/installer.sh | 6 ++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index b17121c..0289f2a 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -15,7 +15,13 @@ RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v1.0. && ./configure --with-wasmtime --enable-embedded-yajl \ && make \ && mv crun crun-wasmtime -RUN curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.3.3/containerd-wasm-shims-v1-linux-$(uname -m|sed s/amd64/aarch64/g).tar.gz | tar -xzf - + +FROM ubuntu:18.04 as builder-containerd-shim + +RUN DEBIAN_FRONTEND=noninteractive apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y curl +RUN curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.3.3/containerd-wasm-shims-v1-linux-$(uname -m).tar.gz | tar -xzf - && \ + curl -L https://github.com/second-state/runwasi/releases/download/v0.3.2/containerd-shim-wasmedge-v1-v0.3.2-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - FROM busybox as crun-wasmtime @@ -38,8 +44,9 @@ FROM busybox COPY --from=builder-crun /crun/crun-* /assets/ COPY --from=builder-crun /usr/local/lib/libwasmedge.so /assets/libwasmedge.so COPY --from=builder-crun /usr/local/lib/libwasmtime.so /assets/libwasmtime.so -COPY --from=builder-crun /containerd-shim-slight-v1 /assets/containerd-shim-slight-v1 -COPY --from=builder-crun /containerd-shim-spin-v1 /assets/containerd-shim-spin-v1 +COPY --from=builder-containerd-shim /containerd-shim-slight-v1 /assets/containerd-shim-slight-v1 +COPY --from=builder-containerd-shim /containerd-shim-spin-v1 /assets/containerd-shim-spin-v1 +COPY --from=builder-containerd-shim /containerd-shim-wasmedge-v1 /assets/containerd-shim-wasmedge-v1 COPY script/installer.sh /script/installer.sh CMD sh /script/installer.sh wasmedge \ No newline at end of file diff --git a/script/installer.sh b/script/installer.sh index 426a114..2be0e19 100755 --- a/script/installer.sh +++ b/script/installer.sh @@ -21,6 +21,8 @@ esac cp /assets/containerd-shim-spin-v1 $NODE_ROOT/opt/kwasm/bin/containerd-shim-spin-v1 ln -s /opt/kwasm/bin/containerd-shim-spin-v1 $NODE_ROOT/bin/ +cp /assets/containerd-shim-wasmedge-v1 $NODE_ROOT/opt/kwasm/bin/containerd-shim-wasmedge-v1 +ln -s /opt/kwasm/bin/containerd-shim-wasmedge-v1 $NODE_ROOT/bin/ CONTAINERD_CONF=/etc/containerd/config.toml IS_MICROK8S=false @@ -37,8 +39,8 @@ if ! grep -q crun $NODE_ROOT$CONTAINERD_CONF; then BinaryName = "/opt/kwasm/bin/crun" [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.spin] runtime_type = "io.containerd.spin.v1" -[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.spin.options] - BinaryName = "/opt/kwasm/bin/containerd-shim-spin-v1"' >> $NODE_ROOT$CONTAINERD_CONF +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasmedge] + runtime_type = "io.containerd.wasmedge.v1"' >> $NODE_ROOT$CONTAINERD_CONF rm -Rf $NODE_ROOT/opt/kwasm/active fi From aa5dbc2c4c480149369bd85823fc02f6807c93f9 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Mon, 21 Nov 2022 19:42:26 +0100 Subject: [PATCH 11/90] adapt to microk8s strict mode Signed-off-by: Sven Pfennig --- script/installer.sh | 58 ++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/script/installer.sh b/script/installer.sh index 2be0e19..f2b494c 100755 --- a/script/installer.sh +++ b/script/installer.sh @@ -1,34 +1,44 @@ #!/usr/bin/env sh set -euo pipefail -mkdir -p $NODE_ROOT/opt/kwasm/bin/ -mkdir -p $NODE_ROOT/opt/kwasm/lib/ +KWASM_DIR=/opt/kwasm + +CONTAINERD_CONF=/etc/containerd/config.toml +IS_MICROK8S=false +if ps aux | grep kubelet | grep -q snap/microk8s; then + CONTAINERD_CONF=/var/snap/microk8s/current/args/containerd-template.toml + IS_MICROK8S=true + if nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- ls /var/snap/microk8s/current/args/containerd-template.toml > /dev/null 2>&1 ;then + KWASM_DIR=/var/snap/microk8s/common/kwasm + else + echo "Installer seems to run on microk8s but 'containerd-template.toml' not found." + exit 1 + fi +fi + +mkdir -p $NODE_ROOT$KWASM_DIR/bin/ +mkdir -p $NODE_ROOT$KWASM_DIR/lib/ case $1 in wasmtime) - cp /assets/crun-wasmtime $NODE_ROOT/opt/kwasm/bin/crun && \ - cp /assets/libwasmtime.so $NODE_ROOT/opt/kwasm/lib/libwasmtime.so && \ - ln -sf /opt/kwasm/lib/libwasmtime.so $NODE_ROOT/lib/libwasmtime.so + cp /assets/crun-wasmtime $NODE_ROOT$KWASM_DIR/bin/crun && \ + cp /assets/libwasmtime.so $NODE_ROOT$KWASM_DIR/lib/libwasmtime.so && \ + ln -sf $KWASM_DIR/lib/libwasmtime.so $NODE_ROOT/lib/libwasmtime.so ;; *) #wasmedge) - cp /assets/crun-wasmedge $NODE_ROOT/opt/kwasm/bin/crun && \ - cp /assets/libwasmedge.so $NODE_ROOT/opt/kwasm/lib/libwasmedge.so && \ - ln -sf /opt/kwasm/lib/libwasmedge.so $NODE_ROOT/lib/libwasmedge.so && \ - ln -sf /opt/kwasm/lib/libwasmedge.so $NODE_ROOT/lib/libwasmedge.so.0 && \ - ln -sf /opt/kwasm/lib/libwasmedge.so $NODE_ROOT/lib/libwasmedge.so.0.0.0 + cp /assets/crun-wasmedge $NODE_ROOT$KWASM_DIR/bin/crun && \ + cp /assets/libwasmedge.so $NODE_ROOT$KWASM_DIR/lib/libwasmedge.so && \ + ln -sf $KWASM_DIR/lib/libwasmedge.so $NODE_ROOT/lib/libwasmedge.so && \ + ln -sf $KWASM_DIR/lib/libwasmedge.so $NODE_ROOT/lib/libwasmedge.so.0 && \ + ln -sf $KWASM_DIR/lib/libwasmedge.so $NODE_ROOT/lib/libwasmedge.so.0.0.0 ;; esac -cp /assets/containerd-shim-spin-v1 $NODE_ROOT/opt/kwasm/bin/containerd-shim-spin-v1 -ln -s /opt/kwasm/bin/containerd-shim-spin-v1 $NODE_ROOT/bin/ -cp /assets/containerd-shim-wasmedge-v1 $NODE_ROOT/opt/kwasm/bin/containerd-shim-wasmedge-v1 -ln -s /opt/kwasm/bin/containerd-shim-wasmedge-v1 $NODE_ROOT/bin/ - -CONTAINERD_CONF=/etc/containerd/config.toml -IS_MICROK8S=false -if ps aux | grep kubelet | grep -q snap/microk8s; then - CONTAINERD_CONF=/var/snap/microk8s/current/args/containerd-template.toml - IS_MICROK8S=true +cp /assets/containerd-shim-spin-v1 $NODE_ROOT$KWASM_DIR/bin/containerd-shim-spin-v1 +cp /assets/containerd-shim-wasmedge-v1 $NODE_ROOT$KWASM_DIR/bin/containerd-shim-wasmedge-v1 +if ! $IS_MICROK8S; then + ln -sf $KWASM_DIR/bin/containerd-shim-spin-v1 $NODE_ROOT/bin/ + ln -sf $KWASM_DIR/bin/containerd-shim-wasmedge-v1 $NODE_ROOT/bin/ fi if ! grep -q crun $NODE_ROOT$CONTAINERD_CONF; then @@ -36,21 +46,21 @@ if ! grep -q crun $NODE_ROOT$CONTAINERD_CONF; then runtime_type = "io.containerd.runc.v2" pod_annotations = ["module.wasm.image/variant", "run.oci.handler"] [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun.options] - BinaryName = "/opt/kwasm/bin/crun" + BinaryName = "'$KWASM_DIR/bin/crun'" [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.spin] runtime_type = "io.containerd.spin.v1" [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasmedge] runtime_type = "io.containerd.wasmedge.v1"' >> $NODE_ROOT$CONTAINERD_CONF - rm -Rf $NODE_ROOT/opt/kwasm/active + rm -Rf $NODE_ROOT$KWASM_DIR/opt/kwasm/active fi -if [ ! -f $NODE_ROOT/opt/kwasm/active ]; then +if [ ! -f $NODE_ROOT$KWASM_DIR/active ]; then if $IS_MICROK8S; then nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- systemctl restart snap.microk8s.daemon-containerd else nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- /bin/systemctl restart containerd fi - touch $NODE_ROOT/opt/kwasm/active + touch $NODE_ROOT$KWASM_DIR/active else echo "No change in containerd/config.toml" fi From 2e267d5633b6bb093202be0d320acc87c4e4f648 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Tue, 24 Jan 2023 16:41:48 +0100 Subject: [PATCH 12/90] chore(build): add --link flag to Dockerfile copy https://www.docker.com/blog/mergediff-building-dags-more-efficiently-and-elegantly Signed-off-by: Sven Pfennig --- images/installer/Dockerfile | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 0289f2a..562cc1d 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -25,28 +25,28 @@ RUN curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/ FROM busybox as crun-wasmtime -COPY --from=builder-crun /crun/crun-wasmtime /assets/crun-wasmtime -COPY --from=builder-crun /usr/local/lib/libwasmtime.so /assets/libwasmtime.so +COPY --link --from=builder-crun /crun/crun-wasmtime /assets/crun-wasmtime +COPY --link --from=builder-crun /usr/local/lib/libwasmtime.so /assets/libwasmtime.so COPY script/installer.sh /script/installer.sh CMD sh /script/installer.sh wasmtime FROM busybox as crun-wasmedge -COPY --from=builder-crun /crun/crun-wasmedge /assets/crun-wasmedge -COPY --from=builder-crun /usr/local/lib/libwasmedge.so /assets/libwasmedge.so +COPY --link --from=builder-crun /crun/crun-wasmedge /assets/crun-wasmedge +COPY --link --from=builder-crun /usr/local/lib/libwasmedge.so /assets/libwasmedge.so COPY script/installer.sh /script/installer.sh CMD sh /script/installer.sh wasmedge FROM busybox -COPY --from=builder-crun /crun/crun-* /assets/ -COPY --from=builder-crun /usr/local/lib/libwasmedge.so /assets/libwasmedge.so -COPY --from=builder-crun /usr/local/lib/libwasmtime.so /assets/libwasmtime.so -COPY --from=builder-containerd-shim /containerd-shim-slight-v1 /assets/containerd-shim-slight-v1 -COPY --from=builder-containerd-shim /containerd-shim-spin-v1 /assets/containerd-shim-spin-v1 -COPY --from=builder-containerd-shim /containerd-shim-wasmedge-v1 /assets/containerd-shim-wasmedge-v1 +COPY --link --from=builder-crun /crun/crun-* /assets/ +COPY --link --from=builder-crun /usr/local/lib/libwasmedge.so /assets/libwasmedge.so +COPY --link --from=builder-crun /usr/local/lib/libwasmtime.so /assets/libwasmtime.so +COPY --link --from=builder-containerd-shim /containerd-shim-slight-v1 /assets/containerd-shim-slight-v1 +COPY --link --from=builder-containerd-shim /containerd-shim-spin-v1 /assets/containerd-shim-spin-v1 +COPY --link --from=builder-containerd-shim /containerd-shim-wasmedge-v1 /assets/containerd-shim-wasmedge-v1 COPY script/installer.sh /script/installer.sh CMD sh /script/installer.sh wasmedge \ No newline at end of file From ba1ec48dc2e44cee9326080eb757023f9a7063e7 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Tue, 7 Mar 2023 08:55:08 +0100 Subject: [PATCH 13/90] upgrade spin shim to v0.4.0 Signed-off-by: Sven Pfennig --- images/installer/Dockerfile | 27 +++++++++++++++++++-------- script/installer.sh | 6 +++++- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 562cc1d..25f3256 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -20,8 +20,18 @@ FROM ubuntu:18.04 as builder-containerd-shim RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y curl -RUN curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.3.3/containerd-wasm-shims-v1-linux-$(uname -m).tar.gz | tar -xzf - && \ - curl -L https://github.com/second-state/runwasi/releases/download/v0.3.2/containerd-shim-wasmedge-v1-v0.3.2-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - + +RUN curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.4.0/containerd-wasm-shims-v1-linux-$(uname -m).tar.gz | tar -xzf - \ + && curl -L https://github.com/second-state/runwasi/releases/download/v0.3.2/containerd-shim-wasmedge-v1-v0.3.2-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - + +FROM ubuntu:18.04 as builder-containerd-shim-spin +RUN DEBIAN_FRONTEND=noninteractive apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y git curl libclang-dev make build-essential clang\ + && git clone --depth 1 --branch main https://github.com/deislabs/containerd-wasm-shims.git +WORKDIR /containerd-wasm-shims +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup && chmod +x ./rustup \ + && ./rustup -y \ + && bash -c "source ~/.cargo/env && make build-spin" FROM busybox as crun-wasmtime @@ -41,12 +51,13 @@ CMD sh /script/installer.sh wasmedge FROM busybox -COPY --link --from=builder-crun /crun/crun-* /assets/ -COPY --link --from=builder-crun /usr/local/lib/libwasmedge.so /assets/libwasmedge.so -COPY --link --from=builder-crun /usr/local/lib/libwasmtime.so /assets/libwasmtime.so -COPY --link --from=builder-containerd-shim /containerd-shim-slight-v1 /assets/containerd-shim-slight-v1 -COPY --link --from=builder-containerd-shim /containerd-shim-spin-v1 /assets/containerd-shim-spin-v1 -COPY --link --from=builder-containerd-shim /containerd-shim-wasmedge-v1 /assets/containerd-shim-wasmedge-v1 COPY script/installer.sh /script/installer.sh +COPY --link --from=builder-crun /crun/crun-* /assets/ +COPY --link --from=builder-crun /usr/local/lib/libwasmedge.so /assets/libwasmedge.so +COPY --link --from=builder-crun /usr/local/lib/libwasmtime.so /assets/libwasmtime.so +COPY --link --from=builder-containerd-shim /containerd-shim-slight-v1 /assets/containerd-shim-slight-v1 +COPY --link --from=builder-containerd-shim /containerd-shim-spin-v1 /assets/containerd-shim-spin-v1 +COPY --link --from=builder-containerd-shim /containerd-shim-wasmedge-v1 /assets/containerd-shim-wasmedge-v1 +#COPY --link --from=builder-containerd-shim-spin /containerd-wasm-shims/containerd-shim-spin-v1/target/release/containerd-shim-spin-v1 /assets/containerd-shim-spin-v1 CMD sh /script/installer.sh wasmedge \ No newline at end of file diff --git a/script/installer.sh b/script/installer.sh index f2b494c..4a86994 100755 --- a/script/installer.sh +++ b/script/installer.sh @@ -36,7 +36,11 @@ esac cp /assets/containerd-shim-spin-v1 $NODE_ROOT$KWASM_DIR/bin/containerd-shim-spin-v1 cp /assets/containerd-shim-wasmedge-v1 $NODE_ROOT$KWASM_DIR/bin/containerd-shim-wasmedge-v1 -if ! $IS_MICROK8S; then +if [ -f $NODE_ROOT/usr/local/bin/containerd-shim-spin-v1 ]; then + # Replace existing spin shim on Azure AKS nodes + ln -sf $KWASM_DIR/bin/containerd-shim-spin-v1 $NODE_ROOT/usr/local/bin/containerd-shim-spin-v1 + ln -sf $KWASM_DIR/bin/containerd-shim-wasmedge-v1 $NODE_ROOT/usr/local/bin/containerd-shim-wasmedge-v1 +elif ! $IS_MICROK8S; then ln -sf $KWASM_DIR/bin/containerd-shim-spin-v1 $NODE_ROOT/bin/ ln -sf $KWASM_DIR/bin/containerd-shim-wasmedge-v1 $NODE_ROOT/bin/ fi From 970fe69242d3c035932650ca6a7304125becc2f8 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Wed, 15 Mar 2023 20:46:58 +0100 Subject: [PATCH 14/90] bump crun & wasmedge version Signed-off-by: Sven Pfennig --- images/installer/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 25f3256..aae305d 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -2,8 +2,8 @@ FROM ubuntu:18.04 as builder-crun RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y curl make git gcc build-essential pkgconf libtool libsystemd-dev libprotobuf-c-dev libcap-dev libseccomp-dev libyajl-dev go-md2man libtool autoconf python3 automake xz-utils \ - && curl https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -p /usr/local --version=0.11.0 \ - && git clone --depth 1 --branch 1.6 https://github.com/containers/crun.git \ + && curl https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -p /usr/local --version=0.11.2 \ + && git clone --depth 1 --branch 1.8.1 https://github.com/containers/crun.git \ && cd crun \ && ./autogen.sh \ && ./configure --with-wasmedge --enable-embedded-yajl\ From ee5178ea665e60fc7359158d3bd2e30496d98838 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Mon, 8 May 2023 08:53:43 +0200 Subject: [PATCH 15/90] enable namespace build #30 Signed-off-by: Sven Pfennig --- .github/workflows/docker-build.yaml | 34 ++++++++++++----------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index 3fe8132..518cf1a 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -7,6 +7,12 @@ on: pull_request: branches: [ main ] +permissions: + # Required for requesting the GitHub Token + id-token: write + # Required for pushing images to GitHub Container Registry + packages: write + env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} @@ -17,14 +23,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v1 + uses: actions/checkout@v3 - name: Log in to the Container registry uses: docker/login-action@v1 @@ -39,18 +38,13 @@ jobs: with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - name: Build and push Docker image - uses: docker/build-push-action@v2 - with: - context: . - push: true - platforms: linux/amd64,linux/arm64 - tags: ghcr.io/kwasm/kwasm-node-installer:crun-wasmtime - target: crun-wasmtime - file: images/installer/Dockerfile - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max + # Install CLI and authenticate to Namespace + name: Install and configure Namespace CLI + uses: namespacelabs/nscloud-setup@v0.0.2 + - + # Setup docker build to use your Namespace workspace builder + name: Set up Namespace Buildx + uses: namespacelabs/nscloud-setup-buildx-action@v0.0.2 - name: Build and push Docker image uses: docker/build-push-action@v2 From 96b50fe827a031bd9d4d0c7eae4f8b00b9386b5f Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Sun, 7 May 2023 20:09:39 +0200 Subject: [PATCH 16/90] Support CIVO K3s #23 --- script/installer.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/script/installer.sh b/script/installer.sh index 4a86994..2752898 100755 --- a/script/installer.sh +++ b/script/installer.sh @@ -5,6 +5,7 @@ KWASM_DIR=/opt/kwasm CONTAINERD_CONF=/etc/containerd/config.toml IS_MICROK8S=false +IS_K3S=false if ps aux | grep kubelet | grep -q snap/microk8s; then CONTAINERD_CONF=/var/snap/microk8s/current/args/containerd-template.toml IS_MICROK8S=true @@ -14,6 +15,10 @@ if ps aux | grep kubelet | grep -q snap/microk8s; then echo "Installer seems to run on microk8s but 'containerd-template.toml' not found." exit 1 fi +elif ls $NODE_ROOT/var/lib/rancher/k3s/agent/etc/containerd/config.toml > /dev/null 2>&1 ; then + IS_K3S=true + cp $NODE_ROOT/var/lib/rancher/k3s/agent/etc/containerd/config.toml $NODE_ROOT/var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl + CONTAINERD_CONF=/var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl fi mkdir -p $NODE_ROOT$KWASM_DIR/bin/ @@ -45,26 +50,32 @@ elif ! $IS_MICROK8S; then ln -sf $KWASM_DIR/bin/containerd-shim-wasmedge-v1 $NODE_ROOT/bin/ fi +CRI='"io.containerd.grpc.v1.cri"' +if $IS_K3S; then + CRI='cri' +fi if ! grep -q crun $NODE_ROOT$CONTAINERD_CONF; then - echo '[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun] + echo '[plugins.'$CRI'.containerd.runtimes.crun] runtime_type = "io.containerd.runc.v2" pod_annotations = ["module.wasm.image/variant", "run.oci.handler"] -[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun.options] +[plugins.'$CRI'.containerd.runtimes.crun.options] BinaryName = "'$KWASM_DIR/bin/crun'" -[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.spin] +[plugins.'$CRI'.containerd.runtimes.spin] runtime_type = "io.containerd.spin.v1" -[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasmedge] +[plugins.'$CRI'.containerd.runtimes.wasmedge] runtime_type = "io.containerd.wasmedge.v1"' >> $NODE_ROOT$CONTAINERD_CONF rm -Rf $NODE_ROOT$KWASM_DIR/opt/kwasm/active fi if [ ! -f $NODE_ROOT$KWASM_DIR/active ]; then + touch $NODE_ROOT$KWASM_DIR/active if $IS_MICROK8S; then nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- systemctl restart snap.microk8s.daemon-containerd + elif ls $NODE_ROOT/etc/init.d/k3s > /dev/null 2>&1 ; then + nsenter --target 1 --mount --uts --ipc --net -- /etc/init.d/k3s restart else nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- /bin/systemctl restart containerd fi - touch $NODE_ROOT$KWASM_DIR/active else echo "No change in containerd/config.toml" fi From 9746667d23edfc04eb0c0b5d31c0646fe622da77 Mon Sep 17 00:00:00 2001 From: Saiyam Pathak Date: Thu, 8 Jun 2023 14:49:45 +0530 Subject: [PATCH 17/90] Update Dockerfile for new spin version Signed-off-by: Saiyam Pathak --- .github/workflows/docker-build.yaml | 4 ++-- images/installer/Dockerfile | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index 518cf1a..c7aa01b 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -40,11 +40,11 @@ jobs: - # Install CLI and authenticate to Namespace name: Install and configure Namespace CLI - uses: namespacelabs/nscloud-setup@v0.0.2 + uses: namespacelabs/nscloud-setup@v0 - # Setup docker build to use your Namespace workspace builder name: Set up Namespace Buildx - uses: namespacelabs/nscloud-setup-buildx-action@v0.0.2 + uses: namespacelabs/nscloud-setup-buildx-action@v0 - name: Build and push Docker image uses: docker/build-push-action@v2 diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index aae305d..3d63814 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -21,7 +21,7 @@ FROM ubuntu:18.04 as builder-containerd-shim RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y curl -RUN curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.4.0/containerd-wasm-shims-v1-linux-$(uname -m).tar.gz | tar -xzf - \ +RUN curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.6.0/containerd-wasm-shims-v1-linux-$(uname -m).tar.gz | tar -xzf - \ && curl -L https://github.com/second-state/runwasi/releases/download/v0.3.2/containerd-shim-wasmedge-v1-v0.3.2-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - FROM ubuntu:18.04 as builder-containerd-shim-spin @@ -60,4 +60,4 @@ COPY --link --from=builder-containerd-shim /containerd-shim-spin-v1 /assets/cont COPY --link --from=builder-containerd-shim /containerd-shim-wasmedge-v1 /assets/containerd-shim-wasmedge-v1 #COPY --link --from=builder-containerd-shim-spin /containerd-wasm-shims/containerd-shim-spin-v1/target/release/containerd-shim-spin-v1 /assets/containerd-shim-spin-v1 -CMD sh /script/installer.sh wasmedge \ No newline at end of file +CMD sh /script/installer.sh wasmedge From dc9d96c311fd82fd3dba3e34d03c4ceb08bf0700 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Fri, 9 Jun 2023 22:30:11 +0200 Subject: [PATCH 18/90] build crun and wasmedge for alpine Signed-off-by: Sven Pfennig --- images/installer/Dockerfile | 25 ++++++++++++++++++++----- script/installer.sh | 16 ++++++++++++++-- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 3d63814..5eac324 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -6,7 +6,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && git clone --depth 1 --branch 1.8.1 https://github.com/containers/crun.git \ && cd crun \ && ./autogen.sh \ - && ./configure --with-wasmedge --enable-embedded-yajl\ + && ./configure --with-wasmedge --enable-embedded-yajl \ && make \ && mv crun crun-wasmedge RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v1.0.1/wasmtime-v1.0.1-$(uname -m)-linux-c-api.tar.xz | tar xJf - -C / \ @@ -16,6 +16,18 @@ RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v1.0. && make \ && mv crun crun-wasmtime +FROM alpine:3.18 as builder-crun-alpine +RUN apk add gcc automake autoconf libtool gettext pkgconf make musl-dev python3 libcap-dev libseccomp-dev yajl-dev argp-standalone go-md2man curl bash coreutils cmake ninja clang lld-dev llvm-dev boost-dev llvm-static git \ + && cd / && git clone --depth 1 --branch 0.12.1 https://github.com/WasmEdge/WasmEdge.git \ + && cd WasmEdge && bash -c "export CC=clang && export CXX=clang++ && cmake -Bbuildmusl -GNinja -DCMAKE_BUILD_TYPE=Release . && cmake --build buildmusl" \ + && curl https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -p /usr/local --version=0.12.1 \ + && cd / && git clone --depth 1 --branch 1.8.1 https://github.com/containers/crun.git \ + && cd crun \ + && ./autogen.sh \ + && ./configure --with-wasmedge --enable-embedded-yajl --disable-systemd \ + && make \ + && mv crun crun-wasmedge-musl + FROM ubuntu:18.04 as builder-containerd-shim RUN DEBIAN_FRONTEND=noninteractive apt-get update \ @@ -35,16 +47,17 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup && chmod FROM busybox as crun-wasmtime -COPY --link --from=builder-crun /crun/crun-wasmtime /assets/crun-wasmtime -COPY --link --from=builder-crun /usr/local/lib/libwasmtime.so /assets/libwasmtime.so +COPY --link --from=builder-crun /crun/crun-wasmtime /assets/crun-wasmtime +COPY --link --from=builder-crun /usr/local/lib/libwasmtime.so /assets/libwasmtime.so COPY script/installer.sh /script/installer.sh CMD sh /script/installer.sh wasmtime FROM busybox as crun-wasmedge -COPY --link --from=builder-crun /crun/crun-wasmedge /assets/crun-wasmedge -COPY --link --from=builder-crun /usr/local/lib/libwasmedge.so /assets/libwasmedge.so +COPY --link --from=builder-crun /crun/crun-wasmedge /assets/crun-wasmedge +COPY --link --from=builder-crun-alpine /crun/crun-wasmedge-musl /assets/crun-wasmedge-musl +COPY --link --from=builder-crun /usr/local/lib/libwasmedge.so /assets/libwasmedge.so COPY script/installer.sh /script/installer.sh CMD sh /script/installer.sh wasmedge @@ -55,6 +68,8 @@ COPY script/installer.sh /script/installer.sh COPY --link --from=builder-crun /crun/crun-* /assets/ COPY --link --from=builder-crun /usr/local/lib/libwasmedge.so /assets/libwasmedge.so COPY --link --from=builder-crun /usr/local/lib/libwasmtime.so /assets/libwasmtime.so +COPY --link --from=builder-crun-alpine /crun/crun-wasmedge-musl /assets/crun-wasmedge-musl +COPY --link --from=builder-crun-alpine /WasmEdge/buildmusl/lib/api/libwasmedge.so /assets/libwasmedge-musl.so COPY --link --from=builder-containerd-shim /containerd-shim-slight-v1 /assets/containerd-shim-slight-v1 COPY --link --from=builder-containerd-shim /containerd-shim-spin-v1 /assets/containerd-shim-spin-v1 COPY --link --from=builder-containerd-shim /containerd-shim-wasmedge-v1 /assets/containerd-shim-wasmedge-v1 diff --git a/script/installer.sh b/script/installer.sh index 2752898..0a30f0d 100755 --- a/script/installer.sh +++ b/script/installer.sh @@ -21,6 +21,15 @@ elif ls $NODE_ROOT/var/lib/rancher/k3s/agent/etc/containerd/config.toml > /dev/n CONTAINERD_CONF=/var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl fi +IS_ALPINE=false +CRUN_WASMEDGE=crun-wasmedge +LIB_WASMEDGE=libwasmedge.so +if grep -iq alpine $NODE_ROOT/etc/issue 2>/dev/null ; then + IS_ALPINE=true + CRUN_WASMEDGE=crun-wasmedge-musl + LIB_WASMEDGE=libwasmedge-musl.so +fi + mkdir -p $NODE_ROOT$KWASM_DIR/bin/ mkdir -p $NODE_ROOT$KWASM_DIR/lib/ case $1 in @@ -31,8 +40,8 @@ case $1 in ;; *) #wasmedge) - cp /assets/crun-wasmedge $NODE_ROOT$KWASM_DIR/bin/crun && \ - cp /assets/libwasmedge.so $NODE_ROOT$KWASM_DIR/lib/libwasmedge.so && \ + cp /assets/$CRUN_WASMEDGE $NODE_ROOT$KWASM_DIR/bin/crun && \ + cp /assets/$LIB_WASMEDGE $NODE_ROOT$KWASM_DIR/lib/libwasmedge.so && \ ln -sf $KWASM_DIR/lib/libwasmedge.so $NODE_ROOT/lib/libwasmedge.so && \ ln -sf $KWASM_DIR/lib/libwasmedge.so $NODE_ROOT/lib/libwasmedge.so.0 && \ ln -sf $KWASM_DIR/lib/libwasmedge.so $NODE_ROOT/lib/libwasmedge.so.0.0.0 @@ -72,6 +81,9 @@ if [ ! -f $NODE_ROOT$KWASM_DIR/active ]; then if $IS_MICROK8S; then nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- systemctl restart snap.microk8s.daemon-containerd elif ls $NODE_ROOT/etc/init.d/k3s > /dev/null 2>&1 ; then + if $IS_ALPINE ; then + nsenter --target 1 --mount --uts --ipc --net -- sh -c "which apk && apk add libseccomp lld-libs" + fi nsenter --target 1 --mount --uts --ipc --net -- /etc/init.d/k3s restart else nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- /bin/systemctl restart containerd From 7f6850f11ea6d8682b156029621c3883d7272531 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Sun, 11 Jun 2023 21:37:36 +0200 Subject: [PATCH 19/90] fix containerd restart for colima Signed-off-by: Sven Pfennig --- script/installer.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/script/installer.sh b/script/installer.sh index 0a30f0d..0458320 100755 --- a/script/installer.sh +++ b/script/installer.sh @@ -28,6 +28,7 @@ if grep -iq alpine $NODE_ROOT/etc/issue 2>/dev/null ; then IS_ALPINE=true CRUN_WASMEDGE=crun-wasmedge-musl LIB_WASMEDGE=libwasmedge-musl.so + nsenter --target 1 --mount --uts --ipc --net -- sh -c "which apk && apk add libseccomp lld-libs" fi mkdir -p $NODE_ROOT$KWASM_DIR/bin/ @@ -80,10 +81,9 @@ if [ ! -f $NODE_ROOT$KWASM_DIR/active ]; then touch $NODE_ROOT$KWASM_DIR/active if $IS_MICROK8S; then nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- systemctl restart snap.microk8s.daemon-containerd + elif ls $NODE_ROOT/etc/init.d/containerd > /dev/null 2>&1 ; then + nsenter --target 1 --mount --uts --ipc --net -- /etc/init.d/containerd restart elif ls $NODE_ROOT/etc/init.d/k3s > /dev/null 2>&1 ; then - if $IS_ALPINE ; then - nsenter --target 1 --mount --uts --ipc --net -- sh -c "which apk && apk add libseccomp lld-libs" - fi nsenter --target 1 --mount --uts --ipc --net -- /etc/init.d/k3s restart else nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- /bin/systemctl restart containerd From bf0503a0452ba1fc205553fac5d1c26726782dc2 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Fri, 7 Jul 2023 15:51:47 +0200 Subject: [PATCH 20/90] switch to namespace.so runner Signed-off-by: Sven Pfennig --- .github/workflows/docker-build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index c7aa01b..379f886 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -19,7 +19,7 @@ env: jobs: buildx: - runs-on: ubuntu-latest + runs-on: nscloud steps: - name: Checkout @@ -56,4 +56,4 @@ jobs: file: images/installer/Dockerfile labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha - cache-to: type=gha,mode=max \ No newline at end of file + cache-to: type=gha,mode=max From 709ea64705bc454269a799988fa6f1e4919af69f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Fern=C3=A1ndez=20L=C3=B3pez?= Date: Tue, 4 Jul 2023 13:56:41 +0200 Subject: [PATCH 21/90] Update containerd-wasm-shims to 0.7.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This version of the shims contains Wasm Workers Server (WWS) Signed-off-by: Rafael Fernández López --- images/installer/Dockerfile | 6 +++--- script/installer.sh | 9 +++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 5eac324..0719e4e 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -23,7 +23,7 @@ RUN apk add gcc automake autoconf libtool gettext pkgconf make musl-dev python3 && curl https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -p /usr/local --version=0.12.1 \ && cd / && git clone --depth 1 --branch 1.8.1 https://github.com/containers/crun.git \ && cd crun \ - && ./autogen.sh \ + && ./autogen.sh \ && ./configure --with-wasmedge --enable-embedded-yajl --disable-systemd \ && make \ && mv crun crun-wasmedge-musl @@ -33,7 +33,7 @@ FROM ubuntu:18.04 as builder-containerd-shim RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y curl -RUN curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.6.0/containerd-wasm-shims-v1-linux-$(uname -m).tar.gz | tar -xzf - \ +RUN curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.7.0/containerd-wasm-shims-v1-linux-$(uname -m).tar.gz | tar -xzf - \ && curl -L https://github.com/second-state/runwasi/releases/download/v0.3.2/containerd-shim-wasmedge-v1-v0.3.2-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - FROM ubuntu:18.04 as builder-containerd-shim-spin @@ -73,6 +73,6 @@ COPY --link --from=builder-crun-alpine /WasmEdge/buildmusl/lib/api/libwasmedge.s COPY --link --from=builder-containerd-shim /containerd-shim-slight-v1 /assets/containerd-shim-slight-v1 COPY --link --from=builder-containerd-shim /containerd-shim-spin-v1 /assets/containerd-shim-spin-v1 COPY --link --from=builder-containerd-shim /containerd-shim-wasmedge-v1 /assets/containerd-shim-wasmedge-v1 -#COPY --link --from=builder-containerd-shim-spin /containerd-wasm-shims/containerd-shim-spin-v1/target/release/containerd-shim-spin-v1 /assets/containerd-shim-spin-v1 +COPY --link --from=builder-containerd-shim /containerd-shim-wws-v1 /assets/containerd-shim-wws-v1 CMD sh /script/installer.sh wasmedge diff --git a/script/installer.sh b/script/installer.sh index 0458320..d01b0d4 100755 --- a/script/installer.sh +++ b/script/installer.sh @@ -51,20 +51,23 @@ esac cp /assets/containerd-shim-spin-v1 $NODE_ROOT$KWASM_DIR/bin/containerd-shim-spin-v1 cp /assets/containerd-shim-wasmedge-v1 $NODE_ROOT$KWASM_DIR/bin/containerd-shim-wasmedge-v1 +cp /assets/containerd-shim-wws-v1 $NODE_ROOT$KWASM_DIR/bin/containerd-shim-wws-v1 if [ -f $NODE_ROOT/usr/local/bin/containerd-shim-spin-v1 ]; then # Replace existing spin shim on Azure AKS nodes ln -sf $KWASM_DIR/bin/containerd-shim-spin-v1 $NODE_ROOT/usr/local/bin/containerd-shim-spin-v1 ln -sf $KWASM_DIR/bin/containerd-shim-wasmedge-v1 $NODE_ROOT/usr/local/bin/containerd-shim-wasmedge-v1 + ln -sf $KWASM_DIR/bin/containerd-shim-wws-v1 $NODE_ROOT/usr/local/bin/containerd-shim-wws-v1 elif ! $IS_MICROK8S; then ln -sf $KWASM_DIR/bin/containerd-shim-spin-v1 $NODE_ROOT/bin/ ln -sf $KWASM_DIR/bin/containerd-shim-wasmedge-v1 $NODE_ROOT/bin/ + ln -sf $KWASM_DIR/bin/containerd-shim-wws-v1 $NODE_ROOT/bin/ fi CRI='"io.containerd.grpc.v1.cri"' if $IS_K3S; then CRI='cri' fi -if ! grep -q crun $NODE_ROOT$CONTAINERD_CONF; then +if ! grep -q crun $NODE_ROOT$CONTAINERD_CONF; then echo '[plugins.'$CRI'.containerd.runtimes.crun] runtime_type = "io.containerd.runc.v2" pod_annotations = ["module.wasm.image/variant", "run.oci.handler"] @@ -73,7 +76,9 @@ if ! grep -q crun $NODE_ROOT$CONTAINERD_CONF; then [plugins.'$CRI'.containerd.runtimes.spin] runtime_type = "io.containerd.spin.v1" [plugins.'$CRI'.containerd.runtimes.wasmedge] - runtime_type = "io.containerd.wasmedge.v1"' >> $NODE_ROOT$CONTAINERD_CONF + runtime_type = "io.containerd.wasmedge.v1" +[plugins.'$CRI'.containerd.runtimes.wws] + runtime_type = "io.containerd.wws.v1"' >> $NODE_ROOT$CONTAINERD_CONF rm -Rf $NODE_ROOT$KWASM_DIR/opt/kwasm/active fi From 0acc83ff37a11ac491b68bc9bd35bdd09029bd68 Mon Sep 17 00:00:00 2001 From: "Jiaxiao Zhou (Mossaka)" Date: Mon, 17 Jul 2023 22:37:20 -0700 Subject: [PATCH 22/90] chore: bump containerd-wasm-shims to 0.8.0 Signed-off-by: Jiaxiao Zhou (Mossaka) --- images/installer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 0719e4e..35a2d47 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -33,7 +33,7 @@ FROM ubuntu:18.04 as builder-containerd-shim RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y curl -RUN curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.7.0/containerd-wasm-shims-v1-linux-$(uname -m).tar.gz | tar -xzf - \ +RUN curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.8.0/containerd-wasm-shims-v1-linux-$(uname -m).tar.gz | tar -xzf - \ && curl -L https://github.com/second-state/runwasi/releases/download/v0.3.2/containerd-shim-wasmedge-v1-v0.3.2-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - FROM ubuntu:18.04 as builder-containerd-shim-spin From d2b507729b3ca0c537fb5d02b46771524626fcac Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Mon, 28 Aug 2023 10:18:55 +0200 Subject: [PATCH 23/90] disable k3s config exception The K3s config on CIVO K3s clusters now seems to be the same than for other containerd clusters. Signed-off-by: Sven Pfennig --- script/installer.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/script/installer.sh b/script/installer.sh index d01b0d4..d908b6c 100755 --- a/script/installer.sh +++ b/script/installer.sh @@ -64,9 +64,9 @@ elif ! $IS_MICROK8S; then fi CRI='"io.containerd.grpc.v1.cri"' -if $IS_K3S; then - CRI='cri' -fi +#if $IS_K3S; then +# CRI='cri' +#fi if ! grep -q crun $NODE_ROOT$CONTAINERD_CONF; then echo '[plugins.'$CRI'.containerd.runtimes.crun] runtime_type = "io.containerd.runc.v2" From e075a67487e0a707311cf345c09c760ffe4765f6 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Tue, 12 Sep 2023 10:03:57 +0200 Subject: [PATCH 24/90] Update shims and remove crun for now Signed-off-by: Sven Pfennig --- .github/workflows/docker-build.yaml | 16 ++++-- example/install-job.yaml | 2 +- images/installer/Dockerfile | 82 +++++++---------------------- script/installer.sh | 72 +++++++------------------ 4 files changed, 49 insertions(+), 123 deletions(-) diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index 379f886..edf04f2 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -23,10 +23,10 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Log in to the Container registry - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -34,7 +34,7 @@ jobs: - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@v3 + uses: docker/metadata-action@v4 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - @@ -45,13 +45,21 @@ jobs: # Setup docker build to use your Namespace workspace builder name: Set up Namespace Buildx uses: namespacelabs/nscloud-setup-buildx-action@v0 + - name: Build runwasi as static muls for amd64 and arm64 + run: | + git clone https://github.com/containerd/runwasi.git && + cd runwasi && + docker build --platform=linux/arm64,linux/amd64 --build-arg BASE_IMAGE=alpine --build-arg CRATE="containerd-shim-wasmtime,containerd-shim-wasmedge,containerd-shim-wasmer" -t nscr.io/a8fcp47vcfori/build-runwasi --push . && + cd - - name: Build and push Docker image - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4 with: context: . push: true platforms: linux/amd64,linux/arm64 + build-args: | + CONTAINERD_RUNWASI=nscr.io/a8fcp47vcfori/build-runwasi tags: ${{ steps.meta.outputs.tags }} file: images/installer/Dockerfile labels: ${{ steps.meta.outputs.labels }} diff --git a/example/install-job.yaml b/example/install-job.yaml index 0b81f87..3108e70 100644 --- a/example/install-job.yaml +++ b/example/install-job.yaml @@ -21,7 +21,7 @@ spec: name: entrypoint defaultMode: 0744 containers: - - image: docker.io/0xe282b0/kwasm-installer:0.1.0 + - image: ghcr.io/kwasm/kwasm-node-installer:pr-42 name: kwasm-initializer env: - name: NODE_ROOT diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 35a2d47..8d16b1c 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -1,78 +1,32 @@ -FROM ubuntu:18.04 as builder-crun - -RUN DEBIAN_FRONTEND=noninteractive apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y curl make git gcc build-essential pkgconf libtool libsystemd-dev libprotobuf-c-dev libcap-dev libseccomp-dev libyajl-dev go-md2man libtool autoconf python3 automake xz-utils \ - && curl https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -p /usr/local --version=0.11.2 \ - && git clone --depth 1 --branch 1.8.1 https://github.com/containers/crun.git \ - && cd crun \ - && ./autogen.sh \ - && ./configure --with-wasmedge --enable-embedded-yajl \ - && make \ - && mv crun crun-wasmedge -RUN curl -L https://github.com/bytecodealliance/wasmtime/releases/download/v1.0.1/wasmtime-v1.0.1-$(uname -m)-linux-c-api.tar.xz | tar xJf - -C / \ - && cp -R /wasmtime-v1.0.1-$(uname -m)-linux-c-api/* /usr/local/ \ - && cd /crun \ - && ./configure --with-wasmtime --enable-embedded-yajl \ - && make \ - && mv crun crun-wasmtime - -FROM alpine:3.18 as builder-crun-alpine -RUN apk add gcc automake autoconf libtool gettext pkgconf make musl-dev python3 libcap-dev libseccomp-dev yajl-dev argp-standalone go-md2man curl bash coreutils cmake ninja clang lld-dev llvm-dev boost-dev llvm-static git \ - && cd / && git clone --depth 1 --branch 0.12.1 https://github.com/WasmEdge/WasmEdge.git \ - && cd WasmEdge && bash -c "export CC=clang && export CXX=clang++ && cmake -Bbuildmusl -GNinja -DCMAKE_BUILD_TYPE=Release . && cmake --build buildmusl" \ - && curl https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -p /usr/local --version=0.12.1 \ - && cd / && git clone --depth 1 --branch 1.8.1 https://github.com/containers/crun.git \ - && cd crun \ - && ./autogen.sh \ - && ./configure --with-wasmedge --enable-embedded-yajl --disable-systemd \ - && make \ - && mv crun crun-wasmedge-musl - -FROM ubuntu:18.04 as builder-containerd-shim +ARG CONTAINERD_RUNWASI="download-containerd-runwasi" +FROM ubuntu:22.04 AS download-containerd-runwasi RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y curl -RUN curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.8.0/containerd-wasm-shims-v1-linux-$(uname -m).tar.gz | tar -xzf - \ - && curl -L https://github.com/second-state/runwasi/releases/download/v0.3.2/containerd-shim-wasmedge-v1-v0.3.2-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - +RUN mkdir /assets \ + && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmedge%2Fv0.1.1/containerd-shim-wasmedge-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - -C /release/bin/ \ + && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmtime%2Fv0.1.1/containerd-shim-wasmtime-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - -C /release/bin/ -FROM ubuntu:18.04 as builder-containerd-shim-spin -RUN DEBIAN_FRONTEND=noninteractive apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y git curl libclang-dev make build-essential clang\ - && git clone --depth 1 --branch main https://github.com/deislabs/containerd-wasm-shims.git -WORKDIR /containerd-wasm-shims -RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup && chmod +x ./rustup \ - && ./rustup -y \ - && bash -c "source ~/.cargo/env && make build-spin" - -FROM busybox as crun-wasmtime +FROM ${CONTAINERD_RUNWASI} AS containerd_runwasi -COPY --link --from=builder-crun /crun/crun-wasmtime /assets/crun-wasmtime -COPY --link --from=builder-crun /usr/local/lib/libwasmtime.so /assets/libwasmtime.so -COPY script/installer.sh /script/installer.sh +FROM ubuntu:22.04 AS deislabs_containerd-wasm-shims -CMD sh /script/installer.sh wasmtime - -FROM busybox as crun-wasmedge +RUN DEBIAN_FRONTEND=noninteractive apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y curl -COPY --link --from=builder-crun /crun/crun-wasmedge /assets/crun-wasmedge -COPY --link --from=builder-crun-alpine /crun/crun-wasmedge-musl /assets/crun-wasmedge-musl -COPY --link --from=builder-crun /usr/local/lib/libwasmedge.so /assets/libwasmedge.so -COPY script/installer.sh /script/installer.sh +RUN mkdir /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.0/containerd-wasm-shims-v1-lunatic-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.0/containerd-wasm-shims-v1-slight-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.0/containerd-wasm-shims-v1-spin-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.0/containerd-wasm-shims-v1-wws-linux-$(uname -m).tar.gz | tar -xzf - -C /assets -CMD sh /script/installer.sh wasmedge FROM busybox COPY script/installer.sh /script/installer.sh -COPY --link --from=builder-crun /crun/crun-* /assets/ -COPY --link --from=builder-crun /usr/local/lib/libwasmedge.so /assets/libwasmedge.so -COPY --link --from=builder-crun /usr/local/lib/libwasmtime.so /assets/libwasmtime.so -COPY --link --from=builder-crun-alpine /crun/crun-wasmedge-musl /assets/crun-wasmedge-musl -COPY --link --from=builder-crun-alpine /WasmEdge/buildmusl/lib/api/libwasmedge.so /assets/libwasmedge-musl.so -COPY --link --from=builder-containerd-shim /containerd-shim-slight-v1 /assets/containerd-shim-slight-v1 -COPY --link --from=builder-containerd-shim /containerd-shim-spin-v1 /assets/containerd-shim-spin-v1 -COPY --link --from=builder-containerd-shim /containerd-shim-wasmedge-v1 /assets/containerd-shim-wasmedge-v1 -COPY --link --from=builder-containerd-shim /containerd-shim-wws-v1 /assets/containerd-shim-wws-v1 - +COPY --link --from=deislabs_containerd-wasm-shims /assets /assets +COPY --link --from=containerd_runwasi /containerd-shim-wasmedge-v1 /assets/ +COPY --link --from=containerd_runwasi /containerd-shim-wasmer-v1 /assets/ +COPY --link --from=containerd_runwasi /containerd-shim-wasmtime-v1 /assets/ CMD sh /script/installer.sh wasmedge diff --git a/script/installer.sh b/script/installer.sh index d908b6c..9002c9b 100755 --- a/script/installer.sh +++ b/script/installer.sh @@ -21,64 +21,28 @@ elif ls $NODE_ROOT/var/lib/rancher/k3s/agent/etc/containerd/config.toml > /dev/n CONTAINERD_CONF=/var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl fi -IS_ALPINE=false -CRUN_WASMEDGE=crun-wasmedge -LIB_WASMEDGE=libwasmedge.so -if grep -iq alpine $NODE_ROOT/etc/issue 2>/dev/null ; then - IS_ALPINE=true - CRUN_WASMEDGE=crun-wasmedge-musl - LIB_WASMEDGE=libwasmedge-musl.so - nsenter --target 1 --mount --uts --ipc --net -- sh -c "which apk && apk add libseccomp lld-libs" -fi - mkdir -p $NODE_ROOT$KWASM_DIR/bin/ -mkdir -p $NODE_ROOT$KWASM_DIR/lib/ -case $1 in - wasmtime) - cp /assets/crun-wasmtime $NODE_ROOT$KWASM_DIR/bin/crun && \ - cp /assets/libwasmtime.so $NODE_ROOT$KWASM_DIR/lib/libwasmtime.so && \ - ln -sf $KWASM_DIR/lib/libwasmtime.so $NODE_ROOT/lib/libwasmtime.so - ;; - *) - #wasmedge) - cp /assets/$CRUN_WASMEDGE $NODE_ROOT$KWASM_DIR/bin/crun && \ - cp /assets/$LIB_WASMEDGE $NODE_ROOT$KWASM_DIR/lib/libwasmedge.so && \ - ln -sf $KWASM_DIR/lib/libwasmedge.so $NODE_ROOT/lib/libwasmedge.so && \ - ln -sf $KWASM_DIR/lib/libwasmedge.so $NODE_ROOT/lib/libwasmedge.so.0 && \ - ln -sf $KWASM_DIR/lib/libwasmedge.so $NODE_ROOT/lib/libwasmedge.so.0.0.0 - ;; -esac -cp /assets/containerd-shim-spin-v1 $NODE_ROOT$KWASM_DIR/bin/containerd-shim-spin-v1 -cp /assets/containerd-shim-wasmedge-v1 $NODE_ROOT$KWASM_DIR/bin/containerd-shim-wasmedge-v1 -cp /assets/containerd-shim-wws-v1 $NODE_ROOT$KWASM_DIR/bin/containerd-shim-wws-v1 -if [ -f $NODE_ROOT/usr/local/bin/containerd-shim-spin-v1 ]; then - # Replace existing spin shim on Azure AKS nodes - ln -sf $KWASM_DIR/bin/containerd-shim-spin-v1 $NODE_ROOT/usr/local/bin/containerd-shim-spin-v1 - ln -sf $KWASM_DIR/bin/containerd-shim-wasmedge-v1 $NODE_ROOT/usr/local/bin/containerd-shim-wasmedge-v1 - ln -sf $KWASM_DIR/bin/containerd-shim-wws-v1 $NODE_ROOT/usr/local/bin/containerd-shim-wws-v1 -elif ! $IS_MICROK8S; then - ln -sf $KWASM_DIR/bin/containerd-shim-spin-v1 $NODE_ROOT/bin/ - ln -sf $KWASM_DIR/bin/containerd-shim-wasmedge-v1 $NODE_ROOT/bin/ - ln -sf $KWASM_DIR/bin/containerd-shim-wws-v1 $NODE_ROOT/bin/ -fi +cp /assets/containerd-shim-* $NODE_ROOT$KWASM_DIR/bin/ -CRI='"io.containerd.grpc.v1.cri"' -#if $IS_K3S; then -# CRI='cri' -#fi +# TODO check if runtime config is already present if ! grep -q crun $NODE_ROOT$CONTAINERD_CONF; then - echo '[plugins.'$CRI'.containerd.runtimes.crun] - runtime_type = "io.containerd.runc.v2" - pod_annotations = ["module.wasm.image/variant", "run.oci.handler"] -[plugins.'$CRI'.containerd.runtimes.crun.options] - BinaryName = "'$KWASM_DIR/bin/crun'" -[plugins.'$CRI'.containerd.runtimes.spin] - runtime_type = "io.containerd.spin.v1" -[plugins.'$CRI'.containerd.runtimes.wasmedge] - runtime_type = "io.containerd.wasmedge.v1" -[plugins.'$CRI'.containerd.runtimes.wws] - runtime_type = "io.containerd.wws.v1"' >> $NODE_ROOT$CONTAINERD_CONF + echo ' +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.lunatic] + runtime_type = "/opt/kwasm/bin/containerd-shim-lunatic-v1" +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.slight] + runtime_type = "/opt/kwasm/bin/containerd-shim-slight-v1" +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.spin] + runtime_type = "/opt/kwasm/bin/containerd-shim-spin-v1" +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wws] + runtime_type = "/opt/kwasm/bin/containerd-shim-wws-v1" +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasmedge] + runtime_type = "/opt/kwasm/bin/containerd-shim-wasmedge-v1" +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasmer] + runtime_type = "/opt/kwasm/bin/containerd-shim-wasmer-v1" +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasmtime] + runtime_type = "/opt/kwasm/bin/containerd-shim-wasmtime-v1" +' >> $NODE_ROOT$CONTAINERD_CONF rm -Rf $NODE_ROOT$KWASM_DIR/opt/kwasm/active fi From 55ab6d4e2f26dd2db3cc6d4428ca36b678bd2ef4 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Fri, 22 Sep 2023 10:00:44 +0200 Subject: [PATCH 25/90] pin runwasi to containerd-shim-wasm/v0.3.0 and deislabs to 0.9.1 Signed-off-by: Sven Pfennig --- .github/workflows/docker-build.yaml | 3 ++- example/install-job.yaml | 2 +- images/installer/Dockerfile | 14 +++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index edf04f2..62ead8d 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -47,8 +47,9 @@ jobs: uses: namespacelabs/nscloud-setup-buildx-action@v0 - name: Build runwasi as static muls for amd64 and arm64 run: | - git clone https://github.com/containerd/runwasi.git && + git clone --branch containerd-shim-wasm/v0.3.0 --depth 1 https://github.com/containerd/runwasi.git && cd runwasi && + rm Cargo.lock && docker build --platform=linux/arm64,linux/amd64 --build-arg BASE_IMAGE=alpine --build-arg CRATE="containerd-shim-wasmtime,containerd-shim-wasmedge,containerd-shim-wasmer" -t nscr.io/a8fcp47vcfori/build-runwasi --push . && cd - - diff --git a/example/install-job.yaml b/example/install-job.yaml index 3108e70..8a06b72 100644 --- a/example/install-job.yaml +++ b/example/install-job.yaml @@ -21,7 +21,7 @@ spec: name: entrypoint defaultMode: 0744 containers: - - image: ghcr.io/kwasm/kwasm-node-installer:pr-42 + - image: ghcr.io/kwasm/kwasm-node-installer:master name: kwasm-initializer env: - name: NODE_ROOT diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 8d16b1c..cd69405 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -4,9 +4,9 @@ FROM ubuntu:22.04 AS download-containerd-runwasi RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y curl -RUN mkdir /assets \ - && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmedge%2Fv0.1.1/containerd-shim-wasmedge-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - -C /release/bin/ \ - && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmtime%2Fv0.1.1/containerd-shim-wasmtime-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - -C /release/bin/ +RUN mkdir -p /release/bin/ \ + && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmedge%2Fv0.2.0/containerd-shim-wasmedge-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - -C /release/bin/ \ + && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmtime%2Fv0.2.0/containerd-shim-wasmtime-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - -C /release/bin/ FROM ${CONTAINERD_RUNWASI} AS containerd_runwasi @@ -16,10 +16,10 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y curl RUN mkdir /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.0/containerd-wasm-shims-v1-lunatic-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.0/containerd-wasm-shims-v1-slight-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.0/containerd-wasm-shims-v1-spin-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.0/containerd-wasm-shims-v1-wws-linux-$(uname -m).tar.gz | tar -xzf - -C /assets + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.1/containerd-wasm-shims-v1-lunatic-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.1/containerd-wasm-shims-v1-slight-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.1/containerd-wasm-shims-v1-spin-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.1/containerd-wasm-shims-v1-wws-linux-$(uname -m).tar.gz | tar -xzf - -C /assets FROM busybox From 65377c2e6a78e73e23d1306f14d44cdc2b091f5d Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Fri, 22 Sep 2023 18:23:19 +0200 Subject: [PATCH 26/90] fix: microk8s Signed-off-by: Sven Pfennig --- script/installer.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/script/installer.sh b/script/installer.sh index 9002c9b..7f9e85b 100755 --- a/script/installer.sh +++ b/script/installer.sh @@ -26,24 +26,24 @@ mkdir -p $NODE_ROOT$KWASM_DIR/bin/ cp /assets/containerd-shim-* $NODE_ROOT$KWASM_DIR/bin/ # TODO check if runtime config is already present -if ! grep -q crun $NODE_ROOT$CONTAINERD_CONF; then +if ! grep -q wasmtime $NODE_ROOT$CONTAINERD_CONF; then echo ' [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.lunatic] - runtime_type = "/opt/kwasm/bin/containerd-shim-lunatic-v1" + runtime_type = "'$KWASM_DIR'/bin/containerd-shim-lunatic-v1" [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.slight] - runtime_type = "/opt/kwasm/bin/containerd-shim-slight-v1" + runtime_type = "'$KWASM_DIR'/bin/containerd-shim-slight-v1" [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.spin] - runtime_type = "/opt/kwasm/bin/containerd-shim-spin-v1" + runtime_type = "'$KWASM_DIR'/bin/containerd-shim-spin-v1" [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wws] - runtime_type = "/opt/kwasm/bin/containerd-shim-wws-v1" + runtime_type = "'$KWASM_DIR'/bin/containerd-shim-wws-v1" [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasmedge] - runtime_type = "/opt/kwasm/bin/containerd-shim-wasmedge-v1" + runtime_type = "'$KWASM_DIR'/bin/containerd-shim-wasmedge-v1" [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasmer] - runtime_type = "/opt/kwasm/bin/containerd-shim-wasmer-v1" + runtime_type = "'$KWASM_DIR'/bin/containerd-shim-wasmer-v1" [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasmtime] - runtime_type = "/opt/kwasm/bin/containerd-shim-wasmtime-v1" + runtime_type = "'$KWASM_DIR'/bin/containerd-shim-wasmtime-v1" ' >> $NODE_ROOT$CONTAINERD_CONF - rm -Rf $NODE_ROOT$KWASM_DIR/opt/kwasm/active + rm -Rf $NODE_ROOT$KWASM_DIR/active fi if [ ! -f $NODE_ROOT$KWASM_DIR/active ]; then From 819fa6f94a8dbc7b57231c94abd7cadde5925842 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Tue, 26 Sep 2023 08:51:27 +0200 Subject: [PATCH 27/90] Adapt examples to 0.3.0 installer linked to KWasm/kwasm-operator#27 Signed-off-by: Sven Pfennig --- example/test-job.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/example/test-job.yaml b/example/test-job.yaml index 4002968..008a908 100644 --- a/example/test-job.yaml +++ b/example/test-job.yaml @@ -1,8 +1,8 @@ apiVersion: node.k8s.io/v1 kind: RuntimeClass metadata: - name: crun -handler: crun + name: wasmedge +handler: wasmedge --- apiVersion: batch/v1 kind: Job @@ -21,5 +21,5 @@ spec: name: wasm-test resources: {} restartPolicy: Never - runtimeClassName: crun + runtimeClassName: wasmedge backoffLimit: 1 From 54fe12300a25e4571d0d0f367006a96b0580350f Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Wed, 4 Oct 2023 20:03:56 +0200 Subject: [PATCH 28/90] Update README.md Signed-off-by: Sven Pfennig --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 897efed..5f75520 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # KWasm-node-installer +> A Go version of this installer is developed at the [go-rewrite](https://github.com/KWasm/kwasm-node-installer/tree/go-rewrite) branch. + The KWasm Node Installer is a container image that contains binaries and configuration to enable a Kubernetes node to run pure webassembly images. > WARNING: Not meant to be used in production! @@ -12,13 +14,13 @@ Since this installer changes the configuration of the node it can make a node un - MicroK8s - Azure AKS - GCP GKE (Ubuntu Nodes) +- AWS EKS (AmazonLinux2) - AWS EKS (Ubuntu Nodes) - Digital Ocean Kubernetes ## Currently not supported Kubernetes distributions -- K3d -- AWS EKS - OCI OKE +- OpenShift ## Quickstart ### KinD From b503a0f643a95825b4c6a5a925c8f77d2dcebfbc Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Fri, 13 Oct 2023 14:53:58 +0200 Subject: [PATCH 29/90] Change runwasi version to latest main Due to the release of protobuf 3.3, building the latest tag (containerd-shim-wasm/v0.3.0) is broken. Therefore, switch to the latest main, which already fixes this problem. Signed-off-by: Sven Pfennig --- .github/workflows/docker-build.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index 62ead8d..9f167fa 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -47,9 +47,8 @@ jobs: uses: namespacelabs/nscloud-setup-buildx-action@v0 - name: Build runwasi as static muls for amd64 and arm64 run: | - git clone --branch containerd-shim-wasm/v0.3.0 --depth 1 https://github.com/containerd/runwasi.git && + git clone --branch main --depth 1 https://github.com/containerd/runwasi.git && cd runwasi && - rm Cargo.lock && docker build --platform=linux/arm64,linux/amd64 --build-arg BASE_IMAGE=alpine --build-arg CRATE="containerd-shim-wasmtime,containerd-shim-wasmedge,containerd-shim-wasmer" -t nscr.io/a8fcp47vcfori/build-runwasi --push . && cd - - From 6593861a36f5387d89e5592c8374d9d0dc55d822 Mon Sep 17 00:00:00 2001 From: Flavio Castelli Date: Mon, 9 Oct 2023 19:01:26 +0200 Subject: [PATCH 30/90] feat: add rancher RKE2 support Enable installation on RKE2 Signed-off-by: Flavio Castelli --- README.md | 8 ++++++++ script/installer.sh | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index 5f75520..aae3012 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,11 @@ The KWasm Node Installer is a container image that contains binaries and configu Since this installer changes the configuration of the node it can make a node unusable. We recommend using a fresh KinD/MiniKube/MicroK8s or a managed cloud service like AKS/GKE/EKS. ## Supported Kubernetes distributions + - KinD - MiniKube - MicroK8s +- Rancher RKE2 - Azure AKS - GCP GKE (Ubuntu Nodes) - AWS EKS (AmazonLinux2) @@ -19,12 +21,16 @@ Since this installer changes the configuration of the node it can make a node un - Digital Ocean Kubernetes ## Currently not supported Kubernetes distributions + - OCI OKE - OpenShift ## Quickstart + ### KinD + Prerequisites: + - Docker - KinD - kubectl @@ -40,7 +46,9 @@ kubectl apply -f https://raw.githubusercontent.com/KWasm/kwasm-node-installer/ma ``` ## How to build + The dockerfile `images/installer/Dockerfile` has multiple stages by building it you create an image that contains a crun version built with WasmEdge support and one with WasmTime. If you only need one of them you can use a different stage with the target parameter `--target crun-wasmedge` or `--target crun-wasmtime`. + ```bash docker build . -f images/installer/Dockerfile -t kwasm/kwasm-installer ``` diff --git a/script/installer.sh b/script/installer.sh index 7f9e85b..16f63ab 100755 --- a/script/installer.sh +++ b/script/installer.sh @@ -6,6 +6,7 @@ KWASM_DIR=/opt/kwasm CONTAINERD_CONF=/etc/containerd/config.toml IS_MICROK8S=false IS_K3S=false +IS_RKE2_AGENT=false if ps aux | grep kubelet | grep -q snap/microk8s; then CONTAINERD_CONF=/var/snap/microk8s/current/args/containerd-template.toml IS_MICROK8S=true @@ -15,6 +16,10 @@ if ps aux | grep kubelet | grep -q snap/microk8s; then echo "Installer seems to run on microk8s but 'containerd-template.toml' not found." exit 1 fi +elif ls $NODE_ROOT/var/lib/rancher/rke2/agent/etc/containerd/config.toml > /dev/null 2>&1 ; then + IS_RKE2_AGENT=true + cp $NODE_ROOT/var/lib/rancher/rke2/agent/etc/containerd/config.toml $NODE_ROOT/var/lib/rancher/rke2/agent/etc/containerd/config.toml.tmpl + CONTAINERD_CONF=/var/lib/rancher/rke2/agent/etc/containerd/config.toml.tmpl elif ls $NODE_ROOT/var/lib/rancher/k3s/agent/etc/containerd/config.toml > /dev/null 2>&1 ; then IS_K3S=true cp $NODE_ROOT/var/lib/rancher/k3s/agent/etc/containerd/config.toml $NODE_ROOT/var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl @@ -54,6 +59,8 @@ if [ ! -f $NODE_ROOT$KWASM_DIR/active ]; then nsenter --target 1 --mount --uts --ipc --net -- /etc/init.d/containerd restart elif ls $NODE_ROOT/etc/init.d/k3s > /dev/null 2>&1 ; then nsenter --target 1 --mount --uts --ipc --net -- /etc/init.d/k3s restart + elif $IS_RKE2_AGENT; then + nsenter --target 1 --mount --uts --ipc --net -- /bin/systemctl restart rke2-agent else nsenter -m/$NODE_ROOT/proc/1/ns/mnt -- /bin/systemctl restart containerd fi From d498c5c12a43c3d3cabb4d66446f887492327f3f Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Thu, 9 Nov 2023 23:28:24 +0100 Subject: [PATCH 31/90] chore: remove custom build from CI Signed-off-by: Sven Pfennig --- .github/workflows/docker-build.yaml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index 9f167fa..e5b3476 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -45,12 +45,13 @@ jobs: # Setup docker build to use your Namespace workspace builder name: Set up Namespace Buildx uses: namespacelabs/nscloud-setup-buildx-action@v0 - - name: Build runwasi as static muls for amd64 and arm64 - run: | - git clone --branch main --depth 1 https://github.com/containerd/runwasi.git && - cd runwasi && - docker build --platform=linux/arm64,linux/amd64 --build-arg BASE_IMAGE=alpine --build-arg CRATE="containerd-shim-wasmtime,containerd-shim-wasmedge,containerd-shim-wasmer" -t nscr.io/a8fcp47vcfori/build-runwasi --push . && - cd - +# TODO: make builds from latest main branch conditional +# - name: Build runwasi as static muls for amd64 and arm64 +# run: | +# git clone --branch main --depth 1 https://github.com/containerd/runwasi.git && +# cd runwasi && +# docker build --platform=linux/arm64,linux/amd64 --build-arg BASE_IMAGE=alpine --build-arg CRATE="containerd-shim-wasmtime,containerd-shim-wasmedge,containerd-shim-wasmer" -t nscr.io/a8fcp47vcfori/build-runwasi --push . && +# cd - - name: Build and push Docker image uses: docker/build-push-action@v4 @@ -58,8 +59,8 @@ jobs: context: . push: true platforms: linux/amd64,linux/arm64 - build-args: | - CONTAINERD_RUNWASI=nscr.io/a8fcp47vcfori/build-runwasi +# build-args: | +# CONTAINERD_RUNWASI=nscr.io/a8fcp47vcfori/build-runwasi tags: ${{ steps.meta.outputs.tags }} file: images/installer/Dockerfile labels: ${{ steps.meta.outputs.labels }} From 7f5a7bb08b4d3176c379aa7fc85a94294a25cd7b Mon Sep 17 00:00:00 2001 From: "Jiaxiao Zhou (Mossaka)" Date: Mon, 6 Nov 2023 11:06:21 -0800 Subject: [PATCH 32/90] chore: bump shims version to the latest Signed-off-by: Jiaxiao Zhou (Mossaka) --- images/installer/Dockerfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index cd69405..de3525a 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -5,8 +5,8 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y curl RUN mkdir -p /release/bin/ \ - && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmedge%2Fv0.2.0/containerd-shim-wasmedge-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - -C /release/bin/ \ - && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmtime%2Fv0.2.0/containerd-shim-wasmtime-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - -C /release/bin/ + && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmedge%2Fv0.3.0/containerd-shim-wasmedge-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - -C /release/bin/ \ + && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmtime%2Fv0.3.0/containerd-shim-wasmtime-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - -C /release/bin/ FROM ${CONTAINERD_RUNWASI} AS containerd_runwasi @@ -16,10 +16,10 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y curl RUN mkdir /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.1/containerd-wasm-shims-v1-lunatic-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.1/containerd-wasm-shims-v1-slight-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.1/containerd-wasm-shims-v1-spin-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.1/containerd-wasm-shims-v1-wws-linux-$(uname -m).tar.gz | tar -xzf - -C /assets + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.2/containerd-wasm-shims-v1-lunatic-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.2/containerd-wasm-shims-v1-slight-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.2/containerd-wasm-shims-v1-spin-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.2/containerd-wasm-shims-v1-wws-linux-$(uname -m).tar.gz | tar -xzf - -C /assets FROM busybox From 1f8b8bdb787eb565c5a6c662c49ae072a07b518c Mon Sep 17 00:00:00 2001 From: "Jiaxiao Zhou (Mossaka)" Date: Mon, 6 Nov 2023 11:26:02 -0800 Subject: [PATCH 33/90] chore: added wasmer shim Signed-off-by: Jiaxiao Zhou (Mossaka) --- images/installer/Dockerfile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index de3525a..0e6619c 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -5,8 +5,9 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y curl RUN mkdir -p /release/bin/ \ - && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmedge%2Fv0.3.0/containerd-shim-wasmedge-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - -C /release/bin/ \ - && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmtime%2Fv0.3.0/containerd-shim-wasmtime-linux-$(uname -m | sed s/aarch64/arm64/g | sed s/x86_64/amd64/g).tar.gz | tar -xzf - -C /release/bin/ + && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmedge%2Fv0.3.0/containerd-shim-wasmedge-$(uname -m | sed s/arm64/aarch64/g | sed s/amd64/x86_64/g).tar.gz | tar -xzf - -C /release/bin/ \ + && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmtime%2Fv0.3.0/containerd-shim-wasmtime-$(uname -m | sed s/arm64/aarch64/g | sed s/amd64/x86_64/g).tar.gz | tar -xzf - -C /release/bin/ \ + && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmer%2Fv0.3.0/containerd-shim-wasmer-$(uname -m | sed s/arm64/aarch64/g | sed s/amd64/x86_64/g).tar.gz | tar -xzf - -C /release/bin/ FROM ${CONTAINERD_RUNWASI} AS containerd_runwasi @@ -26,7 +27,7 @@ FROM busybox COPY script/installer.sh /script/installer.sh COPY --link --from=deislabs_containerd-wasm-shims /assets /assets -COPY --link --from=containerd_runwasi /containerd-shim-wasmedge-v1 /assets/ -COPY --link --from=containerd_runwasi /containerd-shim-wasmer-v1 /assets/ -COPY --link --from=containerd_runwasi /containerd-shim-wasmtime-v1 /assets/ +COPY --link --from=containerd_runwasi /release/bin/containerd-shim-wasmedge-v1 /assets/ +COPY --link --from=containerd_runwasi /release/bin/containerd-shim-wasmer-v1 /assets/ +COPY --link --from=containerd_runwasi /release/bin/containerd-shim-wasmtime-v1 /assets/ CMD sh /script/installer.sh wasmedge From 5c87e534c88194f1430370d710ed6f3d5302468b Mon Sep 17 00:00:00 2001 From: "Jiaxiao Zhou (Mossaka)" Date: Thu, 9 Nov 2023 17:36:21 -0800 Subject: [PATCH 34/90] chore: bump containerd-wasm-shims to v0.9.3 Signed-off-by: Jiaxiao Zhou (Mossaka) --- images/installer/Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 0e6619c..3035684 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -17,10 +17,10 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y curl RUN mkdir /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.2/containerd-wasm-shims-v1-lunatic-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.2/containerd-wasm-shims-v1-slight-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.2/containerd-wasm-shims-v1-spin-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.2/containerd-wasm-shims-v1-wws-linux-$(uname -m).tar.gz | tar -xzf - -C /assets + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.3/containerd-wasm-shims-v1-lunatic-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.3/containerd-wasm-shims-v1-slight-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.3/containerd-wasm-shims-v1-spin-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.3/containerd-wasm-shims-v1-wws-linux-$(uname -m).tar.gz | tar -xzf - -C /assets FROM busybox From daf2efc08e87bb95496928ade781cfa4983a3480 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Fri, 10 Nov 2023 08:15:33 +0100 Subject: [PATCH 35/90] adapt installer to spin shim v2 Signed-off-by: Sven Pfennig --- images/installer/Dockerfile | 2 +- script/installer.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 3035684..6918559 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -19,7 +19,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update \ RUN mkdir /assets \ && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.3/containerd-wasm-shims-v1-lunatic-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.3/containerd-wasm-shims-v1-slight-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.3/containerd-wasm-shims-v1-spin-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.3/containerd-wasm-shims-v2-spin-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.3/containerd-wasm-shims-v1-wws-linux-$(uname -m).tar.gz | tar -xzf - -C /assets diff --git a/script/installer.sh b/script/installer.sh index 16f63ab..349d28b 100755 --- a/script/installer.sh +++ b/script/installer.sh @@ -38,7 +38,7 @@ if ! grep -q wasmtime $NODE_ROOT$CONTAINERD_CONF; then [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.slight] runtime_type = "'$KWASM_DIR'/bin/containerd-shim-slight-v1" [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.spin] - runtime_type = "'$KWASM_DIR'/bin/containerd-shim-spin-v1" + runtime_type = "'$KWASM_DIR'/bin/containerd-shim-spin-v2" [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wws] runtime_type = "'$KWASM_DIR'/bin/containerd-shim-wws-v1" [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.wasmedge] From a811f482115c5a007cce4e88a04622907c7e5d46 Mon Sep 17 00:00:00 2001 From: "Jiaxiao Zhou (Mossaka)" Date: Sat, 18 Nov 2023 19:21:09 -0800 Subject: [PATCH 36/90] chore: bump containerd-wasm-shims to v0.10.0 Signed-off-by: Jiaxiao Zhou (Mossaka) --- images/installer/Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 6918559..71387f6 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -17,10 +17,10 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y curl RUN mkdir /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.3/containerd-wasm-shims-v1-lunatic-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.3/containerd-wasm-shims-v1-slight-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.3/containerd-wasm-shims-v2-spin-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.3/containerd-wasm-shims-v1-wws-linux-$(uname -m).tar.gz | tar -xzf - -C /assets + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.10.0/containerd-wasm-shims-v1-lunatic-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.10.0/containerd-wasm-shims-v1-slight-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.10.0/containerd-wasm-shims-v2-spin-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.10.0/containerd-wasm-shims-v1-wws-linux-$(uname -m).tar.gz | tar -xzf - -C /assets FROM busybox From 0ee6ec416f56d35449fbe2f6af072a8643e61686 Mon Sep 17 00:00:00 2001 From: "Jiaxiao Zhou (Mossaka)" Date: Thu, 15 Feb 2024 11:53:41 -0800 Subject: [PATCH 37/90] chore(*): bump containerd-wasm-shims to v0.11.1 just bump to the latest release version Signed-off-by: Jiaxiao Zhou (Mossaka) --- images/installer/Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 71387f6..b818013 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -17,10 +17,10 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y curl RUN mkdir /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.10.0/containerd-wasm-shims-v1-lunatic-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.10.0/containerd-wasm-shims-v1-slight-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.10.0/containerd-wasm-shims-v2-spin-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.10.0/containerd-wasm-shims-v1-wws-linux-$(uname -m).tar.gz | tar -xzf - -C /assets + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.11.1/containerd-wasm-shims-v1-lunatic-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.11.1/containerd-wasm-shims-v1-slight-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.11.1/containerd-wasm-shims-v2-spin-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ + && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.11.1/containerd-wasm-shims-v1-wws-linux-$(uname -m).tar.gz | tar -xzf - -C /assets FROM busybox From 3ea523d334271ee4bf52c5de52c4d2e19aac385c Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Tue, 29 Aug 2023 15:08:26 +0200 Subject: [PATCH 38/90] bootstrap go cli tool --- cmd/install.go | 38 ++++ cmd/root.go | 97 +++++++++ cmd/uninstall.go | 46 ++++ go.mod | 26 +++ go.sum | 492 +++++++++++++++++++++++++++++++++++++++++++ main.go | 23 ++ pkg/config/config.go | 32 +++ 7 files changed, 754 insertions(+) create mode 100644 cmd/install.go create mode 100644 cmd/root.go create mode 100644 cmd/uninstall.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 pkg/config/config.go diff --git a/cmd/install.go b/cmd/install.go new file mode 100644 index 0000000..3607838 --- /dev/null +++ b/cmd/install.go @@ -0,0 +1,38 @@ +/* + Copyright The KWasm Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package cmd + +import ( + "log/slog" + + "github.com/spf13/cobra" +) + +// installCmd represents the install command +var installCmd = &cobra.Command{ + Use: "install", + Short: "Install containerd shims", + Run: func(cmd *cobra.Command, args []string) { + slog.Info("install called", "config", config) + }, +} + +func init() { + installCmd.Flags().StringVarP(&config.Kwasm.AssetPath, "asset-path", "a", "/assets", "Path to the binaries and libraries to install") + installCmd.Flags().StringVarP(&config.Runtime.CRIPluginName, "cri-plugin-name", "p", "\"io.containerd.grpc.v1.cri\"", "Name of the cri plugin") + rootCmd.AddCommand(installCmd) +} diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..81279c8 --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,97 @@ +/* + Copyright The KWasm Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package cmd + +import ( + "fmt" + "os" + "strings" + + cfg "github.com/kwasm/kwasm-node-installer/pkg/config" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + "github.com/spf13/viper" +) + +var ( + config cfg.Config +) + +// rootCmd represents the base command when called without any subcommands +var rootCmd = &cobra.Command{ + Use: "kwasm-node-installer", + Short: "kwasm-node-installer manages containerd shims", + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + return initializeConfig(cmd) + }, +} + +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the rootCmd. +func Execute() { + err := rootCmd.Execute() + if err != nil { + os.Exit(1) + } +} + +func init() { + rootCmd.PersistentFlags().StringVarP(&config.Runtime.Name, "runtime", "r", "containerd", "Set the container runtime to configure (containerd, cri-o)") + rootCmd.PersistentFlags().StringVarP(&config.Runtime.ConfigPath, "runtime-config", "c", "/etc/containerd/config.toml", "Path to the runtime config file") + rootCmd.PersistentFlags().StringVarP(&config.Kwasm.Path, "kwasm-path", "k", "/opt/kwasm", "Working directory for kwasm on the host") + rootCmd.PersistentFlags().StringVarP(&config.Host.RootPath, "host-root", "H", "/", "Path to the host root path") +} + +func initializeConfig(cmd *cobra.Command) error { + v := viper.New() + + v.SetConfigName("kwasm") + + v.AddConfigPath(".") + v.AddConfigPath("/etc") + + if err := v.ReadInConfig(); err != nil { + if _, ok := err.(viper.ConfigFileNotFoundError); !ok { + return err + } + } + + // Environment variables are prefixed with KWASM_ + v.SetEnvPrefix("KWASM") + + // - is replaced with _ in environment variables + v.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) + + // Bind env variables + v.AutomaticEnv() + + bindFlags(cmd, v) + + return nil +} + +// bindFlags binds each cobra flag to its associated viper configuration +func bindFlags(cmd *cobra.Command, v *viper.Viper) { + cmd.Flags().VisitAll(func(f *pflag.Flag) { + configName := strings.ReplaceAll(f.Name, "-", "_") + + if !f.Changed && v.IsSet(configName) { + val := v.Get(configName) + cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val)) + } + }) +} diff --git a/cmd/uninstall.go b/cmd/uninstall.go new file mode 100644 index 0000000..3d19e55 --- /dev/null +++ b/cmd/uninstall.go @@ -0,0 +1,46 @@ +/* + Copyright The KWasm Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package cmd + +import ( + "log/slog" + + "github.com/spf13/cobra" +) + +// uninstallCmd represents the uninstall command +var uninstallCmd = &cobra.Command{ + Use: "uninstall", + Short: "Uninstall containerd shims", + Run: func(cmd *cobra.Command, args []string) { + slog.Info("install called", "config", config) + }, +} + +func init() { + rootCmd.AddCommand(uninstallCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // uninstallCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // uninstallCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d6c9b1d --- /dev/null +++ b/go.mod @@ -0,0 +1,26 @@ +module github.com/kwasm/kwasm-node-installer + +go 1.21.0 + +require ( + github.com/spf13/cobra v1.7.0 + github.com/spf13/pflag v1.0.5 + github.com/spf13/viper v1.16.0 +) + +require ( + github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/magiconair/properties v1.8.7 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/spf13/afero v1.9.5 // indirect + github.com/spf13/cast v1.5.1 // indirect + github.com/spf13/jwalterweatherman v1.1.0 // indirect + github.com/subosito/gotenv v1.4.2 // indirect + golang.org/x/sys v0.8.0 // indirect + golang.org/x/text v0.9.0 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..8b42396 --- /dev/null +++ b/go.sum @@ -0,0 +1,492 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.44.3/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= +cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= +cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= +cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= +cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKPI= +cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk= +cloud.google.com/go v0.75.0/go.mod h1:VGuuCn7PG0dwsd5XPVm2Mm3wlh3EL55/79EKB6hlPTY= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= +cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= +cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= +cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= +github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= +github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= +github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= +github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= +github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= +github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= +github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= +github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= +github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= +github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc= +github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= +github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= +golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= +google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg= +google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE= +google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= +google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= +google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= +google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/main.go b/main.go new file mode 100644 index 0000000..5bb240b --- /dev/null +++ b/main.go @@ -0,0 +1,23 @@ +/* + Copyright The KWasm Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package main + +import "github.com/kwasm/kwasm-node-installer/cmd" + +func main() { + cmd.Execute() +} diff --git a/pkg/config/config.go b/pkg/config/config.go new file mode 100644 index 0000000..334c658 --- /dev/null +++ b/pkg/config/config.go @@ -0,0 +1,32 @@ +/* + Copyright The KWasm Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package config + +type Config struct { + Runtime struct { + Name string + ConfigPath string + CRIPluginName string + } + Kwasm struct { + Path string + AssetPath string + } + Host struct { + RootPath string + } +} From 5cbd3dc9d9b8d979422d40cd03c5922102326b5c Mon Sep 17 00:00:00 2001 From: Daniel Aberger Date: Thu, 28 Sep 2023 14:13:16 +0200 Subject: [PATCH 39/90] add containerd runtime restart --- cmd/install.go | 7 +++++ go.mod | 1 + go.sum | 2 ++ pkg/containerd/restart.go | 66 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 pkg/containerd/restart.go diff --git a/cmd/install.go b/cmd/install.go index 3607838..b5562d7 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -20,6 +20,8 @@ import ( "log/slog" "github.com/spf13/cobra" + + "github.com/kwasm/kwasm-node-installer/pkg/containerd" ) // installCmd represents the install command @@ -28,6 +30,11 @@ var installCmd = &cobra.Command{ Short: "Install containerd shims", Run: func(cmd *cobra.Command, args []string) { slog.Info("install called", "config", config) + + err := containerd.RestartRuntime() + if err != nil { + slog.Error("failed to restart containerd", "error", err) + } }, } diff --git a/go.mod b/go.mod index d6c9b1d..aa3ef24 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/magiconair/properties v1.8.7 // indirect + github.com/mitchellh/go-ps v1.0.0 github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/spf13/afero v1.9.5 // indirect diff --git a/go.sum b/go.sum index 8b42396..a29bc56 100644 --- a/go.sum +++ b/go.sum @@ -140,6 +140,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc= +github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= diff --git a/pkg/containerd/restart.go b/pkg/containerd/restart.go new file mode 100644 index 0000000..00dd741 --- /dev/null +++ b/pkg/containerd/restart.go @@ -0,0 +1,66 @@ +/* + Copyright The KWasm Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package containerd + +import ( + "fmt" + "log/slog" + "syscall" + + "github.com/mitchellh/go-ps" +) + +func RestartRuntime() error { + pid, err := getPid() + if err != nil { + return err + } + slog.Info("found containerd pid", "pid", pid) + + err = syscall.Kill(pid, syscall.SIGHUP) + + if err != nil { + return fmt.Errorf("failed to send SIGHUP to containerd: %+v", err) + } + return nil +} + +func getPid() (int, error) { + processList, err := ps.Processes() + if err != nil { + slog.Info("ps.Processes() Failed, are you using windows?") + return -1, fmt.Errorf("could not get processes: %+v", err) + } + + var containerdProcessList = []ps.Process{} + + for x := range processList { + process := processList[x] + if process.Executable() == "containerd" { + containerdProcessList = append(containerdProcessList, process) + } + + } + + if len(containerdProcessList) == 1 { + return containerdProcessList[0].Pid(), nil + } else if len(containerdProcessList) == 0 { + return -1, fmt.Errorf("no containerd process found") + } else { + panic("multiple containerd processes found") + } +} From 6506331df6067eca72d75c2a7e145a7d7f02b119 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Thu, 28 Sep 2023 14:33:46 +0200 Subject: [PATCH 40/90] allow installing and configuring of shims --- cmd/install.go | 29 ++++++++++++++++++++++++----- pkg/config/config.go | 5 ++--- pkg/containerd/configure.go | 35 +++++++++++++++++++++++++++++++++++ pkg/shim/install.go | 29 +++++++++++++++++++++++++++++ pkg/shim/shim.go | 7 +++++++ 5 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 pkg/containerd/configure.go create mode 100644 pkg/shim/install.go create mode 100644 pkg/shim/shim.go diff --git a/cmd/install.go b/cmd/install.go index b5562d7..bfeaa16 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -18,10 +18,12 @@ package cmd import ( "log/slog" - - "github.com/spf13/cobra" + "os" + "path" "github.com/kwasm/kwasm-node-installer/pkg/containerd" + "github.com/kwasm/kwasm-node-installer/pkg/shim" + "github.com/spf13/cobra" ) // installCmd represents the install command @@ -29,9 +31,27 @@ var installCmd = &cobra.Command{ Use: "install", Short: "Install containerd shims", Run: func(cmd *cobra.Command, args []string) { - slog.Info("install called", "config", config) + files, err := os.ReadDir(config.Kwasm.AssetPath) + if err != nil { + slog.Error(err.Error()) + return + } + for _, file := range files { + binPath, err := shim.Install(config.Host.RootPath, path.Join(config.Kwasm.AssetPath, file.Name()), path.Join(config.Kwasm.Path, "bin")) + if err != nil { + slog.Error(err.Error()) + return + } + slog.Info("shim installed", "shim", shim.RuntimeName(file.Name()), "path", binPath) + configPath, err := containerd.WriteConfig(&config, binPath) + if err != nil { + slog.Error(err.Error()) + return + } + slog.Info("shim configured", "shim", shim.RuntimeName(file.Name()), "path", configPath) + } - err := containerd.RestartRuntime() + err = containerd.RestartRuntime() if err != nil { slog.Error("failed to restart containerd", "error", err) } @@ -40,6 +60,5 @@ var installCmd = &cobra.Command{ func init() { installCmd.Flags().StringVarP(&config.Kwasm.AssetPath, "asset-path", "a", "/assets", "Path to the binaries and libraries to install") - installCmd.Flags().StringVarP(&config.Runtime.CRIPluginName, "cri-plugin-name", "p", "\"io.containerd.grpc.v1.cri\"", "Name of the cri plugin") rootCmd.AddCommand(installCmd) } diff --git a/pkg/config/config.go b/pkg/config/config.go index 334c658..cb536cd 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -18,9 +18,8 @@ package config type Config struct { Runtime struct { - Name string - ConfigPath string - CRIPluginName string + Name string + ConfigPath string } Kwasm struct { Path string diff --git a/pkg/containerd/configure.go b/pkg/containerd/configure.go new file mode 100644 index 0000000..d5b2260 --- /dev/null +++ b/pkg/containerd/configure.go @@ -0,0 +1,35 @@ +package containerd + +import ( + "fmt" + "os" + "path" + + "github.com/kwasm/kwasm-node-installer/pkg/config" + "github.com/kwasm/kwasm-node-installer/pkg/shim" +) + +func WriteConfig(config *config.Config, shimPath string) (string, error) { + runtimeName := shim.RuntimeName(path.Base(shimPath)) + + cfg := generateConfig(shimPath, runtimeName) + + configPath := path.Join(configDirectory(config), fmt.Sprintf("%s.%s", runtimeName, "toml")) + configHostPath := path.Join(config.Host.RootPath, configPath) + + err := os.MkdirAll(path.Dir(configHostPath), 0755) + if err != nil { + return configPath, err + } + + return configPath, os.WriteFile(configHostPath, []byte(cfg), 0644) +} + +func configDirectory(config *config.Config) string { + return path.Join(path.Dir(config.Runtime.ConfigPath), "conf.d") +} + +func generateConfig(shimPath string, runtimeName string) string { + return fmt.Sprintf(`[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.%s] +runtime_type = "%s"`, runtimeName, shimPath) +} diff --git a/pkg/shim/install.go b/pkg/shim/install.go new file mode 100644 index 0000000..d115732 --- /dev/null +++ b/pkg/shim/install.go @@ -0,0 +1,29 @@ +package shim + +import ( + "io" + "os" + "path" +) + +func Install(hostPath string, shimPath string, binaryDir string) (string, error) { + srcFile, err := os.OpenFile(shimPath, os.O_RDONLY, 0000) + if err != nil { + return "", err + } + dstFilePath := path.Join(binaryDir, path.Base(shimPath)) + dstFilePathHost := path.Join(hostPath, dstFilePath) + + err = os.MkdirAll(path.Dir(dstFilePathHost), 0755) + if err != nil { + return dstFilePath, err + } + + dstFile, err := os.OpenFile(dstFilePathHost, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) + if err != nil { + return "", err + } + _, err = io.Copy(dstFile, srcFile) + + return dstFilePath, err +} diff --git a/pkg/shim/shim.go b/pkg/shim/shim.go new file mode 100644 index 0000000..39af559 --- /dev/null +++ b/pkg/shim/shim.go @@ -0,0 +1,7 @@ +package shim + +import "strings" + +func RuntimeName(bin string) string { + return strings.TrimPrefix(bin, "containerd-shim-") +} From 91b7fed3ca283fe4cae47bfe371098e3761308c0 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Thu, 28 Sep 2023 14:42:53 +0200 Subject: [PATCH 41/90] add some dummy test assets --- test/README.md | 12 ++++++++++++ test/assets/containerd-shim-slight-v1 | 3 +++ test/assets/containerd-shim-spin-v1 | 3 +++ 3 files changed, 18 insertions(+) create mode 100644 test/README.md create mode 100644 test/assets/containerd-shim-slight-v1 create mode 100644 test/assets/containerd-shim-spin-v1 diff --git a/test/README.md b/test/README.md new file mode 100644 index 0000000..24e0740 --- /dev/null +++ b/test/README.md @@ -0,0 +1,12 @@ +# Local testing during development + +Run + +``` +$ go run . install -H test -a ./test/assets +``` + +This will copy the assets from `test/assets` into `test/opt/kwasm/bin` and +create containerd config files in `test/etc/containerd/conf.d`. The config will +have the absolute path of the binary from the host root (`-H test` - `test` is +the host root). \ No newline at end of file diff --git a/test/assets/containerd-shim-slight-v1 b/test/assets/containerd-shim-slight-v1 new file mode 100644 index 0000000..9eca0fc --- /dev/null +++ b/test/assets/containerd-shim-slight-v1 @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo "hello from spin-v1" \ No newline at end of file diff --git a/test/assets/containerd-shim-spin-v1 b/test/assets/containerd-shim-spin-v1 new file mode 100644 index 0000000..9eca0fc --- /dev/null +++ b/test/assets/containerd-shim-spin-v1 @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo "hello from spin-v1" \ No newline at end of file From 66a360c742de768b36235ffeee049694b25ba4cc Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Thu, 28 Sep 2023 14:55:24 +0200 Subject: [PATCH 42/90] refactor path joins --- cmd/install.go | 3 +-- pkg/config/config.go | 10 ++++++++++ pkg/containerd/configure.go | 2 +- pkg/shim/install.go | 9 ++++++--- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/cmd/install.go b/cmd/install.go index bfeaa16..6d91c99 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -19,7 +19,6 @@ package cmd import ( "log/slog" "os" - "path" "github.com/kwasm/kwasm-node-installer/pkg/containerd" "github.com/kwasm/kwasm-node-installer/pkg/shim" @@ -37,7 +36,7 @@ var installCmd = &cobra.Command{ return } for _, file := range files { - binPath, err := shim.Install(config.Host.RootPath, path.Join(config.Kwasm.AssetPath, file.Name()), path.Join(config.Kwasm.Path, "bin")) + binPath, err := shim.Install(&config, file.Name()) if err != nil { slog.Error(err.Error()) return diff --git a/pkg/config/config.go b/pkg/config/config.go index cb536cd..e353714 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -16,6 +16,8 @@ package config +import "path" + type Config struct { Runtime struct { Name string @@ -29,3 +31,11 @@ type Config struct { RootPath string } } + +func (c *Config) PathWithHost(p string) string { + return path.Join(c.Host.RootPath, p) +} + +func (c *Config) AssetPath(assetName string) string { + return path.Join(c.Kwasm.AssetPath, assetName) +} diff --git a/pkg/containerd/configure.go b/pkg/containerd/configure.go index d5b2260..4d4a7b4 100644 --- a/pkg/containerd/configure.go +++ b/pkg/containerd/configure.go @@ -15,7 +15,7 @@ func WriteConfig(config *config.Config, shimPath string) (string, error) { cfg := generateConfig(shimPath, runtimeName) configPath := path.Join(configDirectory(config), fmt.Sprintf("%s.%s", runtimeName, "toml")) - configHostPath := path.Join(config.Host.RootPath, configPath) + configHostPath := config.PathWithHost(configPath) err := os.MkdirAll(path.Dir(configHostPath), 0755) if err != nil { diff --git a/pkg/shim/install.go b/pkg/shim/install.go index d115732..439f618 100644 --- a/pkg/shim/install.go +++ b/pkg/shim/install.go @@ -4,15 +4,18 @@ import ( "io" "os" "path" + + "github.com/kwasm/kwasm-node-installer/pkg/config" ) -func Install(hostPath string, shimPath string, binaryDir string) (string, error) { +func Install(config *config.Config, shimName string) (string, error) { + shimPath := config.AssetPath(shimName) srcFile, err := os.OpenFile(shimPath, os.O_RDONLY, 0000) if err != nil { return "", err } - dstFilePath := path.Join(binaryDir, path.Base(shimPath)) - dstFilePathHost := path.Join(hostPath, dstFilePath) + dstFilePath := path.Join(config.Kwasm.Path, "bin", shimName) + dstFilePathHost := config.PathWithHost(dstFilePath) err = os.MkdirAll(path.Dir(dstFilePathHost), 0755) if err != nil { From 9f87f6f80325ef80cf409876a47896f2cd96d849 Mon Sep 17 00:00:00 2001 From: Daniel Aberger Date: Thu, 28 Sep 2023 14:37:16 +0200 Subject: [PATCH 43/90] update Dockerfile for Go rewrite --- images/installer/Dockerfile | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index b818013..3443b8d 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -1,33 +1,14 @@ -ARG CONTAINERD_RUNWASI="download-containerd-runwasi" +FROM golang:1.21 -FROM ubuntu:22.04 AS download-containerd-runwasi -RUN DEBIAN_FRONTEND=noninteractive apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y curl +WORKDIR /app -RUN mkdir -p /release/bin/ \ - && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmedge%2Fv0.3.0/containerd-shim-wasmedge-$(uname -m | sed s/arm64/aarch64/g | sed s/amd64/x86_64/g).tar.gz | tar -xzf - -C /release/bin/ \ - && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmtime%2Fv0.3.0/containerd-shim-wasmtime-$(uname -m | sed s/arm64/aarch64/g | sed s/amd64/x86_64/g).tar.gz | tar -xzf - -C /release/bin/ \ - && curl -L https://github.com/containerd/runwasi/releases/download/containerd-shim-wasmer%2Fv0.3.0/containerd-shim-wasmer-$(uname -m | sed s/arm64/aarch64/g | sed s/amd64/x86_64/g).tar.gz | tar -xzf - -C /release/bin/ +COPY go.mod go.sum ./ +RUN go mod download -FROM ${CONTAINERD_RUNWASI} AS containerd_runwasi +COPY pkg ./pkg +COPY cmd ./cmd +COPY *.go ./ -FROM ubuntu:22.04 AS deislabs_containerd-wasm-shims +RUN go build -o kwasm-node-installer -RUN DEBIAN_FRONTEND=noninteractive apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y curl - -RUN mkdir /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.11.1/containerd-wasm-shims-v1-lunatic-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.11.1/containerd-wasm-shims-v1-slight-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.11.1/containerd-wasm-shims-v2-spin-linux-$(uname -m).tar.gz | tar -xzf - -C /assets \ - && curl -L https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.11.1/containerd-wasm-shims-v1-wws-linux-$(uname -m).tar.gz | tar -xzf - -C /assets - - -FROM busybox - -COPY script/installer.sh /script/installer.sh -COPY --link --from=deislabs_containerd-wasm-shims /assets /assets -COPY --link --from=containerd_runwasi /release/bin/containerd-shim-wasmedge-v1 /assets/ -COPY --link --from=containerd_runwasi /release/bin/containerd-shim-wasmer-v1 /assets/ -COPY --link --from=containerd_runwasi /release/bin/containerd-shim-wasmtime-v1 /assets/ -CMD sh /script/installer.sh wasmedge +CMD ["/app/kwasm-node-installer", "install"] From f3bf3186d10cbe988b5df6b9727090927ba586a8 Mon Sep 17 00:00:00 2001 From: Daniel Aberger Date: Thu, 28 Sep 2023 15:19:44 +0200 Subject: [PATCH 44/90] add new stage for runtime to Dockerfile --- images/installer/Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 3443b8d..c14e866 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.21 +FROM golang:1.21 as builder WORKDIR /app @@ -11,4 +11,7 @@ COPY *.go ./ RUN go build -o kwasm-node-installer +FROM scratch +COPY --from=builder /app/kwasm-node-installer /kwasm-node-installer + CMD ["/app/kwasm-node-installer", "install"] From c44cf74842414a751ea6c8433e6a4d228176b23f Mon Sep 17 00:00:00 2001 From: Daniel Aberger Date: Thu, 28 Sep 2023 15:24:40 +0200 Subject: [PATCH 45/90] change CMD to ENTRYPOINT --- images/installer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index c14e866..451167e 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -14,4 +14,4 @@ RUN go build -o kwasm-node-installer FROM scratch COPY --from=builder /app/kwasm-node-installer /kwasm-node-installer -CMD ["/app/kwasm-node-installer", "install"] +ENTRYPOINT ["/kwasm-node-installer"] From a0a72d290eacd8074d4e8f3fe6a0de64fe1ec447 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Thu, 28 Sep 2023 15:33:15 +0200 Subject: [PATCH 46/90] add missing copyright notices --- pkg/containerd/configure.go | 16 ++++++++++++++++ pkg/shim/install.go | 16 ++++++++++++++++ pkg/shim/shim.go | 16 ++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/pkg/containerd/configure.go b/pkg/containerd/configure.go index 4d4a7b4..1c7a082 100644 --- a/pkg/containerd/configure.go +++ b/pkg/containerd/configure.go @@ -1,3 +1,19 @@ +/* + Copyright The KWasm Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + package containerd import ( diff --git a/pkg/shim/install.go b/pkg/shim/install.go index 439f618..8bdc6d8 100644 --- a/pkg/shim/install.go +++ b/pkg/shim/install.go @@ -1,3 +1,19 @@ +/* + Copyright The KWasm Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + package shim import ( diff --git a/pkg/shim/shim.go b/pkg/shim/shim.go index 39af559..68b6af3 100644 --- a/pkg/shim/shim.go +++ b/pkg/shim/shim.go @@ -1,3 +1,19 @@ +/* + Copyright The KWasm Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + package shim import "strings" From b7787fdcd4a14d7d08204cf5e4d2f6e1f9c21d6e Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Thu, 28 Sep 2023 17:02:46 +0200 Subject: [PATCH 47/90] build without cgo to avoid any dynamic linking --- images/installer/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 451167e..a22d291 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -9,7 +9,8 @@ COPY pkg ./pkg COPY cmd ./cmd COPY *.go ./ -RUN go build -o kwasm-node-installer +RUN CGO_ENABLED=0 go build -o kwasm-node-installer +RUN /app/kwasm-node-installer -h FROM scratch COPY --from=builder /app/kwasm-node-installer /kwasm-node-installer From f730f49dc322ac4bff4ded2d6da9dc5a4bc5837d Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Thu, 28 Sep 2023 17:08:41 +0200 Subject: [PATCH 48/90] remove runwasi compilation --- .github/workflows/docker-build.yaml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index e5b3476..21db57a 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -45,13 +45,6 @@ jobs: # Setup docker build to use your Namespace workspace builder name: Set up Namespace Buildx uses: namespacelabs/nscloud-setup-buildx-action@v0 -# TODO: make builds from latest main branch conditional -# - name: Build runwasi as static muls for amd64 and arm64 -# run: | -# git clone --branch main --depth 1 https://github.com/containerd/runwasi.git && -# cd runwasi && -# docker build --platform=linux/arm64,linux/amd64 --build-arg BASE_IMAGE=alpine --build-arg CRATE="containerd-shim-wasmtime,containerd-shim-wasmedge,containerd-shim-wasmer" -t nscr.io/a8fcp47vcfori/build-runwasi --push . && -# cd - - name: Build and push Docker image uses: docker/build-push-action@v4 From 563a05b35e99fd58a10eb140615af69c7f9272bd Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Thu, 28 Sep 2023 17:19:30 +0200 Subject: [PATCH 49/90] update daemonset example --- example/daemonset.yaml | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/example/daemonset.yaml b/example/daemonset.yaml index e762e67..a53e3bf 100644 --- a/example/daemonset.yaml +++ b/example/daemonset.yaml @@ -21,19 +21,34 @@ spec: - name: node-root hostPath: path: / - - name: entrypoint - configMap: - name: entrypoint - defaultMode: 0744 + - name: assets + emptyDir: {} initContainers: - - image: ghcr.io/kwasm/kwasm-node-installer:main - name: kwasm-initializer + - image: busybox:latest + name: shim-downloader env: - - name: NODE_ROOT - value: /mnt/node-root + volumeMounts: + - name: assets + mountPath: /assets + command: ["/bin/sh", "-c"] + args: + - | + wget -O- https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.1/containerd-wasm-shims-v1-lunatic-linux-$(uname -m).tar.gz | tar xzf - -C /assets; + wget -O- https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.1/containerd-wasm-shims-v1-slight-linux-$(uname -m).tar.gz | tar -xzf - -C /assets; + wget -O- https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.1/containerd-wasm-shims-v1-spin-linux-$(uname -m).tar.gz | tar -xzf - -C /assets; + wget -O- https://github.com/deislabs/containerd-wasm-shims/releases/download/v0.9.1/containerd-wasm-shims-v1-wws-linux-$(uname -m).tar.gz | tar -xzf - -C /assets + - image: ghcr.io/kwasm/kwasm-node-installer:pr-46 + name: kwasm-initializer + imagePullPolicy: Always + args: + - "install" + - "-H" + - "/mnt/node-root" securityContext: privileged: true volumeMounts: + - name: assets + mountPath: /assets - name: node-root mountPath: /mnt/node-root/ containers: From d6c5ce817657caec1066abd2a24f912648fc162d Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Fri, 29 Sep 2023 11:25:54 +0200 Subject: [PATCH 50/90] implement kwasm lockfile support to avoid unnecessary restarts --- cmd/install.go | 22 ++++++++++++---- pkg/shim/install.go | 32 ++++++++++++++++++----- pkg/state/shim.go | 38 +++++++++++++++++++++++++++ pkg/state/state.go | 62 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 143 insertions(+), 11 deletions(-) create mode 100644 pkg/state/shim.go create mode 100644 pkg/state/state.go diff --git a/cmd/install.go b/cmd/install.go index 6d91c99..22e4dcd 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -35,21 +35,33 @@ var installCmd = &cobra.Command{ slog.Error(err.Error()) return } + anythingChanged := false for _, file := range files { - binPath, err := shim.Install(&config, file.Name()) + fileName := file.Name() + runtimeName := shim.RuntimeName(fileName) + + binPath, changed, err := shim.Install(&config, fileName) if err != nil { - slog.Error(err.Error()) + slog.Error("failed to install shim", "shim", runtimeName, "error", err) return } - slog.Info("shim installed", "shim", shim.RuntimeName(file.Name()), "path", binPath) + anythingChanged = anythingChanged || changed + slog.Info("shim installed", "shim", runtimeName, "path", binPath, "new-version", changed) + configPath, err := containerd.WriteConfig(&config, binPath) if err != nil { - slog.Error(err.Error()) + slog.Error("failed to write containerd config", "shim", runtimeName, "path", configPath, "error", err) return } - slog.Info("shim configured", "shim", shim.RuntimeName(file.Name()), "path", configPath) + slog.Info("shim configured", "shim", runtimeName, "path", configPath) + } + + if !anythingChanged { + slog.Info("nothing changed, nothing more to do") + return } + slog.Info("restarting containerd") err = containerd.RestartRuntime() if err != nil { slog.Error("failed to restart containerd", "error", err) diff --git a/pkg/shim/install.go b/pkg/shim/install.go index 8bdc6d8..0c519fb 100644 --- a/pkg/shim/install.go +++ b/pkg/shim/install.go @@ -17,32 +17,52 @@ package shim import ( + "crypto/sha256" "io" "os" "path" "github.com/kwasm/kwasm-node-installer/pkg/config" + "github.com/kwasm/kwasm-node-installer/pkg/state" ) -func Install(config *config.Config, shimName string) (string, error) { +func Install(config *config.Config, shimName string) (string, bool, error) { shimPath := config.AssetPath(shimName) srcFile, err := os.OpenFile(shimPath, os.O_RDONLY, 0000) if err != nil { - return "", err + return "", false, err } dstFilePath := path.Join(config.Kwasm.Path, "bin", shimName) dstFilePathHost := config.PathWithHost(dstFilePath) err = os.MkdirAll(path.Dir(dstFilePathHost), 0755) if err != nil { - return dstFilePath, err + return dstFilePath, false, err } dstFile, err := os.OpenFile(dstFilePathHost, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) if err != nil { - return "", err + return "", false, err } - _, err = io.Copy(dstFile, srcFile) - return dstFilePath, err + st, err := state.Get(config) + if err != nil { + return "", false, err + } + shimSha256 := sha256.New() + + _, err = io.Copy(io.MultiWriter(dstFile, shimSha256), srcFile) + runtimeName := RuntimeName(shimName) + changed := st.ShimChanged(runtimeName, shimSha256.Sum(nil), dstFilePath) + if changed { + st.UpdateShim(runtimeName, state.Shim{ + Path: dstFilePath, + Sha256: shimSha256.Sum(nil), + }) + if err := st.Write(); err != nil { + return "", false, err + } + } + + return dstFilePath, changed, err } diff --git a/pkg/state/shim.go b/pkg/state/shim.go new file mode 100644 index 0000000..eb00401 --- /dev/null +++ b/pkg/state/shim.go @@ -0,0 +1,38 @@ +package state + +import ( + "encoding/hex" + "encoding/json" +) + +type Shim struct { + Sha256 []byte + Path string +} + +func (s *Shim) MarshalJSON() ([]byte, error) { + return json.Marshal(&struct { + Sha256 string `json:"sha256"` + Path string `json:"path"` + }{ + Sha256: hex.EncodeToString(s.Sha256), + Path: s.Path, + }) +} + +func (s *Shim) UnmarshalJSON(data []byte) error { + aux := &struct { + Sha256 string `json:"sha256"` + Path string `json:"path"` + }{} + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + s.Path = aux.Path + sha256, err := hex.DecodeString(aux.Sha256) + if err != nil { + return err + } + s.Sha256 = sha256 + return nil +} diff --git a/pkg/state/state.go b/pkg/state/state.go new file mode 100644 index 0000000..f22bcc8 --- /dev/null +++ b/pkg/state/state.go @@ -0,0 +1,62 @@ +package state + +import ( + "bytes" + "encoding/json" + "errors" + "log/slog" + "os" + "path" + + "github.com/kwasm/kwasm-node-installer/pkg/config" +) + +type state struct { + Shims map[string]*Shim `json:"shims"` + config *config.Config +} + +func Get(config *config.Config) (*state, error) { + out := state{ + Shims: make(map[string]*Shim), + config: config, + } + content, err := os.ReadFile(filePath(config)) + if err == nil { + err := json.Unmarshal(content, &out) + return &out, err + } + if !errors.Is(err, os.ErrNotExist) { + return nil, err + } + + return &out, nil +} + +func (l *state) ShimChanged(shimName string, sha256 []byte, path string) bool { + shim, ok := l.Shims[shimName] + if !ok { + return true + } + + return !bytes.Equal(shim.Sha256, sha256) || shim.Path != path +} + +func (l *state) UpdateShim(shimName string, shim Shim) { + l.Shims[shimName] = &shim +} + +func (l *state) Write() error { + out, err := json.MarshalIndent(l, "", " ") + if err != nil { + return err + } + + slog.Info("writing lock file", "content", string(out)) + + return os.WriteFile(filePath(l.config), out, 0644) +} + +func filePath(config *config.Config) string { + return config.PathWithHost(path.Join(config.Kwasm.Path, "kwasm-lock.json")) +} From 574fa41bb1263f95b5fbf80d5980c3b28d7cd930 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Tue, 16 Jan 2024 23:12:24 +0100 Subject: [PATCH 51/90] Switch back to single config and add delete Signed-off-by: Sven Pfennig --- cmd/install.go | 28 +++++++++++-- cmd/uninstall.go | 20 ++++++++- pkg/containerd/configure.go | 74 +++++++++++++++++++++++++++++---- pkg/shim/uninstall.go | 34 +++++++++++++++ pkg/state/state.go | 4 ++ test/etc/containerd/config.toml | 3 ++ 6 files changed, 151 insertions(+), 12 deletions(-) create mode 100644 pkg/shim/uninstall.go create mode 100644 test/etc/containerd/config.toml diff --git a/cmd/install.go b/cmd/install.go index 22e4dcd..a91416e 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -17,8 +17,11 @@ package cmd import ( + "fmt" + "io/fs" "log/slog" "os" + "path" "github.com/kwasm/kwasm-node-installer/pkg/containerd" "github.com/kwasm/kwasm-node-installer/pkg/shim" @@ -30,11 +33,28 @@ var installCmd = &cobra.Command{ Use: "install", Short: "Install containerd shims", Run: func(cmd *cobra.Command, args []string) { - files, err := os.ReadDir(config.Kwasm.AssetPath) + + // Get file or directory information. + info, err := os.Stat(config.Kwasm.AssetPath) if err != nil { - slog.Error(err.Error()) + fmt.Println(err) return } + + var files []fs.DirEntry + // Check if the path is a directory. + if info.IsDir() { + files, err = os.ReadDir(config.Kwasm.AssetPath) + if err != nil { + slog.Error(err.Error()) + return + } + } else { + // If the path is not a directory, add the file to the list of files. + files = append(files, fs.FileInfoToDirEntry(info)) + config.Kwasm.AssetPath = path.Dir(config.Kwasm.AssetPath) + } + anythingChanged := false for _, file := range files { fileName := file.Name() @@ -48,7 +68,7 @@ var installCmd = &cobra.Command{ anythingChanged = anythingChanged || changed slog.Info("shim installed", "shim", runtimeName, "path", binPath, "new-version", changed) - configPath, err := containerd.WriteConfig(&config, binPath) + configPath, err := containerd.AddRuntime(&config, binPath) if err != nil { slog.Error("failed to write containerd config", "shim", runtimeName, "path", configPath, "error", err) return @@ -70,6 +90,6 @@ var installCmd = &cobra.Command{ } func init() { - installCmd.Flags().StringVarP(&config.Kwasm.AssetPath, "asset-path", "a", "/assets", "Path to the binaries and libraries to install") + installCmd.Flags().StringVarP(&config.Kwasm.AssetPath, "asset-path", "a", "/assets", "Path to the asset to install") rootCmd.AddCommand(installCmd) } diff --git a/cmd/uninstall.go b/cmd/uninstall.go index 3d19e55..034cb86 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -18,8 +18,12 @@ package cmd import ( "log/slog" + "path" "github.com/spf13/cobra" + + "github.com/kwasm/kwasm-node-installer/pkg/containerd" + "github.com/kwasm/kwasm-node-installer/pkg/shim" ) // uninstallCmd represents the uninstall command @@ -27,7 +31,21 @@ var uninstallCmd = &cobra.Command{ Use: "uninstall", Short: "Uninstall containerd shims", Run: func(cmd *cobra.Command, args []string) { - slog.Info("install called", "config", config) + slog.Info("uninstall called", "config", config) + shimName := config.Runtime.Name + runtimeName := path.Join(config.Kwasm.Path, "bin", shimName) + + binPath, err := shim.Uninstall(&config, shimName) + if err != nil { + slog.Error("failed to uninstall shim", "shim", runtimeName, "error", err) + return + } + + configPath, err := containerd.RemoveRuntime(&config, binPath) + if err != nil { + slog.Error("failed to write containerd config", "shim", runtimeName, "path", configPath, "error", err) + return + } }, } diff --git a/pkg/containerd/configure.go b/pkg/containerd/configure.go index 1c7a082..fca866f 100644 --- a/pkg/containerd/configure.go +++ b/pkg/containerd/configure.go @@ -18,34 +18,94 @@ package containerd import ( "fmt" + "log" "os" "path" + "strings" "github.com/kwasm/kwasm-node-installer/pkg/config" "github.com/kwasm/kwasm-node-installer/pkg/shim" ) -func WriteConfig(config *config.Config, shimPath string) (string, error) { +func AddRuntime(config *config.Config, shimPath string) (string, error) { runtimeName := shim.RuntimeName(path.Base(shimPath)) cfg := generateConfig(shimPath, runtimeName) - configPath := path.Join(configDirectory(config), fmt.Sprintf("%s.%s", runtimeName, "toml")) + configPath := configDirectory(config) configHostPath := config.PathWithHost(configPath) - err := os.MkdirAll(path.Dir(configHostPath), 0755) + // Containerd config file needs to exist, otherwise return the error + data, err := os.ReadFile(configHostPath) if err != nil { return configPath, err } - return configPath, os.WriteFile(configHostPath, []byte(cfg), 0644) + // Fail if config.toml already contains the runtimeName + // Prevents corrupt config but could lead to unexpcted fails for the user. + // Maybe skipping existing config? + if strings.Contains(string(data), runtimeName) { + //return configPath, fmt.Errorf("config file %s already contains runtime config for '%s'", configPath, runtimeName) + log.Printf("runtime '%s' already exists, skipping", runtimeName) + return configPath, nil + } + + // Open file in append mode + file, err := os.OpenFile(configHostPath, os.O_APPEND|os.O_WRONLY, 0644) + if err != nil { + return configPath, err + } + defer file.Close() + + // Append config + _, err = file.WriteString(cfg) + if err != nil { + return configPath, err + } + + return configPath, nil +} + +func RemoveRuntime(config *config.Config, shimPath string) (string, error) { + runtimeName := shim.RuntimeName(path.Base(shimPath)) + + cfg := generateConfig(shimPath, runtimeName) + + configPath := configDirectory(config) + configHostPath := config.PathWithHost(configPath) + + // Containerd config file needs to exist, otherwise return the error + data, err := os.ReadFile(configHostPath) + if err != nil { + return configPath, err + } + + // Fail if config.toml does not contain the runtimeName + if !strings.Contains(string(data), runtimeName) { + return configPath, fmt.Errorf("config file %s does not contain a runtime config for '%s'", configPath, runtimeName) + } + + // Convert the file data to a string and replace the target string with an empty string. + modifiedData := strings.Replace(string(data), cfg, "", -1) + + // Write the modified data back to the file. + err = os.WriteFile(configHostPath, []byte(modifiedData), 0644) + if err != nil { + log.Fatal(err) + } + + return configPath, nil } func configDirectory(config *config.Config) string { - return path.Join(path.Dir(config.Runtime.ConfigPath), "conf.d") + //return path.Join(path.Dir(config.Runtime.ConfigPath), "conf.d") + return config.Runtime.ConfigPath } func generateConfig(shimPath string, runtimeName string) string { - return fmt.Sprintf(`[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.%s] -runtime_type = "%s"`, runtimeName, shimPath) + return fmt.Sprintf(` +# KWASM runtime config for %s +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.%s] +runtime_type = "%s" +`, runtimeName, runtimeName, shimPath) } diff --git a/pkg/shim/uninstall.go b/pkg/shim/uninstall.go new file mode 100644 index 0000000..98e309f --- /dev/null +++ b/pkg/shim/uninstall.go @@ -0,0 +1,34 @@ +package shim + +import ( + "fmt" + "os" + + "github.com/kwasm/kwasm-node-installer/pkg/config" + "github.com/kwasm/kwasm-node-installer/pkg/state" +) + +func Uninstall(config *config.Config, shimName string) (string, error) { + + st, err := state.Get(config) + if err != nil { + return "", err + } + s := st.Shims[shimName] + if s == nil { + return "", fmt.Errorf("shim '%s' not installed", shimName) + } + filePath := s.Path + filePathHost := config.PathWithHost(filePath) + + err = os.Remove(filePathHost) + if err != nil { + return "", err + } + + st.RemoveShim(shimName) + if err := st.Write(); err != nil { + return "", err + } + return filePath, err +} diff --git a/pkg/state/state.go b/pkg/state/state.go index f22bcc8..d491415 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -46,6 +46,10 @@ func (l *state) UpdateShim(shimName string, shim Shim) { l.Shims[shimName] = &shim } +func (l *state) RemoveShim(shimName string) { + delete(l.Shims, shimName) +} + func (l *state) Write() error { out, err := json.MarshalIndent(l, "", " ") if err != nil { diff --git a/test/etc/containerd/config.toml b/test/etc/containerd/config.toml new file mode 100644 index 0000000..7dcb123 --- /dev/null +++ b/test/etc/containerd/config.toml @@ -0,0 +1,3 @@ +###### +###### +###### From 7c9fb4d591bd6e8639f1f1bcf2b0910815937f03 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Tue, 20 Feb 2024 09:09:37 +0100 Subject: [PATCH 52/90] change containerd functions to methods --- cmd/install.go | 6 ++++-- cmd/uninstall.go | 4 +++- pkg/containerd/configure.go | 23 ++++++++++++++++------- pkg/containerd/restart.go | 2 +- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/cmd/install.go b/cmd/install.go index a91416e..5541433 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -55,6 +55,8 @@ var installCmd = &cobra.Command{ config.Kwasm.AssetPath = path.Dir(config.Kwasm.AssetPath) } + containerdConfig := containerd.NewConfig(&config) + anythingChanged := false for _, file := range files { fileName := file.Name() @@ -68,7 +70,7 @@ var installCmd = &cobra.Command{ anythingChanged = anythingChanged || changed slog.Info("shim installed", "shim", runtimeName, "path", binPath, "new-version", changed) - configPath, err := containerd.AddRuntime(&config, binPath) + configPath, err := containerdConfig.AddRuntime(binPath) if err != nil { slog.Error("failed to write containerd config", "shim", runtimeName, "path", configPath, "error", err) return @@ -82,7 +84,7 @@ var installCmd = &cobra.Command{ } slog.Info("restarting containerd") - err = containerd.RestartRuntime() + err = containerdConfig.RestartRuntime() if err != nil { slog.Error("failed to restart containerd", "error", err) } diff --git a/cmd/uninstall.go b/cmd/uninstall.go index 034cb86..8474a5c 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -35,13 +35,15 @@ var uninstallCmd = &cobra.Command{ shimName := config.Runtime.Name runtimeName := path.Join(config.Kwasm.Path, "bin", shimName) + containerdConfig := containerd.NewConfig(&config) + binPath, err := shim.Uninstall(&config, shimName) if err != nil { slog.Error("failed to uninstall shim", "shim", runtimeName, "error", err) return } - configPath, err := containerd.RemoveRuntime(&config, binPath) + configPath, err := containerdConfig.RemoveRuntime(binPath) if err != nil { slog.Error("failed to write containerd config", "shim", runtimeName, "path", configPath, "error", err) return diff --git a/pkg/containerd/configure.go b/pkg/containerd/configure.go index fca866f..d35f80f 100644 --- a/pkg/containerd/configure.go +++ b/pkg/containerd/configure.go @@ -27,13 +27,23 @@ import ( "github.com/kwasm/kwasm-node-installer/pkg/shim" ) -func AddRuntime(config *config.Config, shimPath string) (string, error) { +type Config struct { + config *config.Config +} + +func NewConfig(globalConfig *config.Config) *Config { + return &Config{ + config: globalConfig, + } +} + +func (c *Config) AddRuntime(shimPath string) (string, error) { runtimeName := shim.RuntimeName(path.Base(shimPath)) cfg := generateConfig(shimPath, runtimeName) - configPath := configDirectory(config) - configHostPath := config.PathWithHost(configPath) + configPath := configDirectory(c.config) + configHostPath := c.config.PathWithHost(configPath) // Containerd config file needs to exist, otherwise return the error data, err := os.ReadFile(configHostPath) @@ -66,13 +76,13 @@ func AddRuntime(config *config.Config, shimPath string) (string, error) { return configPath, nil } -func RemoveRuntime(config *config.Config, shimPath string) (string, error) { +func (c *Config) RemoveRuntime(shimPath string) (string, error) { runtimeName := shim.RuntimeName(path.Base(shimPath)) cfg := generateConfig(shimPath, runtimeName) - configPath := configDirectory(config) - configHostPath := config.PathWithHost(configPath) + configPath := configDirectory(c.config) + configHostPath := c.config.PathWithHost(configPath) // Containerd config file needs to exist, otherwise return the error data, err := os.ReadFile(configHostPath) @@ -98,7 +108,6 @@ func RemoveRuntime(config *config.Config, shimPath string) (string, error) { } func configDirectory(config *config.Config) string { - //return path.Join(path.Dir(config.Runtime.ConfigPath), "conf.d") return config.Runtime.ConfigPath } diff --git a/pkg/containerd/restart.go b/pkg/containerd/restart.go index 00dd741..a44d671 100644 --- a/pkg/containerd/restart.go +++ b/pkg/containerd/restart.go @@ -24,7 +24,7 @@ import ( "github.com/mitchellh/go-ps" ) -func RestartRuntime() error { +func (c *Config) RestartRuntime() error { pid, err := getPid() if err != nil { return err From 87e1477be941456f1beba7b1b9c78df610e21147 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Tue, 20 Feb 2024 09:10:00 +0100 Subject: [PATCH 53/90] change shim functions to methods --- cmd/install.go | 3 ++- cmd/uninstall.go | 3 ++- pkg/shim/install.go | 11 +++++------ pkg/shim/shim.go | 16 +++++++++++++++- pkg/shim/uninstall.go | 7 +++---- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/cmd/install.go b/cmd/install.go index 5541433..17861b0 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -56,13 +56,14 @@ var installCmd = &cobra.Command{ } containerdConfig := containerd.NewConfig(&config) + shimConfig := shim.NewConfig(&config) anythingChanged := false for _, file := range files { fileName := file.Name() runtimeName := shim.RuntimeName(fileName) - binPath, changed, err := shim.Install(&config, fileName) + binPath, changed, err := shimConfig.Install(fileName) if err != nil { slog.Error("failed to install shim", "shim", runtimeName, "error", err) return diff --git a/cmd/uninstall.go b/cmd/uninstall.go index 8474a5c..4020016 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -36,8 +36,9 @@ var uninstallCmd = &cobra.Command{ runtimeName := path.Join(config.Kwasm.Path, "bin", shimName) containerdConfig := containerd.NewConfig(&config) + shimConfig := shim.NewConfig(&config) - binPath, err := shim.Uninstall(&config, shimName) + binPath, err := shimConfig.Uninstall(shimName) if err != nil { slog.Error("failed to uninstall shim", "shim", runtimeName, "error", err) return diff --git a/pkg/shim/install.go b/pkg/shim/install.go index 0c519fb..50f14eb 100644 --- a/pkg/shim/install.go +++ b/pkg/shim/install.go @@ -22,18 +22,17 @@ import ( "os" "path" - "github.com/kwasm/kwasm-node-installer/pkg/config" "github.com/kwasm/kwasm-node-installer/pkg/state" ) -func Install(config *config.Config, shimName string) (string, bool, error) { - shimPath := config.AssetPath(shimName) +func (c *Config) Install(shimName string) (string, bool, error) { + shimPath := c.config.AssetPath(shimName) srcFile, err := os.OpenFile(shimPath, os.O_RDONLY, 0000) if err != nil { return "", false, err } - dstFilePath := path.Join(config.Kwasm.Path, "bin", shimName) - dstFilePathHost := config.PathWithHost(dstFilePath) + dstFilePath := path.Join(c.config.Kwasm.Path, "bin", shimName) + dstFilePathHost := c.config.PathWithHost(dstFilePath) err = os.MkdirAll(path.Dir(dstFilePathHost), 0755) if err != nil { @@ -45,7 +44,7 @@ func Install(config *config.Config, shimName string) (string, bool, error) { return "", false, err } - st, err := state.Get(config) + st, err := state.Get(c.config) if err != nil { return "", false, err } diff --git a/pkg/shim/shim.go b/pkg/shim/shim.go index 68b6af3..0f74f8a 100644 --- a/pkg/shim/shim.go +++ b/pkg/shim/shim.go @@ -16,7 +16,21 @@ package shim -import "strings" +import ( + "strings" + + "github.com/kwasm/kwasm-node-installer/pkg/config" +) + +type Config struct { + config *config.Config +} + +func NewConfig(globalConfig *config.Config) *Config { + return &Config{ + config: globalConfig, + } +} func RuntimeName(bin string) string { return strings.TrimPrefix(bin, "containerd-shim-") diff --git a/pkg/shim/uninstall.go b/pkg/shim/uninstall.go index 98e309f..429fdd0 100644 --- a/pkg/shim/uninstall.go +++ b/pkg/shim/uninstall.go @@ -4,13 +4,12 @@ import ( "fmt" "os" - "github.com/kwasm/kwasm-node-installer/pkg/config" "github.com/kwasm/kwasm-node-installer/pkg/state" ) -func Uninstall(config *config.Config, shimName string) (string, error) { +func (c *Config) Uninstall(shimName string) (string, error) { - st, err := state.Get(config) + st, err := state.Get(c.config) if err != nil { return "", err } @@ -19,7 +18,7 @@ func Uninstall(config *config.Config, shimName string) (string, error) { return "", fmt.Errorf("shim '%s' not installed", shimName) } filePath := s.Path - filePathHost := config.PathWithHost(filePath) + filePathHost := c.config.PathWithHost(filePath) err = os.Remove(filePathHost) if err != nil { From 373f76bf603946a26ab24babc4e61cb7b0ce5beb Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 26 Feb 2024 10:16:20 +0100 Subject: [PATCH 54/90] Make shim methods use afero Co-authored-by: Daniel Aberger --- cmd/install.go | 5 ++++- cmd/uninstall.go | 5 ++++- pkg/shim/install.go | 6 +++--- pkg/shim/shim.go | 5 ++++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cmd/install.go b/cmd/install.go index 17861b0..c344699 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -25,6 +25,7 @@ import ( "github.com/kwasm/kwasm-node-installer/pkg/containerd" "github.com/kwasm/kwasm-node-installer/pkg/shim" + "github.com/spf13/afero" "github.com/spf13/cobra" ) @@ -55,8 +56,10 @@ var installCmd = &cobra.Command{ config.Kwasm.AssetPath = path.Dir(config.Kwasm.AssetPath) } + rootFs := afero.NewOsFs() + containerdConfig := containerd.NewConfig(&config) - shimConfig := shim.NewConfig(&config) + shimConfig := shim.NewConfig(&config, rootFs) anythingChanged := false for _, file := range files { diff --git a/cmd/uninstall.go b/cmd/uninstall.go index 4020016..e5946b4 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -20,6 +20,7 @@ import ( "log/slog" "path" + "github.com/spf13/afero" "github.com/spf13/cobra" "github.com/kwasm/kwasm-node-installer/pkg/containerd" @@ -35,8 +36,10 @@ var uninstallCmd = &cobra.Command{ shimName := config.Runtime.Name runtimeName := path.Join(config.Kwasm.Path, "bin", shimName) + rootFs := afero.NewOsFs() + containerdConfig := containerd.NewConfig(&config) - shimConfig := shim.NewConfig(&config) + shimConfig := shim.NewConfig(&config, rootFs) binPath, err := shimConfig.Uninstall(shimName) if err != nil { diff --git a/pkg/shim/install.go b/pkg/shim/install.go index 50f14eb..ad935c5 100644 --- a/pkg/shim/install.go +++ b/pkg/shim/install.go @@ -27,19 +27,19 @@ import ( func (c *Config) Install(shimName string) (string, bool, error) { shimPath := c.config.AssetPath(shimName) - srcFile, err := os.OpenFile(shimPath, os.O_RDONLY, 0000) + srcFile, err := c.fs.OpenFile(shimPath, os.O_RDONLY, 0000) if err != nil { return "", false, err } dstFilePath := path.Join(c.config.Kwasm.Path, "bin", shimName) dstFilePathHost := c.config.PathWithHost(dstFilePath) - err = os.MkdirAll(path.Dir(dstFilePathHost), 0755) + err = c.fs.MkdirAll(path.Dir(dstFilePathHost), 0775) if err != nil { return dstFilePath, false, err } - dstFile, err := os.OpenFile(dstFilePathHost, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) + dstFile, err := c.fs.OpenFile(dstFilePathHost, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) if err != nil { return "", false, err } diff --git a/pkg/shim/shim.go b/pkg/shim/shim.go index 0f74f8a..67207ce 100644 --- a/pkg/shim/shim.go +++ b/pkg/shim/shim.go @@ -20,15 +20,18 @@ import ( "strings" "github.com/kwasm/kwasm-node-installer/pkg/config" + "github.com/spf13/afero" ) type Config struct { config *config.Config + fs afero.Fs } -func NewConfig(globalConfig *config.Config) *Config { +func NewConfig(globalConfig *config.Config, fs afero.Fs) *Config { return &Config{ config: globalConfig, + fs: fs, } } From 823b8fa0a8ac140fdb0dceee253a0fc0ff6e862b Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 26 Feb 2024 10:22:46 +0100 Subject: [PATCH 55/90] Make containerd config use afero --- cmd/install.go | 2 +- cmd/uninstall.go | 2 +- pkg/containerd/configure.go | 13 ++++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cmd/install.go b/cmd/install.go index c344699..54e934f 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -58,7 +58,7 @@ var installCmd = &cobra.Command{ rootFs := afero.NewOsFs() - containerdConfig := containerd.NewConfig(&config) + containerdConfig := containerd.NewConfig(&config, rootFs) shimConfig := shim.NewConfig(&config, rootFs) anythingChanged := false diff --git a/cmd/uninstall.go b/cmd/uninstall.go index e5946b4..fde0054 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -38,7 +38,7 @@ var uninstallCmd = &cobra.Command{ rootFs := afero.NewOsFs() - containerdConfig := containerd.NewConfig(&config) + containerdConfig := containerd.NewConfig(&config, rootFs) shimConfig := shim.NewConfig(&config, rootFs) binPath, err := shimConfig.Uninstall(shimName) diff --git a/pkg/containerd/configure.go b/pkg/containerd/configure.go index d35f80f..da619c7 100644 --- a/pkg/containerd/configure.go +++ b/pkg/containerd/configure.go @@ -25,15 +25,18 @@ import ( "github.com/kwasm/kwasm-node-installer/pkg/config" "github.com/kwasm/kwasm-node-installer/pkg/shim" + "github.com/spf13/afero" ) type Config struct { config *config.Config + fs afero.Fs } -func NewConfig(globalConfig *config.Config) *Config { +func NewConfig(globalConfig *config.Config, fs afero.Fs) *Config { return &Config{ config: globalConfig, + fs: fs, } } @@ -46,7 +49,7 @@ func (c *Config) AddRuntime(shimPath string) (string, error) { configHostPath := c.config.PathWithHost(configPath) // Containerd config file needs to exist, otherwise return the error - data, err := os.ReadFile(configHostPath) + data, err := afero.ReadFile(c.fs, configHostPath) if err != nil { return configPath, err } @@ -61,7 +64,7 @@ func (c *Config) AddRuntime(shimPath string) (string, error) { } // Open file in append mode - file, err := os.OpenFile(configHostPath, os.O_APPEND|os.O_WRONLY, 0644) + file, err := c.fs.OpenFile(configHostPath, os.O_APPEND|os.O_WRONLY, 0644) if err != nil { return configPath, err } @@ -85,7 +88,7 @@ func (c *Config) RemoveRuntime(shimPath string) (string, error) { configHostPath := c.config.PathWithHost(configPath) // Containerd config file needs to exist, otherwise return the error - data, err := os.ReadFile(configHostPath) + data, err := afero.ReadFile(c.fs, configHostPath) if err != nil { return configPath, err } @@ -99,7 +102,7 @@ func (c *Config) RemoveRuntime(shimPath string) (string, error) { modifiedData := strings.Replace(string(data), cfg, "", -1) // Write the modified data back to the file. - err = os.WriteFile(configHostPath, []byte(modifiedData), 0644) + err = afero.WriteFile(c.fs, configHostPath, []byte(modifiedData), 0644) if err != nil { log.Fatal(err) } From 5481fd356a8bd3c532880bf122c860449e6056b8 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 26 Feb 2024 10:59:26 +0100 Subject: [PATCH 56/90] Write tests for containerd config AddRuntime --- pkg/containerd/configure_test.go | 117 +++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 pkg/containerd/configure_test.go diff --git a/pkg/containerd/configure_test.go b/pkg/containerd/configure_test.go new file mode 100644 index 0000000..c505289 --- /dev/null +++ b/pkg/containerd/configure_test.go @@ -0,0 +1,117 @@ +/* + Copyright The KWasm Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package containerd + +import ( + "testing" + + "github.com/kwasm/kwasm-node-installer/pkg/config" + "github.com/spf13/afero" +) + +func newGlobalConfig(configFile string) *config.Config { + return &config.Config{ + Runtime: struct { + Name string + ConfigPath string + }{Name: "containerd", ConfigPath: configFile}, + } +} + +func TestConfig_AddRuntime(t *testing.T) { + type args struct { + shimPath string + } + tests := []struct { + name string + args args + configFile string + initialConfigFileContent string + createFile bool + wantErr bool + wantFileContent string + }{ + {"foobar", args{"/assets/foobar"}, "/etc/containerd/config.toml", "Hello World\n", true, false, + `Hello World + +# KWASM runtime config for foobar +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.foobar] +runtime_type = "/assets/foobar" +`}, + {"foobar", args{"/assets/foobar"}, "/etc/config.toml", "", false, true, ``}, + {"foobar", args{"/assets/foobar"}, "/etc/containerd/config.toml", `Hello World + +# KWASM runtime config for foobar +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.foobar] +runtime_type = "/assets/foobar" + +Foobar +`, true, false, + `Hello World + +# KWASM runtime config for foobar +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.foobar] +runtime_type = "/assets/foobar" + +Foobar +`}, + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + fs := afero.NewMemMapFs() + if tt.createFile { + file, err := fs.Create(tt.configFile) + if err != nil { + t.Fatal(err) + } + + _, err = file.WriteString(tt.initialConfigFileContent) + if err != nil { + t.Fatal(err) + } + } + + c := &Config{ + config: newGlobalConfig(tt.configFile), + fs: fs, + } + got, err := c.AddRuntime(tt.args.shimPath) + if (err != nil) != tt.wantErr { + t.Errorf("Config.AddRuntime() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != c.config.Runtime.ConfigPath { + t.Errorf("Config.AddRuntime() = %v, want %v", got, c.config.Runtime.ConfigPath) + } + + if tt.wantErr { + return + } + + gotFileContent, err := afero.ReadFile(fs, tt.configFile) + if err != nil { + t.Fatal(err) + } + + if string(gotFileContent) != tt.wantFileContent { + t.Errorf("runtimeConfigFile content: %v, want %v", string(gotFileContent), tt.wantFileContent) + } + + }) + } +} From 563479316ceaa85339df0a0f7f594295d92f2ed7 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 26 Feb 2024 16:00:17 +0100 Subject: [PATCH 57/90] refactor containerd config to not get the complete app config --- cmd/install.go | 8 ++--- cmd/uninstall.go | 6 ++-- pkg/containerd/configure.go | 51 +++++++++++++------------------- pkg/containerd/configure_test.go | 32 ++++++++++++-------- 4 files changed, 46 insertions(+), 51 deletions(-) diff --git a/cmd/install.go b/cmd/install.go index 54e934f..2f13b54 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -58,7 +58,7 @@ var installCmd = &cobra.Command{ rootFs := afero.NewOsFs() - containerdConfig := containerd.NewConfig(&config, rootFs) + containerdConfig := containerd.NewConfig(rootFs, config.Runtime.ConfigPath) shimConfig := shim.NewConfig(&config, rootFs) anythingChanged := false @@ -74,12 +74,12 @@ var installCmd = &cobra.Command{ anythingChanged = anythingChanged || changed slog.Info("shim installed", "shim", runtimeName, "path", binPath, "new-version", changed) - configPath, err := containerdConfig.AddRuntime(binPath) + err = containerdConfig.AddRuntime(binPath) if err != nil { - slog.Error("failed to write containerd config", "shim", runtimeName, "path", configPath, "error", err) + slog.Error("failed to write containerd config", "shim", runtimeName, "path", config.Runtime.ConfigPath, "error", err) return } - slog.Info("shim configured", "shim", runtimeName, "path", configPath) + slog.Info("shim configured", "shim", runtimeName, "path", config.Runtime.ConfigPath) } if !anythingChanged { diff --git a/cmd/uninstall.go b/cmd/uninstall.go index fde0054..98a05ed 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -38,7 +38,7 @@ var uninstallCmd = &cobra.Command{ rootFs := afero.NewOsFs() - containerdConfig := containerd.NewConfig(&config, rootFs) + containerdConfig := containerd.NewConfig(rootFs, config.Runtime.ConfigPath) shimConfig := shim.NewConfig(&config, rootFs) binPath, err := shimConfig.Uninstall(shimName) @@ -47,9 +47,9 @@ var uninstallCmd = &cobra.Command{ return } - configPath, err := containerdConfig.RemoveRuntime(binPath) + err = containerdConfig.RemoveRuntime(binPath) if err != nil { - slog.Error("failed to write containerd config", "shim", runtimeName, "path", configPath, "error", err) + slog.Error("failed to write containerd config", "shim", runtimeName, "path", config.Runtime.ConfigPath, "error", err) return } }, diff --git a/pkg/containerd/configure.go b/pkg/containerd/configure.go index da619c7..66a0e01 100644 --- a/pkg/containerd/configure.go +++ b/pkg/containerd/configure.go @@ -23,35 +23,31 @@ import ( "path" "strings" - "github.com/kwasm/kwasm-node-installer/pkg/config" "github.com/kwasm/kwasm-node-installer/pkg/shim" "github.com/spf13/afero" ) type Config struct { - config *config.Config - fs afero.Fs + fs afero.Fs + configPath string } -func NewConfig(globalConfig *config.Config, fs afero.Fs) *Config { +func NewConfig(fs afero.Fs, configPath string) *Config { return &Config{ - config: globalConfig, - fs: fs, + fs: fs, + configPath: configPath, } } -func (c *Config) AddRuntime(shimPath string) (string, error) { +func (c *Config) AddRuntime(shimPath string) error { runtimeName := shim.RuntimeName(path.Base(shimPath)) cfg := generateConfig(shimPath, runtimeName) - configPath := configDirectory(c.config) - configHostPath := c.config.PathWithHost(configPath) - // Containerd config file needs to exist, otherwise return the error - data, err := afero.ReadFile(c.fs, configHostPath) + data, err := afero.ReadFile(c.fs, c.configPath) if err != nil { - return configPath, err + return err } // Fail if config.toml already contains the runtimeName @@ -60,58 +56,51 @@ func (c *Config) AddRuntime(shimPath string) (string, error) { if strings.Contains(string(data), runtimeName) { //return configPath, fmt.Errorf("config file %s already contains runtime config for '%s'", configPath, runtimeName) log.Printf("runtime '%s' already exists, skipping", runtimeName) - return configPath, nil + return nil } // Open file in append mode - file, err := c.fs.OpenFile(configHostPath, os.O_APPEND|os.O_WRONLY, 0644) + file, err := c.fs.OpenFile(c.configPath, os.O_APPEND|os.O_WRONLY, 0644) if err != nil { - return configPath, err + return err } defer file.Close() // Append config _, err = file.WriteString(cfg) if err != nil { - return configPath, err + return err } - return configPath, nil + return nil } -func (c *Config) RemoveRuntime(shimPath string) (string, error) { +func (c *Config) RemoveRuntime(shimPath string) error { runtimeName := shim.RuntimeName(path.Base(shimPath)) cfg := generateConfig(shimPath, runtimeName) - configPath := configDirectory(c.config) - configHostPath := c.config.PathWithHost(configPath) - // Containerd config file needs to exist, otherwise return the error - data, err := afero.ReadFile(c.fs, configHostPath) + data, err := afero.ReadFile(c.fs, c.configPath) if err != nil { - return configPath, err + return err } // Fail if config.toml does not contain the runtimeName if !strings.Contains(string(data), runtimeName) { - return configPath, fmt.Errorf("config file %s does not contain a runtime config for '%s'", configPath, runtimeName) + return fmt.Errorf("config file %s does not contain a runtime config for '%s'", c.configPath, runtimeName) } // Convert the file data to a string and replace the target string with an empty string. modifiedData := strings.Replace(string(data), cfg, "", -1) // Write the modified data back to the file. - err = afero.WriteFile(c.fs, configHostPath, []byte(modifiedData), 0644) + err = afero.WriteFile(c.fs, c.configPath, []byte(modifiedData), 0644) if err != nil { - log.Fatal(err) + return err } - return configPath, nil -} - -func configDirectory(config *config.Config) string { - return config.Runtime.ConfigPath + return nil } func generateConfig(shimPath string, runtimeName string) string { diff --git a/pkg/containerd/configure_test.go b/pkg/containerd/configure_test.go index c505289..31fc7ba 100644 --- a/pkg/containerd/configure_test.go +++ b/pkg/containerd/configure_test.go @@ -17,18 +17,27 @@ package containerd import ( + "fmt" + "path/filepath" "testing" - "github.com/kwasm/kwasm-node-installer/pkg/config" "github.com/spf13/afero" ) -func newGlobalConfig(configFile string) *config.Config { - return &config.Config{ - Runtime: struct { - Name string - ConfigPath string - }{Name: "containerd", ConfigPath: configFile}, +func newTestFs(fixturePath string) afero.Fs { + baseFs := afero.NewBasePathFs(afero.NewOsFs(), filepath.Join("../..", fixturePath)) + p, _ := baseFs.(*afero.BasePathFs).RealPath("/") + fmt.Println(filepath.Abs(p)) + fs := afero.NewCopyOnWriteFs(baseFs, afero.NewMemMapFs()) + return fs +} + +func TestFs(t *testing.T) { + fs := newTestFs("testdata/containerd/valid") + + _, err := fs.Stat("/etc/containerd/config.toml") + if err != nil { + t.Error(err) } } @@ -87,17 +96,14 @@ Foobar } c := &Config{ - config: newGlobalConfig(tt.configFile), - fs: fs, + configPath: "/etc/containerd/config.toml", + fs: fs, } - got, err := c.AddRuntime(tt.args.shimPath) + err := c.AddRuntime(tt.args.shimPath) if (err != nil) != tt.wantErr { t.Errorf("Config.AddRuntime() error = %v, wantErr %v", err, tt.wantErr) return } - if got != c.config.Runtime.ConfigPath { - t.Errorf("Config.AddRuntime() = %v, want %v", got, c.config.Runtime.ConfigPath) - } if tt.wantErr { return From a4702d99e16c58ab5f07ff2280aa2b81fa913534 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 26 Feb 2024 16:35:29 +0100 Subject: [PATCH 58/90] refactor shim config to not get the complete app config --- cmd/install.go | 5 ++- cmd/uninstall.go | 5 ++- pkg/containerd/configure.go | 4 +- pkg/shim/install.go | 14 +++---- pkg/shim/shim.go | 15 ++++--- pkg/shim/uninstall.go | 6 +-- pkg/state/state.go | 24 +++++------ .../valid/assets/containerd-shim-spin-v1 | 3 ++ .../valid/etc/containerd/config.toml | 42 +++++++++++++++++++ 9 files changed, 82 insertions(+), 36 deletions(-) create mode 100644 testdata/containerd/valid/assets/containerd-shim-spin-v1 create mode 100644 testdata/containerd/valid/etc/containerd/config.toml diff --git a/cmd/install.go b/cmd/install.go index 2f13b54..6d3c010 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -57,9 +57,10 @@ var installCmd = &cobra.Command{ } rootFs := afero.NewOsFs() + hostFs := afero.NewBasePathFs(rootFs, config.Host.RootPath) - containerdConfig := containerd.NewConfig(rootFs, config.Runtime.ConfigPath) - shimConfig := shim.NewConfig(&config, rootFs) + containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath) + shimConfig := shim.NewConfig(rootFs, hostFs, config.Kwasm.AssetPath, config.Kwasm.Path) anythingChanged := false for _, file := range files { diff --git a/cmd/uninstall.go b/cmd/uninstall.go index 98a05ed..4433d06 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -37,9 +37,10 @@ var uninstallCmd = &cobra.Command{ runtimeName := path.Join(config.Kwasm.Path, "bin", shimName) rootFs := afero.NewOsFs() + hostFs := afero.NewBasePathFs(rootFs, config.Host.RootPath) - containerdConfig := containerd.NewConfig(rootFs, config.Runtime.ConfigPath) - shimConfig := shim.NewConfig(&config, rootFs) + containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath) + shimConfig := shim.NewConfig(rootFs, hostFs, config.Kwasm.AssetPath, config.Kwasm.Path) binPath, err := shimConfig.Uninstall(shimName) if err != nil { diff --git a/pkg/containerd/configure.go b/pkg/containerd/configure.go index 66a0e01..f3ac9a6 100644 --- a/pkg/containerd/configure.go +++ b/pkg/containerd/configure.go @@ -18,7 +18,7 @@ package containerd import ( "fmt" - "log" + "log/slog" "os" "path" "strings" @@ -55,7 +55,7 @@ func (c *Config) AddRuntime(shimPath string) error { // Maybe skipping existing config? if strings.Contains(string(data), runtimeName) { //return configPath, fmt.Errorf("config file %s already contains runtime config for '%s'", configPath, runtimeName) - log.Printf("runtime '%s' already exists, skipping", runtimeName) + slog.Info(fmt.Sprintf("config for runtime '%s' already exists, skipping", runtimeName)) return nil } diff --git a/pkg/shim/install.go b/pkg/shim/install.go index ad935c5..c6c35a2 100644 --- a/pkg/shim/install.go +++ b/pkg/shim/install.go @@ -21,30 +21,30 @@ import ( "io" "os" "path" + "path/filepath" "github.com/kwasm/kwasm-node-installer/pkg/state" ) func (c *Config) Install(shimName string) (string, bool, error) { - shimPath := c.config.AssetPath(shimName) - srcFile, err := c.fs.OpenFile(shimPath, os.O_RDONLY, 0000) + shimPath := filepath.Join(c.assetPath, shimName) + srcFile, err := c.rootFs.OpenFile(shimPath, os.O_RDONLY, 0000) if err != nil { return "", false, err } - dstFilePath := path.Join(c.config.Kwasm.Path, "bin", shimName) - dstFilePathHost := c.config.PathWithHost(dstFilePath) + dstFilePath := path.Join(c.kwasmPath, "bin", shimName) - err = c.fs.MkdirAll(path.Dir(dstFilePathHost), 0775) + err = c.hostFs.MkdirAll(path.Dir(dstFilePath), 0775) if err != nil { return dstFilePath, false, err } - dstFile, err := c.fs.OpenFile(dstFilePathHost, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) + dstFile, err := c.hostFs.OpenFile(dstFilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) if err != nil { return "", false, err } - st, err := state.Get(c.config) + st, err := state.Get(c.hostFs, c.kwasmPath) if err != nil { return "", false, err } diff --git a/pkg/shim/shim.go b/pkg/shim/shim.go index 67207ce..5666835 100644 --- a/pkg/shim/shim.go +++ b/pkg/shim/shim.go @@ -19,19 +19,22 @@ package shim import ( "strings" - "github.com/kwasm/kwasm-node-installer/pkg/config" "github.com/spf13/afero" ) type Config struct { - config *config.Config - fs afero.Fs + rootFs afero.Fs + hostFs afero.Fs + assetPath string + kwasmPath string } -func NewConfig(globalConfig *config.Config, fs afero.Fs) *Config { +func NewConfig(rootFs afero.Fs, hostFs afero.Fs, assetPath string, kwasmPath string) *Config { return &Config{ - config: globalConfig, - fs: fs, + rootFs: rootFs, + hostFs: hostFs, + assetPath: assetPath, + kwasmPath: kwasmPath, } } diff --git a/pkg/shim/uninstall.go b/pkg/shim/uninstall.go index 429fdd0..6b7f368 100644 --- a/pkg/shim/uninstall.go +++ b/pkg/shim/uninstall.go @@ -2,14 +2,13 @@ package shim import ( "fmt" - "os" "github.com/kwasm/kwasm-node-installer/pkg/state" ) func (c *Config) Uninstall(shimName string) (string, error) { - st, err := state.Get(c.config) + st, err := state.Get(c.hostFs, c.kwasmPath) if err != nil { return "", err } @@ -18,9 +17,8 @@ func (c *Config) Uninstall(shimName string) (string, error) { return "", fmt.Errorf("shim '%s' not installed", shimName) } filePath := s.Path - filePathHost := c.config.PathWithHost(filePath) - err = os.Remove(filePathHost) + err = c.hostFs.Remove(filePath) if err != nil { return "", err } diff --git a/pkg/state/state.go b/pkg/state/state.go index d491415..606bd9c 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -6,22 +6,24 @@ import ( "errors" "log/slog" "os" - "path" + "path/filepath" - "github.com/kwasm/kwasm-node-installer/pkg/config" + "github.com/spf13/afero" ) type state struct { - Shims map[string]*Shim `json:"shims"` - config *config.Config + Shims map[string]*Shim `json:"shims"` + fs afero.Fs + lockFilePath string } -func Get(config *config.Config) (*state, error) { +func Get(fs afero.Fs, kwasmPath string) (*state, error) { out := state{ - Shims: make(map[string]*Shim), - config: config, + Shims: make(map[string]*Shim), + lockFilePath: filepath.Join(kwasmPath, "kwasm-lock.json"), + fs: fs, } - content, err := os.ReadFile(filePath(config)) + content, err := afero.ReadFile(fs, out.lockFilePath) if err == nil { err := json.Unmarshal(content, &out) return &out, err @@ -58,9 +60,5 @@ func (l *state) Write() error { slog.Info("writing lock file", "content", string(out)) - return os.WriteFile(filePath(l.config), out, 0644) -} - -func filePath(config *config.Config) string { - return config.PathWithHost(path.Join(config.Kwasm.Path, "kwasm-lock.json")) + return afero.WriteFile(l.fs, l.lockFilePath, out, 0644) } diff --git a/testdata/containerd/valid/assets/containerd-shim-spin-v1 b/testdata/containerd/valid/assets/containerd-shim-spin-v1 new file mode 100644 index 0000000..2eea022 --- /dev/null +++ b/testdata/containerd/valid/assets/containerd-shim-spin-v1 @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +echo "Hello from spin shim" \ No newline at end of file diff --git a/testdata/containerd/valid/etc/containerd/config.toml b/testdata/containerd/valid/etc/containerd/config.toml new file mode 100644 index 0000000..a7cd1de --- /dev/null +++ b/testdata/containerd/valid/etc/containerd/config.toml @@ -0,0 +1,42 @@ +version = 2 + +root = "/var/lib/containerd" +state = "/run/containerd" +oom_score = 0 +imports = ["/etc/containerd/runtime_*.toml", "./debug.toml"] + +[grpc] + address = "/run/containerd/containerd.sock" + uid = 0 + gid = 0 + +[debug] + address = "/run/containerd/debug.sock" + uid = 0 + gid = 0 + level = "info" + +[metrics] + address = "" + grpc_histogram = false + +[cgroup] + path = "" + +[plugins] + [plugins."io.containerd.monitor.v1.cgroups"] + no_prometheus = false + [plugins."io.containerd.service.v1.diff-service"] + default = ["walking"] + [plugins."io.containerd.gc.v1.scheduler"] + pause_threshold = 0.02 + deletion_threshold = 0 + mutation_threshold = 100 + schedule_delay = 0 + startup_delay = "100ms" + [plugins."io.containerd.runtime.v2.task"] + platforms = ["linux/amd64"] + sched_core = true + [plugins."io.containerd.service.v1.tasks-service"] + blockio_config_file = "" + rdt_config_file = "" \ No newline at end of file From ed36f8606292872b83649272a35b4d4bba7ac56d Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 26 Feb 2024 17:15:04 +0100 Subject: [PATCH 59/90] use test fixtures in containerd config tests --- pkg/containerd/configure.go | 14 +- pkg/containerd/configure_test.go | 138 +++++++++--------- .../valid => }/assets/containerd-shim-spin-v1 | 0 .../etc/containerd/config.toml | 31 +--- .../etc/containerd/.gitkeep | 0 .../etc/containerd/config.toml | 17 +++ 6 files changed, 100 insertions(+), 100 deletions(-) rename testdata/{containerd/valid => }/assets/containerd-shim-spin-v1 (100%) rename testdata/containerd/{valid => existing-containerd-shim-config}/etc/containerd/config.toml (56%) create mode 100644 testdata/containerd/missing-containerd-config/etc/containerd/.gitkeep create mode 100644 testdata/containerd/missing-containerd-shim-config/etc/containerd/config.toml diff --git a/pkg/containerd/configure.go b/pkg/containerd/configure.go index f3ac9a6..ef6fcaf 100644 --- a/pkg/containerd/configure.go +++ b/pkg/containerd/configure.go @@ -28,13 +28,13 @@ import ( ) type Config struct { - fs afero.Fs + hostFs afero.Fs configPath string } -func NewConfig(fs afero.Fs, configPath string) *Config { +func NewConfig(hostFs afero.Fs, configPath string) *Config { return &Config{ - fs: fs, + hostFs: hostFs, configPath: configPath, } } @@ -45,7 +45,7 @@ func (c *Config) AddRuntime(shimPath string) error { cfg := generateConfig(shimPath, runtimeName) // Containerd config file needs to exist, otherwise return the error - data, err := afero.ReadFile(c.fs, c.configPath) + data, err := afero.ReadFile(c.hostFs, c.configPath) if err != nil { return err } @@ -60,7 +60,7 @@ func (c *Config) AddRuntime(shimPath string) error { } // Open file in append mode - file, err := c.fs.OpenFile(c.configPath, os.O_APPEND|os.O_WRONLY, 0644) + file, err := c.hostFs.OpenFile(c.configPath, os.O_APPEND|os.O_WRONLY, 0644) if err != nil { return err } @@ -81,7 +81,7 @@ func (c *Config) RemoveRuntime(shimPath string) error { cfg := generateConfig(shimPath, runtimeName) // Containerd config file needs to exist, otherwise return the error - data, err := afero.ReadFile(c.fs, c.configPath) + data, err := afero.ReadFile(c.hostFs, c.configPath) if err != nil { return err } @@ -95,7 +95,7 @@ func (c *Config) RemoveRuntime(shimPath string) error { modifiedData := strings.Replace(string(data), cfg, "", -1) // Write the modified data back to the file. - err = afero.WriteFile(c.fs, c.configPath, []byte(modifiedData), 0644) + err = afero.WriteFile(c.hostFs, c.configPath, []byte(modifiedData), 0644) if err != nil { return err } diff --git a/pkg/containerd/configure_test.go b/pkg/containerd/configure_test.go index 31fc7ba..86f733e 100644 --- a/pkg/containerd/configure_test.go +++ b/pkg/containerd/configure_test.go @@ -24,7 +24,7 @@ import ( "github.com/spf13/afero" ) -func newTestFs(fixturePath string) afero.Fs { +func newFixtureFs(fixturePath string) afero.Fs { baseFs := afero.NewBasePathFs(afero.NewOsFs(), filepath.Join("../..", fixturePath)) p, _ := baseFs.(*afero.BasePathFs).RealPath("/") fmt.Println(filepath.Abs(p)) @@ -32,92 +32,96 @@ func newTestFs(fixturePath string) afero.Fs { return fs } -func TestFs(t *testing.T) { - fs := newTestFs("testdata/containerd/valid") - - _, err := fs.Stat("/etc/containerd/config.toml") - if err != nil { - t.Error(err) - } -} - func TestConfig_AddRuntime(t *testing.T) { + type fields struct { + hostFs afero.Fs + configPath string + } type args struct { shimPath string } tests := []struct { - name string - args args - configFile string - initialConfigFileContent string - createFile bool - wantErr bool - wantFileContent string + name string + fields fields + args args + wantErr bool + wantFileErr bool + wantFileContent string }{ - {"foobar", args{"/assets/foobar"}, "/etc/containerd/config.toml", "Hello World\n", true, false, - `Hello World - -# KWASM runtime config for foobar -[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.foobar] -runtime_type = "/assets/foobar" + {"missing shim config", fields{ + hostFs: newFixtureFs("testdata/containerd/missing-containerd-shim-config"), + configPath: "/etc/containerd/config.toml", + }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, false, `[plugins] + [plugins."io.containerd.monitor.v1.cgroups"] + no_prometheus = false + [plugins."io.containerd.service.v1.diff-service"] + default = ["walking"] + [plugins."io.containerd.gc.v1.scheduler"] + pause_threshold = 0.02 + deletion_threshold = 0 + mutation_threshold = 100 + schedule_delay = 0 + startup_delay = "100ms" + [plugins."io.containerd.runtime.v2.task"] + platforms = ["linux/amd64"] + sched_core = true + [plugins."io.containerd.service.v1.tasks-service"] + blockio_config_file = "" + rdt_config_file = "" + +# KWASM runtime config for spin-v1 +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.spin-v1] +runtime_type = "/opt/kwasm/bin/containerd-shim-spin-v1" `}, - {"foobar", args{"/assets/foobar"}, "/etc/config.toml", "", false, true, ``}, - {"foobar", args{"/assets/foobar"}, "/etc/containerd/config.toml", `Hello World - -# KWASM runtime config for foobar -[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.foobar] -runtime_type = "/assets/foobar" - -Foobar -`, true, false, - `Hello World - -# KWASM runtime config for foobar -[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.foobar] -runtime_type = "/assets/foobar" - -Foobar + {"missing config", fields{ + hostFs: newFixtureFs("testdata/containerd/missing-containerd-config"), + configPath: "/etc/containerd/config.toml", + }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, true, true, ``}, + {"existing shim config", fields{ + hostFs: newFixtureFs("testdata/containerd/existing-containerd-shim-config"), + configPath: "/etc/containerd/config.toml", + }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, false, `[plugins] + [plugins."io.containerd.monitor.v1.cgroups"] + no_prometheus = false + [plugins."io.containerd.service.v1.diff-service"] + default = ["walking"] + [plugins."io.containerd.gc.v1.scheduler"] + pause_threshold = 0.02 + deletion_threshold = 0 + mutation_threshold = 100 + schedule_delay = 0 + startup_delay = "100ms" + [plugins."io.containerd.runtime.v2.task"] + platforms = ["linux/amd64"] + sched_core = true + [plugins."io.containerd.service.v1.tasks-service"] + blockio_config_file = "" + rdt_config_file = "" + +# KWASM runtime config for spin-v1 +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.spin-v1] +runtime_type = "/opt/kwasm/bin/containerd-shim-spin-v1" `}, - // TODO: Add test cases. } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - fs := afero.NewMemMapFs() - if tt.createFile { - file, err := fs.Create(tt.configFile) - if err != nil { - t.Fatal(err) - } - - _, err = file.WriteString(tt.initialConfigFileContent) - if err != nil { - t.Fatal(err) - } - } - c := &Config{ - configPath: "/etc/containerd/config.toml", - fs: fs, + hostFs: tt.fields.hostFs, + configPath: tt.fields.configPath, } - err := c.AddRuntime(tt.args.shimPath) - if (err != nil) != tt.wantErr { + if err := c.AddRuntime(tt.args.shimPath); (err != nil) != tt.wantErr { t.Errorf("Config.AddRuntime() error = %v, wantErr %v", err, tt.wantErr) - return } - if tt.wantErr { + gotContent, err := afero.ReadFile(c.hostFs, c.configPath) + if (err != nil) != tt.wantFileErr { + t.Errorf("read %s error = %v, wantFileErr %v", c.configPath, err, tt.wantFileErr) return } - gotFileContent, err := afero.ReadFile(fs, tt.configFile) - if err != nil { - t.Fatal(err) - } - - if string(gotFileContent) != tt.wantFileContent { - t.Errorf("runtimeConfigFile content: %v, want %v", string(gotFileContent), tt.wantFileContent) + if string(gotContent) != tt.wantFileContent { + t.Errorf("file content %s got = %s, want = %s", c.configPath, string(gotContent), tt.wantFileContent) } - }) } } diff --git a/testdata/containerd/valid/assets/containerd-shim-spin-v1 b/testdata/assets/containerd-shim-spin-v1 similarity index 100% rename from testdata/containerd/valid/assets/containerd-shim-spin-v1 rename to testdata/assets/containerd-shim-spin-v1 diff --git a/testdata/containerd/valid/etc/containerd/config.toml b/testdata/containerd/existing-containerd-shim-config/etc/containerd/config.toml similarity index 56% rename from testdata/containerd/valid/etc/containerd/config.toml rename to testdata/containerd/existing-containerd-shim-config/etc/containerd/config.toml index a7cd1de..927d258 100644 --- a/testdata/containerd/valid/etc/containerd/config.toml +++ b/testdata/containerd/existing-containerd-shim-config/etc/containerd/config.toml @@ -1,28 +1,3 @@ -version = 2 - -root = "/var/lib/containerd" -state = "/run/containerd" -oom_score = 0 -imports = ["/etc/containerd/runtime_*.toml", "./debug.toml"] - -[grpc] - address = "/run/containerd/containerd.sock" - uid = 0 - gid = 0 - -[debug] - address = "/run/containerd/debug.sock" - uid = 0 - gid = 0 - level = "info" - -[metrics] - address = "" - grpc_histogram = false - -[cgroup] - path = "" - [plugins] [plugins."io.containerd.monitor.v1.cgroups"] no_prometheus = false @@ -39,4 +14,8 @@ imports = ["/etc/containerd/runtime_*.toml", "./debug.toml"] sched_core = true [plugins."io.containerd.service.v1.tasks-service"] blockio_config_file = "" - rdt_config_file = "" \ No newline at end of file + rdt_config_file = "" + +# KWASM runtime config for spin-v1 +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.spin-v1] +runtime_type = "/opt/kwasm/bin/containerd-shim-spin-v1" diff --git a/testdata/containerd/missing-containerd-config/etc/containerd/.gitkeep b/testdata/containerd/missing-containerd-config/etc/containerd/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/testdata/containerd/missing-containerd-shim-config/etc/containerd/config.toml b/testdata/containerd/missing-containerd-shim-config/etc/containerd/config.toml new file mode 100644 index 0000000..3389a42 --- /dev/null +++ b/testdata/containerd/missing-containerd-shim-config/etc/containerd/config.toml @@ -0,0 +1,17 @@ +[plugins] + [plugins."io.containerd.monitor.v1.cgroups"] + no_prometheus = false + [plugins."io.containerd.service.v1.diff-service"] + default = ["walking"] + [plugins."io.containerd.gc.v1.scheduler"] + pause_threshold = 0.02 + deletion_threshold = 0 + mutation_threshold = 100 + schedule_delay = 0 + startup_delay = "100ms" + [plugins."io.containerd.runtime.v2.task"] + platforms = ["linux/amd64"] + sched_core = true + [plugins."io.containerd.service.v1.tasks-service"] + blockio_config_file = "" + rdt_config_file = "" From b9bb64b983262bb2199a172ecfbb97459988e7de Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 26 Feb 2024 17:20:00 +0100 Subject: [PATCH 60/90] add tests for RemoveRuntime --- pkg/containerd/configure.go | 10 ++-- pkg/containerd/configure_test.go | 86 ++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 6 deletions(-) diff --git a/pkg/containerd/configure.go b/pkg/containerd/configure.go index ef6fcaf..8b1df26 100644 --- a/pkg/containerd/configure.go +++ b/pkg/containerd/configure.go @@ -50,11 +50,8 @@ func (c *Config) AddRuntime(shimPath string) error { return err } - // Fail if config.toml already contains the runtimeName - // Prevents corrupt config but could lead to unexpcted fails for the user. - // Maybe skipping existing config? + // Warn if config.toml already contains runtimeName if strings.Contains(string(data), runtimeName) { - //return configPath, fmt.Errorf("config file %s already contains runtime config for '%s'", configPath, runtimeName) slog.Info(fmt.Sprintf("config for runtime '%s' already exists, skipping", runtimeName)) return nil } @@ -86,9 +83,10 @@ func (c *Config) RemoveRuntime(shimPath string) error { return err } - // Fail if config.toml does not contain the runtimeName + // Warn if config.toml does not contain the runtimeName if !strings.Contains(string(data), runtimeName) { - return fmt.Errorf("config file %s does not contain a runtime config for '%s'", c.configPath, runtimeName) + slog.Warn(fmt.Sprintf("config for runtime '%s' does not exist, skipping", runtimeName)) + return nil } // Convert the file data to a string and replace the target string with an empty string. diff --git a/pkg/containerd/configure_test.go b/pkg/containerd/configure_test.go index 86f733e..b4ad8f1 100644 --- a/pkg/containerd/configure_test.go +++ b/pkg/containerd/configure_test.go @@ -125,3 +125,89 @@ runtime_type = "/opt/kwasm/bin/containerd-shim-spin-v1" }) } } + +func TestConfig_RemoveRuntime(t *testing.T) { + type fields struct { + hostFs afero.Fs + configPath string + } + type args struct { + shimPath string + } + tests := []struct { + name string + fields fields + args args + wantErr bool + wantFileErr bool + wantFileContent string + }{ + {"missing shim config", fields{ + hostFs: newFixtureFs("testdata/containerd/missing-containerd-shim-config"), + configPath: "/etc/containerd/config.toml", + }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, false, `[plugins] + [plugins."io.containerd.monitor.v1.cgroups"] + no_prometheus = false + [plugins."io.containerd.service.v1.diff-service"] + default = ["walking"] + [plugins."io.containerd.gc.v1.scheduler"] + pause_threshold = 0.02 + deletion_threshold = 0 + mutation_threshold = 100 + schedule_delay = 0 + startup_delay = "100ms" + [plugins."io.containerd.runtime.v2.task"] + platforms = ["linux/amd64"] + sched_core = true + [plugins."io.containerd.service.v1.tasks-service"] + blockio_config_file = "" + rdt_config_file = "" +`}, + {"missing config", fields{ + hostFs: newFixtureFs("testdata/containerd/missing-containerd-config"), + configPath: "/etc/containerd/config.toml", + }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, true, true, ``}, + {"existing shim config", fields{ + hostFs: newFixtureFs("testdata/containerd/existing-containerd-shim-config"), + configPath: "/etc/containerd/config.toml", + }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, false, `[plugins] + [plugins."io.containerd.monitor.v1.cgroups"] + no_prometheus = false + [plugins."io.containerd.service.v1.diff-service"] + default = ["walking"] + [plugins."io.containerd.gc.v1.scheduler"] + pause_threshold = 0.02 + deletion_threshold = 0 + mutation_threshold = 100 + schedule_delay = 0 + startup_delay = "100ms" + [plugins."io.containerd.runtime.v2.task"] + platforms = ["linux/amd64"] + sched_core = true + [plugins."io.containerd.service.v1.tasks-service"] + blockio_config_file = "" + rdt_config_file = "" +`}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c := &Config{ + hostFs: tt.fields.hostFs, + configPath: tt.fields.configPath, + } + if err := c.RemoveRuntime(tt.args.shimPath); (err != nil) != tt.wantErr { + t.Errorf("Config.RemoveRuntime() error = %v, wantErr %v", err, tt.wantErr) + } + + gotContent, err := afero.ReadFile(c.hostFs, c.configPath) + if (err != nil) != tt.wantFileErr { + t.Errorf("read %s error = %v, wantFileErr %v", c.configPath, err, tt.wantFileErr) + return + } + + if string(gotContent) != tt.wantFileContent { + t.Errorf("file content %s got = %s, want = %s", c.configPath, string(gotContent), tt.wantFileContent) + } + }) + } +} From 2359ca6e36ab7a53be408110037adbca0d46495e Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 26 Feb 2024 17:38:51 +0100 Subject: [PATCH 61/90] create shim tests --- pkg/state/shim.go | 2 +- pkg/state/shim_test.go | 69 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 pkg/state/shim_test.go diff --git a/pkg/state/shim.go b/pkg/state/shim.go index eb00401..46addcd 100644 --- a/pkg/state/shim.go +++ b/pkg/state/shim.go @@ -21,7 +21,7 @@ func (s *Shim) MarshalJSON() ([]byte, error) { } func (s *Shim) UnmarshalJSON(data []byte) error { - aux := &struct { + aux := struct { Sha256 string `json:"sha256"` Path string `json:"path"` }{} diff --git a/pkg/state/shim_test.go b/pkg/state/shim_test.go new file mode 100644 index 0000000..57c9ebe --- /dev/null +++ b/pkg/state/shim_test.go @@ -0,0 +1,69 @@ +package state + +import ( + "testing" +) + +func TestShim_MarshalJSON(t *testing.T) { + type fields struct { + Sha256 []byte + Path string + } + tests := []struct { + name string + fields fields + want string + wantErr bool + }{ + {"default", fields{Sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, Path: "/opt/kwasm/bin/containerd-shim-spin-v1"}, `{"sha256":"6da5e8f17a9bfa9cb04cf22c87b6475394ecec3af4fdc337f72d6dbf3319ea52","path":"/opt/kwasm/bin/containerd-shim-spin-v1"}`, false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + s := &Shim{ + Sha256: tt.fields.Sha256, + Path: tt.fields.Path, + } + got, err := s.MarshalJSON() + if (err != nil) != tt.wantErr { + t.Errorf("Shim.MarshalJSON() error = %v, wantErr %v", err, tt.wantErr) + return + } + if string(got) != string(tt.want) { + t.Errorf("Shim.MarshalJSON() = %v, want %v", string(got), tt.want) + } + }) + } +} + +func TestShim_UnmarshalJSON(t *testing.T) { + type wants struct { + path string + sha256 []byte + } + type args struct { + data string + } + tests := []struct { + name string + args args + want wants + wantErr bool + }{ + {"default", args{`{"sha256":"6da5e8f17a9bfa9cb04cf22c87b6475394ecec3af4fdc337f72d6dbf3319ea52","path":"/opt/kwasm/bin/containerd-shim-spin-v1"}`}, wants{path: "/opt/kwasm/bin/containerd-shim-spin-v1", sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}}, false}, + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + s := Shim{} + if err := s.UnmarshalJSON([]byte(tt.args.data)); (err != nil) != tt.wantErr { + t.Errorf("Shim.UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr) + } + if string(s.Path) != string(tt.want.path) { + t.Errorf("path = %v, want %v", string(s.Path), tt.want.path) + } + if string(s.Sha256) != string(tt.want.sha256) { + t.Errorf("sha256 = %v, want %v", string(s.Sha256), tt.want.sha256) + } + }) + } +} From 4ec5272f6b2091081fb40c3a43911776dc31a97a Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 26 Feb 2024 17:59:58 +0100 Subject: [PATCH 62/90] add tests for state.Get --- pkg/state/state_test.go | 48 +++++++++++++++++++ .../opt/kwasm/bin/containerd-shim-spin-v1 | 3 ++ .../opt/kwasm/kwasm-lock.json | 8 ++++ 3 files changed, 59 insertions(+) create mode 100644 pkg/state/state_test.go create mode 100644 testdata/containerd/existing-containerd-shim-config/opt/kwasm/bin/containerd-shim-spin-v1 create mode 100644 testdata/containerd/existing-containerd-shim-config/opt/kwasm/kwasm-lock.json diff --git a/pkg/state/state_test.go b/pkg/state/state_test.go new file mode 100644 index 0000000..04fe2ae --- /dev/null +++ b/pkg/state/state_test.go @@ -0,0 +1,48 @@ +package state + +import ( + "fmt" + "path/filepath" + "reflect" + "testing" + + "github.com/spf13/afero" +) + +func newFixtureFs(fixturePath string) afero.Fs { + baseFs := afero.NewBasePathFs(afero.NewOsFs(), filepath.Join("../..", fixturePath)) + p, _ := baseFs.(*afero.BasePathFs).RealPath("/") + fmt.Println(filepath.Abs(p)) + fs := afero.NewCopyOnWriteFs(baseFs, afero.NewMemMapFs()) + return fs +} + +func TestGet(t *testing.T) { + type args struct { + fs afero.Fs + kwasmPath string + } + tests := []struct { + name string + args args + want *state + wantErr bool + }{ + {"existing state", args{newFixtureFs("testdata/containerd/existing-containerd-shim-config"), "/opt/kwasm"}, &state{Shims: map[string]*Shim{ + "spin-v1": {Sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, Path: "/opt/kwasm/bin/containerd-shim-spin-v1"}, + }}, false}, + {"missing state", args{newFixtureFs("testdata/containerd/missing-containerd-shim-config"), "/opt/kwasm"}, &state{Shims: map[string]*Shim{}}, false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := Get(tt.args.fs, tt.args.kwasmPath) + if (err != nil) != tt.wantErr { + t.Errorf("Get() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got.Shims, tt.want.Shims) { + t.Errorf("Get() = %v, want %v", got.Shims, tt.want.Shims) + } + }) + } +} diff --git a/testdata/containerd/existing-containerd-shim-config/opt/kwasm/bin/containerd-shim-spin-v1 b/testdata/containerd/existing-containerd-shim-config/opt/kwasm/bin/containerd-shim-spin-v1 new file mode 100644 index 0000000..2eea022 --- /dev/null +++ b/testdata/containerd/existing-containerd-shim-config/opt/kwasm/bin/containerd-shim-spin-v1 @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +echo "Hello from spin shim" \ No newline at end of file diff --git a/testdata/containerd/existing-containerd-shim-config/opt/kwasm/kwasm-lock.json b/testdata/containerd/existing-containerd-shim-config/opt/kwasm/kwasm-lock.json new file mode 100644 index 0000000..a9baf29 --- /dev/null +++ b/testdata/containerd/existing-containerd-shim-config/opt/kwasm/kwasm-lock.json @@ -0,0 +1,8 @@ +{ + "shims": { + "spin-v1": { + "sha256": "6da5e8f17a9bfa9cb04cf22c87b6475394ecec3af4fdc337f72d6dbf3319ea52", + "path": "/opt/kwasm/bin/containerd-shim-spin-v1" + } + } +} \ No newline at end of file From ce33b9d55098fede64fa711f1a5c9aaef97b86c3 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 26 Feb 2024 18:05:19 +0100 Subject: [PATCH 63/90] run tests during build --- images/installer/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index a22d291..27babec 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -9,6 +9,8 @@ COPY pkg ./pkg COPY cmd ./cmd COPY *.go ./ +RUN go test ./... + RUN CGO_ENABLED=0 go build -o kwasm-node-installer RUN /app/kwasm-node-installer -h From bd34b5f0d1da23dba38a8129b9054dd13c6a615a Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 26 Feb 2024 18:08:59 +0100 Subject: [PATCH 64/90] copy test fixtures into build container --- images/installer/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/images/installer/Dockerfile b/images/installer/Dockerfile index 27babec..7dfb34e 100644 --- a/images/installer/Dockerfile +++ b/images/installer/Dockerfile @@ -8,6 +8,7 @@ RUN go mod download COPY pkg ./pkg COPY cmd ./cmd COPY *.go ./ +COPY testdata ./testdata RUN go test ./... From dc1127fc636d0b25c0aba8739a10224945ec9415 Mon Sep 17 00:00:00 2001 From: Daniel Aberger Date: Tue, 27 Feb 2024 17:40:09 +0100 Subject: [PATCH 65/90] add tests for getPid --- pkg/containerd/restart.go | 6 ++- pkg/containerd/restart_test.go | 75 ++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 pkg/containerd/restart_test.go diff --git a/pkg/containerd/restart.go b/pkg/containerd/restart.go index a44d671..849fc34 100644 --- a/pkg/containerd/restart.go +++ b/pkg/containerd/restart.go @@ -24,6 +24,8 @@ import ( "github.com/mitchellh/go-ps" ) +var psProcesses = ps.Processes + func (c *Config) RestartRuntime() error { pid, err := getPid() if err != nil { @@ -40,9 +42,9 @@ func (c *Config) RestartRuntime() error { } func getPid() (int, error) { - processList, err := ps.Processes() + processList, err := psProcesses() if err != nil { - slog.Info("ps.Processes() Failed, are you using windows?") + slog.Info("psProcesses() Failed, are you using windows?") return -1, fmt.Errorf("could not get processes: %+v", err) } diff --git a/pkg/containerd/restart_test.go b/pkg/containerd/restart_test.go new file mode 100644 index 0000000..835dfe4 --- /dev/null +++ b/pkg/containerd/restart_test.go @@ -0,0 +1,75 @@ +package containerd + +import ( + "fmt" + "testing" + + "github.com/mitchellh/go-ps" +) + +type mockProcess struct { + executable string + pid int + ppid int +} + +func (p *mockProcess) Executable() string { + return p.executable +} + +func (p *mockProcess) Pid() int { + return p.pid +} + +func (p *mockProcess) PPid() int { + return p.ppid +} + +func Test_getPid(t *testing.T) { + tests := []struct { + name string + psProccessesMock func() ([]ps.Process, error) + want int + wantErr bool + }{ + {"no containerd process found", func() ([]ps.Process, error) { + return []ps.Process{}, nil + }, -1, true}, + {"single containerd process found", func() ([]ps.Process, error) { + return []ps.Process{ + &mockProcess{executable: "containerd", pid: 123}, + }, nil + }, 123, false}, + {"multiple containerd processes found", func() ([]ps.Process, error) { + return []ps.Process{ + &mockProcess{executable: "containerd"}, + &mockProcess{executable: "containerd"}, + }, nil + }, 0, true}, + {"error getting processes", func() ([]ps.Process, error) { + return nil, fmt.Errorf("error getting processes") + }, -1, true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + defer func() { + if r := recover(); r != nil { + if !tt.wantErr { + // If the test case does not expect an error, re-panic + panic(r) + } + } + }() + + psProcesses = tt.psProccessesMock + got, err := getPid() + if (err != nil) != tt.wantErr { + t.Errorf("getPid() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("getPid() = %v, want %v", got, tt.want) + } + }) + } +} From e101ad8be98eefb7ba1748025dd6fb2616a4bd7d Mon Sep 17 00:00:00 2001 From: Daniel Aberger Date: Wed, 28 Feb 2024 16:39:11 +0100 Subject: [PATCH 66/90] add tests for state.ShimChanged --- pkg/state/state_test.go | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/pkg/state/state_test.go b/pkg/state/state_test.go index 04fe2ae..352d1d8 100644 --- a/pkg/state/state_test.go +++ b/pkg/state/state_test.go @@ -46,3 +46,60 @@ func TestGet(t *testing.T) { }) } } + +func TestShimChanged(t *testing.T) { + state := &state{ + Shims: map[string]*Shim{ + "spin-v1": { + Sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, + Path: "/opt/kwasm/bin/containerd-shim-spin-v1", + }, + }, + } + + tests := []struct { + name string + shimName string + sha256 []byte + path string + wantResult bool + }{ + { + name: "existing shim, same sha256 and path", + shimName: "spin-v1", + sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, + path: "/opt/kwasm/bin/containerd-shim-spin-v1", + wantResult: false, + }, + { + name: "existing shim, different sha256", + shimName: "spin-v1", + sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 83}, + path: "/opt/kwasm/bin/containerd-shim-spin-v1", + wantResult: true, + }, + { + name: "existing shim, different path", + shimName: "spin-v1", + sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, + path: "/opt/kwasm/bin/containerd-shim-spin-v2", + wantResult: true, + }, + { + name: "non-existing shim", + shimName: "non-existing", + sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, + path: "/opt/kwasm/bin/containerd-shim-spin-v1", + wantResult: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := state.ShimChanged(tt.shimName, tt.sha256, tt.path) + if result != tt.wantResult { + t.Errorf("ShimChanged() = %v, want %v", result, tt.wantResult) + } + }) + } +} From d2394d9c5ead7926e2ea6a9cca768816e423b508 Mon Sep 17 00:00:00 2001 From: Daniel Aberger Date: Thu, 29 Feb 2024 11:59:37 +0100 Subject: [PATCH 67/90] add tests for shim Install --- pkg/shim/install_test.go | 125 ++++++++++++++++++ testdata/assets/containerd-shim-slight-v1 | 3 + .../opt/kwasm/bin/containerd-shim-spin-v1 | 3 + testdata/shim/opt/kwasm/kwasm-lock.json | 8 ++ 4 files changed, 139 insertions(+) create mode 100644 pkg/shim/install_test.go create mode 100644 testdata/assets/containerd-shim-slight-v1 create mode 100644 testdata/shim/opt/kwasm/bin/containerd-shim-spin-v1 create mode 100644 testdata/shim/opt/kwasm/kwasm-lock.json diff --git a/pkg/shim/install_test.go b/pkg/shim/install_test.go new file mode 100644 index 0000000..526ee5a --- /dev/null +++ b/pkg/shim/install_test.go @@ -0,0 +1,125 @@ +/* + Copyright The KWasm Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package shim + +import ( + "fmt" + "path/filepath" + "testing" + + "github.com/spf13/afero" +) + +func newFixtureFs(fixturePath string) afero.Fs { + baseFs := afero.NewBasePathFs(afero.NewOsFs(), filepath.Join("../..", fixturePath)) + p, _ := baseFs.(*afero.BasePathFs).RealPath("/") + fmt.Println(filepath.Abs(p)) + fs := afero.NewCopyOnWriteFs(baseFs, afero.NewMemMapFs()) + return fs +} + +func TestConfig_Install(t *testing.T) { + type fields struct { + rootFs afero.Fs + hostFs afero.Fs + assetPath string + kwasmPath string + } + type args struct { + shimName string + } + tests := []struct { + name string + fields fields + args args + want string + want1 bool + wantErr bool + }{ + { + "no changes to shim", + fields{ + newFixtureFs("testdata"), + newFixtureFs("testdata/shim"), + "/assets", + "/opt/kwasm"}, + args{"containerd-shim-spin-v1"}, + "/opt/kwasm/bin/containerd-shim-spin-v1", + false, + false, + }, + { + "install new shim over old", + fields{ + newFixtureFs("testdata"), + newFixtureFs("testdata/shim"), + "/assets", + "/opt/kwasm"}, + args{"containerd-shim-slight-v1"}, + "/opt/kwasm/bin/containerd-shim-slight-v1", + true, + false, + }, + { + "unable to find new shim", + fields{ + afero.NewMemMapFs(), + newFixtureFs("testdata/shim"), + "/assets", + "/opt/kwasm"}, + args{"some-shim"}, + "", + false, + true, + }, + { + "unable to write to hostFs", + fields{ + newFixtureFs("testdata"), + afero.NewReadOnlyFs(newFixtureFs("testdata/shim")), + "/assets", + "/opt/kwasm"}, + args{"containerd-shim-spin-v1"}, + "/opt/kwasm/bin/containerd-shim-spin-v1", + false, + true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c := &Config{ + rootFs: tt.fields.rootFs, + hostFs: tt.fields.hostFs, + assetPath: tt.fields.assetPath, + kwasmPath: tt.fields.kwasmPath, + } + + got, got1, err := c.Install(tt.args.shimName) + + if (err != nil) != tt.wantErr { + t.Errorf("Config.Install() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("Config.Install() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("Config.Install() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} diff --git a/testdata/assets/containerd-shim-slight-v1 b/testdata/assets/containerd-shim-slight-v1 new file mode 100644 index 0000000..9eca0fc --- /dev/null +++ b/testdata/assets/containerd-shim-slight-v1 @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo "hello from spin-v1" \ No newline at end of file diff --git a/testdata/shim/opt/kwasm/bin/containerd-shim-spin-v1 b/testdata/shim/opt/kwasm/bin/containerd-shim-spin-v1 new file mode 100644 index 0000000..2eea022 --- /dev/null +++ b/testdata/shim/opt/kwasm/bin/containerd-shim-spin-v1 @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +echo "Hello from spin shim" \ No newline at end of file diff --git a/testdata/shim/opt/kwasm/kwasm-lock.json b/testdata/shim/opt/kwasm/kwasm-lock.json new file mode 100644 index 0000000..a9baf29 --- /dev/null +++ b/testdata/shim/opt/kwasm/kwasm-lock.json @@ -0,0 +1,8 @@ +{ + "shims": { + "spin-v1": { + "sha256": "6da5e8f17a9bfa9cb04cf22c87b6475394ecec3af4fdc337f72d6dbf3319ea52", + "path": "/opt/kwasm/bin/containerd-shim-spin-v1" + } + } +} \ No newline at end of file From ccda80d7ec903f0be97e677186854de37412983f Mon Sep 17 00:00:00 2001 From: Daniel Aberger Date: Thu, 29 Feb 2024 14:36:04 +0100 Subject: [PATCH 68/90] tidy go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index aa3ef24..5f2049e 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/mitchellh/go-ps v1.0.0 github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect - github.com/spf13/afero v1.9.5 // indirect + github.com/spf13/afero v1.9.5 github.com/spf13/cast v1.5.1 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/subosito/gotenv v1.4.2 // indirect From 23c8518b7c33fa289571a37f053cf920f3b2c917 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Fri, 1 Mar 2024 11:49:25 +0100 Subject: [PATCH 69/90] make restart code a bit more idiomatic --- pkg/containerd/restart.go | 19 ++++++++----------- pkg/containerd/restart_test.go | 4 ++-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/pkg/containerd/restart.go b/pkg/containerd/restart.go index 849fc34..e4377f3 100644 --- a/pkg/containerd/restart.go +++ b/pkg/containerd/restart.go @@ -42,27 +42,24 @@ func (c *Config) RestartRuntime() error { } func getPid() (int, error) { - processList, err := psProcesses() + processes, err := psProcesses() if err != nil { slog.Info("psProcesses() Failed, are you using windows?") - return -1, fmt.Errorf("could not get processes: %+v", err) + return 0, fmt.Errorf("could not get processes: %+v", err) } - var containerdProcessList = []ps.Process{} + var containerdProcesses = []ps.Process{} - for x := range processList { - process := processList[x] + for _, process := range processes { if process.Executable() == "containerd" { - containerdProcessList = append(containerdProcessList, process) + containerdProcesses = append(containerdProcesses, process) } } - if len(containerdProcessList) == 1 { - return containerdProcessList[0].Pid(), nil - } else if len(containerdProcessList) == 0 { - return -1, fmt.Errorf("no containerd process found") + if len(containerdProcesses) == 1 { + return containerdProcesses[0].Pid(), nil } else { - panic("multiple containerd processes found") + return 0, fmt.Errorf("need exactly one containerd process, found: %d", len(containerdProcesses)) } } diff --git a/pkg/containerd/restart_test.go b/pkg/containerd/restart_test.go index 835dfe4..c5cbb63 100644 --- a/pkg/containerd/restart_test.go +++ b/pkg/containerd/restart_test.go @@ -34,7 +34,7 @@ func Test_getPid(t *testing.T) { }{ {"no containerd process found", func() ([]ps.Process, error) { return []ps.Process{}, nil - }, -1, true}, + }, 0, true}, {"single containerd process found", func() ([]ps.Process, error) { return []ps.Process{ &mockProcess{executable: "containerd", pid: 123}, @@ -48,7 +48,7 @@ func Test_getPid(t *testing.T) { }, 0, true}, {"error getting processes", func() ([]ps.Process, error) { return nil, fmt.Errorf("error getting processes") - }, -1, true}, + }, 0, true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { From fd043fae9fa143676b29d330221cd1e90ee4db3b Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 4 Mar 2024 09:02:36 +0100 Subject: [PATCH 70/90] refactor install and uninstall commands --- cmd/install.go | 112 ++++++++++++++++--------------- cmd/uninstall.go | 64 ++++++++++-------- pkg/containerd/configure.go | 10 +-- pkg/containerd/configure_test.go | 2 +- pkg/shim/uninstall.go | 16 +++-- 5 files changed, 112 insertions(+), 92 deletions(-) diff --git a/cmd/install.go b/cmd/install.go index 6d3c010..c4ed954 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -34,69 +34,73 @@ var installCmd = &cobra.Command{ Use: "install", Short: "Install containerd shims", Run: func(cmd *cobra.Command, args []string) { + if err := runInstall(cmd, args); err != nil { + slog.Error("failed to install", "error", err) + os.Exit(1) + } + }, +} + +func init() { + installCmd.Flags().StringVarP(&config.Kwasm.AssetPath, "asset-path", "a", "/assets", "Path to the asset to install") + rootCmd.AddCommand(installCmd) +} - // Get file or directory information. - info, err := os.Stat(config.Kwasm.AssetPath) +func runInstall(_ *cobra.Command, _ []string) error { + // Get file or directory information. + info, err := os.Stat(config.Kwasm.AssetPath) + if err != nil { + return err + } + + var files []fs.DirEntry + // Check if the path is a directory. + if info.IsDir() { + files, err = os.ReadDir(config.Kwasm.AssetPath) if err != nil { - fmt.Println(err) - return + return err } + } else { + // If the path is not a directory, add the file to the list of files. + files = append(files, fs.FileInfoToDirEntry(info)) + config.Kwasm.AssetPath = path.Dir(config.Kwasm.AssetPath) + } - var files []fs.DirEntry - // Check if the path is a directory. - if info.IsDir() { - files, err = os.ReadDir(config.Kwasm.AssetPath) - if err != nil { - slog.Error(err.Error()) - return - } - } else { - // If the path is not a directory, add the file to the list of files. - files = append(files, fs.FileInfoToDirEntry(info)) - config.Kwasm.AssetPath = path.Dir(config.Kwasm.AssetPath) - } + rootFs := afero.NewOsFs() + hostFs := afero.NewBasePathFs(rootFs, config.Host.RootPath) - rootFs := afero.NewOsFs() - hostFs := afero.NewBasePathFs(rootFs, config.Host.RootPath) - - containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath) - shimConfig := shim.NewConfig(rootFs, hostFs, config.Kwasm.AssetPath, config.Kwasm.Path) - - anythingChanged := false - for _, file := range files { - fileName := file.Name() - runtimeName := shim.RuntimeName(fileName) - - binPath, changed, err := shimConfig.Install(fileName) - if err != nil { - slog.Error("failed to install shim", "shim", runtimeName, "error", err) - return - } - anythingChanged = anythingChanged || changed - slog.Info("shim installed", "shim", runtimeName, "path", binPath, "new-version", changed) - - err = containerdConfig.AddRuntime(binPath) - if err != nil { - slog.Error("failed to write containerd config", "shim", runtimeName, "path", config.Runtime.ConfigPath, "error", err) - return - } - slog.Info("shim configured", "shim", runtimeName, "path", config.Runtime.ConfigPath) - } + containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath) + shimConfig := shim.NewConfig(rootFs, hostFs, config.Kwasm.AssetPath, config.Kwasm.Path) - if !anythingChanged { - slog.Info("nothing changed, nothing more to do") - return + anythingChanged := false + for _, file := range files { + fileName := file.Name() + runtimeName := shim.RuntimeName(fileName) + + binPath, changed, err := shimConfig.Install(fileName) + if err != nil { + return fmt.Errorf("failed to install shim '%s': %w", runtimeName, err) } + anythingChanged = anythingChanged || changed + slog.Info("shim installed", "shim", runtimeName, "path", binPath, "new-version", changed) - slog.Info("restarting containerd") - err = containerdConfig.RestartRuntime() + err = containerdConfig.AddRuntime(binPath) if err != nil { - slog.Error("failed to restart containerd", "error", err) + return fmt.Errorf("failed to write containerd config: %w", err) } - }, -} + slog.Info("shim configured", "shim", runtimeName, "path", config.Runtime.ConfigPath) + } -func init() { - installCmd.Flags().StringVarP(&config.Kwasm.AssetPath, "asset-path", "a", "/assets", "Path to the asset to install") - rootCmd.AddCommand(installCmd) + if !anythingChanged { + slog.Info("nothing changed, nothing more to do") + return nil + } + + slog.Info("restarting containerd") + err = containerdConfig.RestartRuntime() + if err != nil { + return fmt.Errorf("failed to restart containerd: %w", err) + } + + return nil } diff --git a/cmd/uninstall.go b/cmd/uninstall.go index 4433d06..e7eb201 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -17,7 +17,9 @@ package cmd import ( + "fmt" "log/slog" + "os" "path" "github.com/spf13/afero" @@ -32,40 +34,48 @@ var uninstallCmd = &cobra.Command{ Use: "uninstall", Short: "Uninstall containerd shims", Run: func(cmd *cobra.Command, args []string) { - slog.Info("uninstall called", "config", config) - shimName := config.Runtime.Name - runtimeName := path.Join(config.Kwasm.Path, "bin", shimName) - - rootFs := afero.NewOsFs() - hostFs := afero.NewBasePathFs(rootFs, config.Host.RootPath) - - containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath) - shimConfig := shim.NewConfig(rootFs, hostFs, config.Kwasm.AssetPath, config.Kwasm.Path) - - binPath, err := shimConfig.Uninstall(shimName) - if err != nil { - slog.Error("failed to uninstall shim", "shim", runtimeName, "error", err) - return - } - - err = containerdConfig.RemoveRuntime(binPath) - if err != nil { - slog.Error("failed to write containerd config", "shim", runtimeName, "path", config.Runtime.ConfigPath, "error", err) - return + if err := runUninstall(cmd, args); err != nil { + slog.Error("failed to uninstall", "error", err) + os.Exit(1) } }, } func init() { rootCmd.AddCommand(uninstallCmd) +} + +func runUninstall(_ *cobra.Command, _ []string) error { + slog.Info("uninstall called") + shimName := config.Runtime.Name + runtimeName := path.Join(config.Kwasm.Path, "bin", shimName) + + rootFs := afero.NewOsFs() + hostFs := afero.NewBasePathFs(rootFs, config.Host.RootPath) + + containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath) + shimConfig := shim.NewConfig(rootFs, hostFs, config.Kwasm.AssetPath, config.Kwasm.Path) + + binPath, err := shimConfig.Uninstall(shimName) + if err != nil { + return fmt.Errorf("failed to delete shim '%s': %w", runtimeName, err) + } + + configChanged, err := containerdConfig.RemoveRuntime(binPath) + if err != nil { + return fmt.Errorf("failed to write conteainerd config for shim '%s': %w", runtimeName, err) + } - // Here you will define your flags and configuration settings. + if !configChanged { + slog.Info("nothing changed, nothing more to do") + return nil + } - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // uninstallCmd.PersistentFlags().String("foo", "", "A help for foo") + slog.Info("restarting containerd") + err = containerdConfig.RestartRuntime() + if err != nil { + return fmt.Errorf("failed to restart containerd: %w", err) + } - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // uninstallCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + return nil } diff --git a/pkg/containerd/configure.go b/pkg/containerd/configure.go index 8b1df26..fab3841 100644 --- a/pkg/containerd/configure.go +++ b/pkg/containerd/configure.go @@ -72,7 +72,7 @@ func (c *Config) AddRuntime(shimPath string) error { return nil } -func (c *Config) RemoveRuntime(shimPath string) error { +func (c *Config) RemoveRuntime(shimPath string) (changed bool, err error) { runtimeName := shim.RuntimeName(path.Base(shimPath)) cfg := generateConfig(shimPath, runtimeName) @@ -80,13 +80,13 @@ func (c *Config) RemoveRuntime(shimPath string) error { // Containerd config file needs to exist, otherwise return the error data, err := afero.ReadFile(c.hostFs, c.configPath) if err != nil { - return err + return false, err } // Warn if config.toml does not contain the runtimeName if !strings.Contains(string(data), runtimeName) { slog.Warn(fmt.Sprintf("config for runtime '%s' does not exist, skipping", runtimeName)) - return nil + return false, nil } // Convert the file data to a string and replace the target string with an empty string. @@ -95,10 +95,10 @@ func (c *Config) RemoveRuntime(shimPath string) error { // Write the modified data back to the file. err = afero.WriteFile(c.hostFs, c.configPath, []byte(modifiedData), 0644) if err != nil { - return err + return false, err } - return nil + return true, nil } func generateConfig(shimPath string, runtimeName string) string { diff --git a/pkg/containerd/configure_test.go b/pkg/containerd/configure_test.go index b4ad8f1..be5f927 100644 --- a/pkg/containerd/configure_test.go +++ b/pkg/containerd/configure_test.go @@ -195,7 +195,7 @@ func TestConfig_RemoveRuntime(t *testing.T) { hostFs: tt.fields.hostFs, configPath: tt.fields.configPath, } - if err := c.RemoveRuntime(tt.args.shimPath); (err != nil) != tt.wantErr { + if _, err := c.RemoveRuntime(tt.args.shimPath); (err != nil) != tt.wantErr { t.Errorf("Config.RemoveRuntime() error = %v, wantErr %v", err, tt.wantErr) } diff --git a/pkg/shim/uninstall.go b/pkg/shim/uninstall.go index 6b7f368..aec5a18 100644 --- a/pkg/shim/uninstall.go +++ b/pkg/shim/uninstall.go @@ -1,7 +1,9 @@ package shim import ( - "fmt" + "errors" + "log/slog" + "os" "github.com/kwasm/kwasm-node-installer/pkg/state" ) @@ -12,15 +14,19 @@ func (c *Config) Uninstall(shimName string) (string, error) { if err != nil { return "", err } - s := st.Shims[shimName] - if s == nil { - return "", fmt.Errorf("shim '%s' not installed", shimName) + s, ok := st.Shims[shimName] + if !ok { + slog.Warn("shim not installed", "shim", shimName) + return "", nil } filePath := s.Path err = c.hostFs.Remove(filePath) if err != nil { - return "", err + if !errors.Is(err, os.ErrNotExist) { + return "", err + } + slog.Warn("shim binary did not exist, nothing to delete") } st.RemoveShim(shimName) From bd762b4d5846ac7a2f9cd7216238d34f49a82e8b Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 4 Mar 2024 09:29:40 +0100 Subject: [PATCH 71/90] make containerd restart code platform specific --- pkg/containerd/configure.go | 6 ++++-- pkg/containerd/{restart.go => restart_unix.go} | 6 ++++-- pkg/containerd/{restart_test.go => restart_unix_test.go} | 3 +++ pkg/containerd/restart_windows.go | 8 ++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) rename pkg/containerd/{restart.go => restart_unix.go} (93%) rename pkg/containerd/{restart_test.go => restart_unix_test.go} (98%) create mode 100644 pkg/containerd/restart_windows.go diff --git a/pkg/containerd/configure.go b/pkg/containerd/configure.go index fab3841..8466c27 100644 --- a/pkg/containerd/configure.go +++ b/pkg/containerd/configure.go @@ -41,6 +41,7 @@ func NewConfig(hostFs afero.Fs, configPath string) *Config { func (c *Config) AddRuntime(shimPath string) error { runtimeName := shim.RuntimeName(path.Base(shimPath)) + l := slog.With("runtime", runtimeName) cfg := generateConfig(shimPath, runtimeName) @@ -52,7 +53,7 @@ func (c *Config) AddRuntime(shimPath string) error { // Warn if config.toml already contains runtimeName if strings.Contains(string(data), runtimeName) { - slog.Info(fmt.Sprintf("config for runtime '%s' already exists, skipping", runtimeName)) + l.Info("runtime config already exists, skipping") return nil } @@ -74,6 +75,7 @@ func (c *Config) AddRuntime(shimPath string) error { func (c *Config) RemoveRuntime(shimPath string) (changed bool, err error) { runtimeName := shim.RuntimeName(path.Base(shimPath)) + l := slog.With("runtime", runtimeName) cfg := generateConfig(shimPath, runtimeName) @@ -85,7 +87,7 @@ func (c *Config) RemoveRuntime(shimPath string) (changed bool, err error) { // Warn if config.toml does not contain the runtimeName if !strings.Contains(string(data), runtimeName) { - slog.Warn(fmt.Sprintf("config for runtime '%s' does not exist, skipping", runtimeName)) + l.Warn("runtime config does not exist, skipping") return false, nil } diff --git a/pkg/containerd/restart.go b/pkg/containerd/restart_unix.go similarity index 93% rename from pkg/containerd/restart.go rename to pkg/containerd/restart_unix.go index e4377f3..63b9261 100644 --- a/pkg/containerd/restart.go +++ b/pkg/containerd/restart_unix.go @@ -1,3 +1,6 @@ +//go:build unix +// +build unix + /* Copyright The KWasm Authors. @@ -31,7 +34,7 @@ func (c *Config) RestartRuntime() error { if err != nil { return err } - slog.Info("found containerd pid", "pid", pid) + slog.Debug("found containerd process", "pid", pid) err = syscall.Kill(pid, syscall.SIGHUP) @@ -44,7 +47,6 @@ func (c *Config) RestartRuntime() error { func getPid() (int, error) { processes, err := psProcesses() if err != nil { - slog.Info("psProcesses() Failed, are you using windows?") return 0, fmt.Errorf("could not get processes: %+v", err) } diff --git a/pkg/containerd/restart_test.go b/pkg/containerd/restart_unix_test.go similarity index 98% rename from pkg/containerd/restart_test.go rename to pkg/containerd/restart_unix_test.go index c5cbb63..5d1fbb4 100644 --- a/pkg/containerd/restart_test.go +++ b/pkg/containerd/restart_unix_test.go @@ -1,3 +1,6 @@ +//go:build unix +// +build unix + package containerd import ( diff --git a/pkg/containerd/restart_windows.go b/pkg/containerd/restart_windows.go new file mode 100644 index 0000000..153c37e --- /dev/null +++ b/pkg/containerd/restart_windows.go @@ -0,0 +1,8 @@ +//go:build windows +// +build windows + +package containerd + +func (c *Config) RestartRuntime() error { + panic("restarting containerd not implemented") +} From f4109b794a0e5a6c56ae559584d1bcf192694840 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 4 Mar 2024 09:30:38 +0100 Subject: [PATCH 72/90] return error instead of panicing --- pkg/containerd/restart_windows.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/containerd/restart_windows.go b/pkg/containerd/restart_windows.go index 153c37e..1b00389 100644 --- a/pkg/containerd/restart_windows.go +++ b/pkg/containerd/restart_windows.go @@ -3,6 +3,8 @@ package containerd +import "errors" + func (c *Config) RestartRuntime() error { - panic("restarting containerd not implemented") + return errors.New("restarting containerd not implemented") } From ce9dd92e4becb01dc33729b7493c043da569ce39 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 4 Mar 2024 10:08:47 +0100 Subject: [PATCH 73/90] add PR template --- .github/pull_request_template.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..44227e4 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,17 @@ +## Describe your changes + +## Issue ticket number and link + +## Checklist before requesting a review +- [ ] I have performed a self-review of my code +- [ ] If it is a core feature, I have added thorough tests. +- I tested the changes with the following distributions: + - [ ] Kind + - [ ] MiniKube + - [ ] MicroK8s + - [ ] Rancher RKE2 + - [ ] Azure AKS + - [ ] GCP GKE (Ubuntu nodes) + - [ ] AWS EKS (AmazonLinux2 nodes) + - [ ] AWS EKS (Ubuntu nodes) + - [ ] Digital Ocean Kubernetes \ No newline at end of file From 907e3d85b670e3d9241a84fca9f65660774e7ede Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 4 Mar 2024 10:09:39 +0100 Subject: [PATCH 74/90] remove test directory --- test/README.md | 12 ------------ test/assets/containerd-shim-slight-v1 | 3 --- test/assets/containerd-shim-spin-v1 | 3 --- test/etc/containerd/config.toml | 3 --- 4 files changed, 21 deletions(-) delete mode 100644 test/README.md delete mode 100644 test/assets/containerd-shim-slight-v1 delete mode 100644 test/assets/containerd-shim-spin-v1 delete mode 100644 test/etc/containerd/config.toml diff --git a/test/README.md b/test/README.md deleted file mode 100644 index 24e0740..0000000 --- a/test/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# Local testing during development - -Run - -``` -$ go run . install -H test -a ./test/assets -``` - -This will copy the assets from `test/assets` into `test/opt/kwasm/bin` and -create containerd config files in `test/etc/containerd/conf.d`. The config will -have the absolute path of the binary from the host root (`-H test` - `test` is -the host root). \ No newline at end of file diff --git a/test/assets/containerd-shim-slight-v1 b/test/assets/containerd-shim-slight-v1 deleted file mode 100644 index 9eca0fc..0000000 --- a/test/assets/containerd-shim-slight-v1 +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -echo "hello from spin-v1" \ No newline at end of file diff --git a/test/assets/containerd-shim-spin-v1 b/test/assets/containerd-shim-spin-v1 deleted file mode 100644 index 9eca0fc..0000000 --- a/test/assets/containerd-shim-spin-v1 +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -echo "hello from spin-v1" \ No newline at end of file diff --git a/test/etc/containerd/config.toml b/test/etc/containerd/config.toml deleted file mode 100644 index 7dcb123..0000000 --- a/test/etc/containerd/config.toml +++ /dev/null @@ -1,3 +0,0 @@ -###### -###### -###### From e6b82ef9866a0d93db528edcd9ed8b387fad9ee9 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 4 Mar 2024 10:09:53 +0100 Subject: [PATCH 75/90] use %w to wrap errors --- pkg/containerd/restart_unix.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/containerd/restart_unix.go b/pkg/containerd/restart_unix.go index 63b9261..f331b89 100644 --- a/pkg/containerd/restart_unix.go +++ b/pkg/containerd/restart_unix.go @@ -39,7 +39,7 @@ func (c *Config) RestartRuntime() error { err = syscall.Kill(pid, syscall.SIGHUP) if err != nil { - return fmt.Errorf("failed to send SIGHUP to containerd: %+v", err) + return fmt.Errorf("failed to send SIGHUP to containerd: %w", err) } return nil } @@ -47,7 +47,7 @@ func (c *Config) RestartRuntime() error { func getPid() (int, error) { processes, err := psProcesses() if err != nil { - return 0, fmt.Errorf("could not get processes: %+v", err) + return 0, fmt.Errorf("could not get processes: %w", err) } var containerdProcesses = []ps.Process{} From 3e794aa66a4e8d678fcd5dc12a3259db2bb0d0d5 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 4 Mar 2024 15:53:39 +0100 Subject: [PATCH 76/90] use testify to simplify test assertions --- go.mod | 6 ++++++ go.sum | 3 ++- pkg/state/shim_test.go | 32 +++++++++++++++++--------------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 5f2049e..f70fa65 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,12 @@ require ( github.com/spf13/viper v1.16.0 ) +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/stretchr/testify v1.9.0 +) + require ( github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect diff --git a/go.sum b/go.sum index a29bc56..6ba763b 100644 --- a/go.sum +++ b/go.sum @@ -176,8 +176,9 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/pkg/state/shim_test.go b/pkg/state/shim_test.go index 57c9ebe..30d581a 100644 --- a/pkg/state/shim_test.go +++ b/pkg/state/shim_test.go @@ -2,6 +2,8 @@ package state import ( "testing" + + "github.com/stretchr/testify/require" ) func TestShim_MarshalJSON(t *testing.T) { @@ -24,13 +26,12 @@ func TestShim_MarshalJSON(t *testing.T) { Path: tt.fields.Path, } got, err := s.MarshalJSON() - if (err != nil) != tt.wantErr { - t.Errorf("Shim.MarshalJSON() error = %v, wantErr %v", err, tt.wantErr) - return - } - if string(got) != string(tt.want) { - t.Errorf("Shim.MarshalJSON() = %v, want %v", string(got), tt.want) + if tt.wantErr { + require.Error(t, err) + } else { + require.Nil(t, err) } + require.Equal(t, tt.want, string(got)) }) } } @@ -50,20 +51,21 @@ func TestShim_UnmarshalJSON(t *testing.T) { wantErr bool }{ {"default", args{`{"sha256":"6da5e8f17a9bfa9cb04cf22c87b6475394ecec3af4fdc337f72d6dbf3319ea52","path":"/opt/kwasm/bin/containerd-shim-spin-v1"}`}, wants{path: "/opt/kwasm/bin/containerd-shim-spin-v1", sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}}, false}, - // TODO: Add test cases. + {"broken sha", args{`{"sha256":"2","path":"/opt/kwasm/bin/containerd-shim-spin-v1"}`}, wants{path: "/opt/kwasm/bin/containerd-shim-spin-v1", sha256: nil}, true}, + {"broken json", args{`broken`}, wants{path: "", sha256: nil}, true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { s := Shim{} - if err := s.UnmarshalJSON([]byte(tt.args.data)); (err != nil) != tt.wantErr { - t.Errorf("Shim.UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr) - } - if string(s.Path) != string(tt.want.path) { - t.Errorf("path = %v, want %v", string(s.Path), tt.want.path) - } - if string(s.Sha256) != string(tt.want.sha256) { - t.Errorf("sha256 = %v, want %v", string(s.Sha256), tt.want.sha256) + err := s.UnmarshalJSON([]byte(tt.args.data)) + + if tt.wantErr { + require.Error(t, err) + } else { + require.Nil(t, err) } + require.Equal(t, tt.want.path, s.Path) + require.Equal(t, tt.want.sha256, s.Sha256) }) } } From 3d818d95ea8b3422c0ef0886e73b06a87d06a07f Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 4 Mar 2024 16:31:18 +0100 Subject: [PATCH 77/90] use testify to simplify test assertions --- pkg/containerd/configure_test.go | 62 ++++++++++++++--------------- pkg/containerd/restart_unix_test.go | 24 +++++------ pkg/shim/install.go | 4 +- pkg/shim/install_test.go | 45 +++++++++------------ pkg/state/shim_test.go | 7 ++-- pkg/state/state.go | 2 +- pkg/state/state_test.go | 33 +++++---------- tests/fs.go | 13 ++++++ 8 files changed, 88 insertions(+), 102 deletions(-) create mode 100644 tests/fs.go diff --git a/pkg/containerd/configure_test.go b/pkg/containerd/configure_test.go index be5f927..99ee6e7 100644 --- a/pkg/containerd/configure_test.go +++ b/pkg/containerd/configure_test.go @@ -17,21 +17,14 @@ package containerd import ( - "fmt" - "path/filepath" "testing" + "github.com/kwasm/kwasm-node-installer/tests" "github.com/spf13/afero" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) -func newFixtureFs(fixturePath string) afero.Fs { - baseFs := afero.NewBasePathFs(afero.NewOsFs(), filepath.Join("../..", fixturePath)) - p, _ := baseFs.(*afero.BasePathFs).RealPath("/") - fmt.Println(filepath.Abs(p)) - fs := afero.NewCopyOnWriteFs(baseFs, afero.NewMemMapFs()) - return fs -} - func TestConfig_AddRuntime(t *testing.T) { type fields struct { hostFs afero.Fs @@ -49,7 +42,7 @@ func TestConfig_AddRuntime(t *testing.T) { wantFileContent string }{ {"missing shim config", fields{ - hostFs: newFixtureFs("testdata/containerd/missing-containerd-shim-config"), + hostFs: tests.FixtureFs("testdata/containerd/missing-containerd-shim-config"), configPath: "/etc/containerd/config.toml", }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, false, `[plugins] [plugins."io.containerd.monitor.v1.cgroups"] @@ -74,11 +67,11 @@ func TestConfig_AddRuntime(t *testing.T) { runtime_type = "/opt/kwasm/bin/containerd-shim-spin-v1" `}, {"missing config", fields{ - hostFs: newFixtureFs("testdata/containerd/missing-containerd-config"), + hostFs: tests.FixtureFs("testdata/containerd/missing-containerd-config"), configPath: "/etc/containerd/config.toml", }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, true, true, ``}, {"existing shim config", fields{ - hostFs: newFixtureFs("testdata/containerd/existing-containerd-shim-config"), + hostFs: tests.FixtureFs("testdata/containerd/existing-containerd-shim-config"), configPath: "/etc/containerd/config.toml", }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, false, `[plugins] [plugins."io.containerd.monitor.v1.cgroups"] @@ -109,19 +102,22 @@ runtime_type = "/opt/kwasm/bin/containerd-shim-spin-v1" hostFs: tt.fields.hostFs, configPath: tt.fields.configPath, } - if err := c.AddRuntime(tt.args.shimPath); (err != nil) != tt.wantErr { - t.Errorf("Config.AddRuntime() error = %v, wantErr %v", err, tt.wantErr) + err := c.AddRuntime(tt.args.shimPath) + + if tt.wantErr { + require.Error(t, err) + } else { + require.Nil(t, err) } gotContent, err := afero.ReadFile(c.hostFs, c.configPath) - if (err != nil) != tt.wantFileErr { - t.Errorf("read %s error = %v, wantFileErr %v", c.configPath, err, tt.wantFileErr) - return + if tt.wantFileErr { + assert.Error(t, err) + } else { + assert.Nil(t, err) } - if string(gotContent) != tt.wantFileContent { - t.Errorf("file content %s got = %s, want = %s", c.configPath, string(gotContent), tt.wantFileContent) - } + assert.Equal(t, tt.wantFileContent, string(gotContent)) }) } } @@ -143,7 +139,7 @@ func TestConfig_RemoveRuntime(t *testing.T) { wantFileContent string }{ {"missing shim config", fields{ - hostFs: newFixtureFs("testdata/containerd/missing-containerd-shim-config"), + hostFs: tests.FixtureFs("testdata/containerd/missing-containerd-shim-config"), configPath: "/etc/containerd/config.toml", }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, false, `[plugins] [plugins."io.containerd.monitor.v1.cgroups"] @@ -164,11 +160,11 @@ func TestConfig_RemoveRuntime(t *testing.T) { rdt_config_file = "" `}, {"missing config", fields{ - hostFs: newFixtureFs("testdata/containerd/missing-containerd-config"), + hostFs: tests.FixtureFs("testdata/containerd/missing-containerd-config"), configPath: "/etc/containerd/config.toml", }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, true, true, ``}, {"existing shim config", fields{ - hostFs: newFixtureFs("testdata/containerd/existing-containerd-shim-config"), + hostFs: tests.FixtureFs("testdata/containerd/existing-containerd-shim-config"), configPath: "/etc/containerd/config.toml", }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, false, `[plugins] [plugins."io.containerd.monitor.v1.cgroups"] @@ -195,19 +191,21 @@ func TestConfig_RemoveRuntime(t *testing.T) { hostFs: tt.fields.hostFs, configPath: tt.fields.configPath, } - if _, err := c.RemoveRuntime(tt.args.shimPath); (err != nil) != tt.wantErr { - t.Errorf("Config.RemoveRuntime() error = %v, wantErr %v", err, tt.wantErr) + _, err := c.RemoveRuntime(tt.args.shimPath) + if tt.wantErr { + require.Error(t, err) + } else { + require.Nil(t, err) } gotContent, err := afero.ReadFile(c.hostFs, c.configPath) - if (err != nil) != tt.wantFileErr { - t.Errorf("read %s error = %v, wantFileErr %v", c.configPath, err, tt.wantFileErr) - return + if tt.wantFileErr { + assert.Error(t, err) + } else { + assert.Nil(t, err) } - if string(gotContent) != tt.wantFileContent { - t.Errorf("file content %s got = %s, want = %s", c.configPath, string(gotContent), tt.wantFileContent) - } + assert.Equal(t, tt.wantFileContent, string(gotContent)) }) } } diff --git a/pkg/containerd/restart_unix_test.go b/pkg/containerd/restart_unix_test.go index 5d1fbb4..d199c91 100644 --- a/pkg/containerd/restart_unix_test.go +++ b/pkg/containerd/restart_unix_test.go @@ -8,6 +8,8 @@ import ( "testing" "github.com/mitchellh/go-ps" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) type mockProcess struct { @@ -55,24 +57,16 @@ func Test_getPid(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - defer func() { - if r := recover(); r != nil { - if !tt.wantErr { - // If the test case does not expect an error, re-panic - panic(r) - } - } - }() - psProcesses = tt.psProccessesMock got, err := getPid() - if (err != nil) != tt.wantErr { - t.Errorf("getPid() error = %v, wantErr %v", err, tt.wantErr) - return - } - if got != tt.want { - t.Errorf("getPid() = %v, want %v", got, tt.want) + + if tt.wantErr { + require.Error(t, err) + } else { + require.Nil(t, err) } + + assert.Equal(t, tt.want, got) }) } } diff --git a/pkg/shim/install.go b/pkg/shim/install.go index c6c35a2..1b8d5e2 100644 --- a/pkg/shim/install.go +++ b/pkg/shim/install.go @@ -26,7 +26,7 @@ import ( "github.com/kwasm/kwasm-node-installer/pkg/state" ) -func (c *Config) Install(shimName string) (string, bool, error) { +func (c *Config) Install(shimName string) (filePath string, changed bool, err error) { shimPath := filepath.Join(c.assetPath, shimName) srcFile, err := c.rootFs.OpenFile(shimPath, os.O_RDONLY, 0000) if err != nil { @@ -52,7 +52,7 @@ func (c *Config) Install(shimName string) (string, bool, error) { _, err = io.Copy(io.MultiWriter(dstFile, shimSha256), srcFile) runtimeName := RuntimeName(shimName) - changed := st.ShimChanged(runtimeName, shimSha256.Sum(nil), dstFilePath) + changed = st.ShimChanged(runtimeName, shimSha256.Sum(nil), dstFilePath) if changed { st.UpdateShim(runtimeName, state.Shim{ Path: dstFilePath, diff --git a/pkg/shim/install_test.go b/pkg/shim/install_test.go index 526ee5a..aa22124 100644 --- a/pkg/shim/install_test.go +++ b/pkg/shim/install_test.go @@ -17,21 +17,14 @@ package shim import ( - "fmt" - "path/filepath" "testing" + "github.com/kwasm/kwasm-node-installer/tests" "github.com/spf13/afero" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) -func newFixtureFs(fixturePath string) afero.Fs { - baseFs := afero.NewBasePathFs(afero.NewOsFs(), filepath.Join("../..", fixturePath)) - p, _ := baseFs.(*afero.BasePathFs).RealPath("/") - fmt.Println(filepath.Abs(p)) - fs := afero.NewCopyOnWriteFs(baseFs, afero.NewMemMapFs()) - return fs -} - func TestConfig_Install(t *testing.T) { type fields struct { rootFs afero.Fs @@ -53,8 +46,8 @@ func TestConfig_Install(t *testing.T) { { "no changes to shim", fields{ - newFixtureFs("testdata"), - newFixtureFs("testdata/shim"), + tests.FixtureFs("testdata"), + tests.FixtureFs("testdata/shim"), "/assets", "/opt/kwasm"}, args{"containerd-shim-spin-v1"}, @@ -65,8 +58,8 @@ func TestConfig_Install(t *testing.T) { { "install new shim over old", fields{ - newFixtureFs("testdata"), - newFixtureFs("testdata/shim"), + tests.FixtureFs("testdata"), + tests.FixtureFs("testdata/shim"), "/assets", "/opt/kwasm"}, args{"containerd-shim-slight-v1"}, @@ -78,7 +71,7 @@ func TestConfig_Install(t *testing.T) { "unable to find new shim", fields{ afero.NewMemMapFs(), - newFixtureFs("testdata/shim"), + tests.FixtureFs("testdata/shim"), "/assets", "/opt/kwasm"}, args{"some-shim"}, @@ -89,8 +82,8 @@ func TestConfig_Install(t *testing.T) { { "unable to write to hostFs", fields{ - newFixtureFs("testdata"), - afero.NewReadOnlyFs(newFixtureFs("testdata/shim")), + tests.FixtureFs("testdata"), + afero.NewReadOnlyFs(tests.FixtureFs("testdata/shim")), "/assets", "/opt/kwasm"}, args{"containerd-shim-spin-v1"}, @@ -108,18 +101,16 @@ func TestConfig_Install(t *testing.T) { kwasmPath: tt.fields.kwasmPath, } - got, got1, err := c.Install(tt.args.shimName) + filepath, changed, err := c.Install(tt.args.shimName) - if (err != nil) != tt.wantErr { - t.Errorf("Config.Install() error = %v, wantErr %v", err, tt.wantErr) - return - } - if got != tt.want { - t.Errorf("Config.Install() got = %v, want %v", got, tt.want) - } - if got1 != tt.want1 { - t.Errorf("Config.Install() got1 = %v, want %v", got1, tt.want1) + if tt.wantErr { + require.Error(t, err) + } else { + require.Nil(t, err) } + + assert.Equal(t, tt.want, filepath) + assert.Equal(t, tt.want1, changed) }) } } diff --git a/pkg/state/shim_test.go b/pkg/state/shim_test.go index 30d581a..7a083b8 100644 --- a/pkg/state/shim_test.go +++ b/pkg/state/shim_test.go @@ -3,6 +3,7 @@ package state import ( "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -31,7 +32,7 @@ func TestShim_MarshalJSON(t *testing.T) { } else { require.Nil(t, err) } - require.Equal(t, tt.want, string(got)) + assert.Equal(t, tt.want, string(got)) }) } } @@ -64,8 +65,8 @@ func TestShim_UnmarshalJSON(t *testing.T) { } else { require.Nil(t, err) } - require.Equal(t, tt.want.path, s.Path) - require.Equal(t, tt.want.sha256, s.Sha256) + assert.Equal(t, tt.want.path, s.Path) + assert.Equal(t, tt.want.sha256, s.Sha256) }) } } diff --git a/pkg/state/state.go b/pkg/state/state.go index 606bd9c..64112df 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -58,7 +58,7 @@ func (l *state) Write() error { return err } - slog.Info("writing lock file", "content", string(out)) + slog.Debug("writing lock file", "content", string(out)) return afero.WriteFile(l.fs, l.lockFilePath, out, 0644) } diff --git a/pkg/state/state_test.go b/pkg/state/state_test.go index 352d1d8..5086915 100644 --- a/pkg/state/state_test.go +++ b/pkg/state/state_test.go @@ -1,22 +1,14 @@ package state import ( - "fmt" - "path/filepath" - "reflect" "testing" + "github.com/kwasm/kwasm-node-installer/tests" "github.com/spf13/afero" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) -func newFixtureFs(fixturePath string) afero.Fs { - baseFs := afero.NewBasePathFs(afero.NewOsFs(), filepath.Join("../..", fixturePath)) - p, _ := baseFs.(*afero.BasePathFs).RealPath("/") - fmt.Println(filepath.Abs(p)) - fs := afero.NewCopyOnWriteFs(baseFs, afero.NewMemMapFs()) - return fs -} - func TestGet(t *testing.T) { type args struct { fs afero.Fs @@ -28,21 +20,20 @@ func TestGet(t *testing.T) { want *state wantErr bool }{ - {"existing state", args{newFixtureFs("testdata/containerd/existing-containerd-shim-config"), "/opt/kwasm"}, &state{Shims: map[string]*Shim{ + {"existing state", args{tests.FixtureFs("testdata/containerd/existing-containerd-shim-config"), "/opt/kwasm"}, &state{Shims: map[string]*Shim{ "spin-v1": {Sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, Path: "/opt/kwasm/bin/containerd-shim-spin-v1"}, }}, false}, - {"missing state", args{newFixtureFs("testdata/containerd/missing-containerd-shim-config"), "/opt/kwasm"}, &state{Shims: map[string]*Shim{}}, false}, + {"missing state", args{tests.FixtureFs("testdata/containerd/missing-containerd-shim-config"), "/opt/kwasm"}, &state{Shims: map[string]*Shim{}}, false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, err := Get(tt.args.fs, tt.args.kwasmPath) - if (err != nil) != tt.wantErr { - t.Errorf("Get() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got.Shims, tt.want.Shims) { - t.Errorf("Get() = %v, want %v", got.Shims, tt.want.Shims) + if tt.wantErr { + require.Error(t, err) + } else { + require.Nil(t, err) } + assert.Equal(t, tt.want.Shims, got.Shims) }) } } @@ -97,9 +88,7 @@ func TestShimChanged(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := state.ShimChanged(tt.shimName, tt.sha256, tt.path) - if result != tt.wantResult { - t.Errorf("ShimChanged() = %v, want %v", result, tt.wantResult) - } + assert.Equal(t, tt.wantResult, result) }) } } diff --git a/tests/fs.go b/tests/fs.go new file mode 100644 index 0000000..891f856 --- /dev/null +++ b/tests/fs.go @@ -0,0 +1,13 @@ +package tests + +import ( + "path/filepath" + + "github.com/spf13/afero" +) + +func FixtureFs(fixturePath string) afero.Fs { + baseFs := afero.NewBasePathFs(afero.NewOsFs(), filepath.Join("../..", fixturePath)) + fs := afero.NewCopyOnWriteFs(baseFs, afero.NewMemMapFs()) + return fs +} From 1c8352634aa31347d092fe0c6deadb22b07eea5d Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 4 Mar 2024 17:13:33 +0100 Subject: [PATCH 78/90] more test refactoring --- pkg/containerd/configure_test.go | 36 +++++------- pkg/shim/install_test.go | 35 ++++++++---- pkg/state/shim_test.go | 46 +++++++++++++-- pkg/state/state_test.go | 96 +++++++++++++++++++++----------- 4 files changed, 144 insertions(+), 69 deletions(-) diff --git a/pkg/containerd/configure_test.go b/pkg/containerd/configure_test.go index 99ee6e7..ab32d91 100644 --- a/pkg/containerd/configure_test.go +++ b/pkg/containerd/configure_test.go @@ -38,13 +38,12 @@ func TestConfig_AddRuntime(t *testing.T) { fields fields args args wantErr bool - wantFileErr bool wantFileContent string }{ {"missing shim config", fields{ hostFs: tests.FixtureFs("testdata/containerd/missing-containerd-shim-config"), configPath: "/etc/containerd/config.toml", - }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, false, `[plugins] + }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, `[plugins] [plugins."io.containerd.monitor.v1.cgroups"] no_prometheus = false [plugins."io.containerd.service.v1.diff-service"] @@ -69,11 +68,11 @@ runtime_type = "/opt/kwasm/bin/containerd-shim-spin-v1" {"missing config", fields{ hostFs: tests.FixtureFs("testdata/containerd/missing-containerd-config"), configPath: "/etc/containerd/config.toml", - }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, true, true, ``}, + }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, true, ``}, {"existing shim config", fields{ hostFs: tests.FixtureFs("testdata/containerd/existing-containerd-shim-config"), configPath: "/etc/containerd/config.toml", - }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, false, `[plugins] + }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, `[plugins] [plugins."io.containerd.monitor.v1.cgroups"] no_prometheus = false [plugins."io.containerd.service.v1.diff-service"] @@ -106,16 +105,13 @@ runtime_type = "/opt/kwasm/bin/containerd-shim-spin-v1" if tt.wantErr { require.Error(t, err) - } else { - require.Nil(t, err) + return } + require.Nil(t, err) + gotContent, err := afero.ReadFile(c.hostFs, c.configPath) - if tt.wantFileErr { - assert.Error(t, err) - } else { - assert.Nil(t, err) - } + require.Nil(t, err) assert.Equal(t, tt.wantFileContent, string(gotContent)) }) @@ -135,13 +131,12 @@ func TestConfig_RemoveRuntime(t *testing.T) { fields fields args args wantErr bool - wantFileErr bool wantFileContent string }{ {"missing shim config", fields{ hostFs: tests.FixtureFs("testdata/containerd/missing-containerd-shim-config"), configPath: "/etc/containerd/config.toml", - }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, false, `[plugins] + }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, `[plugins] [plugins."io.containerd.monitor.v1.cgroups"] no_prometheus = false [plugins."io.containerd.service.v1.diff-service"] @@ -162,11 +157,11 @@ func TestConfig_RemoveRuntime(t *testing.T) { {"missing config", fields{ hostFs: tests.FixtureFs("testdata/containerd/missing-containerd-config"), configPath: "/etc/containerd/config.toml", - }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, true, true, ``}, + }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, true, ``}, {"existing shim config", fields{ hostFs: tests.FixtureFs("testdata/containerd/existing-containerd-shim-config"), configPath: "/etc/containerd/config.toml", - }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, false, `[plugins] + }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, `[plugins] [plugins."io.containerd.monitor.v1.cgroups"] no_prometheus = false [plugins."io.containerd.service.v1.diff-service"] @@ -194,16 +189,13 @@ func TestConfig_RemoveRuntime(t *testing.T) { _, err := c.RemoveRuntime(tt.args.shimPath) if tt.wantErr { require.Error(t, err) - } else { - require.Nil(t, err) + return } + require.Nil(t, err) + gotContent, err := afero.ReadFile(c.hostFs, c.configPath) - if tt.wantFileErr { - assert.Error(t, err) - } else { - assert.Nil(t, err) - } + require.Nil(t, err) assert.Equal(t, tt.wantFileContent, string(gotContent)) }) diff --git a/pkg/shim/install_test.go b/pkg/shim/install_test.go index aa22124..aeb0c84 100644 --- a/pkg/shim/install_test.go +++ b/pkg/shim/install_test.go @@ -26,6 +26,10 @@ import ( ) func TestConfig_Install(t *testing.T) { + type wants struct { + filepath string + changed bool + } type fields struct { rootFs afero.Fs hostFs afero.Fs @@ -39,8 +43,7 @@ func TestConfig_Install(t *testing.T) { name string fields fields args args - want string - want1 bool + want wants wantErr bool }{ { @@ -51,8 +54,10 @@ func TestConfig_Install(t *testing.T) { "/assets", "/opt/kwasm"}, args{"containerd-shim-spin-v1"}, - "/opt/kwasm/bin/containerd-shim-spin-v1", - false, + wants{ + "/opt/kwasm/bin/containerd-shim-spin-v1", + false, + }, false, }, { @@ -63,8 +68,10 @@ func TestConfig_Install(t *testing.T) { "/assets", "/opt/kwasm"}, args{"containerd-shim-slight-v1"}, - "/opt/kwasm/bin/containerd-shim-slight-v1", - true, + wants{ + "/opt/kwasm/bin/containerd-shim-slight-v1", + true, + }, false, }, { @@ -75,8 +82,10 @@ func TestConfig_Install(t *testing.T) { "/assets", "/opt/kwasm"}, args{"some-shim"}, - "", - false, + wants{ + "", + false, + }, true, }, { @@ -87,8 +96,10 @@ func TestConfig_Install(t *testing.T) { "/assets", "/opt/kwasm"}, args{"containerd-shim-spin-v1"}, - "/opt/kwasm/bin/containerd-shim-spin-v1", - false, + wants{ + "/opt/kwasm/bin/containerd-shim-spin-v1", + false, + }, true, }, } @@ -109,8 +120,8 @@ func TestConfig_Install(t *testing.T) { require.Nil(t, err) } - assert.Equal(t, tt.want, filepath) - assert.Equal(t, tt.want1, changed) + assert.Equal(t, tt.want.filepath, filepath) + assert.Equal(t, tt.want.changed, changed) }) } } diff --git a/pkg/state/shim_test.go b/pkg/state/shim_test.go index 7a083b8..9718310 100644 --- a/pkg/state/shim_test.go +++ b/pkg/state/shim_test.go @@ -18,7 +18,15 @@ func TestShim_MarshalJSON(t *testing.T) { want string wantErr bool }{ - {"default", fields{Sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, Path: "/opt/kwasm/bin/containerd-shim-spin-v1"}, `{"sha256":"6da5e8f17a9bfa9cb04cf22c87b6475394ecec3af4fdc337f72d6dbf3319ea52","path":"/opt/kwasm/bin/containerd-shim-spin-v1"}`, false}, + { + "default", + fields{ + Sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, + Path: "/opt/kwasm/bin/containerd-shim-spin-v1", + }, + `{"sha256":"6da5e8f17a9bfa9cb04cf22c87b6475394ecec3af4fdc337f72d6dbf3319ea52","path":"/opt/kwasm/bin/containerd-shim-spin-v1"}`, + false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -51,9 +59,39 @@ func TestShim_UnmarshalJSON(t *testing.T) { want wants wantErr bool }{ - {"default", args{`{"sha256":"6da5e8f17a9bfa9cb04cf22c87b6475394ecec3af4fdc337f72d6dbf3319ea52","path":"/opt/kwasm/bin/containerd-shim-spin-v1"}`}, wants{path: "/opt/kwasm/bin/containerd-shim-spin-v1", sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}}, false}, - {"broken sha", args{`{"sha256":"2","path":"/opt/kwasm/bin/containerd-shim-spin-v1"}`}, wants{path: "/opt/kwasm/bin/containerd-shim-spin-v1", sha256: nil}, true}, - {"broken json", args{`broken`}, wants{path: "", sha256: nil}, true}, + { + "default", + args{ + `{"sha256":"6da5e8f17a9bfa9cb04cf22c87b6475394ecec3af4fdc337f72d6dbf3319ea52","path":"/opt/kwasm/bin/containerd-shim-spin-v1"}`, + }, + wants{ + path: "/opt/kwasm/bin/containerd-shim-spin-v1", + sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, + }, + false, + }, + { + "broken sha", + args{ + `{"sha256":"2","path":"/opt/kwasm/bin/containerd-shim-spin-v1"}`, + }, + wants{ + path: "/opt/kwasm/bin/containerd-shim-spin-v1", + sha256: nil, + }, + true, + }, + { + "broken json", + args{ + `broken`, + }, + wants{ + path: "", + sha256: nil, + }, + true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/state/state_test.go b/pkg/state/state_test.go index 5086915..b8af5ce 100644 --- a/pkg/state/state_test.go +++ b/pkg/state/state_test.go @@ -20,10 +20,33 @@ func TestGet(t *testing.T) { want *state wantErr bool }{ - {"existing state", args{tests.FixtureFs("testdata/containerd/existing-containerd-shim-config"), "/opt/kwasm"}, &state{Shims: map[string]*Shim{ - "spin-v1": {Sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, Path: "/opt/kwasm/bin/containerd-shim-spin-v1"}, - }}, false}, - {"missing state", args{tests.FixtureFs("testdata/containerd/missing-containerd-shim-config"), "/opt/kwasm"}, &state{Shims: map[string]*Shim{}}, false}, + { + "existing state", + args{ + tests.FixtureFs("testdata/containerd/existing-containerd-shim-config"), + "/opt/kwasm", + }, + &state{ + Shims: map[string]*Shim{ + "spin-v1": { + Sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, + Path: "/opt/kwasm/bin/containerd-shim-spin-v1", + }, + }, + }, + false, + }, + { + "missing state", + args{ + tests.FixtureFs("testdata/containerd/missing-containerd-shim-config"), + "/opt/kwasm", + }, + &state{ + Shims: map[string]*Shim{}, + }, + false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -39,6 +62,11 @@ func TestGet(t *testing.T) { } func TestShimChanged(t *testing.T) { + type args struct { + shimName string + sha256 []byte + path string + } state := &state{ Shims: map[string]*Shim{ "spin-v1": { @@ -49,46 +77,52 @@ func TestShimChanged(t *testing.T) { } tests := []struct { - name string - shimName string - sha256 []byte - path string - wantResult bool + name string + args args + want bool }{ { - name: "existing shim, same sha256 and path", - shimName: "spin-v1", - sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, - path: "/opt/kwasm/bin/containerd-shim-spin-v1", - wantResult: false, + "existing shim, same sha256 and path", + args{ + "spin-v1", + []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, + "/opt/kwasm/bin/containerd-shim-spin-v1", + }, + false, }, { - name: "existing shim, different sha256", - shimName: "spin-v1", - sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 83}, - path: "/opt/kwasm/bin/containerd-shim-spin-v1", - wantResult: true, + "existing shim, different sha256", + args{ + "spin-v1", + []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 83}, + "/opt/kwasm/bin/containerd-shim-spin-v1", + }, + true, }, { - name: "existing shim, different path", - shimName: "spin-v1", - sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, - path: "/opt/kwasm/bin/containerd-shim-spin-v2", - wantResult: true, + "existing shim, different path", + args{ + "spin-v1", + []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, + "/opt/kwasm/bin/containerd-shim-spin-v2", + }, + true, }, { - name: "non-existing shim", - shimName: "non-existing", - sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, - path: "/opt/kwasm/bin/containerd-shim-spin-v1", - wantResult: true, + "non-existing shim", + args{ + "non-existing", + []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, + "/opt/kwasm/bin/containerd-shim-spin-v1", + }, + true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - result := state.ShimChanged(tt.shimName, tt.sha256, tt.path) - assert.Equal(t, tt.wantResult, result) + changed := state.ShimChanged(tt.args.shimName, tt.args.sha256, tt.args.path) + assert.Equal(t, tt.want, changed) }) } } From 2fff92299d24ca8bac4880f08464ef009f856d66 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Tue, 5 Mar 2024 11:03:48 +0100 Subject: [PATCH 79/90] configure golangci-lint --- .golangci.yaml | 292 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 292 insertions(+) create mode 100644 .golangci.yaml diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..135cdc4 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,292 @@ +# This code is licensed under the terms of the MIT license https://opensource.org/license/mit +# Copyright (c) 2021 Marat Reymers + +## Golden config for golangci-lint v1.56.2 +# +# This is the best config for golangci-lint based on my experience and opinion. +# It is very strict, but not extremely strict. +# Feel free to adapt and change it for your needs. + +run: + # Timeout for analysis, e.g. 30s, 5m. + # Default: 1m + timeout: 3m + + +# This file contains only configs which differ from defaults. +# All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml +linters-settings: + cyclop: + # The maximal code complexity to report. + # Default: 10 + max-complexity: 30 + # The maximal average package complexity. + # If it's higher than 0.0 (float) the check is enabled + # Default: 0.0 + package-average: 10.0 + + errcheck: + # Report about not checking of errors in type assertions: `a := b.(MyStruct)`. + # Such cases aren't reported by default. + # Default: false + check-type-assertions: true + + exhaustive: + # Program elements to check for exhaustiveness. + # Default: [ switch ] + check: + - switch + - map + + exhaustruct: + # List of regular expressions to exclude struct packages and their names from checks. + # Regular expressions must match complete canonical struct package/name/structname. + # Default: [] + exclude: + # std libs + - "^net/http.Client$" + - "^net/http.Cookie$" + - "^net/http.Request$" + - "^net/http.Response$" + - "^net/http.Server$" + - "^net/http.Transport$" + - "^net/url.URL$" + - "^os/exec.Cmd$" + - "^reflect.StructField$" + # public libs + - "^github.com/Shopify/sarama.Config$" + - "^github.com/Shopify/sarama.ProducerMessage$" + - "^github.com/mitchellh/mapstructure.DecoderConfig$" + - "^github.com/prometheus/client_golang/.+Opts$" + - "^github.com/spf13/cobra.Command$" + - "^github.com/spf13/cobra.CompletionOptions$" + - "^github.com/stretchr/testify/mock.Mock$" + - "^github.com/testcontainers/testcontainers-go.+Request$" + - "^github.com/testcontainers/testcontainers-go.FromDockerfile$" + - "^golang.org/x/tools/go/analysis.Analyzer$" + - "^google.golang.org/protobuf/.+Options$" + - "^gopkg.in/yaml.v3.Node$" + + funlen: + # Checks the number of lines in a function. + # If lower than 0, disable the check. + # Default: 60 + lines: 100 + # Checks the number of statements in a function. + # If lower than 0, disable the check. + # Default: 40 + statements: 50 + # Ignore comments when counting lines. + # Default false + ignore-comments: true + + gocognit: + # Minimal code complexity to report. + # Default: 30 (but we recommend 10-20) + min-complexity: 20 + + gocritic: + # Settings passed to gocritic. + # The settings key is the name of a supported gocritic checker. + # The list of supported checkers can be find in https://go-critic.github.io/overview. + settings: + captLocal: + # Whether to restrict checker to params only. + # Default: true + paramsOnly: false + underef: + # Whether to skip (*x).method() calls where x is a pointer receiver. + # Default: true + skipRecvDeref: false + + gomnd: + # List of function patterns to exclude from analysis. + # Values always ignored: `time.Date`, + # `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`, + # `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`. + # Default: [] + ignored-functions: + - flag.Arg + - flag.Duration.* + - flag.Float.* + - flag.Int.* + - flag.Uint.* + - os.Chmod + - os.Mkdir.* + - os.OpenFile + - os.WriteFile + - prometheus.ExponentialBuckets.* + - prometheus.LinearBuckets + + govet: + # Enable all analyzers. + # Default: false + enable-all: true + # Disable analyzers by name. + # Run `go tool vet help` to see all analyzers. + # Default: [] + disable: + - fieldalignment # too strict + - shadow + # Settings per analyzer. + + inamedparam: + # Skips check for interface methods with only a single parameter. + # Default: false + skip-single-param: true + + nakedret: + # Make an issue if func has more lines of code than this setting, and it has naked returns. + # Default: 30 + max-func-lines: 0 + + nolintlint: + # Exclude following linters from requiring an explanation. + # Default: [] + allow-no-explanation: [ funlen, gocognit, lll ] + # Enable to require an explanation of nonzero length after each nolint directive. + # Default: false + require-explanation: true + # Enable to require nolint directives to mention the specific linter being suppressed. + # Default: false + require-specific: true + + rowserrcheck: + # database/sql is always checked + # Default: [] + packages: + - github.com/jmoiron/sqlx + + tenv: + # The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures. + # Otherwise, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked. + # Default: false + all: true + + +linters: + disable-all: true + enable: + ## enabled by default + - errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases + - gosimple # specializes in simplifying a code + - govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string + - ineffassign # detects when assignments to existing variables are not used + - staticcheck # is a go vet on steroids, applying a ton of static analysis checks + - typecheck # like the front-end of a Go compiler, parses and type-checks Go code + - unused # checks for unused constants, variables, functions and types + ## disabled by default + - asasalint # checks for pass []any as any in variadic func(...any) + - asciicheck # checks that your code does not contain non-ASCII identifiers + - bidichk # checks for dangerous unicode character sequences + - cyclop # checks function and package cyclomatic complexity + - dupl # tool for code clone detection + - errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error + - errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13 + - exhaustive # checks exhaustiveness of enum switch statements + - exhaustruct # checks if all structure fields are initialized + - exportloopref # checks for pointers to enclosing loop variables + - forbidigo # forbids identifiers + - funlen # tool for detection of long functions + - gocognit # computes and checks the cognitive complexity of functions + - goconst # finds repeated strings that could be replaced by a constant + - gocritic # provides diagnostics that check for bugs, performance and style issues + - gocyclo # computes and checks the cyclomatic complexity of functions + - godot # checks if comments end in a period + - goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt + - gomnd # detects magic numbers + - goprintffuncname # checks that printf-like functions are named with f at the end + - gosec # inspects source code for security problems + - makezero # finds slice declarations with non-zero initial length + - nakedret # finds naked returns in functions greater than a specified function length + - nestif # reports deeply nested if statements + - nilerr # finds the code that returns nil even if it checks that the error is not nil + - nilnil # checks that there is no simultaneous return of nil error and an invalid value + - noctx # finds sending http request without context.Context + - nolintlint # reports ill-formed or insufficient nolint directives + - predeclared # finds code that shadows one of Go's predeclared identifiers + - promlinter # checks Prometheus metrics naming via promlint + - reassign # checks that package variables are not reassigned + - revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint + - sloglint # ensure consistent code style when using log/slog + - tenv # detects using os.Setenv instead of t.Setenv since Go1.17 + - testableexamples # checks if examples are testable (have an expected output) + - testifylint # checks usage of github.com/stretchr/testify + - testpackage # makes you use a separate _test package + - tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes + - unconvert # removes unnecessary type conversions + - unparam # reports unused function parameters + - usestdlibvars # detects the possibility to use variables/constants from the Go standard library + - wastedassign # finds wasted assignment statements + - whitespace # detects leading and trailing whitespace + + ## you may want to enable + #- decorder # checks declaration order and count of types, constants, variables and functions + #- gci # controls golang package import order and makes it always deterministic + #- ginkgolinter # [if you use ginkgo/gomega] enforces standards of using ginkgo and gomega + #- godox # detects FIXME, TODO and other comment keywords + #- goheader # checks is file header matches to pattern + #- inamedparam # [great idea, but too strict, need to ignore a lot of cases by default] reports interfaces with unnamed method parameters + #- interfacebloat # checks the number of methods inside an interface + #- ireturn # accept interfaces, return concrete types + #- prealloc # [premature optimization, but can be used in some cases] finds slice declarations that could potentially be preallocated + #- tagalign # checks that struct tags are well aligned + #- varnamelen # [great idea, but too many false positives] checks that the length of a variable's name matches its scope + #- wrapcheck # checks that errors returned from external packages are wrapped + #- zerologlint # detects the wrong usage of zerolog that a user forgets to dispatch zerolog.Event + + ## disabled + #- containedctx # detects struct contained context.Context field + #- contextcheck # [too many false positives] checks the function whether use a non-inherited context + #- depguard # [replaced by gomodguard] checks if package imports are in a list of acceptable packages + #- dogsled # checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) + #- dupword # [useless without config] checks for duplicate words in the source code + #- errchkjson # [don't see profit + I'm against of omitting errors like in the first example https://github.com/breml/errchkjson] checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted + #- forcetypeassert # [replaced by errcheck] finds forced type assertions + #- goerr113 # [too strict] checks the errors handling expressions + #- gofmt # [replaced by goimports] checks whether code was gofmt-ed + #- gofumpt # [replaced by goimports, gofumports is not available yet] checks whether code was gofumpt-ed + #- gosmopolitan # reports certain i18n/l10n anti-patterns in your Go codebase + #- grouper # analyzes expression groups + #- importas # enforces consistent import aliases + #- maintidx # measures the maintainability index of each function + #- misspell # [useless] finds commonly misspelled English words in comments + #- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity + #- paralleltest # [too many false positives] detects missing usage of t.Parallel() method in your Go test + #- tagliatelle # checks the struct tags + #- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers + #- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines + + ## deprecated + #- deadcode # [deprecated, replaced by unused] finds unused code + #- exhaustivestruct # [deprecated, replaced by exhaustruct] checks if all struct's fields are initialized + #- golint # [deprecated, replaced by revive] golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes + #- ifshort # [deprecated] checks that your code uses short syntax for if-statements whenever possible + #- interfacer # [deprecated] suggests narrower interface types + #- maligned # [deprecated, replaced by govet fieldalignment] detects Go structs that would take less memory if their fields were sorted + #- nosnakecase # [deprecated, replaced by revive var-naming] detects snake case of variable naming and function name + #- scopelint # [deprecated, replaced by exportloopref] checks for unpinned variables in go programs + #- structcheck # [deprecated, replaced by unused] finds unused struct fields + #- varcheck # [deprecated, replaced by unused] finds unused global variables and constants + + +issues: + # Maximum count of issues with the same text. + # Set to 0 to disable. + # Default: 3 + max-same-issues: 50 + + exclude-rules: + - source: "(noinspection|TODO)" + linters: [ godot ] + - source: "//noinspection" + linters: [ gocritic ] + - path: "_test\\.go" + linters: + - bodyclose + - dupl + - funlen + - goconst + - gosec + - noctx + - wrapcheck From 3aa78b8526be8384e32f5fdc0b17cd219a2f87de Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Tue, 5 Mar 2024 11:04:03 +0100 Subject: [PATCH 80/90] fix lint complaints --- cmd/install.go | 2 +- cmd/root.go | 11 ++++++----- cmd/uninstall.go | 2 +- go.mod | 2 +- pkg/containerd/configure.go | 6 +++--- pkg/containerd/configure_test.go | 10 +++++----- pkg/containerd/restart_unix.go | 7 +++---- pkg/containerd/restart_unix_test.go | 11 +++++------ pkg/shim/install.go | 6 +++--- pkg/shim/install_test.go | 4 ++-- pkg/shim/uninstall.go | 1 - pkg/state/shim.go | 4 ++-- pkg/state/shim_test.go | 8 ++++---- pkg/state/state.go | 16 ++++++++-------- pkg/state/state_test.go | 21 +++++++++++---------- 15 files changed, 55 insertions(+), 56 deletions(-) diff --git a/cmd/install.go b/cmd/install.go index c4ed954..6f665cf 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -29,7 +29,7 @@ import ( "github.com/spf13/cobra" ) -// installCmd represents the install command +// installCmd represents the install command. var installCmd = &cobra.Command{ Use: "install", Short: "Install containerd shims", diff --git a/cmd/root.go b/cmd/root.go index 81279c8..de8e206 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -17,6 +17,7 @@ package cmd import ( + "errors" "fmt" "os" "strings" @@ -31,11 +32,11 @@ var ( config cfg.Config ) -// rootCmd represents the base command when called without any subcommands +// rootCmd represents the base command when called without any subcommands. var rootCmd = &cobra.Command{ Use: "kwasm-node-installer", Short: "kwasm-node-installer manages containerd shims", - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { return initializeConfig(cmd) }, } @@ -65,7 +66,7 @@ func initializeConfig(cmd *cobra.Command) error { v.AddConfigPath("/etc") if err := v.ReadInConfig(); err != nil { - if _, ok := err.(viper.ConfigFileNotFoundError); !ok { + if !errors.As(err, &viper.ConfigFileNotFoundError{}) { return err } } @@ -84,14 +85,14 @@ func initializeConfig(cmd *cobra.Command) error { return nil } -// bindFlags binds each cobra flag to its associated viper configuration +// bindFlags binds each cobra flag to its associated viper configuration. func bindFlags(cmd *cobra.Command, v *viper.Viper) { cmd.Flags().VisitAll(func(f *pflag.Flag) { configName := strings.ReplaceAll(f.Name, "-", "_") if !f.Changed && v.IsSet(configName) { val := v.Get(configName) - cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val)) + _ = cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val)) } }) } diff --git a/cmd/uninstall.go b/cmd/uninstall.go index e7eb201..dff05ef 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -29,7 +29,7 @@ import ( "github.com/kwasm/kwasm-node-installer/pkg/shim" ) -// uninstallCmd represents the uninstall command +// uninstallCmd represents the uninstall command. var uninstallCmd = &cobra.Command{ Use: "uninstall", Short: "Uninstall containerd shims", diff --git a/go.mod b/go.mod index f70fa65..d92c0d2 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/kwasm/kwasm-node-installer -go 1.21.0 +go 1.22.0 require ( github.com/spf13/cobra v1.7.0 diff --git a/pkg/containerd/configure.go b/pkg/containerd/configure.go index 8466c27..cf58067 100644 --- a/pkg/containerd/configure.go +++ b/pkg/containerd/configure.go @@ -58,7 +58,7 @@ func (c *Config) AddRuntime(shimPath string) error { } // Open file in append mode - file, err := c.hostFs.OpenFile(c.configPath, os.O_APPEND|os.O_WRONLY, 0644) + file, err := c.hostFs.OpenFile(c.configPath, os.O_APPEND|os.O_WRONLY, 0644) //nolint:gomnd // file permissions if err != nil { return err } @@ -92,10 +92,10 @@ func (c *Config) RemoveRuntime(shimPath string) (changed bool, err error) { } // Convert the file data to a string and replace the target string with an empty string. - modifiedData := strings.Replace(string(data), cfg, "", -1) + modifiedData := strings.ReplaceAll(string(data), cfg, "") // Write the modified data back to the file. - err = afero.WriteFile(c.hostFs, c.configPath, []byte(modifiedData), 0644) + err = afero.WriteFile(c.hostFs, c.configPath, []byte(modifiedData), 0644) //nolint:gomnd // file permissions if err != nil { return false, err } diff --git a/pkg/containerd/configure_test.go b/pkg/containerd/configure_test.go index ab32d91..348a3e3 100644 --- a/pkg/containerd/configure_test.go +++ b/pkg/containerd/configure_test.go @@ -14,7 +14,7 @@ limitations under the License. */ -package containerd +package containerd //nolint:testpackage // whitebox test import ( "testing" @@ -108,10 +108,10 @@ runtime_type = "/opt/kwasm/bin/containerd-shim-spin-v1" return } - require.Nil(t, err) + require.NoError(t, err) gotContent, err := afero.ReadFile(c.hostFs, c.configPath) - require.Nil(t, err) + require.NoError(t, err) assert.Equal(t, tt.wantFileContent, string(gotContent)) }) @@ -192,10 +192,10 @@ func TestConfig_RemoveRuntime(t *testing.T) { return } - require.Nil(t, err) + require.NoError(t, err) gotContent, err := afero.ReadFile(c.hostFs, c.configPath) - require.Nil(t, err) + require.NoError(t, err) assert.Equal(t, tt.wantFileContent, string(gotContent)) }) diff --git a/pkg/containerd/restart_unix.go b/pkg/containerd/restart_unix.go index f331b89..466531c 100644 --- a/pkg/containerd/restart_unix.go +++ b/pkg/containerd/restart_unix.go @@ -56,12 +56,11 @@ func getPid() (int, error) { if process.Executable() == "containerd" { containerdProcesses = append(containerdProcesses, process) } - } - if len(containerdProcesses) == 1 { - return containerdProcesses[0].Pid(), nil - } else { + if len(containerdProcesses) != 1 { return 0, fmt.Errorf("need exactly one containerd process, found: %d", len(containerdProcesses)) } + + return containerdProcesses[0].Pid(), nil } diff --git a/pkg/containerd/restart_unix_test.go b/pkg/containerd/restart_unix_test.go index d199c91..866f684 100644 --- a/pkg/containerd/restart_unix_test.go +++ b/pkg/containerd/restart_unix_test.go @@ -1,7 +1,7 @@ //go:build unix // +build unix -package containerd +package containerd //nolint:testpackage // whitebox test import ( "fmt" @@ -15,7 +15,6 @@ import ( type mockProcess struct { executable string pid int - ppid int } func (p *mockProcess) Executable() string { @@ -27,7 +26,7 @@ func (p *mockProcess) Pid() int { } func (p *mockProcess) PPid() int { - return p.ppid + return 0 } func Test_getPid(t *testing.T) { @@ -47,8 +46,8 @@ func Test_getPid(t *testing.T) { }, 123, false}, {"multiple containerd processes found", func() ([]ps.Process, error) { return []ps.Process{ - &mockProcess{executable: "containerd"}, - &mockProcess{executable: "containerd"}, + &mockProcess{executable: "containerd", pid: 0}, + &mockProcess{executable: "containerd", pid: 0}, }, nil }, 0, true}, {"error getting processes", func() ([]ps.Process, error) { @@ -63,7 +62,7 @@ func Test_getPid(t *testing.T) { if tt.wantErr { require.Error(t, err) } else { - require.Nil(t, err) + require.NoError(t, err) } assert.Equal(t, tt.want, got) diff --git a/pkg/shim/install.go b/pkg/shim/install.go index 1b8d5e2..aed7bf4 100644 --- a/pkg/shim/install.go +++ b/pkg/shim/install.go @@ -28,18 +28,18 @@ import ( func (c *Config) Install(shimName string) (filePath string, changed bool, err error) { shimPath := filepath.Join(c.assetPath, shimName) - srcFile, err := c.rootFs.OpenFile(shimPath, os.O_RDONLY, 0000) + srcFile, err := c.rootFs.OpenFile(shimPath, os.O_RDONLY, 0000) //nolint:gomnd // file permissions if err != nil { return "", false, err } dstFilePath := path.Join(c.kwasmPath, "bin", shimName) - err = c.hostFs.MkdirAll(path.Dir(dstFilePath), 0775) + err = c.hostFs.MkdirAll(path.Dir(dstFilePath), 0775) //nolint:gomnd // file permissions if err != nil { return dstFilePath, false, err } - dstFile, err := c.hostFs.OpenFile(dstFilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) + dstFile, err := c.hostFs.OpenFile(dstFilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) //nolint:gomnd // file permissions if err != nil { return "", false, err } diff --git a/pkg/shim/install_test.go b/pkg/shim/install_test.go index aeb0c84..944718a 100644 --- a/pkg/shim/install_test.go +++ b/pkg/shim/install_test.go @@ -14,7 +14,7 @@ limitations under the License. */ -package shim +package shim //nolint:testpackage // whitebox test import ( "testing" @@ -117,7 +117,7 @@ func TestConfig_Install(t *testing.T) { if tt.wantErr { require.Error(t, err) } else { - require.Nil(t, err) + require.NoError(t, err) } assert.Equal(t, tt.want.filepath, filepath) diff --git a/pkg/shim/uninstall.go b/pkg/shim/uninstall.go index aec5a18..88d8e79 100644 --- a/pkg/shim/uninstall.go +++ b/pkg/shim/uninstall.go @@ -9,7 +9,6 @@ import ( ) func (c *Config) Uninstall(shimName string) (string, error) { - st, err := state.Get(c.hostFs, c.kwasmPath) if err != nil { return "", err diff --git a/pkg/state/shim.go b/pkg/state/shim.go index 46addcd..892c1d1 100644 --- a/pkg/state/shim.go +++ b/pkg/state/shim.go @@ -21,10 +21,10 @@ func (s *Shim) MarshalJSON() ([]byte, error) { } func (s *Shim) UnmarshalJSON(data []byte) error { - aux := struct { + var aux struct { Sha256 string `json:"sha256"` Path string `json:"path"` - }{} + } if err := json.Unmarshal(data, &aux); err != nil { return err } diff --git a/pkg/state/shim_test.go b/pkg/state/shim_test.go index 9718310..b2b0c4f 100644 --- a/pkg/state/shim_test.go +++ b/pkg/state/shim_test.go @@ -1,4 +1,4 @@ -package state +package state //nolint:testpackage // whitebox test import ( "testing" @@ -38,7 +38,7 @@ func TestShim_MarshalJSON(t *testing.T) { if tt.wantErr { require.Error(t, err) } else { - require.Nil(t, err) + require.NoError(t, err) } assert.Equal(t, tt.want, string(got)) }) @@ -95,13 +95,13 @@ func TestShim_UnmarshalJSON(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - s := Shim{} + var s Shim err := s.UnmarshalJSON([]byte(tt.args.data)) if tt.wantErr { require.Error(t, err) } else { - require.Nil(t, err) + require.NoError(t, err) } assert.Equal(t, tt.want.path, s.Path) assert.Equal(t, tt.want.sha256, s.Sha256) diff --git a/pkg/state/state.go b/pkg/state/state.go index 64112df..34113d3 100644 --- a/pkg/state/state.go +++ b/pkg/state/state.go @@ -11,14 +11,14 @@ import ( "github.com/spf13/afero" ) -type state struct { +type State struct { Shims map[string]*Shim `json:"shims"` fs afero.Fs lockFilePath string } -func Get(fs afero.Fs, kwasmPath string) (*state, error) { - out := state{ +func Get(fs afero.Fs, kwasmPath string) (*State, error) { + out := State{ Shims: make(map[string]*Shim), lockFilePath: filepath.Join(kwasmPath, "kwasm-lock.json"), fs: fs, @@ -35,7 +35,7 @@ func Get(fs afero.Fs, kwasmPath string) (*state, error) { return &out, nil } -func (l *state) ShimChanged(shimName string, sha256 []byte, path string) bool { +func (l *State) ShimChanged(shimName string, sha256 []byte, path string) bool { shim, ok := l.Shims[shimName] if !ok { return true @@ -44,15 +44,15 @@ func (l *state) ShimChanged(shimName string, sha256 []byte, path string) bool { return !bytes.Equal(shim.Sha256, sha256) || shim.Path != path } -func (l *state) UpdateShim(shimName string, shim Shim) { +func (l *State) UpdateShim(shimName string, shim Shim) { l.Shims[shimName] = &shim } -func (l *state) RemoveShim(shimName string) { +func (l *State) RemoveShim(shimName string) { delete(l.Shims, shimName) } -func (l *state) Write() error { +func (l *State) Write() error { out, err := json.MarshalIndent(l, "", " ") if err != nil { return err @@ -60,5 +60,5 @@ func (l *state) Write() error { slog.Debug("writing lock file", "content", string(out)) - return afero.WriteFile(l.fs, l.lockFilePath, out, 0644) + return afero.WriteFile(l.fs, l.lockFilePath, out, 0644) //nolint:gomnd // file permissions } diff --git a/pkg/state/state_test.go b/pkg/state/state_test.go index b8af5ce..e360fcd 100644 --- a/pkg/state/state_test.go +++ b/pkg/state/state_test.go @@ -1,8 +1,9 @@ -package state +package state_test import ( "testing" + "github.com/kwasm/kwasm-node-installer/pkg/state" "github.com/kwasm/kwasm-node-installer/tests" "github.com/spf13/afero" "github.com/stretchr/testify/assert" @@ -17,7 +18,7 @@ func TestGet(t *testing.T) { tests := []struct { name string args args - want *state + want *state.State wantErr bool }{ { @@ -26,8 +27,8 @@ func TestGet(t *testing.T) { tests.FixtureFs("testdata/containerd/existing-containerd-shim-config"), "/opt/kwasm", }, - &state{ - Shims: map[string]*Shim{ + &state.State{ + Shims: map[string]*state.Shim{ "spin-v1": { Sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, Path: "/opt/kwasm/bin/containerd-shim-spin-v1", @@ -42,19 +43,19 @@ func TestGet(t *testing.T) { tests.FixtureFs("testdata/containerd/missing-containerd-shim-config"), "/opt/kwasm", }, - &state{ - Shims: map[string]*Shim{}, + &state.State{ + Shims: map[string]*state.Shim{}, }, false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := Get(tt.args.fs, tt.args.kwasmPath) + got, err := state.Get(tt.args.fs, tt.args.kwasmPath) if tt.wantErr { require.Error(t, err) } else { - require.Nil(t, err) + require.NoError(t, err) } assert.Equal(t, tt.want.Shims, got.Shims) }) @@ -67,8 +68,8 @@ func TestShimChanged(t *testing.T) { sha256 []byte path string } - state := &state{ - Shims: map[string]*Shim{ + state := &state.State{ + Shims: map[string]*state.Shim{ "spin-v1": { Sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, Path: "/opt/kwasm/bin/containerd-shim-spin-v1", From e1c7c74e120b82624a2246226913412645fddf4b Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Tue, 5 Mar 2024 12:57:07 +0100 Subject: [PATCH 81/90] move main config to cmd package --- {pkg/config => cmd}/config.go | 2 +- cmd/root.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) rename {pkg/config => cmd}/config.go (98%) diff --git a/pkg/config/config.go b/cmd/config.go similarity index 98% rename from pkg/config/config.go rename to cmd/config.go index e353714..a678a9f 100644 --- a/pkg/config/config.go +++ b/cmd/config.go @@ -14,7 +14,7 @@ limitations under the License. */ -package config +package cmd import "path" diff --git a/cmd/root.go b/cmd/root.go index de8e206..9da97d1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -22,14 +22,13 @@ import ( "os" "strings" - cfg "github.com/kwasm/kwasm-node-installer/pkg/config" "github.com/spf13/cobra" "github.com/spf13/pflag" "github.com/spf13/viper" ) var ( - config cfg.Config + config Config ) // rootCmd represents the base command when called without any subcommands. From 0ea09ed801b2b67bb6d0fe5b1adde800f6800ab2 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Tue, 5 Mar 2024 12:59:17 +0100 Subject: [PATCH 82/90] remove unused methods --- cmd/config.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index a678a9f..2f4eff1 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -16,8 +16,6 @@ package cmd -import "path" - type Config struct { Runtime struct { Name string @@ -31,11 +29,3 @@ type Config struct { RootPath string } } - -func (c *Config) PathWithHost(p string) string { - return path.Join(c.Host.RootPath, p) -} - -func (c *Config) AssetPath(assetName string) string { - return path.Join(c.Kwasm.AssetPath, assetName) -} From 08fecbdbde1acbf761f80f3e9325ae2ff49405fd Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Tue, 5 Mar 2024 13:09:59 +0100 Subject: [PATCH 83/90] make config struct private --- cmd/config.go | 18 +++++++++--------- cmd/install.go | 16 ++++++++-------- cmd/root.go | 10 +++++----- cmd/uninstall.go | 10 +++++----- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index 2f4eff1..2ce745c 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -16,16 +16,16 @@ package cmd -type Config struct { - Runtime struct { - Name string - ConfigPath string +type config struct { + runtime struct { + name string + configPath string } - Kwasm struct { - Path string - AssetPath string + kwasm struct { + path string + assetPath string } - Host struct { - RootPath string + host struct { + rootPath string } } diff --git a/cmd/install.go b/cmd/install.go index 6f665cf..a062abf 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -42,13 +42,13 @@ var installCmd = &cobra.Command{ } func init() { - installCmd.Flags().StringVarP(&config.Kwasm.AssetPath, "asset-path", "a", "/assets", "Path to the asset to install") + installCmd.Flags().StringVarP(&conf.kwasm.assetPath, "asset-path", "a", "/assets", "Path to the asset to install") rootCmd.AddCommand(installCmd) } func runInstall(_ *cobra.Command, _ []string) error { // Get file or directory information. - info, err := os.Stat(config.Kwasm.AssetPath) + info, err := os.Stat(conf.kwasm.assetPath) if err != nil { return err } @@ -56,21 +56,21 @@ func runInstall(_ *cobra.Command, _ []string) error { var files []fs.DirEntry // Check if the path is a directory. if info.IsDir() { - files, err = os.ReadDir(config.Kwasm.AssetPath) + files, err = os.ReadDir(conf.kwasm.assetPath) if err != nil { return err } } else { // If the path is not a directory, add the file to the list of files. files = append(files, fs.FileInfoToDirEntry(info)) - config.Kwasm.AssetPath = path.Dir(config.Kwasm.AssetPath) + conf.kwasm.assetPath = path.Dir(conf.kwasm.assetPath) } rootFs := afero.NewOsFs() - hostFs := afero.NewBasePathFs(rootFs, config.Host.RootPath) + hostFs := afero.NewBasePathFs(rootFs, conf.host.rootPath) - containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath) - shimConfig := shim.NewConfig(rootFs, hostFs, config.Kwasm.AssetPath, config.Kwasm.Path) + containerdConfig := containerd.NewConfig(hostFs, conf.runtime.configPath) + shimConfig := shim.NewConfig(rootFs, hostFs, conf.kwasm.assetPath, conf.kwasm.path) anythingChanged := false for _, file := range files { @@ -88,7 +88,7 @@ func runInstall(_ *cobra.Command, _ []string) error { if err != nil { return fmt.Errorf("failed to write containerd config: %w", err) } - slog.Info("shim configured", "shim", runtimeName, "path", config.Runtime.ConfigPath) + slog.Info("shim configured", "shim", runtimeName, "path", conf.runtime.configPath) } if !anythingChanged { diff --git a/cmd/root.go b/cmd/root.go index 9da97d1..a852ab9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -28,7 +28,7 @@ import ( ) var ( - config Config + conf config ) // rootCmd represents the base command when called without any subcommands. @@ -50,10 +50,10 @@ func Execute() { } func init() { - rootCmd.PersistentFlags().StringVarP(&config.Runtime.Name, "runtime", "r", "containerd", "Set the container runtime to configure (containerd, cri-o)") - rootCmd.PersistentFlags().StringVarP(&config.Runtime.ConfigPath, "runtime-config", "c", "/etc/containerd/config.toml", "Path to the runtime config file") - rootCmd.PersistentFlags().StringVarP(&config.Kwasm.Path, "kwasm-path", "k", "/opt/kwasm", "Working directory for kwasm on the host") - rootCmd.PersistentFlags().StringVarP(&config.Host.RootPath, "host-root", "H", "/", "Path to the host root path") + rootCmd.PersistentFlags().StringVarP(&conf.runtime.name, "runtime", "r", "containerd", "Set the container runtime to configure (containerd, cri-o)") + rootCmd.PersistentFlags().StringVarP(&conf.runtime.configPath, "runtime-config", "c", "/etc/containerd/config.toml", "Path to the runtime config file") + rootCmd.PersistentFlags().StringVarP(&conf.kwasm.path, "kwasm-path", "k", "/opt/kwasm", "Working directory for kwasm on the host") + rootCmd.PersistentFlags().StringVarP(&conf.host.rootPath, "host-root", "H", "/", "Path to the host root path") } func initializeConfig(cmd *cobra.Command) error { diff --git a/cmd/uninstall.go b/cmd/uninstall.go index dff05ef..7a8ce05 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -47,14 +47,14 @@ func init() { func runUninstall(_ *cobra.Command, _ []string) error { slog.Info("uninstall called") - shimName := config.Runtime.Name - runtimeName := path.Join(config.Kwasm.Path, "bin", shimName) + shimName := conf.runtime.name + runtimeName := path.Join(conf.kwasm.path, "bin", shimName) rootFs := afero.NewOsFs() - hostFs := afero.NewBasePathFs(rootFs, config.Host.RootPath) + hostFs := afero.NewBasePathFs(rootFs, conf.host.rootPath) - containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath) - shimConfig := shim.NewConfig(rootFs, hostFs, config.Kwasm.AssetPath, config.Kwasm.Path) + containerdConfig := containerd.NewConfig(hostFs, conf.runtime.configPath) + shimConfig := shim.NewConfig(rootFs, hostFs, conf.kwasm.assetPath, conf.kwasm.path) binPath, err := shimConfig.Uninstall(shimName) if err != nil { From 2bf4e111c178227c272454e3a2fd76d9ee847004 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Tue, 5 Mar 2024 13:14:52 +0100 Subject: [PATCH 84/90] make runInstall and runUninstall easier to test --- cmd/install.go | 12 ++++++------ cmd/uninstall.go | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/install.go b/cmd/install.go index a062abf..18a19a9 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -33,8 +33,11 @@ import ( var installCmd = &cobra.Command{ Use: "install", Short: "Install containerd shims", - Run: func(cmd *cobra.Command, args []string) { - if err := runInstall(cmd, args); err != nil { + Run: func(_ *cobra.Command, _ []string) { + rootFs := afero.NewOsFs() + hostFs := afero.NewBasePathFs(rootFs, conf.host.rootPath) + + if err := runInstall(conf, rootFs, hostFs); err != nil { slog.Error("failed to install", "error", err) os.Exit(1) } @@ -46,7 +49,7 @@ func init() { rootCmd.AddCommand(installCmd) } -func runInstall(_ *cobra.Command, _ []string) error { +func runInstall(conf config, rootFs, hostFs afero.Fs) error { // Get file or directory information. info, err := os.Stat(conf.kwasm.assetPath) if err != nil { @@ -66,9 +69,6 @@ func runInstall(_ *cobra.Command, _ []string) error { conf.kwasm.assetPath = path.Dir(conf.kwasm.assetPath) } - rootFs := afero.NewOsFs() - hostFs := afero.NewBasePathFs(rootFs, conf.host.rootPath) - containerdConfig := containerd.NewConfig(hostFs, conf.runtime.configPath) shimConfig := shim.NewConfig(rootFs, hostFs, conf.kwasm.assetPath, conf.kwasm.path) diff --git a/cmd/uninstall.go b/cmd/uninstall.go index 7a8ce05..19cc64b 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -33,8 +33,11 @@ import ( var uninstallCmd = &cobra.Command{ Use: "uninstall", Short: "Uninstall containerd shims", - Run: func(cmd *cobra.Command, args []string) { - if err := runUninstall(cmd, args); err != nil { + Run: func(_ *cobra.Command, _ []string) { + rootFs := afero.NewOsFs() + hostFs := afero.NewBasePathFs(rootFs, conf.host.rootPath) + + if err := runUninstall(conf, rootFs, hostFs); err != nil { slog.Error("failed to uninstall", "error", err) os.Exit(1) } @@ -45,14 +48,11 @@ func init() { rootCmd.AddCommand(uninstallCmd) } -func runUninstall(_ *cobra.Command, _ []string) error { +func runUninstall(conf config, rootFs, hostFs afero.Fs) error { slog.Info("uninstall called") shimName := conf.runtime.name runtimeName := path.Join(conf.kwasm.path, "bin", shimName) - rootFs := afero.NewOsFs() - hostFs := afero.NewBasePathFs(rootFs, conf.host.rootPath) - containerdConfig := containerd.NewConfig(hostFs, conf.runtime.configPath) shimConfig := shim.NewConfig(rootFs, hostFs, conf.kwasm.assetPath, conf.kwasm.path) From d57a24221fca16f149ae579cfe021ea2f3ee9d03 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Tue, 5 Mar 2024 14:29:32 +0100 Subject: [PATCH 85/90] Revert "make config struct private" This reverts commit 08fecbdbde1acbf761f80f3e9325ae2ff49405fd. --- cmd/config.go | 18 +++++++++--------- cmd/install.go | 20 ++++++++++---------- cmd/root.go | 10 +++++----- cmd/uninstall.go | 14 +++++++------- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index 2ce745c..2f4eff1 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -16,16 +16,16 @@ package cmd -type config struct { - runtime struct { - name string - configPath string +type Config struct { + Runtime struct { + Name string + ConfigPath string } - kwasm struct { - path string - assetPath string + Kwasm struct { + Path string + AssetPath string } - host struct { - rootPath string + Host struct { + RootPath string } } diff --git a/cmd/install.go b/cmd/install.go index 18a19a9..bf9ffaf 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -35,9 +35,9 @@ var installCmd = &cobra.Command{ Short: "Install containerd shims", Run: func(_ *cobra.Command, _ []string) { rootFs := afero.NewOsFs() - hostFs := afero.NewBasePathFs(rootFs, conf.host.rootPath) + hostFs := afero.NewBasePathFs(rootFs, config.Host.RootPath) - if err := runInstall(conf, rootFs, hostFs); err != nil { + if err := runInstall(config, rootFs, hostFs); err != nil { slog.Error("failed to install", "error", err) os.Exit(1) } @@ -45,13 +45,13 @@ var installCmd = &cobra.Command{ } func init() { - installCmd.Flags().StringVarP(&conf.kwasm.assetPath, "asset-path", "a", "/assets", "Path to the asset to install") + installCmd.Flags().StringVarP(&config.Kwasm.AssetPath, "asset-path", "a", "/assets", "Path to the asset to install") rootCmd.AddCommand(installCmd) } -func runInstall(conf config, rootFs, hostFs afero.Fs) error { +func runInstall(config Config, rootFs, hostFs afero.Fs) error { // Get file or directory information. - info, err := os.Stat(conf.kwasm.assetPath) + info, err := os.Stat(config.Kwasm.AssetPath) if err != nil { return err } @@ -59,18 +59,18 @@ func runInstall(conf config, rootFs, hostFs afero.Fs) error { var files []fs.DirEntry // Check if the path is a directory. if info.IsDir() { - files, err = os.ReadDir(conf.kwasm.assetPath) + files, err = os.ReadDir(config.Kwasm.AssetPath) if err != nil { return err } } else { // If the path is not a directory, add the file to the list of files. files = append(files, fs.FileInfoToDirEntry(info)) - conf.kwasm.assetPath = path.Dir(conf.kwasm.assetPath) + config.Kwasm.AssetPath = path.Dir(config.Kwasm.AssetPath) } - containerdConfig := containerd.NewConfig(hostFs, conf.runtime.configPath) - shimConfig := shim.NewConfig(rootFs, hostFs, conf.kwasm.assetPath, conf.kwasm.path) + containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath) + shimConfig := shim.NewConfig(rootFs, hostFs, config.Kwasm.AssetPath, config.Kwasm.Path) anythingChanged := false for _, file := range files { @@ -88,7 +88,7 @@ func runInstall(conf config, rootFs, hostFs afero.Fs) error { if err != nil { return fmt.Errorf("failed to write containerd config: %w", err) } - slog.Info("shim configured", "shim", runtimeName, "path", conf.runtime.configPath) + slog.Info("shim configured", "shim", runtimeName, "path", config.Runtime.ConfigPath) } if !anythingChanged { diff --git a/cmd/root.go b/cmd/root.go index a852ab9..9da97d1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -28,7 +28,7 @@ import ( ) var ( - conf config + config Config ) // rootCmd represents the base command when called without any subcommands. @@ -50,10 +50,10 @@ func Execute() { } func init() { - rootCmd.PersistentFlags().StringVarP(&conf.runtime.name, "runtime", "r", "containerd", "Set the container runtime to configure (containerd, cri-o)") - rootCmd.PersistentFlags().StringVarP(&conf.runtime.configPath, "runtime-config", "c", "/etc/containerd/config.toml", "Path to the runtime config file") - rootCmd.PersistentFlags().StringVarP(&conf.kwasm.path, "kwasm-path", "k", "/opt/kwasm", "Working directory for kwasm on the host") - rootCmd.PersistentFlags().StringVarP(&conf.host.rootPath, "host-root", "H", "/", "Path to the host root path") + rootCmd.PersistentFlags().StringVarP(&config.Runtime.Name, "runtime", "r", "containerd", "Set the container runtime to configure (containerd, cri-o)") + rootCmd.PersistentFlags().StringVarP(&config.Runtime.ConfigPath, "runtime-config", "c", "/etc/containerd/config.toml", "Path to the runtime config file") + rootCmd.PersistentFlags().StringVarP(&config.Kwasm.Path, "kwasm-path", "k", "/opt/kwasm", "Working directory for kwasm on the host") + rootCmd.PersistentFlags().StringVarP(&config.Host.RootPath, "host-root", "H", "/", "Path to the host root path") } func initializeConfig(cmd *cobra.Command) error { diff --git a/cmd/uninstall.go b/cmd/uninstall.go index 19cc64b..e0ca662 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -35,9 +35,9 @@ var uninstallCmd = &cobra.Command{ Short: "Uninstall containerd shims", Run: func(_ *cobra.Command, _ []string) { rootFs := afero.NewOsFs() - hostFs := afero.NewBasePathFs(rootFs, conf.host.rootPath) + hostFs := afero.NewBasePathFs(rootFs, config.Host.RootPath) - if err := runUninstall(conf, rootFs, hostFs); err != nil { + if err := runUninstall(config, rootFs, hostFs); err != nil { slog.Error("failed to uninstall", "error", err) os.Exit(1) } @@ -48,13 +48,13 @@ func init() { rootCmd.AddCommand(uninstallCmd) } -func runUninstall(conf config, rootFs, hostFs afero.Fs) error { +func runUninstall(config Config, rootFs, hostFs afero.Fs) error { slog.Info("uninstall called") - shimName := conf.runtime.name - runtimeName := path.Join(conf.kwasm.path, "bin", shimName) + shimName := config.Runtime.Name + runtimeName := path.Join(config.Kwasm.Path, "bin", shimName) - containerdConfig := containerd.NewConfig(hostFs, conf.runtime.configPath) - shimConfig := shim.NewConfig(rootFs, hostFs, conf.kwasm.assetPath, conf.kwasm.path) + containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath) + shimConfig := shim.NewConfig(rootFs, hostFs, config.Kwasm.AssetPath, config.Kwasm.Path) binPath, err := shimConfig.Uninstall(shimName) if err != nil { From 4724a2e73411645f0c088bee8253ee728f577069 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Tue, 5 Mar 2024 15:15:59 +0100 Subject: [PATCH 86/90] write install cmd tests --- cmd/install.go | 15 ++--- cmd/install_test.go | 94 +++++++++++++++++++++++++++++++ cmd/uninstall.go | 7 ++- pkg/containerd/configure.go | 12 +++- pkg/containerd/configure_test.go | 12 ++-- pkg/containerd/restart_unix.go | 4 +- pkg/containerd/restart_windows.go | 4 +- pkg/shim/install_test.go | 14 ++--- pkg/state/state_test.go | 4 +- tests/fs.go | 4 +- 10 files changed, 139 insertions(+), 31 deletions(-) create mode 100644 cmd/install_test.go diff --git a/cmd/install.go b/cmd/install.go index bf9ffaf..fb2c761 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -36,8 +36,9 @@ var installCmd = &cobra.Command{ Run: func(_ *cobra.Command, _ []string) { rootFs := afero.NewOsFs() hostFs := afero.NewBasePathFs(rootFs, config.Host.RootPath) + restarter := containerd.ContainerdRestarter{} - if err := runInstall(config, rootFs, hostFs); err != nil { + if err := RunInstall(config, rootFs, hostFs, restarter); err != nil { slog.Error("failed to install", "error", err) os.Exit(1) } @@ -49,27 +50,27 @@ func init() { rootCmd.AddCommand(installCmd) } -func runInstall(config Config, rootFs, hostFs afero.Fs) error { +func RunInstall(config Config, rootFs, hostFs afero.Fs, restarter containerd.Restarter) error { // Get file or directory information. - info, err := os.Stat(config.Kwasm.AssetPath) + info, err := rootFs.Stat(config.Kwasm.AssetPath) if err != nil { return err } - var files []fs.DirEntry + var files []fs.FileInfo // Check if the path is a directory. if info.IsDir() { - files, err = os.ReadDir(config.Kwasm.AssetPath) + files, err = afero.ReadDir(rootFs, config.Kwasm.AssetPath) if err != nil { return err } } else { // If the path is not a directory, add the file to the list of files. - files = append(files, fs.FileInfoToDirEntry(info)) + files = append(files, info) config.Kwasm.AssetPath = path.Dir(config.Kwasm.AssetPath) } - containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath) + containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath, restarter) shimConfig := shim.NewConfig(rootFs, hostFs, config.Kwasm.AssetPath, config.Kwasm.Path) anythingChanged := false diff --git a/cmd/install_test.go b/cmd/install_test.go new file mode 100644 index 0000000..f08b1ba --- /dev/null +++ b/cmd/install_test.go @@ -0,0 +1,94 @@ +/* + Copyright The KWasm Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package cmd_test + +import ( + "testing" + + "github.com/kwasm/kwasm-node-installer/cmd" + "github.com/kwasm/kwasm-node-installer/tests" + "github.com/spf13/afero" + "github.com/stretchr/testify/require" +) + +type nullRestarter struct{} + +func (n nullRestarter) Restart() error { + return nil +} + +func Test_RunInstall(t *testing.T) { + type args struct { + config cmd.Config + rootFs afero.Fs + hostFs afero.Fs + } + tests := []struct { + name string + args args + wantErr bool + }{ + { + "new shim", + args{ + cmd.Config{ + struct { + Name string + ConfigPath string + }{"containerd", "/etc/containerd/config.toml"}, + struct { + Path string + AssetPath string + }{"/opt/kwasm", "/assets"}, + struct{ RootPath string }{"/containerd/missing-containerd-shim-config"}, + }, + tests.FixtureFs("../testdata"), + tests.FixtureFs("../testdata/containerd/missing-containerd-shim-config"), + }, + false, + }, + { + "existing shim", + args{ + cmd.Config{ + struct { + Name string + ConfigPath string + }{"containerd", "/etc/containerd/config.toml"}, + struct { + Path string + AssetPath string + }{"/opt/kwasm", "/assets"}, + struct{ RootPath string }{"/containerd/existing-containerd-shim-config"}, + }, + tests.FixtureFs("../testdata"), + tests.FixtureFs("../testdata/containerd/existing-containerd-shim-config"), + }, + false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := cmd.RunInstall(tt.args.config, tt.args.rootFs, tt.args.hostFs, nullRestarter{}) + if tt.wantErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/cmd/uninstall.go b/cmd/uninstall.go index e0ca662..973f4eb 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -36,8 +36,9 @@ var uninstallCmd = &cobra.Command{ Run: func(_ *cobra.Command, _ []string) { rootFs := afero.NewOsFs() hostFs := afero.NewBasePathFs(rootFs, config.Host.RootPath) + restarter := containerd.ContainerdRestarter{} - if err := runUninstall(config, rootFs, hostFs); err != nil { + if err := RunUninstall(config, rootFs, hostFs, restarter); err != nil { slog.Error("failed to uninstall", "error", err) os.Exit(1) } @@ -48,12 +49,12 @@ func init() { rootCmd.AddCommand(uninstallCmd) } -func runUninstall(config Config, rootFs, hostFs afero.Fs) error { +func RunUninstall(config Config, rootFs, hostFs afero.Fs, restarter containerd.Restarter) error { slog.Info("uninstall called") shimName := config.Runtime.Name runtimeName := path.Join(config.Kwasm.Path, "bin", shimName) - containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath) + containerdConfig := containerd.NewConfig(hostFs, config.Runtime.ConfigPath, restarter) shimConfig := shim.NewConfig(rootFs, hostFs, config.Kwasm.AssetPath, config.Kwasm.Path) binPath, err := shimConfig.Uninstall(shimName) diff --git a/pkg/containerd/configure.go b/pkg/containerd/configure.go index cf58067..99a6f56 100644 --- a/pkg/containerd/configure.go +++ b/pkg/containerd/configure.go @@ -27,15 +27,21 @@ import ( "github.com/spf13/afero" ) +type Restarter interface { + Restart() error +} + type Config struct { hostFs afero.Fs configPath string + restarter Restarter } -func NewConfig(hostFs afero.Fs, configPath string) *Config { +func NewConfig(hostFs afero.Fs, configPath string, restarter Restarter) *Config { return &Config{ hostFs: hostFs, configPath: configPath, + restarter: restarter, } } @@ -103,6 +109,10 @@ func (c *Config) RemoveRuntime(shimPath string) (changed bool, err error) { return true, nil } +func (c *Config) RestartRuntime() error { + return c.restarter.Restart() +} + func generateConfig(shimPath string, runtimeName string) string { return fmt.Sprintf(` # KWASM runtime config for %s diff --git a/pkg/containerd/configure_test.go b/pkg/containerd/configure_test.go index 348a3e3..d0a1cff 100644 --- a/pkg/containerd/configure_test.go +++ b/pkg/containerd/configure_test.go @@ -41,7 +41,7 @@ func TestConfig_AddRuntime(t *testing.T) { wantFileContent string }{ {"missing shim config", fields{ - hostFs: tests.FixtureFs("testdata/containerd/missing-containerd-shim-config"), + hostFs: tests.FixtureFs("../../testdata/containerd/missing-containerd-shim-config"), configPath: "/etc/containerd/config.toml", }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, `[plugins] [plugins."io.containerd.monitor.v1.cgroups"] @@ -66,11 +66,11 @@ func TestConfig_AddRuntime(t *testing.T) { runtime_type = "/opt/kwasm/bin/containerd-shim-spin-v1" `}, {"missing config", fields{ - hostFs: tests.FixtureFs("testdata/containerd/missing-containerd-config"), + hostFs: tests.FixtureFs("../../testdata/containerd/missing-containerd-config"), configPath: "/etc/containerd/config.toml", }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, true, ``}, {"existing shim config", fields{ - hostFs: tests.FixtureFs("testdata/containerd/existing-containerd-shim-config"), + hostFs: tests.FixtureFs("../../testdata/containerd/existing-containerd-shim-config"), configPath: "/etc/containerd/config.toml", }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, `[plugins] [plugins."io.containerd.monitor.v1.cgroups"] @@ -134,7 +134,7 @@ func TestConfig_RemoveRuntime(t *testing.T) { wantFileContent string }{ {"missing shim config", fields{ - hostFs: tests.FixtureFs("testdata/containerd/missing-containerd-shim-config"), + hostFs: tests.FixtureFs("../../testdata/containerd/missing-containerd-shim-config"), configPath: "/etc/containerd/config.toml", }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, `[plugins] [plugins."io.containerd.monitor.v1.cgroups"] @@ -155,11 +155,11 @@ func TestConfig_RemoveRuntime(t *testing.T) { rdt_config_file = "" `}, {"missing config", fields{ - hostFs: tests.FixtureFs("testdata/containerd/missing-containerd-config"), + hostFs: tests.FixtureFs("../../testdata/containerd/missing-containerd-config"), configPath: "/etc/containerd/config.toml", }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, true, ``}, {"existing shim config", fields{ - hostFs: tests.FixtureFs("testdata/containerd/existing-containerd-shim-config"), + hostFs: tests.FixtureFs("../../testdata/containerd/existing-containerd-shim-config"), configPath: "/etc/containerd/config.toml", }, args{"/opt/kwasm/bin/containerd-shim-spin-v1"}, false, `[plugins] [plugins."io.containerd.monitor.v1.cgroups"] diff --git a/pkg/containerd/restart_unix.go b/pkg/containerd/restart_unix.go index 466531c..9d3961a 100644 --- a/pkg/containerd/restart_unix.go +++ b/pkg/containerd/restart_unix.go @@ -29,7 +29,9 @@ import ( var psProcesses = ps.Processes -func (c *Config) RestartRuntime() error { +type ContainerdRestarter struct{} + +func (c ContainerdRestarter) Restart() error { pid, err := getPid() if err != nil { return err diff --git a/pkg/containerd/restart_windows.go b/pkg/containerd/restart_windows.go index 1b00389..7018205 100644 --- a/pkg/containerd/restart_windows.go +++ b/pkg/containerd/restart_windows.go @@ -5,6 +5,8 @@ package containerd import "errors" -func (c *Config) RestartRuntime() error { +type ContainerdRestarter struct{} + +func (r ContainerdRestarter) Restart() error { return errors.New("restarting containerd not implemented") } diff --git a/pkg/shim/install_test.go b/pkg/shim/install_test.go index 944718a..20375af 100644 --- a/pkg/shim/install_test.go +++ b/pkg/shim/install_test.go @@ -49,8 +49,8 @@ func TestConfig_Install(t *testing.T) { { "no changes to shim", fields{ - tests.FixtureFs("testdata"), - tests.FixtureFs("testdata/shim"), + tests.FixtureFs("../../testdata"), + tests.FixtureFs("../../testdata/shim"), "/assets", "/opt/kwasm"}, args{"containerd-shim-spin-v1"}, @@ -63,8 +63,8 @@ func TestConfig_Install(t *testing.T) { { "install new shim over old", fields{ - tests.FixtureFs("testdata"), - tests.FixtureFs("testdata/shim"), + tests.FixtureFs("../../testdata"), + tests.FixtureFs("../../testdata/shim"), "/assets", "/opt/kwasm"}, args{"containerd-shim-slight-v1"}, @@ -78,7 +78,7 @@ func TestConfig_Install(t *testing.T) { "unable to find new shim", fields{ afero.NewMemMapFs(), - tests.FixtureFs("testdata/shim"), + tests.FixtureFs("../../testdata/shim"), "/assets", "/opt/kwasm"}, args{"some-shim"}, @@ -91,8 +91,8 @@ func TestConfig_Install(t *testing.T) { { "unable to write to hostFs", fields{ - tests.FixtureFs("testdata"), - afero.NewReadOnlyFs(tests.FixtureFs("testdata/shim")), + tests.FixtureFs("../../testdata"), + afero.NewReadOnlyFs(tests.FixtureFs("../../testdata/shim")), "/assets", "/opt/kwasm"}, args{"containerd-shim-spin-v1"}, diff --git a/pkg/state/state_test.go b/pkg/state/state_test.go index e360fcd..a34755b 100644 --- a/pkg/state/state_test.go +++ b/pkg/state/state_test.go @@ -24,7 +24,7 @@ func TestGet(t *testing.T) { { "existing state", args{ - tests.FixtureFs("testdata/containerd/existing-containerd-shim-config"), + tests.FixtureFs("../../testdata/containerd/existing-containerd-shim-config"), "/opt/kwasm", }, &state.State{ @@ -40,7 +40,7 @@ func TestGet(t *testing.T) { { "missing state", args{ - tests.FixtureFs("testdata/containerd/missing-containerd-shim-config"), + tests.FixtureFs("../../testdata/containerd/missing-containerd-shim-config"), "/opt/kwasm", }, &state.State{ diff --git a/tests/fs.go b/tests/fs.go index 891f856..eb95876 100644 --- a/tests/fs.go +++ b/tests/fs.go @@ -1,13 +1,11 @@ package tests import ( - "path/filepath" - "github.com/spf13/afero" ) func FixtureFs(fixturePath string) afero.Fs { - baseFs := afero.NewBasePathFs(afero.NewOsFs(), filepath.Join("../..", fixturePath)) + baseFs := afero.NewBasePathFs(afero.NewOsFs(), fixturePath) fs := afero.NewCopyOnWriteFs(baseFs, afero.NewMemMapFs()) return fs } From efc00bf2cbb12969933267210b514c8ba9a66465 Mon Sep 17 00:00:00 2001 From: Christoph Voigt Date: Sat, 9 Mar 2024 10:59:39 +0100 Subject: [PATCH 87/90] add node-installer --- cmd/install.go | 4 +- cmd/install_test.go | 4 +- main.go => cmd/node-installer/main.go | 2 +- cmd/{ => rcm}/main.go | 0 cmd/uninstall.go | 4 +- go.mod | 27 +- go.sum | 409 +++----------------------- pkg/containerd/configure.go | 6 +- pkg/containerd/configure_test.go | 2 +- pkg/shim/install.go | 8 +- pkg/shim/install_test.go | 14 +- pkg/shim/uninstall.go | 2 +- pkg/state/state_test.go | 4 +- 13 files changed, 93 insertions(+), 393 deletions(-) rename main.go => cmd/node-installer/main.go (92%) rename cmd/{ => rcm}/main.go (100%) diff --git a/cmd/install.go b/cmd/install.go index fb2c761..b93207d 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -23,10 +23,10 @@ import ( "os" "path" - "github.com/kwasm/kwasm-node-installer/pkg/containerd" - "github.com/kwasm/kwasm-node-installer/pkg/shim" "github.com/spf13/afero" "github.com/spf13/cobra" + "github.com/spinkube/runtime-class-manager/pkg/containerd" + "github.com/spinkube/runtime-class-manager/pkg/shim" ) // installCmd represents the install command. diff --git a/cmd/install_test.go b/cmd/install_test.go index f08b1ba..bc33146 100644 --- a/cmd/install_test.go +++ b/cmd/install_test.go @@ -19,9 +19,9 @@ package cmd_test import ( "testing" - "github.com/kwasm/kwasm-node-installer/cmd" - "github.com/kwasm/kwasm-node-installer/tests" "github.com/spf13/afero" + "github.com/spinkube/runtime-class-manager/cmd" + "github.com/spinkube/runtime-class-manager/tests" "github.com/stretchr/testify/require" ) diff --git a/main.go b/cmd/node-installer/main.go similarity index 92% rename from main.go rename to cmd/node-installer/main.go index 5bb240b..7c8de6f 100644 --- a/main.go +++ b/cmd/node-installer/main.go @@ -16,7 +16,7 @@ package main -import "github.com/kwasm/kwasm-node-installer/cmd" +import "github.com/spinkube/runtime-class-manager/cmd" func main() { cmd.Execute() diff --git a/cmd/main.go b/cmd/rcm/main.go similarity index 100% rename from cmd/main.go rename to cmd/rcm/main.go diff --git a/cmd/uninstall.go b/cmd/uninstall.go index 973f4eb..3d40a84 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -25,8 +25,8 @@ import ( "github.com/spf13/afero" "github.com/spf13/cobra" - "github.com/kwasm/kwasm-node-installer/pkg/containerd" - "github.com/kwasm/kwasm-node-installer/pkg/shim" + "github.com/spinkube/runtime-class-manager/pkg/containerd" + "github.com/spinkube/runtime-class-manager/pkg/shim" ) // uninstallCmd represents the uninstall command. diff --git a/go.mod b/go.mod index 61d025d..f0009d7 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,16 @@ module github.com/spinkube/runtime-class-manager go 1.21 require ( + github.com/mitchellh/go-ps v1.0.0 github.com/onsi/ginkgo/v2 v2.15.0 github.com/onsi/gomega v1.31.1 github.com/prometheus/common v0.48.0 github.com/rs/zerolog v1.31.0 + github.com/spf13/afero v1.11.0 + github.com/spf13/cobra v1.7.0 + github.com/spf13/pflag v1.0.5 + github.com/spf13/viper v1.18.2 + github.com/stretchr/testify v1.8.4 k8s.io/api v0.29.2 k8s.io/apimachinery v0.29.2 k8s.io/client-go v0.29.2 @@ -16,7 +22,7 @@ require ( require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch/v5 v5.8.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect @@ -33,35 +39,46 @@ require ( github.com/google/go-cmp v0.6.0 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect - github.com/google/uuid v1.3.0 // indirect + github.com/google/uuid v1.4.0 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect github.com/imdario/mergo v0.3.6 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect + github.com/magiconair/properties v1.8.7 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.18.0 // indirect github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect - github.com/spf13/pflag v1.0.5 // indirect + github.com/sagikazarmark/locafero v0.4.0 // indirect + github.com/sagikazarmark/slog-shim v0.1.0 // indirect + github.com/sourcegraph/conc v0.3.0 // indirect + github.com/spf13/cast v1.6.0 // indirect + github.com/subosito/gotenv v1.6.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.26.0 // indirect - golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect + golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect golang.org/x/net v0.20.0 // indirect golang.org/x/oauth2 v0.16.0 // indirect golang.org/x/sys v0.16.0 // indirect golang.org/x/term v0.16.0 // indirect golang.org/x/text v0.14.0 // indirect - golang.org/x/time v0.3.0 // indirect + golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.16.1 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.32.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/apiextensions-apiserver v0.29.0 // indirect diff --git a/go.sum b/go.sum index eb14615..911551c 100644 --- a/go.sum +++ b/go.sum @@ -6,16 +6,20 @@ github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWR github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch/v5 v5.8.0 h1:lRj6N9Nci7MvzrXuX6HFzU8XjmhPiXPlsKEy1u0KQro= github.com/evanphx/json-patch/v5 v5.8.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -51,11 +55,15 @@ github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28= github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= @@ -69,7 +77,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -<<<<<<< HEAD +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -77,6 +86,10 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc= +github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -88,10 +101,13 @@ github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM= github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo= github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0= +github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= +github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= @@ -105,8 +121,23 @@ github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncj github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= +github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= +github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= +github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= +github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= +github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= +github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -117,6 +148,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= @@ -128,8 +161,8 @@ go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA= -golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -160,264 +193,18 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= -golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA= golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= -======= -github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= -github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= -github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc= -github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg= -github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= -github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= -github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= -github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= -github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= -github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= -github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= -github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= -github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= -github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc= -github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= -github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= -github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= -go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= -go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= -golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= -golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= -golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= -golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= -golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= -golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= -golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= -golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= -golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= -golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= -golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= -golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= ->>>>>>> go-rewrite/go-rewrite golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -<<<<<<< HEAD gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw= gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= @@ -431,6 +218,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= @@ -461,113 +250,3 @@ sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+s sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08= sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= -======= -google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= -google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= -google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= -google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= -google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= -google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= -google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg= -google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE= -google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= -google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= -google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= -google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= -google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= -google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= -google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= -google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= -gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= -rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= -rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= ->>>>>>> go-rewrite/go-rewrite diff --git a/pkg/containerd/configure.go b/pkg/containerd/configure.go index 99a6f56..de50a37 100644 --- a/pkg/containerd/configure.go +++ b/pkg/containerd/configure.go @@ -23,8 +23,8 @@ import ( "path" "strings" - "github.com/kwasm/kwasm-node-installer/pkg/shim" "github.com/spf13/afero" + "github.com/spinkube/runtime-class-manager/pkg/shim" ) type Restarter interface { @@ -64,7 +64,7 @@ func (c *Config) AddRuntime(shimPath string) error { } // Open file in append mode - file, err := c.hostFs.OpenFile(c.configPath, os.O_APPEND|os.O_WRONLY, 0644) //nolint:gomnd // file permissions + file, err := c.hostFs.OpenFile(c.configPath, os.O_APPEND|os.O_WRONLY, 0o644) //nolint:gomnd // file permissions if err != nil { return err } @@ -101,7 +101,7 @@ func (c *Config) RemoveRuntime(shimPath string) (changed bool, err error) { modifiedData := strings.ReplaceAll(string(data), cfg, "") // Write the modified data back to the file. - err = afero.WriteFile(c.hostFs, c.configPath, []byte(modifiedData), 0644) //nolint:gomnd // file permissions + err = afero.WriteFile(c.hostFs, c.configPath, []byte(modifiedData), 0o644) //nolint:gomnd // file permissions if err != nil { return false, err } diff --git a/pkg/containerd/configure_test.go b/pkg/containerd/configure_test.go index d0a1cff..e40944c 100644 --- a/pkg/containerd/configure_test.go +++ b/pkg/containerd/configure_test.go @@ -19,8 +19,8 @@ package containerd //nolint:testpackage // whitebox test import ( "testing" - "github.com/kwasm/kwasm-node-installer/tests" "github.com/spf13/afero" + "github.com/spinkube/runtime-class-manager/tests" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/shim/install.go b/pkg/shim/install.go index aed7bf4..3f4f0a9 100644 --- a/pkg/shim/install.go +++ b/pkg/shim/install.go @@ -23,23 +23,23 @@ import ( "path" "path/filepath" - "github.com/kwasm/kwasm-node-installer/pkg/state" + "github.com/spinkube/runtime-class-manager/pkg/state" ) func (c *Config) Install(shimName string) (filePath string, changed bool, err error) { shimPath := filepath.Join(c.assetPath, shimName) - srcFile, err := c.rootFs.OpenFile(shimPath, os.O_RDONLY, 0000) //nolint:gomnd // file permissions + srcFile, err := c.rootFs.OpenFile(shimPath, os.O_RDONLY, 0o000) //nolint:gomnd // file permissions if err != nil { return "", false, err } dstFilePath := path.Join(c.kwasmPath, "bin", shimName) - err = c.hostFs.MkdirAll(path.Dir(dstFilePath), 0775) //nolint:gomnd // file permissions + err = c.hostFs.MkdirAll(path.Dir(dstFilePath), 0o775) //nolint:gomnd // file permissions if err != nil { return dstFilePath, false, err } - dstFile, err := c.hostFs.OpenFile(dstFilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) //nolint:gomnd // file permissions + dstFile, err := c.hostFs.OpenFile(dstFilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o755) //nolint:gomnd // file permissions if err != nil { return "", false, err } diff --git a/pkg/shim/install_test.go b/pkg/shim/install_test.go index 20375af..220e8a9 100644 --- a/pkg/shim/install_test.go +++ b/pkg/shim/install_test.go @@ -19,8 +19,8 @@ package shim //nolint:testpackage // whitebox test import ( "testing" - "github.com/kwasm/kwasm-node-installer/tests" "github.com/spf13/afero" + "github.com/spinkube/runtime-class-manager/tests" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -52,7 +52,8 @@ func TestConfig_Install(t *testing.T) { tests.FixtureFs("../../testdata"), tests.FixtureFs("../../testdata/shim"), "/assets", - "/opt/kwasm"}, + "/opt/kwasm", + }, args{"containerd-shim-spin-v1"}, wants{ "/opt/kwasm/bin/containerd-shim-spin-v1", @@ -66,7 +67,8 @@ func TestConfig_Install(t *testing.T) { tests.FixtureFs("../../testdata"), tests.FixtureFs("../../testdata/shim"), "/assets", - "/opt/kwasm"}, + "/opt/kwasm", + }, args{"containerd-shim-slight-v1"}, wants{ "/opt/kwasm/bin/containerd-shim-slight-v1", @@ -80,7 +82,8 @@ func TestConfig_Install(t *testing.T) { afero.NewMemMapFs(), tests.FixtureFs("../../testdata/shim"), "/assets", - "/opt/kwasm"}, + "/opt/kwasm", + }, args{"some-shim"}, wants{ "", @@ -94,7 +97,8 @@ func TestConfig_Install(t *testing.T) { tests.FixtureFs("../../testdata"), afero.NewReadOnlyFs(tests.FixtureFs("../../testdata/shim")), "/assets", - "/opt/kwasm"}, + "/opt/kwasm", + }, args{"containerd-shim-spin-v1"}, wants{ "/opt/kwasm/bin/containerd-shim-spin-v1", diff --git a/pkg/shim/uninstall.go b/pkg/shim/uninstall.go index 88d8e79..f2dd93b 100644 --- a/pkg/shim/uninstall.go +++ b/pkg/shim/uninstall.go @@ -5,7 +5,7 @@ import ( "log/slog" "os" - "github.com/kwasm/kwasm-node-installer/pkg/state" + "github.com/spinkube/runtime-class-manager/pkg/state" ) func (c *Config) Uninstall(shimName string) (string, error) { diff --git a/pkg/state/state_test.go b/pkg/state/state_test.go index a34755b..7fd67af 100644 --- a/pkg/state/state_test.go +++ b/pkg/state/state_test.go @@ -3,9 +3,9 @@ package state_test import ( "testing" - "github.com/kwasm/kwasm-node-installer/pkg/state" - "github.com/kwasm/kwasm-node-installer/tests" "github.com/spf13/afero" + "github.com/spinkube/runtime-class-manager/pkg/state" + "github.com/spinkube/runtime-class-manager/tests" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) From deaf5e71cbd4255c4d7dd4f07deebf1ad40573a3 Mon Sep 17 00:00:00 2001 From: Christoph Voigt Date: Sat, 9 Mar 2024 11:12:52 +0100 Subject: [PATCH 88/90] fix linter issues --- .golangci.yaml | 40 ++++++++++--- .golangci.yml | 94 ------------------------------- internal/controller/suite_test.go | 2 +- 3 files changed, 32 insertions(+), 104 deletions(-) delete mode 100644 .golangci.yml diff --git a/.golangci.yaml b/.golangci.yaml index 135cdc4..3cdf0c1 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -12,7 +12,6 @@ run: # Default: 1m timeout: 3m - # This file contains only configs which differ from defaults. # All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml linters-settings: @@ -117,6 +116,7 @@ linters-settings: - os.WriteFile - prometheus.ExponentialBuckets.* - prometheus.LinearBuckets + - math.Min govet: # Enable all analyzers. @@ -163,6 +163,15 @@ linters-settings: # Default: false all: true + wrapcheck: + ignoreSigs: + - ".Complete(" + - "client.IgnoreNotFound(" + - "fmt.Errorf(" + + nestif: + min-complexity: 8 + linters: disable-all: true @@ -183,8 +192,6 @@ linters: - dupl # tool for code clone detection - errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error - errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13 - - exhaustive # checks exhaustiveness of enum switch statements - - exhaustruct # checks if all structure fields are initialized - exportloopref # checks for pointers to enclosing loop variables - forbidigo # forbids identifiers - funlen # tool for detection of long functions @@ -192,7 +199,6 @@ linters: - goconst # finds repeated strings that could be replaced by a constant - gocritic # provides diagnostics that check for bugs, performance and style issues - gocyclo # computes and checks the cyclomatic complexity of functions - - godot # checks if comments end in a period - goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt - gomnd # detects magic numbers - goprintffuncname # checks that printf-like functions are named with f at the end @@ -221,6 +227,8 @@ linters: - whitespace # detects leading and trailing whitespace ## you may want to enable + #- exhaustive # checks exhaustiveness of enum switch statements + #- exhaustruct # checks if all structure fields are initialized #- decorder # checks declaration order and count of types, constants, variables and functions #- gci # controls golang package import order and makes it always deterministic #- ginkgolinter # [if you use ginkgo/gomega] enforces standards of using ginkgo and gomega @@ -236,6 +244,7 @@ linters: #- zerologlint # detects the wrong usage of zerolog that a user forgets to dispatch zerolog.Event ## disabled + #- godot # checks if comments end in a period #- containedctx # detects struct contained context.Context field #- contextcheck # [too many false positives] checks the function whether use a non-inherited context #- depguard # [replaced by gomodguard] checks if package imports are in a list of acceptable packages @@ -269,12 +278,8 @@ linters: #- structcheck # [deprecated, replaced by unused] finds unused struct fields #- varcheck # [deprecated, replaced by unused] finds unused global variables and constants - issues: - # Maximum count of issues with the same text. - # Set to 0 to disable. - # Default: 3 - max-same-issues: 50 + max-same-issues: 30 exclude-rules: - source: "(noinspection|TODO)" @@ -290,3 +295,20 @@ issues: - gosec - noctx - wrapcheck + - linters: + - funlen + # Disable 'funlen' linter for test functions. + # It's common for table-driven tests to be more than 60 characters long + source: "^func Test" + - path: '(.+)_test\.go' + linters: + - revive + text: "dot-imports: should not use dot imports" + - path: internal/controller/shim_controller.go + linters: + - unparam + source: "ctrl.Result" + - path: pkg/containerd/restart_unix.go + linters: + - revive + text: "exported: type name will be used as containerd.ContainerdRestarter by other packages, and that stutters; consider calling this Restarter" diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index c7f2f8b..0000000 --- a/.golangci.yml +++ /dev/null @@ -1,94 +0,0 @@ -# This file contains all available configuration options -# with their default values. - -# options for analysis running -run: - tests: true - timeout: 10m - -issues: - exclude-rules: - - linters: - - funlen - # Disable 'funlen' linter for test functions. - # It's common for table-driven tests to be more than 60 characters long - source: "^func Test" - - path: '(.+)_test\.go' - linters: - - revive - text: "dot-imports: should not use dot imports" - - path: internal/controller/shim_controller.go - linters: - - unparam - source: "ctrl.Result" - -linters: - enable-all: true - disable: - - exhaustivestruct - - exhaustruct - - gci - - gochecknoglobals - - gochecknoinits - - gocognit - - godot - - goerr113 - - golint - - gofumpt - - gomnd - - maligned - - nlreturn - - paralleltest - - scopelint - - testpackage - - wsl - - lll # long lines - # https://github.com/golangci/golangci-lint/issues/541 - - interfacer - - interfacebloat - # TODO: enable once we can set some exceptions - - funlen - - ifshort # deprecated - -linters-settings: - wrapcheck: - ignoreSigs: - - ".Complete(" - - "client.IgnoreNotFound(" - - "fmt.Errorf(" - cyclop: - max-complexity: 16 - nestif: - min-complexity: 8 - depguard: - # Rules to apply. - # - # Variables: - # - File Variables - # you can still use and exclamation mark ! in front of a variable to say not to use it. - # Example !$test will match any file that is not a go test file. - # - # `$all` - matches all go files - # `$test` - matches all go test files - # - # - Package Variables - # - # `$gostd` - matches all of go's standard library (Pulled from `GOROOT`) - # - # Default: Only allow $gostd in all files. - rules: - # Name of a rule. - main: - # List of file globs that will match this list of settings to compare against. - # Default: $all - files: - - $all - - "!$test" - deny: - - pkg: "github.com/sirupsen/logrus" - desc: not allowed - - pkg: "github.com/pkg/errors" - desc: Should be replaced by standard lib errors package - godox: - keywords: - - "FIXME" diff --git a/internal/controller/suite_test.go b/internal/controller/suite_test.go index ac131a4..54434f1 100644 --- a/internal/controller/suite_test.go +++ b/internal/controller/suite_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package controller +package controller_test import ( "fmt" From eb8783beeef70f54899c2bea49e1d7993652bb66 Mon Sep 17 00:00:00 2001 From: Christoph Voigt Date: Sat, 9 Mar 2024 11:13:40 +0100 Subject: [PATCH 89/90] delete namespace.so docker build --- .github/workflows/docker-build.yaml | 61 ----------------------------- 1 file changed, 61 deletions(-) delete mode 100644 .github/workflows/docker-build.yaml diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml deleted file mode 100644 index 21db57a..0000000 --- a/.github/workflows/docker-build.yaml +++ /dev/null @@ -1,61 +0,0 @@ -name: Docker Image CI - -on: - push: - branches: [ main ] - tags: [ '*' ] - pull_request: - branches: [ main ] - -permissions: - # Required for requesting the GitHub Token - id-token: write - # Required for pushing images to GitHub Container Registry - packages: write - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - -jobs: - buildx: - runs-on: nscloud - steps: - - - name: Checkout - uses: actions/checkout@v4 - - - name: Log in to the Container registry - uses: docker/login-action@v2 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - - # Install CLI and authenticate to Namespace - name: Install and configure Namespace CLI - uses: namespacelabs/nscloud-setup@v0 - - - # Setup docker build to use your Namespace workspace builder - name: Set up Namespace Buildx - uses: namespacelabs/nscloud-setup-buildx-action@v0 - - - name: Build and push Docker image - uses: docker/build-push-action@v4 - with: - context: . - push: true - platforms: linux/amd64,linux/arm64 -# build-args: | -# CONTAINERD_RUNWASI=nscr.io/a8fcp47vcfori/build-runwasi - tags: ${{ steps.meta.outputs.tags }} - file: images/installer/Dockerfile - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max From a44cf0c9a7063c49ab1468cb8ef2935dc0fe429f Mon Sep 17 00:00:00 2001 From: Christoph Voigt Date: Sat, 9 Mar 2024 11:15:54 +0100 Subject: [PATCH 90/90] update linter --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76159c4..b3591c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,4 +30,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0 with: - version: v1.54.2 + version: v1.55.2