Skip to content

Commit

Permalink
Merge pull request #4 from graillus/features/trigger-refresh-by-api
Browse files Browse the repository at this point in the history
feat: trigger refresh through API endpoint
  • Loading branch information
graillus committed May 12, 2022
2 parents 4349ee7 + b3901b1 commit bf64235
Show file tree
Hide file tree
Showing 6 changed files with 439 additions and 59 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ helm install translations-refresher deploy/helm \
```

5. Install the test deployment
```bash
kubectl apply -f test/deployment.yaml
```

The refresher is now running in the cluster and should have mutated the test deployment.
```bash
Expand Down
15 changes: 15 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import "net/http"

func (app *App) ApiHandler(resp http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
resp.Header().Add("Allow", "POST")
resp.WriteHeader(http.StatusMethodNotAllowed)
return
}

hashes := app.translations.Fetch()
app.refresher.Refresh(hashes)
resp.WriteHeader(http.StatusAccepted)
}
1 change: 1 addition & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (app *App) Run() {
w.WriteHeader(200)
}))
mux.Handle("/metrics", http.Handler(promhttp.Handler()))
mux.Handle("/api/v1/refresh", http.HandlerFunc(app.ApiHandler))

fmt.Println("Listening on port 8080")
err := http.ListenAndServe(":8080", mux)
Expand Down
59 changes: 46 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,52 @@
module translations-refresher

go 1.15
go 1.18

require (
github.com/google/go-cmp v0.5.2 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/prometheus/client_golang v1.8.0
github.com/prometheus/client_golang v1.11.1
github.com/robfig/cron/v3 v3.0.1
github.com/slok/kubewebhook v0.3.0
github.com/stretchr/testify v1.6.1 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
k8s.io/api v0.19.3
k8s.io/apimachinery v0.19.3
k8s.io/client-go v0.19.0
github.com/slok/kubewebhook v0.11.0
k8s.io/api v0.22.9
k8s.io/apimachinery v0.22.9
k8s.io/client-go v0.22.9
)

require (
cloud.google.com/go v0.54.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v0.4.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/imdario/mergo v0.3.5 // indirect
github.com/json-iterator/go v1.1.11 // 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 v1.0.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
gomodules.xyz/jsonpatch/v3 v3.0.1 // indirect
gomodules.xyz/orderedmap v0.1.0 // indirect
google.golang.org/appengine v1.6.5 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/klog/v2 v2.9.0 // indirect
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)
Loading

0 comments on commit bf64235

Please sign in to comment.