Skip to content

Commit 67d7676

Browse files
authored
Add Linux functions (#21)
* Add missing entry in Helm README list * Add suselinux_install_openiscsi function * Use single quote strings when possible * Add linux_create_fileAndDevice function
1 parent 616d7d4 commit 67d7676

File tree

11 files changed

+118
-40
lines changed

11 files changed

+118
-40
lines changed

charts/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* [Let's Encrypt](letsencrypt/README.md)
88
* [NFS-Ganesha](nfs-ganesha/README.md)
99
* [NFS Server Provisioner](nfs-server-provisioner/README.md)
10+
* [Portworx BBQ](portworx-bbq/README.md)
1011
* [Rancher Cluster Template](rancher-cluster-templates/README.md)
1112
* [WordPress](wordpress/README.md)
1213

scripts/README.md

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,45 @@
22

33
## Bash functions
44

5+
### Instruqt
6+
7+
Name | Source
8+
----------------------------|-------------------------------------
9+
`instruqt_wait_hoststartup` | [instruqt/host.sh](instruqt/host.sh)
10+
11+
### K3s
12+
13+
Name | Source
14+
----------------------|-----------------------------------------------------
15+
`k3s_copy_kubeconfig` | [k3s/cluster_lifecycle.sh](k3s/cluster_lifecycle.sh)
16+
`k3s_create_cluster` | [k3s/cluster_lifecycle.sh](k3s/cluster_lifecycle.sh)
17+
18+
### Kubernetes
19+
20+
Name | Source
21+
--------------------------------------|-----------------------------------------------------------------------------
22+
`k8s_create_letsencryptclusterissuer` | [kubernetes/certificate_management.sh](kubernetes/certificate_management.sh)
23+
`k8s_install_certmanager` | [kubernetes/certificate_management.sh](kubernetes/certificate_management.sh)
24+
`k8s_wait_fornodesandpods` | [kubernetes/cluster_status.sh](kubernetes/cluster_status.sh)
25+
26+
### Keycloak
27+
28+
Name | Source
29+
-----------------------|---------------------------------------------------------
30+
`keycloak_login` | [authentication/keycloak.sh](authentication/keycloak.sh)
31+
`keycloak_create_user` | [authentication/keycloak.sh](authentication/keycloak.sh)
32+
`keycloak_delete_user` | [authentication/keycloak.sh](authentication/keycloak.sh)
33+
34+
### Linux
35+
36+
Name | Source
37+
-----------------------------|-------------------------------
38+
`linux_create_fileAndLoopDevice` | [linux/disk.sh](linux/disk.sh)
39+
40+
### Rancher
41+
542
Name | Source
6-
-----------------------------------------------|-----------------------------------------------------------------------------
7-
`instruqt_wait_hoststartup` | [instruqt/host.sh](instruqt/host.sh)
8-
`k3s_copy_kubeconfig` | [k3s/cluster_lifecycle.sh](k3s/cluster_lifecycle.sh)
9-
`k3s_create_cluster` | [k3s/cluster_lifecycle.sh](k3s/cluster_lifecycle.sh)
10-
`k8s_create_letsencryptclusterissuer` | [kubernetes/certificate_management.sh](kubernetes/certificate_management.sh)
11-
`k8s_install_certmanager` | [kubernetes/certificate_management.sh](kubernetes/certificate_management.sh)
12-
`k8s_wait_fornodesandpods` | [kubernetes/cluster_status.sh](kubernetes/cluster_status.sh)
13-
`keycloak_login` | [authentication/keycloak.sh](authentication/keycloak.sh)
14-
`keycloak_create_user` | [authentication/keycloak.sh](authentication/keycloak.sh)
15-
`keycloak_delete_user` | [authentication/keycloak.sh](authentication/keycloak.sh)
16-
`observability_check_stackpack` | [observability/stackpack.sh](observability/stackpack.sh)
17-
`observability_create_ingestion_api_key` | [observability/api_key.sh](observability/api_key.sh)
18-
`observability_delete_ingestion_api_key` | [observability/api_key.sh](observability/api_key.sh)
19-
`observability_delete_stackpack` | [observability/stackpack.sh](observability/stackpack.sh)
20-
`observability_get_component_snapshot` | [observability/stql.sh](observability/stql.sh)
21-
`observability_get_component_state` | [observability/stql.sh](observability/stql.sh)
22-
`observability_install_cli` | [observability/cli.sh](observability/cli.sh)
43+
-----------------------------------------------|-------------------------------------------------------------
2344
`rancher_create_apikey` | [rancher/user_actions.sh](rancher/user_actions.sh)
2445
`rancher_create_customcluster` | [rancher/cluster_actions.sh](rancher/cluster_actions.sh)
2546
`rancher_first_login` | [rancher/manager_lifecycle.sh](rancher/manager_lifecycle.sh)
@@ -31,11 +52,29 @@ Name | Source
3152
`rancher_update_password` | [rancher/user_actions.sh](rancher/user_actions.sh)
3253
`rancher_update_serverurl` | [rancher/manager_settings.sh](rancher/manager_settings.sh)
3354
`rancher_wait_capiready` | [rancher/manager_lifecycle.sh](rancher/manager_lifecycle.sh)
34-
`suselinux_install_git` | [suselinux/packages.sh](suselinux/packages.sh)
35-
`suselinux_install_helm` | [suselinux/packages.sh](suselinux/packages.sh)
36-
`suselinux_install_kubectl` | [suselinux/packages.sh](suselinux/packages.sh)
37-
`suselinux_install_podman` | [suselinux/packages.sh](suselinux/packages.sh)
38-
`suselinux_register_cloudguest` | [suselinux/registration.sh](suselinux/registration.sh)
55+
56+
### SUSE Observability
57+
58+
Name | Source
59+
-----------------------------------------|---------------------------------------------------------
60+
`observability_check_stackpack` | [observability/stackpack.sh](observability/stackpack.sh)
61+
`observability_create_ingestion_api_key` | [observability/api_key.sh](observability/api_key.sh)
62+
`observability_delete_ingestion_api_key` | [observability/api_key.sh](observability/api_key.sh)
63+
`observability_delete_stackpack` | [observability/stackpack.sh](observability/stackpack.sh)
64+
`observability_get_component_snapshot` | [observability/stql.sh](observability/stql.sh)
65+
`observability_get_component_state` | [observability/stql.sh](observability/stql.sh)
66+
`observability_install_cli` | [observability/cli.sh](observability/cli.sh)
67+
68+
### SUSE Linux (previously SLES, SLE Micro)
69+
70+
Name | Source
71+
--------------------------------|-------------------------------------------------------
72+
`suselinux_install_git` | [suselinux/packages.sh](suselinux/packages.sh)
73+
`suselinux_install_helm` | [suselinux/packages.sh](suselinux/packages.sh)
74+
`suselinux_install_kubectl` | [suselinux/packages.sh](suselinux/packages.sh)
75+
`suselinux_install_openiscsi` | [suselinux/packages.sh](suselinux/packages.sh)
76+
`suselinux_install_podman` | [suselinux/packages.sh](suselinux/packages.sh)
77+
`suselinux_register_cloudguest` | [suselinux/registration.sh](suselinux/registration.sh)
3978

4079
## Concrete examples
4180

scripts/k3s/cluster_lifecycle.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
k3s_create_cluster() {
1212
local version=$1
1313

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

scripts/kubernetes/certificate_management.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
k8s_install_certmanager() {
1212
local version=$1
1313

14-
echo "Installing cert-manager..."
14+
echo 'Installing cert-manager...'
1515
helm repo add jetstack https://charts.jetstack.io
1616
helm repo update
1717
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/${version}/cert-manager.crds.yaml

scripts/kubernetes/cluster_status.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
k8s_wait_fornodesandpods() {
1212
# checks nodes are ready
1313
while ! kubectl get nodes --no-headers 2>/dev/null | grep -q .; do
14-
echo "Waiting for nodes to be available..."
14+
echo 'Waiting for nodes to be available...'
1515
sleep 5
1616
done
1717
while true; do
1818
NOT_READY_NODES=$(kubectl get nodes --no-headers 2>/dev/null | grep -v " Ready" | wc -l)
1919
if [ "$NOT_READY_NODES" -eq 0 ]; then
20-
echo "All nodes are ready."
20+
echo 'All nodes are ready.'
2121
break
2222
else
2323
sleep 5
@@ -26,13 +26,13 @@ k8s_wait_fornodesandpods() {
2626

2727
# checks pods are completed or running
2828
while ! kubectl get pods --all-namespaces --no-headers 2>/dev/null | grep -q .; do
29-
echo "Waiting for pods to be available..."
29+
echo 'Waiting for pods to be available...'
3030
sleep 5
3131
done
3232
while true; do
3333
NOT_READY_PODS=$(kubectl get pods --all-namespaces --field-selector=status.phase!=Running,status.phase!=Succeeded --no-headers 2>/dev/null | wc -l)
3434
if [ "$NOT_READY_PODS" -eq 0 ]; then
35-
echo "All pods are in Running or Completed status."
35+
echo 'All pods are in Running or Completed status.'
3636
break
3737
else
3838
sleep 5

scripts/linux/disk.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
# Collection of functions to work with disks on Linux
3+
4+
#######################################
5+
# Create a file and binds it to a loop device
6+
# Arguments:
7+
# File name
8+
# Size file (number of blocks)
9+
# Look device
10+
# Examples:
11+
# linux_create_fileAndLoopDevice '/loop-file1' '10240' '/dev/loop1'
12+
#######################################
13+
linux_create_fileAndLoopDevice() {
14+
local fileName=$1
15+
local sizeFile=$2
16+
local loopDevice=$3
17+
18+
echo "Creating local file ${fileName} and loop device ${fileName}..."
19+
20+
# prepares the file for use with loopback device (creates a file filled with zero bytes)
21+
dd if=/dev/zero of=${fileName} bs=1M count=${sizeFile} status=progress
22+
23+
# binds the file to the loop device (enabling to work with the file as if it were a block device, like a physical disk)
24+
losetup ${loopDevice} ${fileName}
25+
}

scripts/rancher/cluster_actions.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# rancher_list_clusters
88
#######################################
99
rancher_list_clusters() {
10-
echo "Listing clusters registered in Rancher..."
10+
echo 'Listing clusters registered in Rancher...'
1111
kubectl get clusters.provisioning.cattle.io --all-namespaces -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'
1212
}
1313

@@ -27,7 +27,7 @@ rancher_create_customcluster_nowait() {
2727

2828
rancher_wait_capiready
2929

30-
echo "Creating downstream cluster in Rancher..."
30+
echo 'Creating downstream cluster in Rancher...'
3131
cat <<EOF | kubectl apply -f -
3232
apiVersion: provisioning.cattle.io/v1
3333
kind: Cluster

scripts/rancher/manager_lifecycle.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ rancher_install_withcertmanagerclusterissuer() {
1919
local hostname=$4
2020
local clusterissuer=$5
2121

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

51-
echo "Do first login on Rancher..."
51+
echo 'Do first login on Rancher...'
5252
BOOTSTRAP_PASSWORD=$(kubectl get secret --namespace cattle-system bootstrap-secret -o go-template='{{.data.bootstrapPassword|base64decode}}{{ "\n" }}')
5353
echo "DEBUG BOOTSTRAP_PASSWORD=${BOOTSTRAP_PASSWORD}"
5454
rancher_login_withpassword $rancherUrl 'admin' $BOOTSTRAP_PASSWORD
@@ -67,14 +67,14 @@ rancher_first_login() {
6767
rancher_wait_capiready() {
6868
while true; do
6969
status=$(kubectl get deployment capi-controller-manager -n cattle-provisioning-capi-system -o jsonpath='{.status.conditions[?(@.type=="Available")].status}' 2>/dev/null)
70-
if [ "$status" == "True" ]; then
71-
echo "Deployment capi-controller-manager is available"
70+
if [ "$status" == 'True' ]; then
71+
echo 'Deployment capi-controller-manager is available'
7272
break
7373
fi
7474
sleep 10
7575
done
76-
while [[ $(kubectl get endpoints capi-webhook-service -n cattle-provisioning-capi-system -o jsonpath='{.subsets}' 2>/dev/null) == "" ]]; do
76+
while [[ $(kubectl get endpoints capi-webhook-service -n cattle-provisioning-capi-system -o jsonpath='{.subsets}' 2>/dev/null) == '' ]]; do
7777
sleep 10
7878
done
79-
echo "Service capi-webhook-service is ready"
79+
echo 'Service capi-webhook-service is ready'
8080
}

scripts/rancher/manager_settings.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
rancher_update_serverurl() {
1212
local rancherUrl=$1
1313

14-
echo "Sets Rancher URL in settings..."
14+
echo 'Sets Rancher URL in settings...'
1515
kubectl patch settings.management.cattle.io server-url --type='merge' --patch '{ "value": "'$rancherUrl'" }'
1616
}

scripts/rancher/user_actions.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ rancher_update_password() {
4444
local currentPassword=$3
4545
local newPassword=$4
4646

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

74-
echo "Creates a Rancher API Key..."
74+
echo 'Creates a Rancher API Key...'
7575
API_KEY_RESPONSE=$(curl -s -k "$rancherUrl/v3/tokens" \
7676
-H 'Content-Type: application/json' \
7777
-H "Authorization: Bearer $token" \

0 commit comments

Comments
 (0)