Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify rke2-killall.sh to handle RKE2_DATA_DIR #6531

Merged
merged 1 commit into from
Aug 12, 2024

Conversation

aceeric
Copy link
Contributor

@aceeric aceeric commented Aug 11, 2024

Proposed Changes

Modify rke2-killall.sh to handle RKE2_DATA_DIR

Types of Changes

Bugfix

Verification

Here is my test script. Place this script and the modified rke2-killall.sh into a temp dir on the host and then run the test script with the temp dir as the working directory:

#!/usr/bin/env bash

set -e

function wait_cluster() {
  while true; do
    if ! $1/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml -n kube-system wait job --all --for condition=Complete --timeout=30s; then
      sleep 2s
      continue
    fi
    $1/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml -n kube-system get ds,deploy -oname | while read -r unit; do
      if ! $1/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml -n kube-system rollout status $unit; then
        sleep 2s
        continue
      fi
    done
    break
  done
  # list out all the pods
  $1/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml get po -A
}

function configure_rke2() {
  if [[ "$1" == "/var/lib/rancher/rke2" ]]; then
    cat <<EOF >| /etc/rancher/rke2/config.yaml
selinux: false
EOF
  else
    cat <<EOF >| /etc/rancher/rke2/config.yaml
selinux: false
data-dir: /var/foobar
EOF
  fi
}

function one_test() {
  # install RKE2
  curl -sfL https://get.rke2.io | sh -
  # configure the data dir
  configure_rke2 "$1"
  # start RKE2
  systemctl enable --now rke2-server &
  # wait for the cluster
  wait_cluster "$1"
  # replace default killall script with PR version
  cp -f ./rke2-killall.sh /usr/bin/rke2-killall.sh
  # uninstall
  if [[ "$1" == "/var/lib/rancher/rke2" ]]; then
    /usr/bin/rke2-uninstall.sh
  else
    export RKE2_DATA_DIR="$1" && /usr/bin/rke2-uninstall.sh
    unset RKE2_DATA_DIR
  fi
}

function do_tests() {
  # install with no data dir override
  one_test "/var/lib/rancher/rke2"
  # re-install
  one_test "/var/lib/rancher/rke2"
  # install with data dir override
  one_test "/var/foobar"
  # re-install
  one_test "/var/foobar"
}

# entry point
do_tests

Testing

See above.

Linked Issues

#6522

User-Facing Change

NONE

@aceeric aceeric requested a review from a team as a code owner August 11, 2024 20:05
@codecov-commenter
Copy link

codecov-commenter commented Aug 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 25.18%. Comparing base (c416fa5) to head (a8453e5).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6531   +/-   ##
=======================================
  Coverage   25.18%   25.18%           
=======================================
  Files          33       33           
  Lines        2831     2831           
=======================================
  Hits          713      713           
  Misses       2071     2071           
  Partials       47       47           
Flag Coverage Δ
inttests 9.57% <ø> (ø)
unittests 17.80% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@brandond brandond merged commit 00a4c5c into rancher:master Aug 12, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants