Skip to content

Commit

Permalink
Merge pull request #16 from iquzart/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
iquzart authored Jan 5, 2022
2 parents 6aa1cfb + 8eed7b4 commit cce981c
Show file tree
Hide file tree
Showing 1,083 changed files with 348,002 additions and 398 deletions.
2 changes: 1 addition & 1 deletion azure-pipeline/templates/setup_go.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
goVersion: '1.14'
goVersion: ''

steps:
- task: GoTool@0
Expand Down
26 changes: 14 additions & 12 deletions azure-pipeline/templates/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
go.version: '1.14'
GoVersion_1_15:
go.version: '1.15'
GoVersion_1_16:
go.version: '1.16'

pool:
vmImage: '${{parameters.vmImage}}'
Expand All @@ -34,7 +36,7 @@ jobs:

- script: |
set -e -x
go test -v -coverprofile=coverage.txt -covermode count ./... > test_results.txt
go test -v -mod=readonly -coverprofile=coverage.txt -covermode count ./... > test_results.txt
go-junit-report < test_results.txt > report.xml
displayName: 'Run Unit Tests'
Expand All @@ -44,14 +46,14 @@ jobs:
testRunner: JUnit
testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml

- script: |
set -e -x
gocov convert coverage.txt > coverage.json
gocov-xml < coverage.json > coverage.xml
displayName: 'Run Code Coverage Tests'
- task: PublishCodeCoverageResults@1
displayName: 'Publish Code Coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(System.DefaultWorkingDirectory)/**/coverage.xml
# - script: |
# set -e -x
# gocov convert coverage.txt > coverage.json
# gocov-xml < coverage.json > coverage.xml
# displayName: 'Run Code Coverage Tests'

# - task: PublishCodeCoverageResults@1
# displayName: 'Publish Code Coverage'
# inputs:
# codeCoverageTool: Cobertura
# summaryFileLocation: $(System.DefaultWorkingDirectory)/**/coverage.xml
4 changes: 2 additions & 2 deletions controllers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
func TestApi(t *testing.T) {

router := getRouter()
router.GET("/api", Api)
router.GET("/api/v1/check", Api)

w := performRequest(router, "GET", "/api")
w := performRequest(router, "GET", "/api/v1/check")

// Check the response status code is what we expect.
assert.Equal(t, http.StatusOK, w.Code)
Expand Down
1 change: 0 additions & 1 deletion controllers/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controllers
import (
"net/http"
"testing"

"github.com/stretchr/testify/assert"
)

Expand Down
18 changes: 9 additions & 9 deletions controllers/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,62 @@ import (
// http status 403 Forbidden
func Forbidden(ctx *gin.Context) {
ctx.String(
http.StatusForbidden,
http.StatusForbidden,
"Forbidden")
}

// http status 404 NotFound
func NotFound(ctx *gin.Context) {
ctx.String(
http.StatusNotFound,
http.StatusNotFound,
"Not Found")
}

// http status 405 MethodNotAllowed
func MethodNotAllowed(ctx *gin.Context) {
ctx.String(
http.StatusMethodNotAllowed,
http.StatusMethodNotAllowed,
"Method Not Allowed")
}

// http status 500 InternalServerError
func InternalServerError(ctx *gin.Context) {
ctx.String(
http.StatusInternalServerError,
http.StatusInternalServerError,
"Application error")
}

// http status 501 NotImplemented
func NotImplemented(ctx *gin.Context) {
ctx.String(
http.StatusNotImplemented,
http.StatusNotImplemented,
"Not Implemented")
}

// http status 502 BadGateway
func BadGateway(ctx *gin.Context) {
ctx.String(
http.StatusBadGateway,
http.StatusBadGateway,
"Bad Gateway")
}

// http status 503 ServiceUnavailable
func ServiceUnavailable(ctx *gin.Context) {
ctx.String(
http.StatusServiceUnavailable,
http.StatusServiceUnavailable,
"Application error")
}

// http status 504 GatewayTimeout
func GatewayTimeout(ctx *gin.Context) {
ctx.String(
http.StatusGatewayTimeout,
http.StatusGatewayTimeout,
"Service Unavailable")
}

// http status 505 HTTPVersionNotSupported
func HTTPVersionNotSupported(ctx *gin.Context) {
ctx.String(
http.StatusHTTPVersionNotSupported,
http.StatusHTTPVersionNotSupported,
"HTTP Version Not Supported")
}
10 changes: 5 additions & 5 deletions controllers/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import (
"github.com/stretchr/testify/assert"
)

func TestForbidden(t *testing.T) {
func TestInternalServerError(t *testing.T) {

router := getRouter()
router.GET("/403", Forbidden)
router.GET("/500", InternalServerError)

w := performRequest(router, "GET", "/403")
w := performRequest(router, "GET", "/500")

// Check the response status code is what we expect.
assert.Equal(t, http.StatusForbidden, w.Code)
assert.Equal(t, http.StatusInternalServerError, w.Code)

// Check the response body is what we expect.
expected := "Forbidden"
expected := "Application error"
assert.Equal(t, expected, w.Body.String())

}
23 changes: 23 additions & 0 deletions deployement/helm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
6 changes: 6 additions & 0 deletions deployement/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: go-app
description: Go App chart for kubernetes
type: application
version: 1.1.0
appVersion: "latest"
22 changes: 22 additions & 0 deletions deployement/helm/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "go-app.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "go-app.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "go-app.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "go-app.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
62 changes: 62 additions & 0 deletions deployement/helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "go-app.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "go-app.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "go-app.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "go-app.labels" -}}
helm.sh/chart: {{ include "go-app.chart" . }}
{{ include "go-app.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "go-app.selectorLabels" -}}
app.kubernetes.io/name: {{ include "go-app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "go-app.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "go-app.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
61 changes: 61 additions & 0 deletions deployement/helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "go-app.fullname" . }}
labels:
{{- include "go-app.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "go-app.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "go-app.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "go-app.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 8080
protocol: TCP
livenessProbe:
httpGet:
path: /health
port: http
readinessProbe:
httpGet:
path: /health
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
28 changes: 28 additions & 0 deletions deployement/helm/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "go-app.fullname" . }}
labels:
{{- include "go-app.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "go-app.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
Loading

0 comments on commit cce981c

Please sign in to comment.