This repository was archived by the owner on Jul 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 216
Move repo store from in memory to redis #333
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a770f39
Move repo store from in memory to redis
f4cd3b1
Enable Redis in Travis and run test container with host network
3f6f913
fix restapi package tests
09d3d56
small fixes from review
1011c51
move StrToPtr to util package
0626e65
add tests
3e30598
improving coverage
545bba6
move to single pool during tests
70add94
create pointerto package
767ef61
don't crash if repo name not set
384cde5
don't close redis pool
28e1ce1
avoid repeating type in array declaration
cd78906
make reposSingleton thread safe
bf157c7
reorg repos collection methods
52bacf7
fix tests
d5518d6
review changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ REPO_PATH := github.com/kubernetes-helm/${SHORT_NAME} | |
| DEV_ENV_IMAGE := quay.io/deis/go-dev:v0.22.0 | ||
| SWAGGER_IMAGE := quay.io/goswagger/swagger:0.6.0 | ||
| DEV_ENV_WORK_DIR := /go/src/${REPO_PATH}/src/api | ||
| DEV_ENV_PREFIX := docker run --rm -e GO15VENDOREXPERIMENT=1 -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR} | ||
| DEV_ENV_PREFIX := docker run --rm -e GO15VENDOREXPERIMENT=1 -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR} --net=host | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is interesting, why is this needed?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than change the Makefile to start the test using Docker Compose, I opted to keep this as is and instead make sure a Redis server is running locally. In Travis, I enabled the Redis server and locally I am exporting 6379 from the container. Perhaps this is a bit lazy, and what I should do is change the Makefile to use Compose. What do you think? |
||
| DEV_ENV_CMD := ${DEV_ENV_PREFIX} ${DEV_ENV_IMAGE} | ||
| SWAGGER_CMD := docker run --rm -e GOPATH=/go -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR} ${SWAGGER_IMAGE} | ||
| SWAGGER_GEN_DIR := swagger | ||
|
|
||
This file contains hidden or 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 hidden or 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,45 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "sync" | ||
|
|
||
| log "github.com/Sirupsen/logrus" | ||
| "github.com/albrow/zoom" | ||
| ) | ||
|
|
||
| const defaultHost = "localhost:6379" | ||
|
|
||
| var ( | ||
| pool *zoom.Pool | ||
| once sync.Once | ||
| ) | ||
|
|
||
| type redisConfig struct { | ||
| Host string | ||
| } | ||
|
|
||
| // GetRedisPool returns a pool of Zoom connections | ||
| func GetRedisPool() *zoom.Pool { | ||
| once.Do(func() { | ||
| pool = newRedisPool() | ||
| }) | ||
| return pool | ||
| } | ||
|
|
||
| func newRedisPool() *zoom.Pool { | ||
| config := getRedisConf() | ||
| return zoom.NewPool(config.Host) | ||
| } | ||
|
|
||
| func getRedisConf() redisConfig { | ||
| config, err := GetConfig() | ||
| if err != nil { | ||
| log.Fatalf("unable to read config") | ||
| } | ||
| redis := config.Redis | ||
| // Set default Redis host | ||
| if redis.Host == "" { | ||
| redis.Host = defaultHost | ||
| } | ||
| return redis | ||
| } |
This file contains hidden or 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,38 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/arschles/assert" | ||
| ) | ||
|
|
||
| func TestGetRedisPool(t *testing.T) { | ||
| currentConfig = Configuration{} | ||
| pool := GetRedisPool() | ||
| assert.NotNil(t, pool, "Redis Pool") | ||
| } | ||
|
|
||
| func Test_getRedisConf(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| configFileName string | ||
| expectedHost string | ||
| }{ | ||
| {"No Redis config", "noredis_config.yaml", defaultHost}, | ||
| {"Blank Redis config", "emptyredis_config.yaml", defaultHost}, | ||
| {"Custom Redis config", "config.yaml", "myredis:1234"}, | ||
| } | ||
| configFileOrig := configFile | ||
| defer func() { configFile = configFileOrig }() | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| currentConfig = Configuration{} | ||
| configFile = func() string { | ||
| return filepath.Join("./testdata", tt.configFileName) | ||
| } | ||
| conf := getRedisConf() | ||
| assert.Equal(t, conf.Host, tt.expectedHost, tt.name) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -12,3 +12,5 @@ cors: | |
| - "x-xsrf-token" | ||
| releasesEnabled: true | ||
| cacheRefreshInterval: 3600 | ||
| redis: | ||
| host: myredis:1234 | ||
This file contains hidden or 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,2 @@ | ||
| redis: | ||
| host: "" |
This file contains hidden or 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 @@ | ||
| otheroption: foo |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this port needed to be exposed in the host?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm exposing it because I was testing through my editor so needed to connect from my host, I think it's useful for that especially given testing locally in Go is very common.
(on a side note, I've been considering whether we should remove Docker Compose entirely and move to Minikube with host mounts and something like telepresence.io for the Go service).