Fixed invocation of registry. Basic run works hardcoded

Console logs are left in place and should be deleted
This commit is contained in:
Nikola Jokic
2022-09-21 13:54:25 +02:00
parent 5f0dc3f3b6
commit f400db92cc
3 changed files with 72 additions and 34 deletions

View File

@@ -60,6 +60,12 @@ export const requiredPermissions = [
verbs: ['create', 'delete', 'get', 'list'],
resource: 'secrets',
subresource: ''
},
{
group: '',
verbs: ['create', 'delete', 'get', 'list'],
resource: 'configmaps',
subresource: ''
}
]
@@ -334,7 +340,14 @@ export async function waitForPodPhases(
let phase: PodPhase = PodPhase.UNKNOWN
try {
while (true) {
phase = await getPodPhase(podName)
try {
phase = await getPodPhase(podName)
} catch (err) {
const e = err as k8s.HttpError
if (e?.body?.reason === 'NotFound') {
phase = PodPhase.UNKNOWN
}
}
if (awaitingPhases.has(phase)) {
return
}
@@ -482,9 +495,30 @@ export async function buildContainer(): Promise<void> {
k8sApi.createNamespacedConfigMap(namespace(), cm),
k8sApi.createNamespacedSecret(namespace(), secret)
])
await k8sAppsV1.createNamespacedStatefulSet(namespace(), ss)
await k8sApi.createNamespacedService(namespace(), svc)
await k8sApi.createNamespacedPod(namespace(), pod)
try {
await k8sAppsV1.createNamespacedStatefulSet(namespace(), ss)
await waitForPodPhases(
'docker-registry-0',
new Set([PodPhase.RUNNING]),
new Set([PodPhase.PENDING, PodPhase.UNKNOWN])
)
} catch (err) {
console.log(err)
console.log(JSON.stringify(err))
throw err
}
try {
await k8sApi.createNamespacedService(namespace(), svc)
} catch (err) {
console.log(JSON.stringify(err))
throw err
}
try {
await k8sApi.createNamespacedPod(namespace(), pod)
} catch (err) {
console.log(JSON.stringify(err))
throw err
}
}
async function getCurrentNodeName(): Promise<string> {

View File

@@ -1,6 +1,10 @@
import * as k8s from '@kubernetes/client-node'
const REGISTRY_CONFIG_MAP_YAML = `
storage:
filesystem:
rootdirectory: /var/lib/registry
maxthreads: 100
health:
storagedriver:
enabled: true
@@ -96,6 +100,13 @@ export function registryStatefulSet(): k8s.V1StatefulSet {
}
]
c.volumeMounts = [
{
mountPath: '/etc/docker/registry',
name: 'docker-registry-config'
}
]
c.livenessProbe = new k8s.V1Probe()
c.livenessProbe.failureThreshold = 3
c.livenessProbe.periodSeconds = 10
@@ -118,12 +129,6 @@ export function registryStatefulSet(): k8s.V1StatefulSet {
tmpl.spec.containers = [c]
tmpl.spec.volumes = [
{
name: 'data',
persistentVolumeClaim: {
claimName: 'docker-registry'
}
},
{
name: 'docker-registry-config',
configMap: {
@@ -133,22 +138,6 @@ export function registryStatefulSet(): k8s.V1StatefulSet {
]
spec.template = tmpl
spec.volumeClaimTemplates = [
{
metadata: {
name: 'data'
},
spec: {
accessModes: ['ReadWriteOnce'],
storageClassName: 'local-storage',
resources: {
requests: {
storage: '5Gi'
}
}
}
}
]
ss.spec = spec
return ss
@@ -196,19 +185,20 @@ export function kanikoPod(): k8s.V1Pod {
c.image = 'gcr.io/kaniko-project/executor:latest'
c.name = 'kaniko'
c.imagePullPolicy = 'Always'
c.env = [
{
name: 'GIT_TOKEN',
value: process.env.GITHUB_TOKEN
}
]
c.args = [
'--dockerfile=',
'--context=',
'--dockerfile=Dockerfile',
'--context=git://github.com/nikola-jokic/dockeraction.git',
'--destination=docker-registry.default.svc.cluster.local:5000/test/app:1.0'
]
c.volumeMounts = [
// TODO: ...
]
spec.containers = [c]
spec.dnsPolicy = 'ClusterFirst'
spec.restartPolicy = 'Never'
spec.volumes = [
// TODO: ...
]
pod.spec = spec
return pod

View File

@@ -0,0 +1,14 @@
import { buildContainer } from '../src/k8s'
import { TestHelper } from './test-setup'
jest.useRealTimers()
describe('container build', () => {
beforeAll(async () => {
process.env['ACTIONS_RUNNER_KUBERNETES_NAMESPACE'] = 'default'
})
it('should finish without throwing an exception', async () => {
await expect(buildContainer()).resolves.not.toThrow()
})
})