Skip to content

Commit a15dddb

Browse files
authored
Refactor project from k8s-aws-ebs-tagger to k8s-pvc-tagger (mtougeron#56)
* Start the rename to k8s-pvc-tagger * Support new & legacy metric names * track the storageclass in the metrics * Update default annotation name * conditionals to support legacy annotations * update unit tests * add a note about the rename * Clarify the aws-ebs only for legacy annotation support * only publish to new registry names * Fix helm chart version since it's been renamed not updated * dockle bugfix
1 parent 7c24fdc commit a15dddb

20 files changed

+315
-125
lines changed

.github/workflows/containerscan.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
pull_request:
77
branches: [ main ]
88

9+
env:
10+
# See https://github.com/goodwithtech/dockle/issues/188
11+
DOCKLE_HOST: "unix:///var/run/docker.sock"
12+
913
jobs:
1014

1115
ContainerScan:
@@ -16,7 +20,7 @@ jobs:
1620
- name: Set up Go 1.x
1721
uses: actions/setup-go@v2
1822
with:
19-
go-version: ^1.16
23+
go-version: ^1.18
2024
id: go
2125

2226
- name: Check out code into the Go module directory

.github/workflows/publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
id: docker_meta
4040
uses: crazy-max/ghaction-docker-meta@v1
4141
with:
42-
images: ${{ secrets.DOCKER_HUB_USERNAME }}/k8s-aws-ebs-tagger,ghcr.io/${{ github.repository_owner }}/k8s-aws-ebs-tagger
42+
images: ${{ secrets.DOCKER_HUB_USERNAME }}/k8s-pvc-tagger,ghcr.io/${{ github.repository_owner }}/k8s-pvc-tagger
4343
-
4444
name: Set up QEMU
4545
uses: docker/setup-qemu-action@v1

Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM golang:1.18-alpine AS builder
33
ARG VERSION=0.0.1
44
ARG TARGETARCH
55

6-
ENV APP_NAME=k8s-aws-ebs-tagger \
6+
ENV APP_NAME=k8s-pvc-tagger \
77
GO111MODULE=on \
88
CGO_ENABLED=0 \
99
GOOS=linux \
@@ -32,14 +32,14 @@ WORKDIR /app
3232
# Copy binary from build to main folder
3333
RUN cp /build/${APP_NAME} .
3434

35-
RUN addgroup -S k8s-aws-ebs-tagger && adduser -S k8s-aws-ebs-tagger -G k8s-aws-ebs-tagger
35+
RUN addgroup -S k8s-pvc-tagger && adduser -S k8s-pvc-tagger -G k8s-pvc-tagger
3636

3737
# Build a small image
3838
FROM scratch
3939
COPY --from=builder /etc/passwd /etc/passwd
40-
USER k8s-aws-ebs-tagger
40+
USER k8s-pvc-tagger
4141
# https://github.com/aws/aws-sdk-go/issues/2322
4242
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
4343
COPY --from=builder /app/${APP_NAME} /
4444

45-
ENTRYPOINT ["/k8s-aws-ebs-tagger"]
45+
ENTRYPOINT ["/k8s-pvc-tagger"]

README.md

+21-17
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
1-
# k8s-aws-ebs-tagger
1+
# k8s-pvc-tagger
22

3-
A utility to tag AWS EBS volumes based on the PVC's `aws-ebs-tagger/tags` annotation
3+
NOTE: This project was originally named `k8s-aws-ebs-tagger` but was renamed to `k8s-pvc-tagger` as the scope has expanded to more than aws ebs volumes.
44

5-
![Go](https://github.com/mtougeron/k8s-aws-ebs-tagger/workflows/Go/badge.svg) ![Gosec](https://github.com/mtougeron/k8s-aws-ebs-tagger/workflows/Gosec/badge.svg) ![ContainerScan](https://github.com/mtougeron/k8s-aws-ebs-tagger/workflows/ContainerScan/badge.svg) [![GitHub tag](https://img.shields.io/github/v/tag/mtougeron/k8s-aws-ebs-tagger)](https://github.com/mtougeron/k8s-aws-ebs-tagger/tags/)
5+
A utility to tag PVC volumes based on the PVC's `k8s-pvc-tagger/tags` annotation
66

7-
The `k8s-aws-ebs-tagger` watches for new PersistentVolumeClaims and when new AWS EBS volumes are created it adds tags based on the PVC's `aws-ebs-tagger/tags` annotation to the created EBS volume.
7+
![Go](https://github.com/mtougeron/k8s-pvc-tagger/workflows/Go/badge.svg) ![Gosec](https://github.com/mtougeron/k8s-pvc-tagger/workflows/Gosec/badge.svg) ![ContainerScan](https://github.com/mtougeron/k8s-pvc-tagger/workflows/ContainerScan/badge.svg) [![GitHub tag](https://img.shields.io/github/v/tag/mtougeron/k8s-pvc-tagger)](https://github.com/mtougeron/k8s-pvc-tagger/tags/)
8+
9+
The `k8s-pvc-tagger` watches for new PersistentVolumeClaims and when new AWS EBS volumes are created it adds tags based on the PVC's `k8s-pvc-tagger/tags` annotation to the created EBS volume. Other cloud provider and volume times are coming soon.
810

911
### How to set tags
1012

1113
#### cmdline args
1214

13-
`--default-tags` - A json or csv encoded key/value map of the tags to set by default on EBS Volumes. Values can be overwritten by the `aws-ebs-tagger/tags` annotation.
15+
`--default-tags` - A json or csv encoded key/value map of the tags to set by default on EBS Volumes. Values can be overwritten by the `k8s-pvc-tagger/tags` annotation.
1416

15-
`--tag-format` - Either `json` or `csv` for the format the `aws-ebs-tagger/tags` and `--default-tags` are in.
17+
`--tag-format` - Either `json` or `csv` for the format the `k8s-pvc-tagger/tags` and `--default-tags` are in.
1618

1719
`--allow-all-tags` - Allow all tags to be set via the PVC; even those used by the EBS controllers. Use with caution!
1820

1921
#### Annotations
2022

21-
`aws-ebs-tagger/ignore` - When this annotation is set (any value) it will ignore this PVC and not add any tags to it
23+
`k8s-pvc-tagger/ignore` - When this annotation is set (any value) it will ignore this PVC and not add any tags to it
24+
25+
`k8s-pvc-tagger/tags` - A json encoded key/value map of the tags to set on the EBS Volume (in addition to the `--default-tags`). It can also be used to override the values set in the `--default-tags`
2226

23-
`aws-ebs-tagger/tags` - A json encoded key/value map of the tags to set on the EBS Volume (in addition to the `--default-tags`). It can also be used to override the values set in the `--default-tags`
27+
NOTE: Until version `v1.1.0` the legacy annotation prefix of `aws-ebs-tagger` will continue to be supported for aws-ebs volumes ONLY.
2428

2529
#### Examples
2630

2731
1. The cmdline arg `--default-tags={"me": "touge"}` and no annotation will set the tag `me=touge`
2832

29-
2. The cmdline arg `--default-tags={"me": "touge"}` and the annotation `aws-ebs-tagger/tags: | {"me": "someone else", "another tag": "some value"}` will create the tags `me=someone else` and `another tag=some value` on the EBS Volume
33+
2. The cmdline arg `--default-tags={"me": "touge"}` and the annotation `k8s-pvc-tagger/tags: | {"me": "someone else", "another tag": "some value"}` will create the tags `me=someone else` and `another tag=some value` on the EBS Volume
3034

31-
3. The cmdline arg `--default-tags={"me": "touge"}` and the annotation `aws-ebs-tagger/ignore: ""` will not set any tags on the EBS Volume
35+
3. The cmdline arg `--default-tags={"me": "touge"}` and the annotation `k8s-pvc-tagger/ignore: ""` will not set any tags on the EBS Volume
3236

33-
4. The cmdline arg `--default-tags={"me": "touge"}` and the annotation `aws-ebs-tagger/tags: | {"cost-center": "abc", "environment": "prod"}` will create the tags `me=touge`, `cost-center=abc` and `environment=prod` on the EBS Volume
37+
4. The cmdline arg `--default-tags={"me": "touge"}` and the annotation `k8s-pvc-tagger/tags: | {"cost-center": "abc", "environment": "prod"}` will create the tags `me=touge`, `cost-center=abc` and `environment=prod` on the EBS Volume
3438

3539
#### ignored tags
3640

@@ -55,7 +59,7 @@ metadata:
5559
TeamID: "Frontend"
5660
annotations:
5761
CostCenter: "1234"
58-
aws-ebs-tagger/tags: |
62+
k8s-pvc-tagger/tags: |
5963
{"Owner": "{{ .Labels.TeamID }}-{{ .Annotations.CostCenter }}"}
6064
---
6165
apiVersion: v1
@@ -64,29 +68,29 @@ metadata:
6468
name: app-1
6569
namespace: my-app
6670
annotations:
67-
aws-ebs-tagger/tags: |
71+
k8s-pvc-tagger/tags: |
6872
{"OwnerID": "{{ .Namespace }}/{{ .Name }}"}
6973
```
7074
7175
### Installation
7276
7377
#### AWS IAM Role
7478
75-
You need to create an AWS IAM Role that can be used by `k8s-aws-ebs-tagger`. I recommend using a tool like [kube2iam](https://github.com/jtblin/kube2iam) instead of using an AWS access key/secret. An example policy is in [examples/iam-role.json](examples/iam-role.json).
79+
You need to create an AWS IAM Role that can be used by `k8s-pvc-tagger`. I recommend using a tool like [kube2iam](https://github.com/jtblin/kube2iam) instead of using an AWS access key/secret. An example policy is in [examples/iam-role.json](examples/iam-role.json).
7680

7781
#### Install via helm
7882

7983
```
8084
helm repo add mtougeron https://mtougeron.github.io/helm-charts/
8185
helm repo update
82-
helm install k8s-aws-ebs-tagger mtougeron/k8s-aws-ebs-tagger
86+
helm install k8s-pvc-tagger mtougeron/k8s-pvc-tagger
8387
```
8488
8589
#### Container Image
8690
87-
Images are available on the [GitHub Container Registry](https://github.com/users/mtougeron/packages/container/k8s-aws-ebs-tagger/versions) and [DockerHub](https://hub.docker.com/r/mtougeron/k8s-aws-ebs-tagger). Containers are published for `linux/amd64` & `linux/arm64`.
91+
Images are available on the [GitHub Container Registry](https://github.com/users/mtougeron/packages/container/k8s-pvc-tagger/versions) and [DockerHub](https://hub.docker.com/r/mtougeron/k8s-pvc-tagger). Containers are published for `linux/amd64` & `linux/arm64`.
8892
8993
9094
### Licensing
9195
92-
This project is licensed under the Apache V2 License. See [LICENSE](https://github.com/mtougeron/k8s-aws-ebs-tagger/blob/main/LICENSE) for more information.
96+
This project is licensed under the Apache V2 License. See [LICENSE](https://github.com/mtougeron/k8s-pvc-tagger/blob/main/LICENSE) for more information.

SECURITY.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
| Version | Supported | gosec |
66
| ------- | ------------------ | ------ |
7-
| latest | :white_check_mark: | ![Gosec](https://github.com/mtougeron/k8s-aws-ebs-tagger/workflows/Gosec/badge.svg) |
7+
| latest | :white_check_mark: | ![Gosec](https://github.com/mtougeron/k8s-pvc-tagger/workflows/Gosec/badge.svg) |
88

99
## Scanning
1010

11-
Security scanning uses [gosec](https://github.com/securego/gosec) via a [GitHub workflow](https://github.com/mtougeron/k8s-aws-ebs-tagger/actions?query=workflow%3AGosec)
11+
Security scanning uses [gosec](https://github.com/securego/gosec) via a [GitHub workflow](https://github.com/mtougeron/k8s-pvc-tagger/actions?query=workflow%3AGosec)
1212

1313
## Reporting a Vulnerability
1414

aws.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func getMetadataRegion() (string, error) {
9090
return doc.Region, nil
9191
}
9292

93-
func (client *Client) addVolumeTags(volumeID string, tags map[string]string) {
93+
func (client *Client) addVolumeTags(volumeID string, tags map[string]string, storageclass string) {
9494
var ec2Tags []*ec2.Tag
9595
for k, v := range tags {
9696
ec2Tags = append(ec2Tags, &ec2.Tag{Key: aws.String(k), Value: aws.String(v)})
@@ -103,14 +103,16 @@ func (client *Client) addVolumeTags(volumeID string, tags map[string]string) {
103103
})
104104
if err != nil {
105105
log.Errorln("Could not create tags for volumeID:", volumeID, err)
106-
promActionsTotal.With(prometheus.Labels{"status": "error"}).Inc()
106+
promActionsTotal.With(prometheus.Labels{"status": "error", "storageclass": storageclass}).Inc()
107+
promActionsLegacyTotal.With(prometheus.Labels{"status": "error"}).Inc()
107108
return
108109
}
109110

110-
promActionsTotal.With(prometheus.Labels{"status": "success"}).Inc()
111+
promActionsTotal.With(prometheus.Labels{"status": "success", "storageclass": storageclass}).Inc()
112+
promActionsLegacyTotal.With(prometheus.Labels{"status": "success"}).Inc()
111113
}
112114

113-
func (client *Client) deleteVolumeTags(volumeID string, tags []string) {
115+
func (client *Client) deleteVolumeTags(volumeID string, tags []string, storageclass string) {
114116
var ec2Tags []*ec2.Tag
115117
for _, k := range tags {
116118
ec2Tags = append(ec2Tags, &ec2.Tag{Key: aws.String(k)})
@@ -123,9 +125,11 @@ func (client *Client) deleteVolumeTags(volumeID string, tags []string) {
123125
})
124126
if err != nil {
125127
log.Errorln("Could not delete tags for volumeID:", volumeID, err)
126-
promActionsTotal.With(prometheus.Labels{"status": "error"}).Inc()
128+
promActionsTotal.With(prometheus.Labels{"status": "error", "storageclass": storageclass}).Inc()
129+
promActionsLegacyTotal.With(prometheus.Labels{"status": "error"}).Inc()
127130
return
128131
}
129132

130-
promActionsTotal.With(prometheus.Labels{"status": "success"}).Inc()
133+
promActionsTotal.With(prometheus.Labels{"status": "success", "storageclass": storageclass}).Inc()
134+
promActionsLegacyTotal.With(prometheus.Labels{"status": "success"}).Inc()
131135
}

charts/k8s-aws-ebs-tagger/Chart.yaml

-17
This file was deleted.
File renamed without changes.

charts/k8s-pvc-tagger/Chart.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v2
2+
name: k8s-pvc-tagger
3+
description: An app to tag PVC volumes based on a PVC annotation
4+
home: https://github.com/mtougeron/k8s-pvc-tagger
5+
type: application
6+
maintainers:
7+
- name: mtougeron
8+
9+
keywords:
10+
- kubernetes
11+
- aws
12+
- aws-ebs
13+
- persistent-volumes
14+
sources:
15+
- https://github.com/mtougeron/k8s-pvc-tagger
16+
17+
version: 1.0.0
18+
appVersion: v1.0.0

charts/k8s-aws-ebs-tagger/templates/_helpers.tpl charts/k8s-pvc-tagger/templates/_helpers.tpl

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{/*
33
Expand the name of the chart.
44
*/}}
5-
{{- define "k8s-aws-ebs-tagger.name" -}}
5+
{{- define "k8s-pvc-tagger.name" -}}
66
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
77
{{- end }}
88

@@ -11,7 +11,7 @@ Create a default fully qualified app name.
1111
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
1212
If release name contains chart name it will be used as a full name.
1313
*/}}
14-
{{- define "k8s-aws-ebs-tagger.fullname" -}}
14+
{{- define "k8s-pvc-tagger.fullname" -}}
1515
{{- if .Values.fullnameOverride }}
1616
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
1717
{{- else }}
@@ -27,16 +27,16 @@ If release name contains chart name it will be used as a full name.
2727
{{/*
2828
Create chart name and version as used by the chart label.
2929
*/}}
30-
{{- define "k8s-aws-ebs-tagger.chart" -}}
30+
{{- define "k8s-pvc-tagger.chart" -}}
3131
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
3232
{{- end }}
3333

3434
{{/*
3535
Common labels
3636
*/}}
37-
{{- define "k8s-aws-ebs-tagger.labels" -}}
38-
helm.sh/chart: {{ include "k8s-aws-ebs-tagger.chart" . }}
39-
{{ include "k8s-aws-ebs-tagger.selectorLabels" . }}
37+
{{- define "k8s-pvc-tagger.labels" -}}
38+
helm.sh/chart: {{ include "k8s-pvc-tagger.chart" . }}
39+
{{ include "k8s-pvc-tagger.selectorLabels" . }}
4040
{{- if .Chart.AppVersion }}
4141
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
4242
{{- end }}
@@ -46,17 +46,17 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
4646
{{/*
4747
Selector labels
4848
*/}}
49-
{{- define "k8s-aws-ebs-tagger.selectorLabels" -}}
50-
app.kubernetes.io/name: {{ include "k8s-aws-ebs-tagger.name" . }}
49+
{{- define "k8s-pvc-tagger.selectorLabels" -}}
50+
app.kubernetes.io/name: {{ include "k8s-pvc-tagger.name" . }}
5151
app.kubernetes.io/instance: {{ .Release.Name }}
5252
{{- end }}
5353

5454
{{/*
5555
Create the name of the service account to use
5656
*/}}
57-
{{- define "k8s-aws-ebs-tagger.serviceAccountName" -}}
57+
{{- define "k8s-pvc-tagger.serviceAccountName" -}}
5858
{{- if .Values.serviceAccount.create }}
59-
{{- default (include "k8s-aws-ebs-tagger.fullname" .) .Values.serviceAccount.name }}
59+
{{- default (include "k8s-pvc-tagger.fullname" .) .Values.serviceAccount.name }}
6060
{{- else }}
6161
{{- default "default" .Values.serviceAccount.name }}
6262
{{- end }}

charts/k8s-aws-ebs-tagger/templates/deployment.yaml charts/k8s-pvc-tagger/templates/deployment.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
apiVersion: apps/v1
22
kind: Deployment
33
metadata:
4-
name: {{ include "k8s-aws-ebs-tagger.fullname" . }}
4+
name: {{ include "k8s-pvc-tagger.fullname" . }}
55
labels:
6-
{{- include "k8s-aws-ebs-tagger.labels" . | nindent 4 }}
6+
{{- include "k8s-pvc-tagger.labels" . | nindent 4 }}
77
spec:
88
replicas: {{ .Values.replicaCount }}
99
selector:
1010
matchLabels:
11-
{{- include "k8s-aws-ebs-tagger.selectorLabels" . | nindent 6 }}
11+
{{- include "k8s-pvc-tagger.selectorLabels" . | nindent 6 }}
1212
template:
1313
metadata:
1414
{{- with .Values.podAnnotations }}
1515
annotations:
1616
{{- toYaml . | nindent 8 }}
1717
{{- end }}
1818
labels:
19-
{{- include "k8s-aws-ebs-tagger.selectorLabels" . | nindent 8 }}
19+
{{- include "k8s-pvc-tagger.selectorLabels" . | nindent 8 }}
2020
spec:
2121
{{- with .Values.imagePullSecrets }}
2222
imagePullSecrets:
2323
{{- toYaml . | nindent 8 }}
2424
{{- end }}
25-
serviceAccountName: {{ include "k8s-aws-ebs-tagger.serviceAccountName" . }}
25+
serviceAccountName: {{ include "k8s-pvc-tagger.serviceAccountName" . }}
2626
securityContext:
2727
{{- toYaml .Values.podSecurityContext | nindent 8 }}
2828
containers:

0 commit comments

Comments
 (0)