Skip to content

Commit

Permalink
Merge pull request #84 from SamYuan1990/supportConfigClusterFollowing
Browse files Browse the repository at this point in the history
enable config a ready cluster
  • Loading branch information
SamYuan1990 authored Jun 15, 2024
2 parents 6956624 + d83d33f commit c8bb735
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 39 deletions.
58 changes: 32 additions & 26 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,46 +31,24 @@ jobs:
fail-fast: false
matrix:
include:
- cluster_provider: kind
prometheus_operator_version: v0.12.0
PROMETHEUS_ENABLE: false
GRAFANA_ENABLE: false
TEKTON_ENABLE: false
- cluster_provider: kind
prometheus_operator_version: v0.12.0
PROMETHEUS_ENABLE: true
GRAFANA_ENABLE: true
TEKTON_ENABLE: false
- cluster_provider: kind
prometheus_operator_version: v0.12.0
PROMETHEUS_ENABLE: false
GRAFANA_ENABLE: false
TEKTON_ENABLE: true
- cluster_provider: kind
prometheus_operator_version: v0.12.0
PROMETHEUS_ENABLE: true
GRAFANA_ENABLE: true
TEKTON_ENABLE: true
LOADPROMETHEUSIMAGE: true
- cluster_provider: microshift
prometheus_operator_version: v0.12.0
PROMETHEUS_ENABLE: false
GRAFANA_ENABLE: false
TEKTON_ENABLE: false
LOADPROMETHEUSIMAGE: true
- cluster_provider: microshift
prometheus_operator_version: v0.12.0
PROMETHEUS_ENABLE: true
GRAFANA_ENABLE: true
TEKTON_ENABLE: false
#- cluster_provider: microshift
# prometheus_operator_version: v0.12.0
# PROMETHEUS_ENABLE: false
# GRAFANA_ENABLE: false
# TEKTON_ENABLE: true
#- cluster_provider: microshift
# prometheus_operator_version: v0.12.0
# PROMETHEUS_ENABLE: true
# GRAFANA_ENABLE: true
# TEKTON_ENABLE: true
LOADPROMETHEUSIMAGE: true
steps:
- uses: actions/checkout@v3
- name: start from local
Expand All @@ -80,13 +58,41 @@ jobs:
export GRAFANA_ENABLE=${{matrix.GRAFANA_ENABLE}}
export CLUSTER_PROVIDER=${{matrix.cluster_provider}}
export TEKTON_ENABLE=${{matrix.TEKTON_ENABLE}}
./main.sh prerequisites
export LOADPROMETHEUSIMAGE=${{matrix.LOADPROMETHEUSIMAGE}}
./main.sh up
- name: verify
run: |
export CLUSTER_PROVIDER=${{matrix.cluster_provider}}
./verify.sh
# test local cluster without prometheus grafana
test_precreated_cluster:
needs:
- shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: start a cluster from local
run: |
export PROMETHEUS_ENABLE=false
export TEKTON_ENABLE=false
export LOADPROMETHEUSIMAGE=false
export CLUSTER_CONFIG=false
./main.sh up
mkdir -p /tmp/kubeconfig
cp .kube/config /tmp/kubeconfig
ls /tmp/kubeconfig
- name: config a cluster
run: |
export PROMETHEUS_ENABLE=true
export TEKTON_ENABLE=true
export LOADPROMETHEUSIMAGE=false
export KUBECONFIG_ROOT_DIR=/tmp/kubeconfig
./main.sh config
- name: verify cluster
run: |
./verify.sh verify_cluster
containertestubuntu:
needs:
- shellcheck
Expand Down
5 changes: 4 additions & 1 deletion lib/prometheus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# configuration
declare -r PROMETHEUS_OPERATOR_VERSION=${PROMETHEUS_OPERATOR_VERSION:-v0.11.0}
declare -r PROMETHEUS_REPLICAS=${PROMETHEUS_REPLICAS:-1}
declare -r LOADPROMETHEUSIMAGE=${LOADPROMETHEUSIMAGE:-true}

# constants
declare -r KUBE_PROM_DIR="$PROJECT_ROOT/tmp/kube-prometheus"
Expand All @@ -44,7 +45,9 @@ deploy_prometheus_operator() {
mv kube-prometheus/manifests/prometheus-prometheus.yaml.tmp \
kube-prometheus/manifests/prometheus-prometheus.yaml

_load_prometheus_operator_images_to_local_registry
if is_set "$LOADPROMETHEUSIMAGE"; then
_load_prometheus_operator_images_to_local_registry
fi
kubectl create -f kube-prometheus/manifests/setup
kubectl wait \
--for condition=Established \
Expand Down
24 changes: 13 additions & 11 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,14 @@ declare -r KUBEVIRT_ENABLE=${KUBEVIRT_ENABLE:-false}
declare -r LIBBPF_VERSION=${LIBBPF_VERSION:-v1.2.0}
declare -r RESTARTCONTAINERRUNTIME=${RESTARTCONTAINERRUNTIME:-false}
declare -r REDHAT_SUB=${REDHAT_SUB:-false}
declare -r CLUSTER_CONFIG=${CLUSTER_CONFIG:-true}

source "$PROJECT_ROOT/lib/utils.sh"

config_cluster() {
kubeconfig="$KUBECONFIG_ROOT_DIR/config":$(find "$KUBECONFIG_ROOT_DIR" \
-type f -name "*config*" | tr '\n' ':')
kubeconfig=${kubeconfig%:}
KUBECONFIG=$kubeconfig kubectl config view --merge --flatten >all-in-one-kubeconfig.yaml
mv -f all-in-one-kubeconfig.yaml "${KUBECONFIG_ROOT_DIR}/config"

info "start config cluster"
export KUBECONFIG="${KUBECONFIG_ROOT_DIR}/$KEPLER_KUBECONFIG"

info "finish load kubeconfig"
if is_set "$PROMETHEUS_ENABLE" || is_set "$GRAFANA_ENABLE"; then
source "$PROJECT_ROOT/lib/prometheus.sh"
deploy_prometheus_operator
Expand Down Expand Up @@ -98,7 +94,15 @@ cluster_up() {
mkdir -p "$(basename "$KUBECONFIG_ROOT_DIR")"
mv -f "$kubeconfig" "${KUBECONFIG_ROOT_DIR}/${KEPLER_KUBECONFIG}"

config_cluster
kubeconfig="$KUBECONFIG_ROOT_DIR/$KEPLER_KUBECONFIG":$(find "$KUBECONFIG_ROOT_DIR" \
-type f -name "*config*" | tr '\n' ':')
kubeconfig=${kubeconfig%:}
KUBECONFIG=$kubeconfig kubectl config view --merge --flatten >all-in-one-kubeconfig.yaml
mv -f all-in-one-kubeconfig.yaml "${KUBECONFIG_ROOT_DIR}/config"

if is_set "$CLUSTER_CONFIG"; then
config_cluster
fi
}

cluster_down() {
Expand All @@ -107,8 +111,6 @@ cluster_down() {
}

print_config() {
local cluster_config
cluster_config=$("${CLUSTER_PROVIDER}"_print_config)

local prom_install_msg="$PROMETHEUS_ENABLE"
if ! is_set "$PROMETHEUS_ENABLE" && is_set "$GRAFANA_ENABLE"; then
Expand Down Expand Up @@ -136,7 +138,6 @@ print_config() {
KubeVirt
* Install KubeVirt : $KUBEVIRT_ENABLE
$cluster_config
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EOF
Expand Down Expand Up @@ -265,6 +266,7 @@ main() {
;;
config)
source "$cluster_lib"
print_config
config_cluster
return $?
;;
Expand Down
1 change: 0 additions & 1 deletion verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ main() {
containerruntime
;;
all | *)
verify_bcc
verify_cluster
;;
esac
Expand Down

0 comments on commit c8bb735

Please sign in to comment.