Skip to content

Commit

Permalink
Merge branch 'release/0.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
takama committed Sep 18, 2017
2 parents 1117494 + 84c694b commit a06e76b
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ REGISTRY?=docker.io/takama
CA_DIR?=certs

# Use the 0.0.0 tag for testing, it shouldn't clobber any release builds
RELEASE?=0.4.0
RELEASE?=0.4.1
GOOS?=linux
GOARCH?=amd64

Expand Down
2 changes: 1 addition & 1 deletion charts/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: k8sapp
description: A Helm charts for Kubernetes application
version: 0.4.0
version: 0.4.1
home: https://my.domain/
sources:
- https://github.com/takama/k8sapp
Expand Down
2 changes: 1 addition & 1 deletion charts/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ image:
##
registry: docker.io/takama
name: k8sapp
tag: 0.4.0
tag: 0.4.1

## Docker Registry/Hub auth secret name, always use `registry-pull-secret` if registry inside if k8s
##
Expand Down
2 changes: 1 addition & 1 deletion charts/values-stable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ image:
##
registry: docker.io/takama
name: k8sapp
tag: 0.4.0
tag: 0.4.1

## Docker Registry/Hub auth secret name, always use `registry-pull-secret` if registry inside if k8s
##
Expand Down
11 changes: 9 additions & 2 deletions cmd/k8sapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/takama/k8sapp/pkg/config"
"github.com/takama/k8sapp/pkg/service"
"github.com/takama/k8sapp/pkg/system"
)

func main() {
Expand All @@ -20,11 +21,17 @@ func main() {
}

// Configure service and get router
router, err := service.Setup(cfg)
router, logger, err := service.Setup(cfg)
if err != nil {
log.Fatal(err)
}

// Listen and serve handlers
router.Listen(fmt.Sprintf("%s:%d", cfg.LocalHost, cfg.LocalPort))
go router.Listen(fmt.Sprintf("%s:%d", cfg.LocalHost, cfg.LocalPort))

// Wait signals
signals := system.NewSignals()
if err := signals.Wait(logger, new(system.Handling)); err != nil {
logger.Fatal(err)
}
}
8 changes: 7 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# Version 0.4.0
# Version 0.4.1

[Documentation](README.md)

## Changelog since 0.4.0

### Codebase

- Used system signal handling and info handler ([#33](https://github.com/takama/k8sapp/pull/33), [@takama](https://github.com/takama))

## Changelog since 0.3.1

### Documentation
Expand Down
16 changes: 14 additions & 2 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package service

import (
"net/http"

"github.com/takama/k8sapp/pkg/config"
"github.com/takama/k8sapp/pkg/handlers"
"github.com/takama/k8sapp/pkg/logger"
Expand All @@ -15,9 +17,9 @@ import (
)

// Setup configures the service
func Setup(cfg *config.Config) (r router.BitRoute, err error) {
func Setup(cfg *config.Config) (r router.BitRoute, log logger.Logger, err error) {
// Setup logger
log := stdlog.New(&logger.Config{
log = stdlog.New(&logger.Config{
Level: cfg.LogLevel,
Time: true,
UTC: true,
Expand All @@ -33,11 +35,21 @@ func Setup(cfg *config.Config) (r router.BitRoute, err error) {
// Register new router
r = bitroute.New()

// Response for undefined methods
r.SetupNotFoundHandler(h.Base(notFound))

// Configure router
r.SetupMiddleware(h.Base)
r.GET("/", h.Root)
r.GET("/healthz", h.Health)
r.GET("/readyz", h.Ready)
r.GET("/info", h.Info)

return
}

// Response for undefined methods
func notFound(c router.Control) {
c.Code(http.StatusNotFound)
c.Write("Method not found for " + c.Request().URL.Path)
}
28 changes: 26 additions & 2 deletions pkg/service/service_test.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,46 @@
package service

import (
"net/http"
"net/http/httptest"
"testing"

"github.com/takama/k8sapp/pkg/config"
"github.com/takama/k8sapp/pkg/handlers"
"github.com/takama/k8sapp/pkg/router/bitroute"
)

func TestRun(t *testing.T) {
func TestSetup(t *testing.T) {
cfg := new(config.Config)
err := cfg.Load(config.SERVICENAME)
if err != nil {
t.Error("Expected loading of environment vars, got", err)
}
router, err := Setup(cfg)
router, logger, err := Setup(cfg)
if err != nil {
t.Errorf("Fail, got '%s', want '%v'", err, nil)
}
if router == nil {
t.Error("Expected new router, got nil")
}
if logger == nil {
t.Error("Expected new logger, got nil")
}

h := handlers.New(logger, cfg)
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h.Base(notFound)(bitroute.NewControl(w, r))
})

req, err := http.NewRequest("GET", "/notfound", nil)
if err != nil {
t.Error(err)
}

trw := httptest.NewRecorder()
handler.ServeHTTP(trw, req)

if trw.Code != http.StatusNotFound {
t.Error("Expected status:", http.StatusNotFound, "got", trw.Code)
}
}

0 comments on commit a06e76b

Please sign in to comment.