Skip to content

Commit f9dafee

Browse files
committed
🎨 helm and actions
new file: .github/workflows/docker.yml; new file: .github/workflows/goreleaser.yml; new file: .github/workflows/helm.yml; new file: .github/workflows/lint.yml; new file: .github/workflows/test.yml; modified: README.md; new file: kube-reqsizer/.helmignore; new file: kube-reqsizer/Chart.yaml; new file: kube-reqsizer/templates/_helpers.tpl; new file: kube-reqsizer/templates/deployment.yaml; new file: kube-reqsizer/templates/leader-election-rbac.yaml; new file: kube-reqsizer/templates/manager-config.yaml; new file: kube-reqsizer/templates/manager-rbac.yaml; new file: kube-reqsizer/templates/metrics-reader-rbac.yaml; new file: kube-reqsizer/templates/metrics-service.yaml; new file: kube-reqsizer/templates/proxy-rbac.yaml; new file: kube-reqsizer/values.yaml
1 parent 6e70aac commit f9dafee

17 files changed

+541
-3
lines changed

.github/workflows/docker.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: docker
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
docker:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
14+
- uses: actions/setup-go@v3
15+
with:
16+
go-version: '1.19'
17+
18+
- name: go get
19+
run: go get ./...
20+
21+
- name: go mod tidy
22+
run: go mod tidy
23+
24+
- name: Checkout
25+
uses: actions/checkout@v2
26+
27+
- name: Set up QEMU
28+
uses: docker/setup-qemu-action@v1
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v1
32+
33+
- name: Login to DockerHub
34+
uses: docker/login-action@v1
35+
with:
36+
username: ${{ secrets.DOCKERHUB_USERNAME }}
37+
password: ${{ secrets.DOCKERHUB_TOKEN }}
38+
39+
- name: Docker meta
40+
id: meta
41+
uses: docker/metadata-action@v4
42+
with:
43+
# list of Docker images to use as base name for tags
44+
images: |
45+
jatalocks333/kube-reqsizer
46+
47+
- name: Build and push
48+
uses: docker/build-push-action@v2
49+
with:
50+
context: .
51+
push: true
52+
# platforms: linux/amd64,linux/arm64
53+
tags: ${{ steps.meta.outputs.tags }}
54+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/goreleaser.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: goreleaser
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
goreleaser:
13+
runs-on: ubuntu-latest
14+
steps:
15+
-
16+
name: Checkout
17+
uses: actions/checkout@v2
18+
with:
19+
fetch-depth: 0
20+
-
21+
name: Set up Go
22+
uses: actions/setup-go@v2
23+
with:
24+
go-version: 1.19
25+
-
26+
name: Run GoReleaser
27+
uses: goreleaser/goreleaser-action@v2
28+
with:
29+
version: latest
30+
args: release --rm-dist
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/helm.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Release Charts
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v1
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Configure Git
18+
run: |
19+
git config user.name "$GITHUB_ACTOR"
20+
git config user.email "[email protected]"
21+
22+
- name: Run chart-releaser
23+
uses: helm/[email protected]
24+
env:
25+
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

.github/workflows/lint.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: golangci-lint
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
golangci:
7+
name: lint
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
12+
- uses: actions/setup-go@v3
13+
with:
14+
go-version: '1.19'
15+
16+
- name: go get
17+
run: go get ./...
18+
19+
- name: go mod tidy
20+
run: go mod tidy
21+
22+
- name: golangci-lint
23+
uses: golangci/golangci-lint-action@v3
24+
with:
25+
version: v1.50.0
26+
args: -c .golang-ci.yml -v --timeout=5m
27+
env:
28+
GO111MODULES: off

.github/workflows/test.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Test and coverage
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
strategy:
8+
matrix:
9+
go-version: [1.19.x]
10+
os: [ubuntu-latest, macos-latest]
11+
12+
runs-on: ${{ matrix.os }}
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 2
18+
19+
- uses: actions/setup-go@v2
20+
with:
21+
go-version: ${{ matrix.go-version }}
22+
23+
- name: go get
24+
run: go get ./...
25+
26+
- name: go mod tidy
27+
run: go mod tidy
28+
29+
- name: Run coverage
30+
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
31+
32+
- name: Upload coverage to Codecov
33+
if: matrix.os == 'ubuntu-latest'
34+
run: bash <(curl -s https://codecov.io/bash)

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,22 @@ You’ll need a Kubernetes cluster to run against. You can use [KIND](https://si
3232
**Note:** Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster `kubectl cluster-info` shows).
3333

3434
### Running on the cluster
35-
1. Install Instances of Custom Resources:
35+
36+
37+
38+
~~1. Install Instances of Custom Resources:~~ _this controller does not use CRDs_
3639

3740
```sh
3841
kubectl apply -f config/samples/
3942
```
4043

41-
2. Build and push your image to the location specified by `IMG`:
44+
1. Build and push your image to the location specified by `IMG`:
4245

4346
```sh
4447
make docker-build docker-push IMG=<some-registry>/kube-reqsizer:tag
4548
```
4649

47-
3. Deploy the controller to the cluster with the image specified by `IMG`:
50+
2. Deploy the controller to the cluster with the image specified by `IMG`:
4851

4952
```sh
5053
make deploy IMG=<some-registry>/kube-reqsizer:tag

kube-reqsizer/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

kube-reqsizer/Chart.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: v2
2+
name: kube-reqsizer
3+
description: A Helm chart for Kubernetes
4+
# A chart can be either an 'application' or a 'library' chart.
5+
#
6+
# Application charts are a collection of templates that can be packaged into versioned archives
7+
# to be deployed.
8+
#
9+
# Library charts provide useful utilities or functions for the chart developer. They're included as
10+
# a dependency of application charts to inject those utilities and functions into the rendering
11+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
12+
type: application
13+
# This is the chart version. This version number should be incremented each time you make changes
14+
# to the chart and its templates, including the app version.
15+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
16+
version: 0.1.0
17+
# This is the version number of the application being deployed. This version number should be
18+
# incremented each time you make changes to the application. Versions are not expected to
19+
# follow Semantic Versioning. They should reflect the version the application is using.
20+
# It is recommended to use it with quotes.
21+
appVersion: "0.1.0"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "kube-reqsizer.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "kube-reqsizer.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "kube-reqsizer.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "kube-reqsizer.labels" -}}
37+
helm.sh/chart: {{ include "kube-reqsizer.chart" . }}
38+
{{ include "kube-reqsizer.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "kube-reqsizer.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "kube-reqsizer.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "kube-reqsizer.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "kube-reqsizer.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "kube-reqsizer.fullname" . }}-controller-manager
5+
labels:
6+
control-plane: controller-manager
7+
{{- include "kube-reqsizer.labels" . | nindent 4 }}
8+
spec:
9+
replicas: {{ .Values.controllerManager.replicas }}
10+
selector:
11+
matchLabels:
12+
control-plane: controller-manager
13+
{{- include "kube-reqsizer.selectorLabels" . | nindent 6 }}
14+
template:
15+
metadata:
16+
labels:
17+
control-plane: controller-manager
18+
{{- include "kube-reqsizer.selectorLabels" . | nindent 8 }}
19+
spec:
20+
containers:
21+
- args:
22+
- --secure-listen-address=0.0.0.0:8443
23+
- --upstream=http://127.0.0.1:8080/
24+
- --logtostderr=true
25+
- --v=10
26+
env:
27+
- name: KUBERNETES_CLUSTER_DOMAIN
28+
value: {{ .Values.kubernetesClusterDomain }}
29+
image: {{ .Values.controllerManager.kubeRbacProxy.image.repository }}:{{ .Values.controllerManager.kubeRbacProxy.image.tag | default .Chart.AppVersion }}
30+
name: kube-rbac-proxy
31+
ports:
32+
- containerPort: 8443
33+
name: https
34+
resources: {}
35+
- args:
36+
- --health-probe-bind-address=:8081
37+
- --metrics-bind-address=127.0.0.1:8080
38+
- --leader-elect
39+
command:
40+
- /manager
41+
env:
42+
- name: KUBERNETES_CLUSTER_DOMAIN
43+
value: {{ .Values.kubernetesClusterDomain }}
44+
image: {{ .Values.controllerManager.manager.image.repository }}:{{ .Values.controllerManager.manager.image.tag | default .Chart.AppVersion }}
45+
livenessProbe:
46+
httpGet:
47+
path: /healthz
48+
port: 8081
49+
initialDelaySeconds: 15
50+
periodSeconds: 20
51+
name: manager
52+
readinessProbe:
53+
httpGet:
54+
path: /readyz
55+
port: 8081
56+
initialDelaySeconds: 5
57+
periodSeconds: 10
58+
resources: {{- toYaml .Values.controllerManager.manager.resources | nindent 10
59+
}}
60+
securityContext:
61+
allowPrivilegeEscalation: false
62+
securityContext:
63+
runAsUser: 65532
64+
terminationGracePeriodSeconds: 10

0 commit comments

Comments
 (0)