Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootkube.sh: CEO: properly handle etcd endpoints on retry #2767

Merged
merged 1 commit into from Dec 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 34 additions & 30 deletions data/data/bootstrap/files/usr/local/bin/bootkube.sh.template
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