Skip to content

Commit 3a9561a

Browse files
authored
Merge pull request #28 from bryopsida/11-private-registries
Private registry support
2 parents ef27acb + 78f7bec commit 3a9561a

File tree

8 files changed

+303
-41
lines changed

8 files changed

+303
-41
lines changed

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ This inspects your statefulsets, daemonsets, deployments and checks the associat
88

99
This is still very early in development and has a few limitations.
1010

11-
1. Does not support private registries
12-
2. Does not pull updates for things without `imagePullPolicy = Always`
13-
3. Only looks for updates to the same tag, IE for cases where base patches have been pushed to a tag
11+
1. Does not pull updates for things without `imagePullPolicy = Always`
12+
2. Only looks for updates to the same tag, IE for cases where base patches have been pushed to a tag
1413

1514
## How to deploy
1615

charts/patchwork/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
name: patchwork
33
description: Watches deployments, daemonsets, and statefulsets for image updates and will automatically trigger rollouts to pull in updates
44
type: application
5-
version: 0.6.0
5+
version: 0.7.0
66
appVersion: '0.4.0'
77
dependencies:
88
- name: redis

charts/patchwork/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# patchwork
22

3-
![Version: 0.6.0](https://img.shields.io/badge/Version-0.6.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.4.0](https://img.shields.io/badge/AppVersion-0.4.0-informational?style=flat-square)
3+
![Version: 0.7.0](https://img.shields.io/badge/Version-0.7.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.4.0](https://img.shields.io/badge/AppVersion-0.4.0-informational?style=flat-square)
44

55
Watches deployments, daemonsets, and statefulsets for image updates and will automatically trigger rollouts to pull in updates
66

package-lock.json

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "patchwork",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "",
55
"author": "",
66
"private": true,
@@ -45,6 +45,7 @@
4545
"ioredis": "^5.3.2",
4646
"nestjs-pino": "^3.3.0",
4747
"pino-http": "^8.3.3",
48+
"psl": "^1.9.0",
4849
"reflect-metadata": "^0.1.13",
4950
"rxjs": "^7.2.0"
5051
},

src/analyzer/image-descriptor.consumer.ts

+28-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
import { Processor, Process, InjectQueue } from '@nestjs/bull'
2-
import { Logger } from '@nestjs/common'
2+
import { Inject, Logger } from '@nestjs/common'
33
import { Job, Queue } from 'bull'
4-
import { ImageDescriptor } from '../kubernetes/k8s.service'
4+
import { IK8sService, ImageDescriptor } from '../kubernetes/k8s.service'
55
import { getManifest, contentTypes } from '@snyk/docker-registry-v2-client'
66
@Processor('analyzer.check.updates')
77
export class ImageDescriptorWorker {
88
private readonly logger = new Logger(ImageDescriptorWorker.name)
99
private readonly patchQueue: Queue
10+
private readonly k8sService: IK8sService
1011

11-
constructor(@InjectQueue('patcher.update') queue: Queue) {
12+
constructor(
13+
@InjectQueue('patcher.update') queue: Queue,
14+
@Inject('K8S_SERVICE') k8sService: IK8sService
15+
) {
1216
this.patchQueue = queue
17+
this.k8sService = k8sService
1318
}
1419

1520
@Process()
16-
async fetchImageList(job: Job<ImageDescriptor>) {
21+
async checkForUpdates(job: Job<ImageDescriptor>) {
1722
try {
1823
this.logger.debug(
1924
`Checking for updates of ${job.data.repository}:${
@@ -49,34 +54,42 @@ export class ImageDescriptorWorker {
4954
acceptManifest: `${contentTypes.MANIFEST_V2}, ${contentTypes.MANIFEST_LIST_V2}, ${contentTypes.OCI_INDEX_V1}, ${contentTypes.OCI_MANIFEST_V1}`,
5055
}
5156
: undefined
57+
let username
58+
let password
59+
if (job.data.pullSecret) {
60+
const creds = await this.k8sService.getPullSecretCredentials(job.data)
61+
username = creds.username
62+
password = creds.password
63+
}
5264
const manifest = await getManifest(
5365
registry,
5466
repo,
5567
job.data.tag,
56-
undefined,
57-
undefined,
68+
username,
69+
password,
5870
reqOptions,
5971
{
6072
os: 'linux',
6173
architecture: job.data.arch,
6274
}
6375
)
64-
if (manifest == null || manifest?.indexDigest == null) {
76+
if (
77+
manifest == null ||
78+
(manifest?.indexDigest == null && manifest.manifestDigest == null)
79+
) {
6580
this.logger.warn(
6681
'Failed to get a workable manifest for %s with tag %s from registry %s',
6782
repo,
6883
job.data.tag,
6984
registry
7085
)
7186
}
87+
const digest = manifest.indexDigest ?? manifest.manifestDigest
7288
this.logger.debug(
73-
`Fetched manifest digest = ${manifest?.indexDigest}, running hash = ${job.data.hash}, repo = ${job.data.repository}`,
89+
`Fetched manifest digest = ${digest}, running hash = ${job.data.hash}, repo = ${job.data.repository}`,
7490
manifest
7591
)
76-
if (
77-
manifest.indexDigest !== job.data.hash &&
78-
manifest.indexDigest != null
79-
) {
92+
if (digest !== job.data.hash && digest != null) {
8093
this.logger.warn(
8194
`Found an update for ${registry}/${repo}:${job.data.tag}`
8295
)
@@ -85,19 +98,19 @@ export class ImageDescriptorWorker {
8598
...job.data,
8699
...{
87100
currentSha: job.data.hash,
88-
targetSha: manifest.indexDigest,
101+
targetSha: digest,
89102
},
90103
})
91104
return {
92105
detectedUpdate: true,
93106
current: job.data.hash,
94-
detectedLatest: manifest.indexDigest,
107+
detectedLatest: digest,
95108
}
96109
} else {
97110
return {
98111
detectedUpdate: false,
99112
current: job.data.hash,
100-
detectedLatest: manifest.indexDigest,
113+
detectedLatest: digest,
101114
}
102115
}
103116
} catch (err) {

0 commit comments

Comments
 (0)