-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The first test is a very simple test. It installs NPD on a VM, and then verifies that NPD reports metric host_uptime in Prometheus format.
- Loading branch information
Xuewei Zhang
committed
Aug 13, 2019
1 parent
4a31954
commit f04baab
Showing
13 changed files
with
758 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/*.tar.gz | ||
ci.env | ||
pr.env | ||
junit*.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[Unit] | ||
Description=Node problem detector | ||
Wants=local-fs.target | ||
After=local-fs.target | ||
|
||
[Service] | ||
Restart=always | ||
RestartSec=10 | ||
ExecStart=/home/kubernetes/bin/node-problem-detector --v=2 --logtostderr --enable-k8s-exporter=false \ | ||
--config.system-log-monitor=/home/kubernetes/node-problem-detector/config/kernel-monitor.json,/home/kubernetes/node-problem-detector/config/docker-monitor.json,/home/kubernetes/node-problem-detector/config/systemd-monitor.json \ | ||
--config.custom-plugin-monitor=/home/kubernetes/node-problem-detector/config/kernel-monitor-counter.json,/home/kubernetes/node-problem-detector/config/systemd-monitor-counter.json \ | ||
--config.system-stats-monitor=/home/kubernetes/node-problem-detector/config/system-stats-monitor.json | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2019 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# This script is for installing node problem detector (NPD) on a running node | ||
# in metric-only mode, as a setup for NPD e2e tests. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
readonly BIN_DIR=/home/kubernetes/bin | ||
readonly CONFIG_DIR=/home/kubernetes/node-problem-detector/config | ||
|
||
function print-help() { | ||
echo "Usage: e2e-install.sh [flags] [command]" | ||
echo | ||
echo "Available flags:" | ||
echo " -t [TARBALL] Specify the path of the NPD tarball (generated by 'make build-tar')." | ||
echo | ||
echo "Available commands:" | ||
echo " help Print this help message" | ||
echo " install Installs NPD to the this machine" | ||
echo | ||
echo "Examples:" | ||
echo " e2e-install.sh help" | ||
echo " e2e-install.sh -t /tmp/npd.tar.gz install" | ||
} | ||
|
||
function install-npd() { | ||
if [[ -z "${TARBALL}" ]]; then | ||
echo "ERROR: tarball flag is missing." | ||
exit 1 | ||
fi | ||
|
||
readonly workdir=$(mktemp -d) | ||
tar -xf "${TARBALL}" --directory "${workdir}" | ||
|
||
echo "Preparing NPD binary directory." | ||
mkdir -p "${BIN_DIR}" | ||
mount --bind "${BIN_DIR}" "${BIN_DIR}" | ||
# Below remount is to work around COS's noexec mount on /home. | ||
mount -o remount,exec "${BIN_DIR}" | ||
|
||
echo "Installing NPD binary." | ||
cp "${workdir}"/bin/node-problem-detector "${BIN_DIR}" | ||
|
||
echo "Installing log-counter binary." | ||
cp "${workdir}"/bin/log-counter "${BIN_DIR}" | ||
|
||
echo "Installing NPD configurations." | ||
mkdir -p "${CONFIG_DIR}" | ||
cp -r "${workdir}"/config/* "${CONFIG_DIR}" | ||
|
||
echo "Installing NPD systemd service." | ||
cp "${workdir}"/config/systemd/node-problem-detector-metric-only.service /etc/systemd/system/node-problem-detector.service | ||
|
||
rm -rf "${workdir}" | ||
|
||
# Start systemd service. | ||
echo "Starting NPD systemd service." | ||
systemctl daemon-reload | ||
systemctl stop node-problem-detector.service || true | ||
systemctl start node-problem-detector.service | ||
} | ||
|
||
function main() { | ||
case ${1:-} in | ||
help) print-help;; | ||
install) install-npd;; | ||
*) print-help;; | ||
esac | ||
} | ||
|
||
TARBALL="" | ||
|
||
while getopts "t:" opt; do | ||
case ${opt} in | ||
t) TARBALL="${OPTARG}";; | ||
esac | ||
done | ||
shift "$((OPTIND-1))" | ||
|
||
|
||
main "${@}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Node Problem Detector End-To-End tests | ||
|
||
NPD e2e tests are meant for testing the NPD on a VM environment. | ||
|
||
Currently the tests only support Google Compute Engine (GCE) environment. Support for other vendors can be added in future. | ||
|
||
## Prerequisites | ||
|
||
1. Setup [Google Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials), which is [required for authentication](https://godoc.org/google.golang.org/api/compute/v1#hdr-Creating_a_client) by the Compute Engine API. | ||
2. Setup a [project-wide SSH key](https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys#project-wide) that can be used to SSH into the GCE VMs. | ||
|
||
## Running tests | ||
|
||
From the node-problem-detector base directory, run: | ||
|
||
``` | ||
export GOOGLE_APPLICATION_CREDENTIALS=[YOUR_ADC_PATH:~/.config/gcloud/application_default_credentials.json] | ||
export ZONE=[ANY_GCE_ZONE:us-central1-a] | ||
export PROJECT=[YOUR_PROJECT_ID] | ||
export VM_IMAGE=[TESTED_OS_IMAGE:cos-73-11647-217-0] | ||
export IMAGE_PROJECT=[TESTED_OS_IMAGE_PROJECT:cos-cloud] | ||
export SSH_USER=${USER} | ||
export SSH_KEY=~/.ssh/id_rsa | ||
make e2e-test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package gce | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
"golang.org/x/oauth2" | ||
"golang.org/x/oauth2/google" | ||
compute "google.golang.org/api/compute/v1" | ||
) | ||
|
||
// GetComputeClient creates a GCE client with a 1 minute deadline. | ||
func GetComputeClient() (*compute.Service, error) { | ||
const retries = 10 | ||
const backoff = time.Second * 6 | ||
|
||
// Setup the gce client for provisioning instances | ||
// Getting credentials on gce jenkins is flaky, so try a couple times | ||
var err error | ||
var cs *compute.Service | ||
for i := 0; i < retries; i++ { | ||
if i > 0 { | ||
time.Sleep(backoff) | ||
} | ||
|
||
var client *http.Client | ||
client, err = google.DefaultClient(oauth2.NoContext, compute.ComputeScope) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
cs, err = compute.New(client) | ||
if err != nil { | ||
continue | ||
} | ||
return cs, nil | ||
} | ||
return nil, err | ||
} |
Oops, something went wrong.