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

asset/ignition: add event on bootstrap completion #459

Merged
merged 3 commits into from
Oct 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pkg/asset/ignition/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/ignition"
"github.com/openshift/installer/pkg/asset/ignition/content"
"github.com/openshift/installer/pkg/asset/ignition/bootstrap/content"
"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/asset/kubeconfig"
"github.com/openshift/installer/pkg/asset/manifests"
Expand Down Expand Up @@ -103,7 +103,8 @@ func (a *Bootstrap) Generate(dependencies asset.Parents) error {
a.Config.Systemd.Units = append(
a.Config.Systemd.Units,
igntypes.Unit{Name: "bootkube.service", Contents: content.BootkubeSystemdContents},
igntypes.Unit{Name: "tectonic.service", Contents: content.TectonicSystemdContents, Enabled: util.BoolToPtr(true)},
igntypes.Unit{Name: "tectonic.service", Contents: content.TectonicSystemdContents},
igntypes.Unit{Name: "progress.service", Contents: content.ReportSystemdContents, Enabled: util.BoolToPtr(true)},
igntypes.Unit{Name: "kubelet.service", Contents: applyTemplateData(content.KubeletSystemdTemplate, templateData), Enabled: util.BoolToPtr(true)},
)

Expand Down Expand Up @@ -183,6 +184,10 @@ func (a *Bootstrap) addBootstrapFiles(dependencies asset.Parents) {
a.Config.Storage.Files,
ignition.FilesFromAsset(rootDir, 0644, kubeCoreOperator)...,
)
a.Config.Storage.Files = append(
a.Config.Storage.Files,
ignition.FileFromString("/opt/tectonic/report-progress.sh", 0555, content.ReportShFileContents),
)
}

func (a *Bootstrap) addBootkubeFiles(dependencies asset.Parents, templateData *bootstrapTemplateData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
const (
// BootkubeSystemdContents is a service for running bootkube on the bootstrap
// nodes
BootkubeSystemdContents = `[Unit]
BootkubeSystemdContents = `
[Unit]
Description=Bootstrap a Kubernetes cluster
Wants=kubelet.service
After=kubelet.service
Expand All @@ -16,9 +17,12 @@ After=kubelet.service
WorkingDirectory=/opt/tectonic

ExecStart=/opt/tectonic/bootkube.sh
# Workaround for https://github.com/opencontainers/runc/pull/1807
ExecStartPost=/usr/bin/touch /opt/tectonic/.bootkube.done

Restart=on-failure
RestartSec=5s`
RestartSec=5s
`
)

var (
Expand Down Expand Up @@ -113,22 +117,22 @@ fi

if [ ! -d kube-scheduler-bootstrap ]
then
echo "Rendering Kubernetes Scheduler core manifests..."

# shellcheck disable=SC2154
podman run \
--volume "$PWD:/assets:z" \
"${KUBE_SCHEDULER_OPERATOR_IMAGE}" \
/usr/bin/cluster-kube-scheduler-operator render \
--asset-input-dir=/assets/tls \
--asset-output-dir=/assets/kube-scheduler-bootstrap \
--config-override-file=/usr/share/bootkube/manifests/config/config-overrides.yaml \
--config-output-file=/assets/kube-scheduler-bootstrap/config

# TODO: copy the bootstrap manifests to replace kube-core-operator
cp --recursive kube-scheduler-bootstrap/manifests/00_openshift-kube-scheduler-ns.yaml manifests/00_openshift-kube-scheduler-ns.yaml
cp --recursive kube-scheduler-bootstrap/manifests/secret-* manifests/
cp --recursive kube-scheduler-bootstrap/manifests/configmap-* manifests/
echo "Rendering Kubernetes Scheduler core manifests..."

# shellcheck disable=SC2154
podman run \
--volume "$PWD:/assets:z" \
"${KUBE_SCHEDULER_OPERATOR_IMAGE}" \
/usr/bin/cluster-kube-scheduler-operator render \
--asset-input-dir=/assets/tls \
--asset-output-dir=/assets/kube-scheduler-bootstrap \
--config-override-file=/usr/share/bootkube/manifests/config/config-overrides.yaml \
--config-output-file=/assets/kube-scheduler-bootstrap/config

# TODO: copy the bootstrap manifests to replace kube-core-operator
cp --recursive kube-scheduler-bootstrap/manifests/00_openshift-kube-scheduler-ns.yaml manifests/00_openshift-kube-scheduler-ns.yaml
cp --recursive kube-scheduler-bootstrap/manifests/secret-* manifests/
cp --recursive kube-scheduler-bootstrap/manifests/configmap-* manifests/
fi

if [ ! -d mco-bootstrap ]
Expand Down Expand Up @@ -230,5 +234,6 @@ podman run \
--network=host \
--entrypoint=/bootkube \
"{{.BootkubeImage}}" \
start --asset-dir=/assets`))
start --asset-dir=/assets
`))
)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Package content contains the contents of files and systemd units to be added
// to Ignition configs.
// to bootstrap Ignition configs.
package content
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
var (
// KubeletSystemdTemplate is a service for running the kubelet on the
// bootstrap nodes.
KubeletSystemdTemplate = template.Must(template.New("kubelet.service").Parse(`[Unit]
KubeletSystemdTemplate = template.Must(template.New("kubelet.service").Parse(`
[Unit]
Description=Kubernetes Kubelet
Wants=rpc-statd.service

Expand Down Expand Up @@ -46,5 +47,6 @@ Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target`))
WantedBy=multi-user.target
`))
)
54 changes: 54 additions & 0 deletions pkg/asset/ignition/bootstrap/content/report.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package content

const (
// ReportSystemdContents is a service that reports the bootstrap progress
// via a Kubernetes Event.
ReportSystemdContents = `
[Unit]
Description=Report the completion of the cluster bootstrap process
# Workaround for https://github.com/systemd/systemd/issues/1312
Wants=bootkube.service tectonic.service
After=bootkube.service tectonic.service

[Service]
# Workaround for https://github.com/systemd/systemd/issues/1312 and https://github.com/opencontainers/runc/pull/1807
ExecStartPre=/usr/bin/test -f /opt/tectonic/.bootkube.done
ExecStartPre=/usr/bin/test -f /opt/tectonic/.tectonic.done
ExecStart=/opt/tectonic/report-progress.sh /opt/tectonic/auth/kubeconfig bootstrap-complete "cluster bootstrapping has completed"

Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target
`

// ReportShFileContents is a script for reporting the bootstrap progress.
ReportShFileContents = `#!/usr/bin/env bash
set -e

KUBECONFIG="${1}"
NAME="${2}"
MESSAGE="${3}"
TIMESTAMP="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"

echo "Reporting install progress..."

oc --config="$KUBECONFIG" create <<EOF
apiVersion: v1
kind: Event
metadata:
name: "${NAME}"
namespace: kube-system
involvedObject:
namespace: kube-system
message: "${MESSAGE}"
firstTimestamp: "${TIMESTAMP}"
lastTimestamp: "${TIMESTAMP}"
count: 1
source:
component: cluster
host: $(hostname)
EOF
`
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package content

const (
// TectonicSystemdContents is a service that runs tectonic on the masters.
TectonicSystemdContents = `[Unit]
TectonicSystemdContents = `
[Unit]
Description=Bootstrap a Tectonic cluster
Wants=bootkube.service
After=bootkube.service
Expand All @@ -11,12 +12,12 @@ After=bootkube.service
WorkingDirectory=/opt/tectonic/tectonic

ExecStart=/opt/tectonic/tectonic.sh /opt/tectonic/auth/kubeconfig
# Workaround for https://github.com/opencontainers/runc/pull/1807
ExecStartPost=/usr/bin/touch /opt/tectonic/.tectonic.done

Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target`
`

// TectonicShFileContents is a script file for running tectonic on bootstrap
// nodes.
Expand Down Expand Up @@ -90,5 +91,6 @@ done
# Wait for Tectonic pods
wait_for_pods tectonic-system

echo "Tectonic installation is done"`
echo "Tectonic installation is done"
`
)