Skip to content

Commit

Permalink
Add Linux functions (#21)
Browse files Browse the repository at this point in the history
* Add missing entry in Helm README list

* Add suselinux_install_openiscsi function

* Use single quote strings when possible

* Add linux_create_fileAndDevice function
  • Loading branch information
devpro authored Oct 23, 2024
1 parent 616d7d4 commit 67d7676
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 40 deletions.
1 change: 1 addition & 0 deletions charts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* [Let's Encrypt](letsencrypt/README.md)
* [NFS-Ganesha](nfs-ganesha/README.md)
* [NFS Server Provisioner](nfs-server-provisioner/README.md)
* [Portworx BBQ](portworx-bbq/README.md)
* [Rancher Cluster Template](rancher-cluster-templates/README.md)
* [WordPress](wordpress/README.md)

Expand Down
83 changes: 61 additions & 22 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,45 @@

## Bash functions

### Instruqt

Name | Source
----------------------------|-------------------------------------
`instruqt_wait_hoststartup` | [instruqt/host.sh](instruqt/host.sh)

### K3s

Name | Source
----------------------|-----------------------------------------------------
`k3s_copy_kubeconfig` | [k3s/cluster_lifecycle.sh](k3s/cluster_lifecycle.sh)
`k3s_create_cluster` | [k3s/cluster_lifecycle.sh](k3s/cluster_lifecycle.sh)

### Kubernetes

Name | Source
--------------------------------------|-----------------------------------------------------------------------------
`k8s_create_letsencryptclusterissuer` | [kubernetes/certificate_management.sh](kubernetes/certificate_management.sh)
`k8s_install_certmanager` | [kubernetes/certificate_management.sh](kubernetes/certificate_management.sh)
`k8s_wait_fornodesandpods` | [kubernetes/cluster_status.sh](kubernetes/cluster_status.sh)

### Keycloak

Name | Source
-----------------------|---------------------------------------------------------
`keycloak_login` | [authentication/keycloak.sh](authentication/keycloak.sh)
`keycloak_create_user` | [authentication/keycloak.sh](authentication/keycloak.sh)
`keycloak_delete_user` | [authentication/keycloak.sh](authentication/keycloak.sh)

### Linux

Name | Source
-----------------------------|-------------------------------
`linux_create_fileAndLoopDevice` | [linux/disk.sh](linux/disk.sh)

### Rancher

Name | Source
-----------------------------------------------|-----------------------------------------------------------------------------
`instruqt_wait_hoststartup` | [instruqt/host.sh](instruqt/host.sh)
`k3s_copy_kubeconfig` | [k3s/cluster_lifecycle.sh](k3s/cluster_lifecycle.sh)
`k3s_create_cluster` | [k3s/cluster_lifecycle.sh](k3s/cluster_lifecycle.sh)
`k8s_create_letsencryptclusterissuer` | [kubernetes/certificate_management.sh](kubernetes/certificate_management.sh)
`k8s_install_certmanager` | [kubernetes/certificate_management.sh](kubernetes/certificate_management.sh)
`k8s_wait_fornodesandpods` | [kubernetes/cluster_status.sh](kubernetes/cluster_status.sh)
`keycloak_login` | [authentication/keycloak.sh](authentication/keycloak.sh)
`keycloak_create_user` | [authentication/keycloak.sh](authentication/keycloak.sh)
`keycloak_delete_user` | [authentication/keycloak.sh](authentication/keycloak.sh)
`observability_check_stackpack` | [observability/stackpack.sh](observability/stackpack.sh)
`observability_create_ingestion_api_key` | [observability/api_key.sh](observability/api_key.sh)
`observability_delete_ingestion_api_key` | [observability/api_key.sh](observability/api_key.sh)
`observability_delete_stackpack` | [observability/stackpack.sh](observability/stackpack.sh)
`observability_get_component_snapshot` | [observability/stql.sh](observability/stql.sh)
`observability_get_component_state` | [observability/stql.sh](observability/stql.sh)
`observability_install_cli` | [observability/cli.sh](observability/cli.sh)
-----------------------------------------------|-------------------------------------------------------------
`rancher_create_apikey` | [rancher/user_actions.sh](rancher/user_actions.sh)
`rancher_create_customcluster` | [rancher/cluster_actions.sh](rancher/cluster_actions.sh)
`rancher_first_login` | [rancher/manager_lifecycle.sh](rancher/manager_lifecycle.sh)
Expand All @@ -31,11 +52,29 @@ Name | Source
`rancher_update_password` | [rancher/user_actions.sh](rancher/user_actions.sh)
`rancher_update_serverurl` | [rancher/manager_settings.sh](rancher/manager_settings.sh)
`rancher_wait_capiready` | [rancher/manager_lifecycle.sh](rancher/manager_lifecycle.sh)
`suselinux_install_git` | [suselinux/packages.sh](suselinux/packages.sh)
`suselinux_install_helm` | [suselinux/packages.sh](suselinux/packages.sh)
`suselinux_install_kubectl` | [suselinux/packages.sh](suselinux/packages.sh)
`suselinux_install_podman` | [suselinux/packages.sh](suselinux/packages.sh)
`suselinux_register_cloudguest` | [suselinux/registration.sh](suselinux/registration.sh)

### SUSE Observability

Name | Source
-----------------------------------------|---------------------------------------------------------
`observability_check_stackpack` | [observability/stackpack.sh](observability/stackpack.sh)
`observability_create_ingestion_api_key` | [observability/api_key.sh](observability/api_key.sh)
`observability_delete_ingestion_api_key` | [observability/api_key.sh](observability/api_key.sh)
`observability_delete_stackpack` | [observability/stackpack.sh](observability/stackpack.sh)
`observability_get_component_snapshot` | [observability/stql.sh](observability/stql.sh)
`observability_get_component_state` | [observability/stql.sh](observability/stql.sh)
`observability_install_cli` | [observability/cli.sh](observability/cli.sh)

### SUSE Linux (previously SLES, SLE Micro)

Name | Source
--------------------------------|-------------------------------------------------------
`suselinux_install_git` | [suselinux/packages.sh](suselinux/packages.sh)
`suselinux_install_helm` | [suselinux/packages.sh](suselinux/packages.sh)
`suselinux_install_kubectl` | [suselinux/packages.sh](suselinux/packages.sh)
`suselinux_install_openiscsi` | [suselinux/packages.sh](suselinux/packages.sh)
`suselinux_install_podman` | [suselinux/packages.sh](suselinux/packages.sh)
`suselinux_register_cloudguest` | [suselinux/registration.sh](suselinux/registration.sh)

## Concrete examples

Expand Down
2 changes: 1 addition & 1 deletion scripts/k3s/cluster_lifecycle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
k3s_create_cluster() {
local version=$1

echo "Create management cluster (K3s)..."
echo 'Create management cluster (K3s)...'
curl -sfL https://get.k3s.io | INSTALL_K3S_CHANNEL="${version}" K3S_KUBECONFIG_MODE="644" sh -
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/kubernetes/certificate_management.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
k8s_install_certmanager() {
local version=$1

echo "Installing cert-manager..."
echo 'Installing cert-manager...'
helm repo add jetstack https://charts.jetstack.io
helm repo update
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/${version}/cert-manager.crds.yaml
Expand Down
8 changes: 4 additions & 4 deletions scripts/kubernetes/cluster_status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
k8s_wait_fornodesandpods() {
# checks nodes are ready
while ! kubectl get nodes --no-headers 2>/dev/null | grep -q .; do
echo "Waiting for nodes to be available..."
echo 'Waiting for nodes to be available...'
sleep 5
done
while true; do
NOT_READY_NODES=$(kubectl get nodes --no-headers 2>/dev/null | grep -v " Ready" | wc -l)
if [ "$NOT_READY_NODES" -eq 0 ]; then
echo "All nodes are ready."
echo 'All nodes are ready.'
break
else
sleep 5
Expand All @@ -26,13 +26,13 @@ k8s_wait_fornodesandpods() {

# checks pods are completed or running
while ! kubectl get pods --all-namespaces --no-headers 2>/dev/null | grep -q .; do
echo "Waiting for pods to be available..."
echo 'Waiting for pods to be available...'
sleep 5
done
while true; do
NOT_READY_PODS=$(kubectl get pods --all-namespaces --field-selector=status.phase!=Running,status.phase!=Succeeded --no-headers 2>/dev/null | wc -l)
if [ "$NOT_READY_PODS" -eq 0 ]; then
echo "All pods are in Running or Completed status."
echo 'All pods are in Running or Completed status.'
break
else
sleep 5
Expand Down
25 changes: 25 additions & 0 deletions scripts/linux/disk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
# Collection of functions to work with disks on Linux

#######################################
# Create a file and binds it to a loop device
# Arguments:
# File name
# Size file (number of blocks)
# Look device
# Examples:
# linux_create_fileAndLoopDevice '/loop-file1' '10240' '/dev/loop1'
#######################################
linux_create_fileAndLoopDevice() {
local fileName=$1
local sizeFile=$2
local loopDevice=$3

echo "Creating local file ${fileName} and loop device ${fileName}..."

# prepares the file for use with loopback device (creates a file filled with zero bytes)
dd if=/dev/zero of=${fileName} bs=1M count=${sizeFile} status=progress

# binds the file to the loop device (enabling to work with the file as if it were a block device, like a physical disk)
losetup ${loopDevice} ${fileName}
}
4 changes: 2 additions & 2 deletions scripts/rancher/cluster_actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# rancher_list_clusters
#######################################
rancher_list_clusters() {
echo "Listing clusters registered in Rancher..."
echo 'Listing clusters registered in Rancher...'
kubectl get clusters.provisioning.cattle.io --all-namespaces -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'
}

Expand All @@ -27,7 +27,7 @@ rancher_create_customcluster_nowait() {

rancher_wait_capiready

echo "Creating downstream cluster in Rancher..."
echo 'Creating downstream cluster in Rancher...'
cat <<EOF | kubectl apply -f -
apiVersion: provisioning.cattle.io/v1
kind: Cluster
Expand Down
14 changes: 7 additions & 7 deletions scripts/rancher/manager_lifecycle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ rancher_install_withcertmanagerclusterissuer() {
local hostname=$4
local clusterissuer=$5

echo "Installing Rancher..."
echo 'Installing Rancher...'
helm repo add rancher-${repository} https://releases.rancher.com/server-charts/${repository}
helm repo update
helm upgrade --install rancher rancher-${repository}/rancher --namespace cattle-system --create-namespace \
Expand All @@ -31,7 +31,7 @@ rancher_install_withcertmanagerclusterissuer() {
--set ingress.tls.secretName=rancher-tls \
--set agentTLSMode="system-store"
kubectl wait pods -n cattle-system -l app=rancher --for condition=Ready --timeout=180s
echo "Waiting for Rancher web app to be running with a valid certificate..."
echo 'Waiting for Rancher web app to be running with a valid certificate...'
while ! kubectl get secret rancher-tls --namespace cattle-system 2>/dev/null; do sleep 1; done
sleep 10
}
Expand All @@ -48,7 +48,7 @@ rancher_first_login() {
local rancherUrl=$1
local newPassword=$2

echo "Do first login on Rancher..."
echo 'Do first login on Rancher...'
BOOTSTRAP_PASSWORD=$(kubectl get secret --namespace cattle-system bootstrap-secret -o go-template='{{.data.bootstrapPassword|base64decode}}{{ "\n" }}')
echo "DEBUG BOOTSTRAP_PASSWORD=${BOOTSTRAP_PASSWORD}"
rancher_login_withpassword $rancherUrl 'admin' $BOOTSTRAP_PASSWORD
Expand All @@ -67,14 +67,14 @@ rancher_first_login() {
rancher_wait_capiready() {
while true; do
status=$(kubectl get deployment capi-controller-manager -n cattle-provisioning-capi-system -o jsonpath='{.status.conditions[?(@.type=="Available")].status}' 2>/dev/null)
if [ "$status" == "True" ]; then
echo "Deployment capi-controller-manager is available"
if [ "$status" == 'True' ]; then
echo 'Deployment capi-controller-manager is available'
break
fi
sleep 10
done
while [[ $(kubectl get endpoints capi-webhook-service -n cattle-provisioning-capi-system -o jsonpath='{.subsets}' 2>/dev/null) == "" ]]; do
while [[ $(kubectl get endpoints capi-webhook-service -n cattle-provisioning-capi-system -o jsonpath='{.subsets}' 2>/dev/null) == '' ]]; do
sleep 10
done
echo "Service capi-webhook-service is ready"
echo 'Service capi-webhook-service is ready'
}
2 changes: 1 addition & 1 deletion scripts/rancher/manager_settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
rancher_update_serverurl() {
local rancherUrl=$1

echo "Sets Rancher URL in settings..."
echo 'Sets Rancher URL in settings...'
kubectl patch settings.management.cattle.io server-url --type='merge' --patch '{ "value": "'$rancherUrl'" }'
}
4 changes: 2 additions & 2 deletions scripts/rancher/user_actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ rancher_update_password() {
local currentPassword=$3
local newPassword=$4

echo "Updates Rancher user password..."
echo 'Updates Rancher user password...'
curl -s -k -H "Authorization: Bearer $token" \
-H 'Content-Type: application/json' \
-X POST \
Expand All @@ -71,7 +71,7 @@ rancher_create_apikey() {
local token=$2
local description=$3

echo "Creates a Rancher API Key..."
echo 'Creates a Rancher API Key...'
API_KEY_RESPONSE=$(curl -s -k "$rancherUrl/v3/tokens" \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $token" \
Expand Down
13 changes: 13 additions & 0 deletions scripts/suselinux/packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ suselinux_install_git() {
zypper install -y git
}

#######################################
# Install open-iscsi on SUSE Linux
# Examples:
# suselinux_install_openiscsi
#######################################
suselinux_install_openiscsi() {
zypper --gpg-auto-import-keys -q refresh
zypper --gpg-auto-import-keys -q install -y open-iscsi
systemctl -q enable iscsid
systemctl start iscsid
modprobe iscsi_tcp
}

#######################################
# Install Podman on SUSE Linux
# Examples:
Expand Down

0 comments on commit 67d7676

Please sign in to comment.