Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from deislabs/grampelberg/scaffold
Browse files Browse the repository at this point in the history
Implement metrics.smi-spec.io for Linkerd
  • Loading branch information
grampelberg committed May 10, 2019
2 parents ba2b4bb + ecb4298 commit b0754d1
Show file tree
Hide file tree
Showing 37 changed files with 2,732 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
@@ -0,0 +1,7 @@
tmp
*.yml
*.yaml
Makefile
Tiltfile
*.md
chart
19 changes: 19 additions & 0 deletions .gitignore
@@ -0,0 +1,19 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Output of swag generator
pkg/docs

tmp

.vscode
40 changes: 40 additions & 0 deletions .golangci.yml
@@ -0,0 +1,40 @@
linters:
enable-all: true
disable:
- maligned
- prealloc
- gochecknoglobals

skip-dirs:
# ignore the system libraries
- libexec/src/strings

linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0
gocyclo:
min-complexity: 10
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2
misspell:
locale: US
lll:
line-length: 140
goimports:
local-prefixes: github.com/golangci/golangci-lint
gocritic:
enabled-tags:
- performance
- style
- experimental
disabled-checks:
- wrapperFunc
- dupImport # https://github.com/go-critic/go-critic/issues/845
- rangeValCopy
25 changes: 25 additions & 0 deletions Dockerfile
@@ -0,0 +1,25 @@
FROM golang:1.12-alpine as builder
ARG NETRC

WORKDIR /src

RUN apk add --no-cache \
git

COPY go.mod .
COPY go.sum .

RUN echo "${NETRC}" > ~/.netrc
RUN go mod download

COPY . .

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./cmd/smi-metrics/...

FROM scratch

WORKDIR /src

COPY --from=builder /src/smi-metrics /

CMD /smi-metrics
27 changes: 27 additions & 0 deletions Makefile
@@ -0,0 +1,27 @@
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

HAS_TILT := $(shell command -v tilt;)

TAG := $(shell git describe --exact-match --tags $(git log -n1 --pretty='%h'))

IMAGE := thomasr/smi-metrics

.PHONY: bootstrap
bootstrap:
@# Bootstrap the required binaries
ifndef HAS_TILT
echo "Install tilt from https://docs.tilt.dev/install.html"
endif

.PHONY: dev
dev: bootstrap
tilt up

.PHONY: push
push: build
docker push $(IMAGE):$(TAG)

.PHONY: build
build:
NETRC=$$(cat ~/.netrc) && \
docker build --build-arg NETRC -t $(IMAGE):$(TAG) .
8 changes: 5 additions & 3 deletions README.md
@@ -1,8 +1,10 @@
## Running

Take a look at [k8s/dev.yaml](k8s/dev.yaml). The image will either need to be
local or hosted elsewhere (not currently public). Change `prometheus-url` to
point to where it is installed.
For the defaults, run:

```bash
helm template chart --name dev | kubectl apply -f -
```

## Development

Expand Down
8 changes: 8 additions & 0 deletions Tiltfile
@@ -0,0 +1,8 @@
k8s_yaml(local("helm template chart -f dev.yaml --name dev"))
watch_file('chart')

docker_build('thomasr/smi-metrics', '.', build_args={
'NETRC': str(local('cat ~/.netrc'))
})

k8s_resource('dev-smi-metrics', port_forwards=['8080:8080', '8081:8081'])
20 changes: 20 additions & 0 deletions bin/wait.sh
@@ -0,0 +1,20 @@
#!/bin/sh -x

exit_script() {
echo "Shutting down..."
trap - EXIT HUP INT QUIT PIPE TERM # clear the trap
kill -- -$$ # Sends SIGTERM to child/sub processes
}

trap exit_script EXIT HUP INT QUIT PIPE TERM

echo "Sleeping. Pid=$$"
sleep 2147483647 &

# Install dev helpers
apk add --no-cache \
alpine-sdk

go mod download

wait $!
22 changes: 22 additions & 0 deletions chart/.helmignore
@@ -0,0 +1,22 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
5 changes: 5 additions & 0 deletions chart/Chart.yaml
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "0.1"
description: Provider for metrics.smi-spec.io
name: smi-metrics
version: 0.1.0
32 changes: 32 additions & 0 deletions chart/templates/_helpers.tpl
@@ -0,0 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "smi-metrics.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 "smi-metrics.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 "smi-metrics.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
36 changes: 36 additions & 0 deletions chart/templates/apiservice.yaml
@@ -0,0 +1,36 @@
{{- $cn := list (include "smi-metrics.fullname" .) .Release.Namespace "svc" | join "." -}}
{{- $ca := genCA $cn 365 -}}
{{- $cert := genSignedCert $cn nil nil 365 $ca -}}
apiVersion: apiregistration.k8s.io/v1beta1
kind: APIService
metadata:
labels:
app.kubernetes.io/name: {{ include "smi-metrics.name" . }}
helm.sh/chart: {{ include "smi-metrics.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
name: v1alpha1.metrics.smi-spec.io
spec:
service:
name: {{ include "smi-metrics.fullname" . }}
namespace: {{ .Release.Namespace }}
caBundle: {{ b64enc $ca.Cert }}
group: metrics.smi-spec.io
version: v1alpha1
insecureSkipTLSVerify: false
groupPriorityMinimum: 100
versionPriority: 100
---
apiVersion: v1
kind: Secret
metadata:
labels:
app.kubernetes.io/name: {{ include "smi-metrics.name" . }}
helm.sh/chart: {{ include "smi-metrics.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
name: {{ include "smi-metrics.fullname" . }}
type: kubernetes.io/tls
data:
tls.crt: {{ b64enc $cert.Cert }}
tls.key: {{ b64enc $cert.Key }}
12 changes: 12 additions & 0 deletions chart/templates/config.yaml
@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app.kubernetes.io/name: {{ include "smi-metrics.name" . }}
helm.sh/chart: {{ include "smi-metrics.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
name: {{ include "smi-metrics.fullname" . }}
data:
config.yml: |
{{- .Values.config | toYaml | nindent 4 }}
66 changes: 66 additions & 0 deletions chart/templates/deployment.yaml
@@ -0,0 +1,66 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "smi-metrics.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "smi-metrics.name" . }}
helm.sh/chart: {{ include "smi-metrics.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "smi-metrics.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "smi-metrics.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
containers:
- name: shim
image: {{ .Values.image.name }}
imagePullPolicy: {{ .Values.image.pullPolicy }}

command:
- /smi-metrics
- --config=/config.yml

ports:
- containerPort: 8080
name: api
protocol: TCP
- containerPort: 8081
name: admin
protocol: TCP

volumeMounts:
- name: config
mountPath: /config.yml
subPath: config.yml
- mountPath: /var/run/smi-metrics
name: tls
readOnly: true

{{ if .Values.probes }}
livenessProbe:
httpGet:
path: /status
port: 8081
readinessProbe:
httpGet:
path: /status
port: 8081
{{ end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}

volumes:
- name: config
configMap:
name: {{ include "smi-metrics.fullname" . }}
- name: tls
secret:
secretName: {{ include "smi-metrics.fullname" . }}
29 changes: 29 additions & 0 deletions chart/templates/rbac.yaml
@@ -0,0 +1,29 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app.kubernetes.io/name: {{ include "smi-metrics.name" . }}
helm.sh/chart: {{ include "smi-metrics.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
name: {{ include "smi-metrics.fullname" . }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
labels:
app.kubernetes.io/name: {{ include "smi-metrics.name" . }}
helm.sh/chart: {{ include "smi-metrics.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
name: {{ include "smi-metrics.fullname" . }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: extension-apiserver-authentication-reader
subjects:
- kind: ServiceAccount
name: {{ include "smi-metrics.fullname" . }}
namespace: {{ .Release.Namespace }}
---
17 changes: 17 additions & 0 deletions chart/templates/service.yaml
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "smi-metrics.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "smi-metrics.name" . }}
helm.sh/chart: {{ include "smi-metrics.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
ports:
- port: 443
targetPort: api
protocol: TCP
selector:
app.kubernetes.io/name: {{ include "smi-metrics.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}

0 comments on commit b0754d1

Please sign in to comment.