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

Updating Boskos to hold the lock when config is being synced #13990

Merged
merged 3 commits into from
Aug 22, 2019
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
/_artifacts
/_output
node_modules/
token
.DS_Store
# Files generated by JetBrains IDEs, e.g. IntelliJ IDEA
.idea/
Expand Down
2 changes: 2 additions & 0 deletions boskos/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ go_library(
"//boskos/common:go_default_library",
"//boskos/crds:go_default_library",
"//boskos/ranch:go_default_library",
"//vendor/github.com/fsnotify/fsnotify:go_default_library",
"//vendor/github.com/sirupsen/logrus:go_default_library",
"//vendor/github.com/spf13/viper:go_default_library",
],
)

Expand Down
23 changes: 13 additions & 10 deletions boskos/boskos.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ import (
"strings"
"time"

"github.com/fsnotify/fsnotify"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"

"k8s.io/test-infra/boskos/common"
"k8s.io/test-infra/boskos/crds"
"k8s.io/test-infra/boskos/ranch"
)

const (
defaultSyncPeriod = 10 * time.Minute
defaultRequestTTL = 30 * time.Second
defaultRequestGCPeriod = time.Minute
)

var (
configPath = flag.String("config", "config.yaml", "Path to init resource file")
storagePath = flag.String("storage", "", "Path to persistent volume to load the state")
syncPeriod = flag.Duration("sync-period", defaultSyncPeriod, "Period at which to sync config")
requestTTL = flag.Duration("request-ttl", defaultRequestTTL, "request TTL before losing priority in the queue")
kubeClientOptions crds.KubernetesClientOptions
)
Expand Down Expand Up @@ -80,15 +80,18 @@ func main() {
Addr: ":8080",
}

go func() {
configTick := time.NewTicker(*syncPeriod).C
for {
select {
case <-configTick:
r.SyncConfig(*configPath)
}
v := viper.New()
v.SetConfigFile(*configPath)
v.SetConfigType("yaml")
v.WatchConfig()
v.OnConfigChange(func(in fsnotify.Event) {
logrus.Infof("Updating Boskos Config")
if err := r.SyncConfig(*configPath); err != nil {
logrus.WithError(err).Errorf("Failed to update config")
} else {
logrus.Infof("Updated Boskos Config successfully")
}
}()
})

r.StartRequestGC(defaultRequestGCPeriod)

Expand Down
3 changes: 3 additions & 0 deletions boskos/ranch/ranch.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func NewRanch(config string, s *Storage, ttl time.Duration) (*Ranch, error) {
if err := newRanch.SyncConfig(config); err != nil {
return nil, err
}
logrus.Infof("Loaded Boskos configuration successfully")
}
return newRanch, nil
}
Expand Down Expand Up @@ -355,6 +356,8 @@ func (r *Ranch) SyncConfig(configPath string) error {
if err := common.ValidateConfig(config); err != nil {
return err
}
r.resourcesLock.Lock()
defer r.resourcesLock.Unlock()
if err := r.Storage.SyncResources(config); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ require (
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.3.2
github.com/tektoncd/pipeline v0.1.1-0.20190327171839-7c43fbae2816
github.com/xlab/handysort v0.0.0-20150421192137-fb3537ed64a1 // indirect
go.opencensus.io v0.20.2 // indirect
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCO
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.3 h1:YPkqC67at8FYaadspW/6uE0COsBxS2656RLEr8Bppgk=
github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
Expand Down Expand Up @@ -255,6 +256,7 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mailru/easyjson v0.0.0-20171120080333-32fa128f234d h1:bM4HYnlVXPgUKmzl7o3drEaVfOk+sTBiADAQOWjU+8I=
github.com/mailru/easyjson v0.0.0-20171120080333-32fa128f234d/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand All @@ -274,6 +276,7 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/ioprogress v0.0.0-20180201004757-6a23b12fa88e/go.mod h1:waEya8ee1Ro/lgxpVhkJI4BVASzkm3UZqkx/cFJiYHM=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
Expand Down Expand Up @@ -360,17 +363,21 @@ github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
7 changes: 7 additions & 0 deletions vendor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ filegroup(
"//vendor/github.com/hashicorp/errwrap:all-srcs",
"//vendor/github.com/hashicorp/go-multierror:all-srcs",
"//vendor/github.com/hashicorp/golang-lru:all-srcs",
"//vendor/github.com/hashicorp/hcl:all-srcs",
"//vendor/github.com/imdario/mergo:all-srcs",
"//vendor/github.com/inconshreveable/mousetrap:all-srcs",
"//vendor/github.com/influxdata/influxdb/client/v2:all-srcs",
Expand All @@ -136,13 +137,15 @@ filegroup(
"//vendor/github.com/knative/pkg/kmeta:all-srcs",
"//vendor/github.com/knative/pkg/kmp:all-srcs",
"//vendor/github.com/konsorten/go-windows-terminal-sequences:all-srcs",
"//vendor/github.com/magiconair/properties:all-srcs",
"//vendor/github.com/mailru/easyjson/buffer:all-srcs",
"//vendor/github.com/mailru/easyjson/jlexer:all-srcs",
"//vendor/github.com/mailru/easyjson/jwriter:all-srcs",
"//vendor/github.com/mattbaird/jsonpatch:all-srcs",
"//vendor/github.com/mattn/go-sqlite3:all-srcs",
"//vendor/github.com/mattn/go-zglob:all-srcs",
"//vendor/github.com/matttproud/golang_protobuf_extensions/pbutil:all-srcs",
"//vendor/github.com/mitchellh/mapstructure:all-srcs",
"//vendor/github.com/modern-go/concurrent:all-srcs",
"//vendor/github.com/modern-go/reflect2:all-srcs",
"//vendor/github.com/opencontainers/go-digest:all-srcs",
Expand All @@ -163,8 +166,12 @@ filegroup(
"//vendor/github.com/shurcooL/go/ctxhttp:all-srcs",
"//vendor/github.com/shurcooL/graphql:all-srcs",
"//vendor/github.com/sirupsen/logrus:all-srcs",
"//vendor/github.com/spf13/afero:all-srcs",
"//vendor/github.com/spf13/cast:all-srcs",
"//vendor/github.com/spf13/cobra:all-srcs",
"//vendor/github.com/spf13/jwalterweatherman:all-srcs",
"//vendor/github.com/spf13/pflag:all-srcs",
"//vendor/github.com/spf13/viper:all-srcs",
"//vendor/github.com/tektoncd/pipeline/pkg/apis/pipeline:all-srcs",
"//vendor/github.com/tektoncd/pipeline/pkg/client/clientset/versioned:all-srcs",
"//vendor/github.com/tektoncd/pipeline/pkg/client/informers/externalversions:all-srcs",
Expand Down
45 changes: 45 additions & 0 deletions vendor/github.com/hashicorp/hcl/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading