Skip to content

Commit

Permalink
Better phrasing for workload availability
Browse files Browse the repository at this point in the history
  • Loading branch information
razo7 committed Sep 29, 2023
1 parent 79a4891 commit 530a812
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ metadata:
categories: OpenShift Optional
containerImage: ""
createdAt: ""
description: Fence Agents Remediation Operator can help to increase availability
of workloads in an automatic manner using well-known fence agents.
description: Fence Agents Remediation Operator can help to increase workload availability
in an automatic manner using well-known fence agents.
olm.skipRange: '>=0.0.1'
repository: https://github.com/medik8s/fence-agents-remediation
support: Medik8s
Expand Down Expand Up @@ -77,7 +77,7 @@ spec:
path: template.spec.sharedparameters
version: v1alpha1
description: |
Fence Agents Remediation (*FAR*) is a Kubernetes operator that can help to increase availability of workloads in an automatic manner using well-known fence agents.
Fence Agents Remediation (*FAR*) is a Kubernetes operator that can help to increase workload availability in an automatic manner using well-known fence agents.
Using a management interface or traditional API, FAR runs a fence agent to remediate a node from an unhealthy state by power cycling the node.
By doing so it minimizes downtime for stateful applications and restores compute capacity if transient failures occur.
Expand Down
117 changes: 117 additions & 0 deletions hack/auotomate_far_cr.sh
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

0 comments on commit 530a812

Please sign in to comment.