-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better phrasing for workload availability
- Loading branch information
Showing
2 changed files
with
120 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#!/bin/bash | ||
# The below script is meant for creating FenceAgentsRemediation CR for the following platforms | ||
# AWS, BareMetal, Azure, and GCP | ||
# Install fence-agents-gce package | ||
# set -ex | ||
SAMPLES_LOCARTION="config/samples/" | ||
OPERATOR_NS="openshift-operators" | ||
MACHINE_NAMESPACE="openshift-machine-api" | ||
# AWS | ||
AWS_EXAMPLE_NAME=${SAMPLES_LOCARTION}"aws_fence-agents-remediation_v1alpha1_fenceagentsremediation.yaml" | ||
SECRET_AWS_NAME="aws-cloud-fencing-credentials-secret" | ||
SECRET_AWS_NAMESPACE="openshift-operators" | ||
|
||
# BareMetal | ||
BMH_EXAMPLE_NAME=${SAMPLES_LOCARTION}"bmh_fence-agents-remediation_v1alpha1_fenceagentsremediation.yaml" | ||
SECRET_BMH_NAME="ostest-master-0-bmc-secret" | ||
SECRET_BMH_NAMESPACE=${MACHINE_NAMESPACE} | ||
|
||
# Azure | ||
AZURE_EXAMPLE_NAME=${SAMPLES_LOCARTION}"azure_fence-agents-remediation_v1alpha1_fenceagentsremediation.yaml" | ||
SECRET_AZURE_NAME="azure-cloud-credentials" | ||
SECRET_AZURE_NAMESPACE=${MACHINE_NAMESPACE} | ||
|
||
# GCP | ||
SECRET_GCP_NAME="gcp-cloud-credentials" | ||
# Choose platform | ||
platform=$(oc get Infrastructure.config.openshift.io/cluster -o jsonpath='{.spec.platformSpec.type}') | ||
case "${platform}" in | ||
"AWS") | ||
echo "Platform is AWS, thus we are creating fence_aws FA and the secret is" "${SECRET_AWS_NAME}" | ||
# make ocp-aws-credentials | ||
aws_key_id=$(oc get secrets -n "${SECRET_AWS_NAMESPACE}" "${SECRET_AWS_NAME}" -o jsonpath='{.data.aws_access_key_id}' | base64 -d) | ||
aws_key=$(oc get secrets -n ${SECRET_AWS_NAMESPACE} ${SECRET_AWS_NAME} -o jsonpath='{.data.aws_secret_access_key}' | base64 -d) | ||
aws_region=$(oc get machines -o json -n ${MACHINE_NAMESPACE} | jq -r '.items[0].spec.providerID' | cut -d'/' -f4 | sed 's/.$//') | ||
# Get the instance IDs from the Kubernetes API | ||
instance_ids=$(oc get machines -o json -n ${MACHINE_NAMESPACE} | jq -r '.items[].spec.providerID' | awk -F/ '{print $NF}') | ||
# Create an array by splitting the multiline string on line breaks | ||
IFS=$'\n' read -r -d '' -a array_instance_ids <<< "${instance_ids}" | ||
;; | ||
"BareMetal") | ||
echo "Platform is BareMetal, thus we are creating fence_ipmilan FA and the secret is" "${SECRET_BMH_NAME}" | ||
bmh_username=$(oc get secrets -n "${SECRET_BMH_NAMESPACE}" "${SECRET_BMH_NAME}" -o jsonpath='{.data.username}' | base64 -d) | ||
bmh_password=$(oc get secrets -n "${SECRET_BMH_NAMESPACE}" "${SECRET_BMH_NAME}" -o jsonpath='{.data.password}' | base64 -d) | ||
# TODO: Find the ports | ||
;; | ||
"Azure") | ||
echo "Platform is Azure, thus we are creating fence_azure_arm FA and the secret is" "${SECRET_AZURE_NAME}" | ||
;; | ||
"GCP") | ||
echo "Platform is GCP, thus we are creating fence_gce FA and the secret is" "${SECRET_GCP_NAME}" | ||
;; | ||
*) | ||
;; | ||
esac | ||
|
||
# Get the node names from the Kubernetes API | ||
nodes=$(oc get machines -o json -n ${MACHINE_NAMESPACE} | jq -r '.items[].status.nodeRef.name') | ||
# Create an array by splitting the multiline string on line breaks | ||
IFS=$'\n' read -r -d '' -a array_nodes <<< "${nodes}" | ||
|
||
machine=$(oc get machines -o=custom-columns=node:.status.nodeRef.name,machine:.metadata.name,ProviderID:.spec.providerID -n "${MACHINE_NAMESPACE}") | ||
|
||
echo "${machine}" | ||
|
||
# Generate the FenceAgentsRemediation CR manifest | ||
case "${platform}" in | ||
"AWS") | ||
cat <<EOF > "${AWS_EXAMPLE_NAME}" | ||
apiVersion: fence-agents-remediation.medik8s.io/v1alpha1 | ||
kind: FenceAgentsRemediation | ||
metadata: | ||
name: ${array_nodes[3]} | ||
namespace: ${OPERATOR_NS} | ||
spec: | ||
nodeparameters: | ||
'--plug': | ||
EOF | ||
for i in "${!array_instance_ids[@]}"; do | ||
echo " ${array_nodes[${i}]}: '${array_instance_ids[${i}]}'" >> "${AWS_EXAMPLE_NAME}" | ||
done | ||
|
||
cat <<EOF >> "${AWS_EXAMPLE_NAME}" | ||
sharedparameters: | ||
'--region': ${aws_region} | ||
'--skip-race-check': '' | ||
'--access-key': ${aws_key_id} | ||
'--secret-key': ${aws_key} | ||
agent: fence_aws | ||
EOF | ||
;; | ||
"BareMetal") | ||
cat <<EOF > "${BMH_EXAMPLE_NAME}" | ||
apiVersion: fence-agents-remediation.medik8s.io/v1alpha1 | ||
kind: FenceAgentsRemediation | ||
metadata: | ||
name: ${array_nodes[3]} | ||
namespace: ${OPERATOR_NS} | ||
spec: | ||
nodeparameters: | ||
'--ipport': | ||
master-0: '6230' | ||
master-1: '6231' | ||
master-2: '6232' | ||
worker-0: '6233' | ||
worker-1: '6234' | ||
worker-2: '6235' | ||
sharedparameters: | ||
'--ip': 192.168.111.1 | ||
'--lanplus': '' | ||
'--username': ${bmh_username} | ||
'--password': ${bmh_password} | ||
agent: fence_ipmilan | ||
EOF | ||
;; | ||
*) | ||
;; | ||
esac |