Skip to content

Commit a4405ec

Browse files
authored
Merge pull request #18 from bryopsida/12-populate-correct-architecture
Populate node arch
2 parents 3182033 + 2d1cdc7 commit a4405ec

File tree

7 files changed

+26
-9
lines changed

7 files changed

+26
-9
lines changed

.env

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PATCHWORK_REDIS_HOST=localhost
2+
PATCHWORK_REDIS_PORT=6379
3+
PATCHWORK_UPDATE_CRON="* * * * *"
4+

charts/patchwork/Chart.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ apiVersion: v2
22
name: patchwork
33
description: A Helm chart for Kubernetes
44
type: application
5-
version: 0.3.0
6-
appVersion: '0.1.0'
5+
version: 0.4.0
6+
appVersion: '0.2.0'
77
dependencies:
88
- name: redis
99
repository: https://groundhog2k.github.io/helm-charts/

charts/patchwork/README.md

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

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

55
A Helm chart for Kubernetes
66

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "patchwork",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "",
55
"author": "",
66
"private": true,

src/analyzer/image-list.consumer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class ImageListWorker {
2020
@Process()
2121
async fetchImageList(job: Job<unknown>) {
2222
try {
23-
this.logger.debug('Fetching list of images')
23+
this.logger.log('Fetching list of images')
2424
const images = await this.k8sService.getImageList()
2525
this.logger.debug('Found images', images)
2626
// push jobs into the queue

src/analyzer/task-register.service.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ export class TaskRegisterService {
1414

1515
@Timeout(5000)
1616
async handleTimeout(): Promise<void> {
17-
this.logger.log('Ensuring fetch image list job is registered in queue')
17+
const cron = process.env.PATCHWORK_UPDATE_CRON ?? '*/30 * * * *'
18+
this.logger.log(
19+
'Ensuring fetch image list job is registered in queue with cron %s',
20+
cron
21+
)
1822
await this.fetchImageListQueue.add(
1923
{},
2024
{
2125
repeat: {
22-
cron: process.env.PATCHWORK_UPDATE_CRON ?? '*/30 * * * *',
26+
cron,
2327
},
2428
attempts: -1,
2529
backoff: {

src/kubernetes/k8s.service.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
V1Pod,
1111
V1StatefulSet,
1212
PatchUtils,
13+
V1Node,
1314
} from '@kubernetes/client-node'
1415

1516
export enum ResourceType {
@@ -46,6 +47,13 @@ function getSelector(
4647
): V1LabelSelector {
4748
return controllerObj.spec.selector
4849
}
50+
async function getNode(
51+
nodeNode: string,
52+
coreClient: CoreV1Api
53+
): Promise<V1Node> {
54+
const node = await coreClient.readNode(nodeNode)
55+
return node.body
56+
}
4957

5058
async function getFirstPod(
5159
selector: V1LabelSelector,
@@ -115,18 +123,19 @@ async function getImageDescriptors(
115123
if (pod == null) {
116124
return null
117125
}
126+
const node = await getNode(pod.spec.nodeName, coreClient)
118127
return pod.spec.containers.map((container: V1Container): ImageDescriptor => {
119128
return {
120129
repository: getImageRepo(container),
121130
tag: getImageTag(container),
122131
hash: getImageHash(container, pod),
123132
// TODO: find nodes with this image in their cache, do not try and use the active pod list which is always in flux during rollouts/scaling etc
124-
nodes: [],
133+
nodes: [node.metadata.name],
125134
// For now we are going to sample based on this pod, in the real world their could be mixed usage in non homogenus clusters but
126135
// we aren't dealing with that yet
127136
// TODO: need to pull node information from pod.spec.nodeName and get the arch from its spec.nodeInfo.architecture or spec.metadata.labels.kubernetes.io/arch
128137
// current test cluster is
129-
arch: 'arm64',
138+
arch: node.metadata.labels['kubernetes.io/arch'],
130139
owner: {
131140
type: getResourceType(controllerObj),
132141
namespace: controllerObj.metadata.namespace,

0 commit comments

Comments
 (0)