Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Commit

Permalink
allow monocular home dir to be configurable (#268)
Browse files Browse the repository at this point in the history
* allow monocular home dir to be configurable

* update chart
  • Loading branch information
prydonius authored Jun 7, 2017
1 parent 7018415 commit 3c08906
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion deployment/monocular/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
name: monocular
description: Monocular is a search and discovery front end for Helm Charts Repositories.
version: 0.3.0
version: 0.4.0
appVersion: 0.2.0
home: https://github.com/helm/monocular
sources:
Expand Down
9 changes: 8 additions & 1 deletion deployment/monocular/templates/api-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ spec:
- name: {{ .Chart.Name }}
image: "{{ .Values.api.image.repository }}:{{ .Values.api.image.tag }}"
imagePullPolicy: {{ .Values.api.image.pullPolicy }}
env:
- name: MONOCULAR_HOME
value: /monocular
ports:
- containerPort: {{ .Values.api.service.internalPort }}
livenessProbe:
Expand All @@ -32,11 +35,15 @@ spec:
initialDelaySeconds: 30
timeoutSeconds: 5
volumeMounts:
- name: cache
mountPath: /monocular
- name: config
mountPath: /root/monocular/config
mountPath: /monocular/config
resources:
{{ toYaml .Values.api.resources | indent 12 }}
volumes:
- name: config
configMap:
name: {{ template "fullname" . }}-api-config
- name: cache
emptyDir: {}
4 changes: 4 additions & 0 deletions src/api/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func GetConfig() (Configuration, error) {
// BaseDir returns the location of the directory
// where the configuration files are stored
func BaseDir() string {
if basedir, ok := os.LookupEnv("MONOCULAR_HOME"); ok {
return basedir
}

return filepath.Join(os.Getenv("HOME"), "monocular")
}

Expand Down
14 changes: 14 additions & 0 deletions src/api/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ func TestBaseDir(t *testing.T) {
assert.Equal(t, BaseDir(), path, "BaseDir uses home + monocular")
}

func TestBaseDirWithEnvVar(t *testing.T) {
path := "/path/to/monocular/home"
os.Setenv("MONOCULAR_HOME", path)
defer func() { os.Unsetenv("MONOCULAR_HOME") }()
assert.Equal(t, BaseDir(), path, "BaseDir uses MONOCULAR_HOME value")
}

func TestBaseDirWithEmptyEnvVar(t *testing.T) {
path := ""
os.Setenv("MONOCULAR_HOME", path)
defer func() { os.Unsetenv("MONOCULAR_HOME") }()
assert.Equal(t, BaseDir(), path, "BaseDir uses MONOCULAR_HOME value")
}

func TestConfigFile(t *testing.T) {
path := filepath.Join(BaseDir(), "config", "monocular.yaml")
assert.Equal(t, configFile(), path, "Config file = BaseDir + config + monocular.yaml")
Expand Down

0 comments on commit 3c08906

Please sign in to comment.