From 84f2c86a500bef1080e66c73d26e96cab78f8664 Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Tue, 6 Apr 2021 17:07:43 -0700 Subject: [PATCH] minikube-pr-bot enhancements --- .../installers/check_install_golang.sh | 2 +- hack/jenkins/prbot.sh | 47 +++++++++++++++++++ pkg/minikube/perf/result_manager.go | 2 - pkg/minikube/perf/start.go | 40 ++++++++++------ 4 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 hack/jenkins/prbot.sh diff --git a/hack/jenkins/installers/check_install_golang.sh b/hack/jenkins/installers/check_install_golang.sh index b01ef8595d..3009d7aea5 100755 --- a/hack/jenkins/installers/check_install_golang.sh +++ b/hack/jenkins/installers/check_install_golang.sh @@ -62,7 +62,7 @@ function install_golang() { # using sudo because previously installed versions might have been installed by a different user. # as it was the case on jenkins VM. sudo curl -qL -O "https://storage.googleapis.com/golang/go${1}.${INSTALLOS}-${ARCH}.tar.gz" && - sudo tar -xf go${1}.${INSTALLOS}-amd64.tar.gz && + sudo tar -xzf go${1}.${INSTALLOS}-amd64.tar.gz && sudo rm -rf "${2}/go" && sudo mv go "${2}/" && sudo chown -R $(whoami): ${2}/go popd >/dev/null diff --git a/hack/jenkins/prbot.sh b/hack/jenkins/prbot.sh new file mode 100644 index 0000000000..2849f1c5a4 --- /dev/null +++ b/hack/jenkins/prbot.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# Copyright 2021 The Kubernetes Authors All rights reserved. +# +# 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. + +set -x -o pipefail +# Only run this on PRs +if [[ "${MINIKUBE_LOCATION}" == "master" ]]; then + exit 0 +fi + +# Make sure docker is installed and configured +./hack/jenkins/installers/check_install_docker.sh + +# Make sure gh is installed and configured +./hack/jenkins/installers/check_install_gh.sh + +# Make sure go is installed and configured +./hack/jenkins/installers/check_install_golang.sh + +# Grab latest code +git clone https://github.com/kubernetes/minikube.git +cd minikube + +# Build minikube binary and mkcmp binary +make out/minikube out/mkcmp + +# Run mkcmp +out/mkcmp out/minikube pr://${MINIKUBE_LOCATION} | mkcmp.log +if [ $? -gt 0 ]; then + # Comment that mkcmp failed + gh pr comment ${MINIKUBE_LOCATION} --body "timing minikube failed, please try again" + exit 1 +fi +output=$(cat mkcmp.log) +gh pr comment ${MINIKUBE_LOCATION} --body ${output} diff --git a/pkg/minikube/perf/result_manager.go b/pkg/minikube/perf/result_manager.go index 61f857d4c1..7cce174cc0 100644 --- a/pkg/minikube/perf/result_manager.go +++ b/pkg/minikube/perf/result_manager.go @@ -66,8 +66,6 @@ func (rm *resultManager) averageTime(binary *Binary) float64 { func (rm *resultManager) summarizeResults(binaries []*Binary, driver string) { // print total and average times - fmt.Printf("**%s Driver**\n", driver) - for _, b := range binaries { fmt.Printf("Times for %s: ", b.Name()) for _, tt := range rm.totalTimes(b) { diff --git a/pkg/minikube/perf/start.go b/pkg/minikube/perf/start.go index 3a9c62bf9b..a8d85371dd 100644 --- a/pkg/minikube/perf/start.go +++ b/pkg/minikube/perf/start.go @@ -23,18 +23,22 @@ import ( "log" "os" "os/exec" + "runtime" "github.com/pkg/errors" ) const ( // runs is the number of times each binary will be timed for 'minikube start' - runs = 3 + runs = 5 ) // CompareMinikubeStart compares the time to run `minikube start` between two minikube binaries func CompareMinikubeStart(ctx context.Context, out io.Writer, binaries []*Binary) error { drivers := []string{"kvm2", "docker"} + if runtime.GOOS == "darwin" { + drivers = []string{"hyperkit", "docker"} + } for _, d := range drivers { fmt.Printf("**%s Driver**\n", d) if err := downloadArtifacts(ctx, binaries, d); err != nil { @@ -62,11 +66,17 @@ func collectResults(ctx context.Context, binaries []*Binary, driver string) (*re return nil, errors.Wrapf(err, "timing run %d with %s", run, binary.Name()) } rm.addResult(binary, r) - r, err = timeEnableIngress(ctx, binary) - if err != nil { - return nil, errors.Wrapf(err, "timing run %d with %s", run, binary.Name()) + if runtime.GOOS != "darwin" { + r, err = timeEnableIngress(ctx, binary) + if err != nil { + return nil, errors.Wrapf(err, "timing run %d with %s", run, binary.Name()) + } + rm.addResult(binary, r) + } + deleteCmd := exec.CommandContext(ctx, binary.path, "delete") + if err := deleteCmd.Run(); err != nil { + log.Printf("error deleting minikube: %v", err) } - rm.addResult(binary, r) } } return rm, nil @@ -74,10 +84,19 @@ func collectResults(ctx context.Context, binaries []*Binary, driver string) (*re func average(nums []float64) float64 { total := float64(0) + max := float64(0) + min := float64(0) for _, a := range nums { + if a > max { + max = a + } + if min > a { + min = a + } total += a } - return total / float64(len(nums)) + total = total - min - max + return total / float64(len(nums)-2) } func downloadArtifacts(ctx context.Context, binaries []*Binary, driver string) error { @@ -108,16 +127,9 @@ func timeMinikubeStart(ctx context.Context, binary *Binary, driver string) (*res // timeEnableIngress returns the time it takes to execute `minikube addons enable ingress` // It deletes the VM after `minikube addons enable ingress`. func timeEnableIngress(ctx context.Context, binary *Binary) (*result, error) { - enableCmd := exec.CommandContext(ctx, binary.path, "addons enable ingress") + enableCmd := exec.CommandContext(ctx, binary.path, "addons", "enable", "ingress") enableCmd.Stderr = os.Stderr - deleteCmd := exec.CommandContext(ctx, binary.path, "delete") - defer func() { - if err := deleteCmd.Run(); err != nil { - log.Printf("error deleting minikube: %v", err) - } - }() - log.Printf("Running: %v...", enableCmd.Args) r, err := timeCommandLogs(enableCmd) if err != nil {