Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
Refactorings and more tests
Browse files Browse the repository at this point in the history
* Created a Kiam Server integration test to make it easier to test
* Extracted server and gateway into builders, tidies complicated construction and makes it easier to test
* Move the cacheSize metric from a counter to a gauge and define in metrics.go and outside of DefaultCache func, removes duplicate panic in tests
* KiamGatewayBuilder adds WithMaxRetries to configure the gRPC retry behaviour (by default, doesn't retry operations) and potentially helps address #425
  • Loading branch information
pingles committed Oct 22, 2020
1 parent daf1762 commit 4d7c245
Show file tree
Hide file tree
Showing 14 changed files with 901 additions and 282 deletions.
9 changes: 8 additions & 1 deletion cmd/kiam/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ func (opts *agentCommand) run() error {
ctxGateway, cancelCtxGateway := context.WithTimeout(context.Background(), opts.timeoutKiamGateway)
defer cancelCtxGateway()

gateway, err := kiamserver.NewGateway(ctxGateway, opts.serverAddress, opts.caPath, opts.certificatePath, opts.keyPath, opts.keepaliveParams)
b := kiamserver.NewKiamGatewayBuilder().WithAddress(opts.serverAddress).WithKeepAlive(opts.keepaliveParams)
_, err := b.WithTLS(opts.certificatePath, opts.keyPath, opts.caPath)
if err != nil {
log.Errorf("error configuring TLS: ", err.Error())
return err
}

gateway, err := b.Build(ctxGateway)
if err != nil {
log.Errorf("error creating server gateway: %s", err.Error())
return err
Expand Down
6 changes: 5 additions & 1 deletion cmd/kiam/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ func (cmd *healthCommand) Run() {
ctxGateway, cancelCtxGateway := context.WithTimeout(context.Background(), cmd.timeoutKiamGateway)
defer cancelCtxGateway()

gateway, err := kiamserver.NewGateway(ctxGateway, cmd.serverAddress, cmd.caPath, cmd.certificatePath, cmd.keyPath, cmd.keepaliveParams)
b, err := kiamserver.NewKiamGatewayBuilder().WithAddress(cmd.serverAddress).WithKeepAlive(cmd.keepaliveParams).WithTLS(cmd.certificatePath, cmd.keyPath, cmd.caPath)
if err != nil {
log.Fatalf("error creating server gateway: %s", err.Error())
}
gateway, err := b.Build(ctxGateway)
if err != nil {
log.Fatalf("error creating server gateway: %s", err.Error())
}
Expand Down
17 changes: 16 additions & 1 deletion cmd/kiam/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,22 @@ func (cmd *serverCommand) Run() {
signal.Notify(stopChan, syscall.SIGTERM)

cmd.Config.TLS = serv.TLSConfig{ServerCert: cmd.certificatePath, ServerKey: cmd.keyPath, CA: cmd.caPath}
server, err := serv.NewServer(&cmd.Config)

serverBuilder := serv.NewKiamServerBuilder(&cmd.Config)
_, err := serverBuilder.WithAWSSTSGateway()
if err != nil {
log.Fatal("error using AWS STS Gateway: ", err.Error())
}
_, err = serverBuilder.WithKubernetesClient()
if err != nil {
log.Fatal("error configuring Kubernetes client: ", err.Error())
}
_, err = serverBuilder.WithTLS()
if err != nil {
log.Fatal("error configuring TLS: ", err.Error())
}

server, err := serverBuilder.Build()
if err != nil {
log.Fatal("error creating listener: ", err.Error())
}
Expand Down
34 changes: 6 additions & 28 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,29 @@ module github.com/uswitch/kiam
go 1.13

require (
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
github.com/aws/aws-sdk-go v1.35.10
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 // indirect
github.com/cenkalti/backoff v2.0.0+incompatible
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/coreos/go-iptables v0.3.0
github.com/fortytw2/leaktest v1.3.0
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gogo/protobuf v1.0.0 // indirect
github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7 // indirect
github.com/golang/protobuf v1.4.2
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
github.com/golang/protobuf v1.4.3
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/mux v1.6.2
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0
github.com/gorilla/mux v1.7.3
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/hashicorp/golang-lru v0.0.0-20180201235237-0fb14efe8c47 // indirect
github.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c // indirect
github.com/imdario/mergo v0.3.4 // indirect
github.com/json-iterator/go v0.0.0-20180315132816-ca39e5af3ece // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v0.0.0-20180228065516-1df9eeb2bb81 // indirect
github.com/onsi/ginkgo v1.10.3 // indirect
github.com/onsi/gomega v1.7.1 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/prometheus/client_golang v0.9.0-pre1
github.com/prometheus/common v0.0.0-20180518154759-7600349dcfe1 // indirect
github.com/prometheus/procfs v0.0.0-20180601124529-94663424ae5a // indirect
github.com/sirupsen/logrus v1.0.5
github.com/spf13/pflag v1.0.1 // indirect
github.com/stretchr/testify v1.4.0 // indirect
github.com/prometheus/client_golang v1.8.0
github.com/sirupsen/logrus v1.6.0
github.com/uswitch/k8sc v0.0.0-20170525133932-475c8175b340
github.com/vmg/backoff v1.0.0
golang.org/x/net v0.0.0-20200202094626-16171245cfb2
golang.org/x/sys v0.0.0-20200117145432-59e60aa80a0c // indirect
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 // indirect
google.golang.org/grpc v1.27.0
google.golang.org/grpc/security/advancedtls v0.0.0-20200204204621-648cf9b00e25
google.golang.org/protobuf v1.25.0
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/fsnotify.v1 v1.4.7
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/api v0.0.0-20180521142803-feb48db456a5
k8s.io/apimachinery v0.0.0-20180515182440-31dade610c05
Expand Down
Loading

0 comments on commit 4d7c245

Please sign in to comment.