From ee92b7824fe2e7d5ba0ed2d84f75e0b0e09660c0 Mon Sep 17 00:00:00 2001 From: subhamkrai Date: Tue, 21 Sep 2021 14:02:25 +0530 Subject: [PATCH] core: add initial code This commit adds inital code with ceph command supported. Also, adding the initial CI and updating the Readme file. Closes: https://github.com/rook/kubectl-rook-ceph/issues/2 Signed-off-by: subhamkrai --- .github/workflows/ci.yaml | 55 ++++++++++++++++++++++++++++++ .github/workflows/shell-check.yaml | 17 +++++++++ README.md | 13 ++++++- kubectl-rook-ceph.sh | 48 ++++++++++++++++++++++++++ tests/github-action-helper.sh | 32 +++++++++++++++++ 5 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/shell-check.yaml create mode 100755 kubectl-rook-ceph.sh create mode 100644 tests/github-action-helper.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..83249002 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,55 @@ +name: kubectl plugin test +on: + pull_request: + +defaults: + run: + # reference: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell + shell: bash --noprofile --norc -eo pipefail -x {0} + +jobs: + Plugin-test: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: setup minikube + uses: manusa/actions-setup-minikube@v2.4.2 + with: + minikube version: 'v1.23.2' + kubernetes version: 'v1.22.2' + start args: --memory 6g --cpus=2 + github token: ${{ secrets.GITHUB_TOKEN }} + + - name: print k8s cluster status + run: | + minikube status + kubectl get nodes + + - name: use local disk + run: tests/github-action-helper.sh use_local_disk + + - name: deploy rook cluster + run: tests/github-action-helper.sh deploy_rook + + - name: wait for operator pod to be ready + run: tests/github-action-helper.sh wait_for_pod_to_be_ready_state + + - name: Test pluging with ceph commands + run: | + # when we have the kubectl krew plugin available we can use like `kubectl rook-ceph` but for now in local deployment we have to use `kubectl rook_ceph` as kubectl plugin has this limitation. + # Doc link to clear the comment above: + # https://krew.sigs.k8s.io/docs/developer-guide/develop/naming-guide/ + # https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/#naming-a-plugin + # https://krew.sigs.k8s.io/docs/developer-guide/distributing-with-krew/ + sudo install kubectl-rook-ceph.sh /usr/local/bin/kubectl-rook_ceph + # run ceph commands with the plugin + kubectl rook_ceph ceph status + kubectl rook_ceph ceph status -f json + kubectl rook_ceph ceph status --format json-pretty + kubectl rook_ceph ceph mon dump + kubectl rook_ceph ceph mon stat + kubectl rook_ceph ceph osd tree diff --git a/.github/workflows/shell-check.yaml b/.github/workflows/shell-check.yaml new file mode 100644 index 00000000..56ec6110 --- /dev/null +++ b/.github/workflows/shell-check.yaml @@ -0,0 +1,17 @@ +name: ShellCheck +on: + pull_request: + +jobs: + shellcheck: + name: Shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@master + with: + severity: warning + check_together: 'yes' + disable_matcher: false + format: gcc diff --git a/README.md b/README.md index 1118e926..e80395aa 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,18 @@ Provide common management and troubleshooting tools for the Rook Ceph storage pr ## Install -TBD +To install tool without krew + +1. Download the [kubectl-rook-ceph.sh](kubectl-rook-ceph.sh) +2. ```sudo install kubectl-rook-ceph.sh /usr/local/bin/kubectl-rook_ceph``` + +Now, use the tool with `kubectl` + +```console +# example: `kubectl rook_ceph` as prefix with `ceph` command +kubectl rook_ceph ceph status +``` + ## Commands diff --git a/kubectl-rook-ceph.sh b/kubectl-rook-ceph.sh new file mode 100755 index 00000000..19cdaf8a --- /dev/null +++ b/kubectl-rook-ceph.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +# Copyright 2021 The Rook Authors. All rights reserved. +# +# 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. + +set -eEuo pipefail + +usages() { + cat <