Skip to content

Commit

Permalink
Merge pull request #2767 from hexfusion/persist_etcd
Browse files Browse the repository at this point in the history
bootkube.sh: CEO: properly handle etcd endpoints on retry
  • Loading branch information
openshift-merge-robot authored Dec 9, 2019
2 parents a42419d + 04ad81e commit 5dd2719
Showing 1 changed file with 34 additions and 30 deletions.
64 changes: 34 additions & 30 deletions data/data/bootstrap/files/usr/local/bin/bootkube.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euoE pipefail ## -E option will cause functions to inherit trap

mkdir --parents /etc/kubernetes/{manifests,bootstrap-configs,bootstrap-manifests}

ETCD_ENDPOINTS={{.EtcdCluster}}
ETCD_ENDPOINTS=

bootkube_podman_run() {
# we run all commands in the host-network to prevent IP conflicts with
Expand Down Expand Up @@ -110,40 +110,44 @@ bootkube_podman_run \
# during initial operator rollout phase this logic allows us to deploy the operator via CVO
# in an `Unmanaged` no-op state. after all of the pieces have merged and the operator is
# deemed stable we can remove this logic and the operator will be `Managed` by default.
if [ ! -z "$CLUSTER_ETCD_OPERATOR_MANAGED" ] && [ ! -f etcd-bootstrap.done ]
if [ ! -z "$CLUSTER_ETCD_OPERATOR_MANAGED" ]
then
echo "Rendering CEO Manifests..."
bootkube_podman_run \
--volume "$PWD:/assets:z" \
"${CLUSTER_ETCD_OPERATOR_IMAGE}" \
/usr/bin/cluster-etcd-operator render \
--etcd-ca=/assets/tls/etcd-ca-bundle.crt \
--etcd-metric-ca=/assets/tls/etcd-metric-ca-bundle.crt \
--manifest-etcd-image "${MACHINE_CONFIG_ETCD_IMAGE}" \
--etcd-discovery-domain {{.ClusterDomain}} \
--manifest-cluster-etcd-operator-image "${CLUSTER_ETCD_OPERATOR_IMAGE}" \
--manifest-setup-etcd-env-image "${MACHINE_CONFIG_OPERATOR_IMAGE}" \
--manifest-kube-client-agent-image "${MACHINE_CONFIG_KUBE_CLIENT_AGENT_IMAGE}" \
--asset-input-dir /assets/tls \
--asset-output-dir /assets/etcd-bootstrap \
--config-output-file /assets/etcd-bootstrap/config \
--cluster-config-file=/assets/manifests/cluster-network-02-config.yml

# TODO: host-etcd endpoint rendered by cluster-etcd-operator
BOOTSTRAP_IP=$(hostname -I | awk '{ print $1 }')
ETCD_ENDPOINTS=https://"${BOOTSTRAP_IP}":2379
sed -i "s/__BOOTSTRAP_IP__/${BOOTSTRAP_IP}/" /opt/openshift/manifests/etcd-host-service-endpoints.yaml

cp etcd-bootstrap/manifests/* manifests/
cp etcd-bootstrap/bootstrap-manifests/etcd-member-pod.yaml /etc/kubernetes/manifests/

# /etc/kubernetes/static-pod-resources/etcd-member is the location etcd-bootstrap tls assets.
mkdir --parents /etc/kubernetes/static-pod-resources/etcd-member
cp tls/etcd-ca-bundle.crt /etc/kubernetes/static-pod-resources/etcd-member/ca.crt
cp tls/etcd-metric-ca-bundle.crt /etc/kubernetes/static-pod-resources/etcd-member/metric-ca.crt

touch etcd-bootstrap.done
if [ ! -f etcd-bootstrap.done ]
then
echo "Rendering CEO Manifests..."
bootkube_podman_run \
--volume "$PWD:/assets:z" \
"${CLUSTER_ETCD_OPERATOR_IMAGE}" \
/usr/bin/cluster-etcd-operator render \
--etcd-ca=/assets/tls/etcd-ca-bundle.crt \
--etcd-metric-ca=/assets/tls/etcd-metric-ca-bundle.crt \
--manifest-etcd-image="${MACHINE_CONFIG_ETCD_IMAGE}" \
--etcd-discovery-domain={{.ClusterDomain}} \
--manifest-cluster-etcd-operator-image="${CLUSTER_ETCD_OPERATOR_IMAGE}" \
--manifest-setup-etcd-env-image="${MACHINE_CONFIG_OPERATOR_IMAGE}" \
--manifest-kube-client-agent-image="${MACHINE_CONFIG_KUBE_CLIENT_AGENT_IMAGE}" \
--asset-input-dir=/assets/tls \
--asset-output-dir=/assets/etcd-bootstrap \
--config-output-file=/assets/etcd-bootstrap/config \
--cluster-config-file=/assets/manifests/cluster-network-02-config.yml

sed -i "s/__BOOTSTRAP_IP__/${BOOTSTRAP_IP}/" /opt/openshift/manifests/etcd-host-service-endpoints.yaml

cp etcd-bootstrap/manifests/* manifests/
cp etcd-bootstrap/bootstrap-manifests/etcd-member-pod.yaml /etc/kubernetes/manifests/

# /etc/kubernetes/static-pod-resources/etcd-member is the location etcd-bootstrap tls assets.
mkdir --parents /etc/kubernetes/static-pod-resources/etcd-member
cp tls/etcd-ca-bundle.crt /etc/kubernetes/static-pod-resources/etcd-member/ca.crt
cp tls/etcd-metric-ca-bundle.crt /etc/kubernetes/static-pod-resources/etcd-member/metric-ca.crt

touch etcd-bootstrap.done
fi
else
ETCD_ENDPOINTS={{.EtcdCluster}}
CLUSTER_ETCD_OPERATOR_IMAGE=
sed -i '/etcd-bootstrap/I,+1 d' /opt/openshift/manifests/etcd-host-service-endpoints.yaml
fi
Expand Down

0 comments on commit 5dd2719

Please sign in to comment.