Skip to content

Commit 5212ed4

Browse files
authored
workflow with lint and docker build-push (deckhouse#39)
Also fixed linter warnings
1 parent e9bba77 commit 5212ed4

File tree

9 files changed

+62
-24
lines changed

9 files changed

+62
-24
lines changed

.github/workflows/ci.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: CI
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
branches:
7+
- master
8+
pull_request:
9+
branches:
10+
- master
11+
env:
12+
REGISTRY: registry-write.deckhouse.io
13+
IMAGE_NAME: k8s-image-availability-exporter/k8s-image-availability-exporter
14+
jobs:
15+
lint:
16+
runs-on: ubuntu-latest
17+
if: github.event_name == 'pull_request'
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: golangci-lint
21+
uses: golangci/golangci-lint-action@v2
22+
with:
23+
version: v1.42
24+
build:
25+
runs-on: ubuntu-latest
26+
permissions:
27+
contents: read
28+
packages: write
29+
steps:
30+
- uses: actions/checkout@v2
31+
# Login against a Docker registry except on PR
32+
# https://github.com/docker/login-action
33+
- name: Log into registry ${{ env.REGISTRY }}
34+
if: github.event_name != 'pull_request'
35+
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
36+
with:
37+
registry: ${{ env.REGISTRY }}
38+
username: ${{ secrets.DECKHOUSE_REGISTRY_USER }}
39+
password: ${{ secrets.DECKHOUSE_REGISTRY_PASSWORD }}
40+
# Extract metadata (tags, labels) for Docker
41+
# https://github.com/docker/metadata-action
42+
- name: Extract Docker metadata
43+
id: meta
44+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
45+
with:
46+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
47+
# Build and push Docker image with Buildx (don't push on PR)
48+
# https://github.com/docker/build-push-action
49+
- name: Build and push Docker image
50+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
51+
with:
52+
context: .
53+
push: ${{ github.event_name != 'pull_request' }}
54+
tags: ${{ steps.meta.outputs.tags }}
55+
labels: ${{ steps.meta.outputs.labels }}

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# k8s-image-availability-exporter
22

3-
[![Docker images](https://img.shields.io/docker/cloud/automated/flant/k8s-image-availability-exporter)](https://hub.docker.com/r/flant/k8s-image-availability-exporter)
4-
[![Latest Docker image](https://img.shields.io/docker/v/flant/k8s-image-availability-exporter?sort=semver)](https://hub.docker.com/r/flant/k8s-image-availability-exporter)
5-
63
k8s-image-availability-exporter (or *k8s-iae* for short) is a Prometheus exporter that warns you proactively about images that are defined in Kubernetes objects (e.g., an `image` field in the Deployment) but are not available in the container registry (such as Docker Registry, etc.).
74

85
Receiving alerts when container images related to running Kubernetes controllers are missing helps you to solve the problem before it manifests itself. For more details on the reasons behind k8s-iae and how it works, please read [this article](https://blog.flant.com/announcing-k8s-image-availability-exporter/).

deploy/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ spec:
2727
ports:
2828
- containerPort: 8080
2929
name: http-metrics
30-
image: flant/k8s-image-availability-exporter:v0.1.14
30+
image: registry.deckhouse.io/k8s-image-availability-exporter/k8s-image-availability-exporter:v0.1.17
3131
imagePullPolicy: IfNotPresent
3232
livenessProbe:
3333
httpGet:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apiVersion: v1
2-
appVersion: "v0.1.14"
2+
appVersion: "v0.1.17"
33
description: Application for monitoring the cluster workloads image presence in docker registry.
44
name: k8s-image-availability-exporter
55
version: "0.0.2"

helm/k8s-image-availability-exporter/values.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
k8sImageAvailabilityExporter:
22
image:
3-
repository: flant/k8s-image-availability-exporter
4-
tag: v0.1.13
3+
repository: registry.deckhouse.io/k8s-image-availability-exporter/k8s-image-availability-exporter
4+
tag: v0.1.17
55
pullPolicy: IfNotPresent
66
replicas: 1
77
resources: {}

pkg/registry_checker/checker.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,13 @@ import (
2222
"github.com/flant/k8s-image-availability-exporter/pkg/store"
2323
"k8s.io/client-go/kubernetes"
2424
"k8s.io/client-go/tools/cache"
25-
26-
"github.com/prometheus/client_golang/prometheus"
2725
)
2826

2927
const (
3028
resyncPeriod = time.Hour
3129
)
3230

3331
type RegistryChecker struct {
34-
lock sync.RWMutex
35-
3632
imageStore *store.ImageStore
3733

3834
deploymentsInformer appsv1informers.DeploymentInformer
@@ -45,8 +41,6 @@ type RegistryChecker struct {
4541

4642
ignoredImages map[string]struct{}
4743

48-
imageExistsVectors []prometheus.Metric
49-
5044
registryTransport *http.Transport
5145

5246
kubeClient *kubernetes.Clientset

pkg/registry_checker/image_pull.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,5 @@ func IsOldRegistry(err error) bool {
6161
var schemaErr *remote.ErrSchema1
6262
errors.As(err, &schemaErr)
6363

64-
if schemaErr != nil {
65-
return true
66-
}
67-
68-
return false
64+
return schemaErr != nil
6965
}

pkg/registry_checker/indexers.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,7 @@ func (ci ControllerIndexers) GetKeysByIndex(image string) (ret []string) {
210210
func (ci ControllerIndexers) CheckImageExistence(image string) bool {
211211
keys := ci.GetKeysByIndex(image)
212212

213-
if len(keys) > 0 {
214-
return true
215-
}
216-
217-
return false
213+
return len(keys) > 0
218214
}
219215

220216
func (ci ControllerIndexers) GetContainerInfosForImage(image string) (ret []store.ContainerInfo) {

pkg/store/image_store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (imgStore *ImageStore) Length() int {
160160

161161
func (imgStore *ImageStore) PopOldestImages(count int) (ret []string) {
162162
imgStore.lock.Lock()
163-
imgStore.lock.Unlock()
163+
defer imgStore.lock.Unlock()
164164

165165
if count == 0 {
166166
count = 1

0 commit comments

Comments
 (0)