Skip to content

Commit

Permalink
Merge pull request rook#4 from subhamkrai/initial-code
Browse files Browse the repository at this point in the history
core: add initial code
  • Loading branch information
travisn authored Sep 29, 2021
2 parents 20afd78 + ee92b78 commit 6068cbd
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 1 deletion.
55 changes: 55 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions .github/workflows/shell-check.yaml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
48 changes: 48 additions & 0 deletions kubectl-rook-ceph.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
Description:
'kubectl rook-ceph ceph' provides common management and troubleshooting tools for Ceph.
Commands:
ceph - run any 'ceph' CLI command as given
args - any 'ceph' CLI argument or flag
Usage:
kubectl rook-ceph ceph [command] [args...]
EOF
}

ceph_command() {
kubectl --namespace rook-ceph exec deploy/rook-ceph-operator -- /bin/bash -c "${*} --conf=/var/lib/rook/rook-ceph/rook-ceph.config"
}

main() {
if [ $# -ge 2 ]; then
if [ "$1" = "ceph" ]; then
ceph_command "$@"
fi
else
usages
fi
}

main "$@"
32 changes: 32 additions & 0 deletions tests/github-action-helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -eEuo pipefail

# source https://github.com/rook/rook
use_local_disk() {
sudo swapoff --all --verbose
sudo umount /mnt
# search for the device since it keeps changing between sda and sdb
sudo wipefs --all --force /dev/$(lsblk|awk '/14G/ {print $1}'| head -1)1
sudo lsblk
}

deploy_rook() {
kubectl create -f https://raw.githubusercontent.com/rook/rook/master/cluster/examples/kubernetes/ceph/common.yaml
kubectl create -f https://raw.githubusercontent.com/rook/rook/master/cluster/examples/kubernetes/ceph/crds.yaml
kubectl create -f https://raw.githubusercontent.com/rook/rook/master/cluster/examples/kubernetes/ceph/operator.yaml
curl https://raw.githubusercontent.com/rook/rook/master/cluster/examples/kubernetes/ceph/cluster-test.yaml -o cluster-test.yaml
sed -i "s|#deviceFilter:|deviceFilter: $(lsblk|awk '/14G/ {print $1}'| head -1)|g" cluster-test.yaml
kubectl create -f cluster-test.yaml
}

# wait_for_pod_to_be_ready_state check for operator pod to in ready state
wait_for_pod_to_be_ready_state() {
timeout 20 bash <<-'EOF'
until [ $(kubectl get pod -l app=rook-ceph-operator -n rook-ceph -o jsonpath='{.items[*].metadata.name}' -o custom-columns=READY:status.containerStatuses[*].ready | grep -c true) -eq 1 ]; do
echo "waiting for the pods to be in ready state"
sleep 1
done
EOF

}

0 comments on commit 6068cbd

Please sign in to comment.