Skip to content

Commit

Permalink
update: script functions
Browse files Browse the repository at this point in the history
  • Loading branch information
codekow committed Sep 16, 2023
1 parent d66be6f commit 5d4be18
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
39 changes: 39 additions & 0 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ aws_get_key(){
echo "AWS_DEFAULT_REGION: ${AWS_DEFAULT_REGION}"
}

aws_get_all_ec2(){
aws ec2 describe-instances --filters Name=instance-state-name,Values=running --query 'Reservations[].Instances[].InstanceId' --output text | sed 's/\t/ /g'
aws ec2 describe-instances --filters Name=tag:Name,Values=bastion --query 'Reservations[].Instances[].InstanceId' --output text
}

aws_stop_all_ec2(){
RUNNING_IDS=$(aws ec2 describe-instances --filters Name=instance-state-name,Values=running --query 'Reservations[].Instances[].InstanceId' --output text | sed 's/\t/ /g')
BASTION_ID=$(aws ec2 describe-instances --filters Name=tag:Name,Values=bastion --query 'Reservations[].Instances[].InstanceId' --output text)
Expand Down Expand Up @@ -363,6 +368,40 @@ ocp_remove_kubeadmin(){
oc delete secret kubeadmin -n kube-system
}

ocp_upgrade_cluster(){
OCP_VERSION="${1:-latest}"

if [ "${OCP_VERSION}" == "latest" ]; then
oc adm upgrade --to-latest=true
else
oc adm upgrade --to="${OCP_VERSION}"
fi
}

rhdp_fix_api_certs(){
echo "
issue: RHDP can not start cluster due to ca.crt change
fix:
# user: lab-user
sed -i.bak '/certificate-authority-data/d' ~/.kube/config
# user: ec2-user
sudo su ec2-user /bin/bash -c 'id; sed -i.bak '/certificate-authority-data/d' ~/.kube/config'
"

CERT_NAME=$(oc -n openshift-ingress-operator get ingresscontrollers default --template='{{.spec.defaultCertificate.name}}')
# API_HOST_NAME=$(oc -n openshift-console extract cm/console-config --to=- | sed -n '/masterPublicURL/ s/.*:\/\///; s/:6443//p')
API_HOST_NAME=$(oc whoami --show-server | sed 's@https://@@; s@:.*@@')

oc -n openshift-ingress get secret "${CERT_NAME}" -o yaml | \
sed 's/namespace: .*/namespace: openshift-config/' | \
oc -n openshift-config apply -f-

oc patch apiserver cluster --type=merge -p '{"spec":{"servingCerts": {"namedCertificates": [{"names": ["'"${API_HOST_NAME}"'"], "servingCertificate": {"name": "'"${CERT_NAME}"'"}}]}}}'

}

# get functions
# sed -n '/(){/ s/(){$//p' scripts/kludges.sh

Expand Down
24 changes: 1 addition & 23 deletions scripts/wip/kludges.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# shellcheck disable=SC2155

# kludges
# TODO: ArgoCD Hooks
# these may be useful but not mature

setup_namespace(){
NAMESPACE=${1}
Expand Down Expand Up @@ -30,27 +30,5 @@ setup_ack_system(){
done
}

# lets encrypt api cert
fix_api_cert(){
echo "
issue: RHDP can not start cluster due to ca.crt change
fix:
# login to bastion
# user: ec2-user
sed -i.bak '/certificate-authority-data/d' ~/.kube/config
"

CERT_NAME=$(oc -n openshift-ingress-operator get ingresscontrollers default --template='{{.spec.defaultCertificate.name}}')
# API_HOST_NAME=$(oc -n openshift-console extract cm/console-config --to=- | sed -n '/masterPublicURL/ s/.*:\/\///; s/:6443//p')
API_HOST_NAME=$(oc whoami --show-server | sed 's@https://@@; s@:.*@@')

oc -n openshift-ingress get secret "${CERT_NAME}" -o yaml | \
sed 's/namespace: .*/namespace: openshift-config/' | \
oc -n openshift-config apply -f-

oc patch apiserver cluster --type=merge -p '{"spec":{"servingCerts": {"namedCertificates": [{"names": ["'"${API_HOST_NAME}"'"], "servingCertificate": {"name": "'"${CERT_NAME}"'"}}]}}}'
}

# get functions
# sed -n '/(){/ s/(){$//p' scripts/kludges.sh

0 comments on commit 5d4be18

Please sign in to comment.