This commit is contained in:
Martin Strobel 2018-11-15 12:35:11 -08:00
Родитель 2e8a8f9725
Коммит 5e0bd725bf
9 изменённых файлов: 84 добавлений и 53 удалений

2
.gitignore поставляемый
Просмотреть файл

@ -3,6 +3,8 @@
*.dll
*.so
*.dylib
a01dispatcher
a01droid
# Test binary, build with `go test -c`
*.test

Просмотреть файл

@ -1,14 +1,30 @@
language: go
before_install:
- echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ `lsb_release
-cs` main" | sudo tee /etc/apt/sources.list.d/azure-cli.list
- curl -L https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
- sudo apt-get install -y apt-transport-https
- sudo apt-get -qq update && sudo apt-get install -y azure-cli
- echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ `lsb_release
-cs` main" | sudo tee /etc/apt/sources.list.d/azure-cli.list
- curl -L https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
- sudo apt-get install -y apt-transport-https
- sudo apt-get -qq update && sudo apt-get install -y azure-cli
env:
- GO111MODULE=on
go:
- '1.x'
- 1.11.x
- master
matrix:
fast_finish: true
allow_failures:
- go: master
install:
- go get -u golang.org/x/lint/golint
script:
- ./build $TRAVIS_TAG
- make all
deploy:
provider: script
script: ./scripts/publish

39
Makefile Normal file
Просмотреть файл

@ -0,0 +1,39 @@
SRC = $(shell find . -name '*.go')
REV = $(shell git rev-parse --verify HEAD)
.PHONY: all
all: mod test fmt lint vet a01dispatcher a01droid
.PHONY: test
test: ${SRC}
go test ./...
.PHONY: fmt
fmt: ${SRC}
go fmt ./...
.PHONY: lint
lint: ${SRC}
golint ./...
.PHONY: vet
vet: ${SRC}
go vet ./...
a01dispatcher: $(shell find ./agents/dispatcher -name '*.go') $(shell find ./sdk -name '*.go')
go build -o a01dispatcher -ldflags "-X main.version=${TRAVIS_TAG} -X main.sourceCommit=${REV}" ./agents/dispatcher
a01droid: $(shell find ./agents/droid -name '*.go') $(shell find ./sdk -name '*.go')
go build -o a01droid -ldflags "-X main.version=${TRAVIS_TAG} -X main.sourceCommit=${REV}" ./agents/droid
.PHONY: clean
clean:
rm -f a01dispatcher a01droid
go clean -modcache
.PHONY: mod
mod: go.sum
go mod download
go.sum: go.mod
go mod tidy

Просмотреть файл

@ -5,7 +5,6 @@ import (
"encoding/base32"
"flag"
"fmt"
"log"
"os"
"strconv"
"strings"
@ -45,7 +44,7 @@ func main() {
flag.Parse()
if *pRunID == -1 {
log.Fatal("Missing runID")
logrus.Fatal("Missing runID")
}
// query the run and then update the product name in the details
@ -89,7 +88,7 @@ func main() {
// creates a kubernete job to manage test droid
jobDef, err := createTaskJob(run, jobName)
if err != nil {
log.Fatal(err.Error())
logrus.Fatal(err.Error())
}
// ignore this error for now. This API's latest version seems to sending
@ -97,7 +96,7 @@ func main() {
clientset.BatchV1().Jobs(namespace).Create(jobDef)
_, err = clientset.BatchV1().Jobs(namespace).Get(jobDef.Name, metav1.GetOptions{})
if err != nil {
log.Fatal(err.Error())
logrus.Fatal(err.Error())
}
run.Status = common.RunStatusRunning

Просмотреть файл

@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
"log"
"os"
"os/exec"
"path"
@ -34,7 +33,7 @@ func ckEnvironment() {
for _, r := range required {
_, exists := os.LookupEnv(r)
if !exists {
log.Fatalf("Missing environment variable %s.\n", r)
logrus.Fatalf("Missing environment variable %s.\n", r)
}
}
}
@ -42,15 +41,15 @@ func ckEnvironment() {
func preparePod() {
_, statErr := os.Stat(common.PathScriptPreparePod)
if statErr != nil && os.IsNotExist(statErr) {
log.Printf("Executable %s doesn't exist. Skip preparing the pod.\n", common.PathScriptPreparePod)
logrus.Infof("Executable %s doesn't exist. Skip preparing the pod.\n", common.PathScriptPreparePod)
return
}
output, err := exec.Command(common.PathScriptPreparePod).CombinedOutput()
if err != nil {
log.Fatalf("Fail to prepare the pod: %s.\n%s\n", err, string(output))
logrus.Fatalf("Fail to prepare the pod: %s.\n%s\n", err, string(output))
}
log.Printf("Preparing Pod: \n%s\n", string(output))
logrus.Infof("Preparing Pod: \n%s\n", string(output))
}
func afterTask(taskResult *models.TaskResult) error {
@ -60,7 +59,7 @@ func afterTask(taskResult *models.TaskResult) error {
return nil
}
log.Printf("Executing after task %s.", common.PathScriptAfterTest)
logrus.Infof("Executing after task %s.", common.PathScriptAfterTest)
taskInBytes, err := json.Marshal(taskResult)
if err != nil {

22
build
Просмотреть файл

@ -1,22 +0,0 @@
#!/bin/bash
root=$(cd `dirname $0`; pwd)
version=$1
commit=${TRAVIS_COMMIT:-`git rev-parse --verify HEAD`}
echo "Version: ${version:=`date -u +local-%Y%m%d-%H%M%S`}"
export CGO_ENABLED=0
for os in linux; do # add darwin and windows in the future
export GOOS=$os
mkdir -p $root/bin/$os
for agent_name in `ls $root/agents`; do
echo "Build $agent_name for $os"
artifact=$root/bin/$os/a01$agent_name
go build -o $artifact \
-ldflags "-X main.version=$version -X main.sourceCommit=$commit" \
agents/$agent_name/main.go
chmod +x $artifact
done
done

4
go.mod
Просмотреть файл

@ -18,11 +18,11 @@ require (
github.com/streadway/amqp v0.0.0-20180806233856-70e15c650864
golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b // indirect
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd // indirect
golang.org/x/oauth2 v0.0.0-20181003184128-c57b0facaced // indirect
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288 // indirect
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f // indirect
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e // indirect
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 // indirect
google.golang.org/appengine v1.2.0 // indirect
google.golang.org/appengine v1.3.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.2.1
k8s.io/api v0.0.0-20180911000052-49f236fe119e

10
go.sum
Просмотреть файл

@ -45,8 +45,8 @@ golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/oauth2 v0.0.0-20181003184128-c57b0facaced h1:4oqSq7eft7MdPKBGQK11X9WYUxmj6ZLgGTqYIbY1kyw=
golang.org/x/oauth2 v0.0.0-20181003184128-c57b0facaced/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288 h1:JIqe8uIcRBHXDQVvZtHwp80ai3Lw3IJAeJEs55Dc1W0=
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@ -56,8 +56,8 @@ golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 h1:+DCIGbF/swA92ohVg0//6X2IVY3KZs6p9mix0ziNYJM=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
google.golang.org/appengine v1.2.0 h1:S0iUepdCWODXRvtE+gcRDd15L+k+k1AiHlMiMjefH24=
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.3.0 h1:FBSsiFRMz3LBeXIomRnVzrQwSDj4ibvcRexLG0LZGQk=
google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
@ -68,5 +68,5 @@ k8s.io/api v0.0.0-20180911000052-49f236fe119e h1:K6ZWCvyoK2cMC12nMOjJ4dRqjVrnwFs
k8s.io/api v0.0.0-20180911000052-49f236fe119e/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
k8s.io/apimachinery v0.0.0-20180908133737-0dbe21f815eb h1:Q+q1qi+vhGTvH9ryVhp9Ks3qrLqC3B3YfjWtRgIilM0=
k8s.io/apimachinery v0.0.0-20180908133737-0dbe21f815eb/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0=
k8s.io/client-go v9.0.0+incompatible h1:/PdJjifJTjMFe0G4ESclZDcwF1+bFePTJ2xf+MXjcvs=
k8s.io/client-go v9.0.0+incompatible h1:2kqW3X2xQ9SbFvWZjGEHBLlWc1LG9JIJNXWkuqwdZ3A=
k8s.io/client-go v9.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=

Просмотреть файл

@ -3,8 +3,6 @@ package schedule
import (
"encoding/json"
"fmt"
"log"
"github.com/Azure/adx-automation-agent/sdk/common"
"github.com/Azure/adx-automation-agent/sdk/kubeutils"
"github.com/Azure/adx-automation-agent/sdk/models"
@ -147,27 +145,27 @@ func CreateLocalTaskBroker() *TaskBroker {
func CreateInClusterTaskBroker() *TaskBroker {
endpoint, exists := kubeutils.TryGetSystemConfig(common.ConfigKeyEndpointTaskBroker)
if !exists {
log.Fatalln("Fail to fetch taskbroker's endpoint from system config.")
logrus.Fatal("Fail to fetch taskbroker's endpoint from system config.")
}
username, exists := kubeutils.TryGetSystemConfig(common.ConfigKeyUsernameTaskBroker)
if !exists {
log.Fatalln("Fail to fetch taskbroker's user name from system config.")
logrus.Fatal("Fail to fetch taskbroker's user name from system config.")
}
secretName, exists := kubeutils.TryGetSystemConfig(common.ConfigKeySecretTaskBroker)
if !exists {
log.Fatalln("Fail to fetch taskbroker's secret name from system config.")
logrus.Fatal("Fail to fetch taskbroker's secret name from system config.")
}
passwordKey, exists := kubeutils.TryGetSystemConfig(common.ConfigKeyPasswordKeyTaskBroker)
if !exists {
log.Fatalln("Fail to fetch taskbroker's password key name from system config.")
logrus.Fatal("Fail to fetch taskbroker's password key name from system config.")
}
passwordInBytes, exists := kubeutils.TryGetSecretInBytes(secretName, passwordKey)
if !exists {
log.Fatalf("Fail to fetch taskbroker's password from secret %s using key %s.", secretName, passwordKey)
logrus.Fatalf("Fail to fetch taskbroker's password from secret %s using key %s.", secretName, passwordKey)
}
password := string(passwordInBytes)