Skip to content

Commit 5ef6c3e

Browse files
committed
feat: add semantic-release and Helm chart; push Docker image and Helm chart to ghcr.io
BREAKING CHANGE: not really a breaking change, just bumping to v1.0.0
1 parent 42b94f2 commit 5ef6c3e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+324
-589
lines changed

.github/workflows/branches.yaml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
name: Build Container (branches)
1+
name: Build docker image on branches
22
on:
33
push:
4-
branches:
5-
- /refs/heads/*
6-
- !master
4+
branches-ignore:
5+
- main
76
jobs:
87
build:
98
name: Docker Build and Publish
109
runs-on: ubuntu-latest
1110
steps:
12-
- name: Check out code into the Go module directory
13-
uses: actions/checkout@v2
11+
- name: Check out code
12+
uses: actions/checkout@v3
1413

15-
- name: Docker build and publish
16-
uses: docker/build-push-action@v1
14+
- name: Docker build
15+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
1716
with:
18-
username: ${{ secrets.DOCKERHUB_USER }}
19-
password: ${{ secrets.DOCKERHUB_PASSWORD }}
20-
repository: logmein/k8s-aws-operator
21-
tag_with_ref: false
22-
tag_with_sha: false
17+
context: .
2318
push: false
24-

.github/workflows/master.yaml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/publish.yaml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Publish Docker image and Helm chart
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
env:
8+
REGISTRY: ghcr.io
9+
IMAGE_NAME: ${{ github.repository }}
10+
11+
jobs:
12+
build-and-push-image:
13+
name: Buld and push Docker image
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v3
21+
22+
- name: Log in to the Container registry
23+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
24+
with:
25+
registry: ${{ env.REGISTRY }}
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Extract metadata (tags, labels) for Docker
30+
id: meta
31+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
32+
with:
33+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
34+
35+
- name: Build and push Docker image
36+
id: build-and-push
37+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
38+
with:
39+
context: .
40+
push: true
41+
tags: ${{ steps.meta.outputs.tags }}
42+
labels: ${{ steps.meta.outputs.labels }}
43+
outputs:
44+
imageDigest: ${{ steps.build-and-push.outputs.digest }}
45+
46+
build-and-push-chart:
47+
name: Buld and push Helm chart
48+
needs: build-and-push-image
49+
runs-on: ubuntu-latest
50+
permissions:
51+
contents: write
52+
packages: write
53+
steps:
54+
- name: Checkout repository
55+
uses: actions/checkout@v3
56+
57+
- name: Helm login
58+
shell: bash
59+
run: echo ${{ secrets.GITHUB_TOKEN }} | helm registry login -u ${{ github.actor }} --password-stdin ghcr.io
60+
61+
- name: Helm package
62+
shell: bash
63+
run: helm package charts/${{ github.event.repository.name }} --app-version ${{ github.event.release.tag_name }}@${{needs.build-and-push-image.outputs.imageDigest}} --version ${{ github.event.release.tag_name }}-chart
64+
65+
- name: Helm push
66+
shell: bash
67+
run: helm push ${{ github.event.repository.name }}-${{ github.event.release.tag_name }}-chart.tgz oci://ghcr.io/${{ github.repository_owner }}
68+
69+
- name: Helm logout
70+
shell: bash
71+
run: helm registry logout ghcr.io

.github/workflows/release.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
8+
jobs:
9+
semantic-release:
10+
name: Run semantic-release
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
packages: write
15+
issues: write
16+
pull-requests: write
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
21+
- name: Semantic Release
22+
uses: cycjimmy/semantic-release-action@071ef4c9640be3700de2aa7f39e8f4038e0269ed
23+
with:
24+
extra_plugins: |
25+
26+
@semantic-release/[email protected]
27+
@semantic-release/[email protected]
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.releaserc.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
verifyConditions: []
2+
branches:
3+
- main
4+
plugins:
5+
- '@semantic-release/commit-analyzer'
6+
- - '@semantic-release/release-notes-generator'
7+
- preset: conventionalcommits
8+
- - '@semantic-release/changelog'
9+
- changelogFile: CHANGELOG.md
10+
- - '@semantic-release/git'
11+
- assets:
12+
- CHANGELOG.md
13+
message: "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ deploy: manifests
4747

4848
# Generate manifests e.g. CRD, RBAC etc.
4949
manifests: controller-gen
50-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
50+
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=charts/k8s-aws-operator/crds
5151

5252
# Run go fmt against code
5353
fmt:

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
Manage AWS Elastic IPs (EIPs) and Elastic Network Interfaces (ENIs) as Custom Resources in your Kubernetes cluster and assign them your pods.
44

5-
**Warning:** This project is still work in progress. There might be breaking API changes in the future. Use at your own risk.
6-
75
## Requirements
86

97
* Your pod IPs must be allocated from your VPC subnets. This is the default setup on AWS EKS by using the [AWS VPC CNI plugin](https://github.com/aws/amazon-vpc-cni-k8s).
@@ -18,13 +16,14 @@ Create an IAM role with the policy [here](iam/policy.json).
1816

1917
### Install the operator
2018

21-
Ensure that the k8s-aws-operator uses this role, e.g. using [»IAM Roles for Service Accounts« (IRSA)](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html) or [kube2iam](https://github.com/jtblin/kube2iam)/[kiam](https://github.com/uswitch/kiam). Modify the manifests [here](deploy) accordingly, then run:
19+
Run:
2220

2321
```bash
24-
$ kubectl apply -f config/crd/bases/ # install Custom Resource Definition (CRD) for EIP Custom Resource
25-
$ kubectl apply -f deploy/ # install the operator
22+
$ helm install --namespace kube-system --set aws.region=us-east-1 oci://ghcr.io/goto-opensource/k8s-aws-operator --version v1.0.0 # adjust version
2623
```
2724

25+
If you want to use [IAM roles for service accounts](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html), add the required trust relationship with your cluster to the IAM role and add the corresponding annotation on the service account (e.g. by setting the Helm value `serviceAccount.annotations."eks.amazonaws.com/role-arn"` accordingly).
26+
2827
## Usage
2928

3029
### EIPs

charts/k8s-aws-operator/Chart.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
type: application
3+
name: k8s-aws-operator
4+
version: 0.0.0-placeholder
5+
appVersion: v0.0.0-placeholder
6+
description: Operator for managing ENIs and EIPs in AWS from within Kubernetes
7+
home: https://github.com/goto-opensource/k8s-aws-operator
8+
maintainers:
9+
- name: Alfred Krohmer
10+
11+
url: https://github.com/alfredkrohmer
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ .Chart.Name }}
5+
labels:
6+
app.kubernetes.io/name: {{ .Chart.Name }}
7+
spec:
8+
replicas: {{ .Values.replicas }}
9+
selector:
10+
matchLabels:
11+
app.kubernetes.io/name: {{ .Chart.Name }}
12+
template:
13+
metadata:
14+
labels:
15+
app.kubernetes.io/name: {{ .Chart.Name }}
16+
spec:
17+
serviceAccountName: {{ .Chart.Name }}
18+
{{- with .Values.nodeSelector }}
19+
nodeSelector: {{ . | toYaml | nindent 6 }}
20+
{{- end }}
21+
{{- with .Values.tolerations }}
22+
tolerations: {{ . | toYaml | nindent 6 }}
23+
{{- end }}
24+
{{- with .Values.affinity }}
25+
affinity: {{ . | toYaml | nindent 6 }}
26+
{{- end }}
27+
{{- with .Values.topologySpreadConstraints }}
28+
topologySpreadConstraints: {{ . | toYaml | nindent 6 }}
29+
{{- end }}
30+
containers:
31+
- name: k8s-aws-operator
32+
image: {{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}
33+
resources: {{ .Values.resources | toYaml | nindent 10 }}
34+
args:
35+
- -region={{ required "aws.region is required" .Values.aws.region }}
36+
{{- if or .Values.leaderElection.enabled (gt (.Values.replicas | int) 1) }}
37+
- -leader-election-namespace={{ .Release.Namespace }}
38+
{{- end }}
39+
ports:
40+
- name: metrics
41+
containerPort: 8080
42+
protocol: TCP
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: {{ .Chart.Name }}
5+
labels:
6+
app.kubernetes.io/name: {{ .Chart.Name }}
7+
{{- with .Values.serviceAccount.annotations }}
8+
annotations:
9+
{{ . | toYaml | nindent 4 }}
10+
{{- end }}
11+
12+
---
13+
apiVersion: rbac.authorization.k8s.io/v1
14+
kind: ClusterRole
15+
metadata:
16+
name: {{ .Chart.Name }}
17+
labels:
18+
app.kubernetes.io/name: {{ .Chart.Name }}
19+
rules:
20+
- apiGroups: [""]
21+
resources: ["pods"]
22+
verbs: ["get"]
23+
- apiGroups: ["aws.k8s.logmein.com"]
24+
resources: ["eips", "enis"]
25+
verbs: ["*"]
26+
---
27+
apiVersion: rbac.authorization.k8s.io/v1
28+
kind: ClusterRoleBinding
29+
metadata:
30+
name: {{ .Chart.Name }}
31+
labels:
32+
app.kubernetes.io/name: {{ .Chart.Name }}
33+
roleRef:
34+
apiGroup: rbac.authorization.k8s.io
35+
kind: ClusterRole
36+
name: {{ .Chart.Name }}
37+
subjects:
38+
- kind: ServiceAccount
39+
name: {{ .Chart.Name }}
40+
namespace: {{ .Release.Namespace }}
41+
42+
# for leader election:
43+
---
44+
apiVersion: rbac.authorization.k8s.io/v1
45+
kind: Role
46+
metadata:
47+
name: {{ .Chart.Name }}
48+
labels:
49+
app.kubernetes.io/name: {{ .Chart.Name }}
50+
rules:
51+
- apiGroups: ["coordination.k8s.io"]
52+
resources: ["leases"]
53+
verbs: ["create"]
54+
- apiGroups: ["coordination.k8s.io"]
55+
resources: ["leases"]
56+
resourceNames: ["k8s-aws-operator"]
57+
verbs: ["delete","get","update","watch"]
58+
- apiGroups: [""]
59+
resources: ["events"]
60+
verbs: ["create"]
61+
---
62+
apiVersion: rbac.authorization.k8s.io/v1
63+
kind: RoleBinding
64+
metadata:
65+
name: {{ .Chart.Name }}
66+
labels:
67+
app.kubernetes.io/name: {{ .Chart.Name }}
68+
roleRef:
69+
apiGroup: rbac.authorization.k8s.io
70+
kind: Role
71+
name: {{ .Chart.Name }}
72+
subjects:
73+
- kind: ServiceAccount
74+
name: {{ .Chart.Name }}
75+
namespace: {{ .Release.Namespace }}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{- if .Values.metrics.serviceMonitor.enable }}
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: {{ .Chart.Name }}-metrics
6+
labels:
7+
app.kubernetes.io/name: {{ .Chart.Name }}
8+
spec:
9+
{{- with .Values.metrics.service.clusterIP }}
10+
clusterIP: {{ . | quote }}
11+
{{- end }}
12+
ports:
13+
- name: metrics
14+
port: 8080
15+
protocol: TCP
16+
targetPort: 8080
17+
selector:
18+
app.kubernetes.io/name: {{ .Chart.Name }}
19+
{{- end }}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{- if .Values.metrics.serviceMonitor.enabled }}
2+
apiVersion: monitoring.coreos.com/v1
3+
kind: ServiceMonitor
4+
metadata:
5+
name: {{ .Chart.Name }}
6+
labels:
7+
app.kubernetes.io/name: {{ .Chart.Name }}
8+
spec:
9+
selector:
10+
matchLabels:
11+
app.kubernetes.io/name: {{ .Chart.Name }}
12+
endpoints:
13+
{{- with .Values.metrics.serviceMonitor.endpoints }}
14+
{{ . | toYaml | nindent 2 }}
15+
{{- end}}
16+
{{- end }}

0 commit comments

Comments
 (0)