This commit is contained in:
Morten Olsen
2025-08-06 21:18:02 +02:00
parent 757b2fcfac
commit cfb90f7c9f
72 changed files with 16675 additions and 823 deletions

4
scripts/apply-test.sh Executable file
View File

@@ -0,0 +1,4 @@
for f in "./test-manifests/"*; do
echo "Applying $f"
kubectl apply -f "$f"
done

View File

@@ -1,24 +0,0 @@
import fs from 'node:fs';
import { mkdir } from 'node:fs/promises';
import { dirname, resolve } from 'node:path';
import YAML from 'yaml';
import openapiTS, { astToString } from 'openapi-typescript';
const schemaRequest = await fetch('https://authentik.olsen.cloud/api/v3/schema/');
if (!schemaRequest.ok) {
console.error(schemaRequest.status, schemaRequest.statusText);
throw new Error('Failed to fetch schema');
}
const schemaYaml = await schemaRequest.text();
const schema = YAML.parse(schemaYaml);
const ast = await openapiTS(schema);
const contents = astToString(ast);
const targetLocation = resolve(import.meta.dirname, '..', 'src', 'clients', 'authentik', 'authentik.types.d.ts');
await mkdir(dirname(targetLocation), { recursive: true });
fs.writeFileSync(
targetLocation,
['// This file is generated by scripts/create-clients.ts', '/* eslint-disable */', contents].join('\n'),
);

20
scripts/create-secrets.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
# Load environment variables from .env file
if [ -f .env ]; then
export $(cat .env | grep -v '#' | awk '/=/ {print $1}')
fi
# Check if CLOUDFLARE_API_KEY is set
if [ -z "${CLOUDFLARE_API_KEY}" ]; then
echo "Error: CLOUDFLARE_API_KEY is not set. Please add it to your .env file."
exit 1
fi
# Create the postgres namespace if it doesn't exist
kubectl get namespace postgres > /dev/null 2>&1 || kubectl create namespace postgres
# Create the secret
kubectl create secret generic cloudflare-api-token-secret \
--namespace cert-manager \
--from-literal=api-token="${CLOUDFLARE_API_KEY}"

View File

@@ -1,2 +0,0 @@
kubectl delete -f "$1"
kubectl apply -f "$1"

3
scripts/setup-server.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
flux install --components="source-controller,helm-controller"
kubectl create namespace homelab

49
scripts/update-manifests.ts Executable file
View File

@@ -0,0 +1,49 @@
#!/usr/bin/env node
import { mkdir, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import { compile } from 'json-schema-to-typescript';
import { K8sService } from '../src/services/k8s/k8s.ts';
import { Services } from '../src/utils/service.ts';
const services = new Services();
const k8s = services.get(K8sService);
const manifests = await k8s.extensionsApi.listCustomResourceDefinition();
const root = join(import.meta.dirname, '..', 'src', '__generated__', 'resources');
await mkdir(root, { recursive: true });
const firstUpsercase = (input: string) => {
const [first, ...rest] = input.split('');
return [first.toUpperCase(), ...rest].join('');
};
for (const manifest of manifests.items) {
for (const version of manifest.spec.versions) {
try {
const schema = version.schema?.openAPIV3Schema;
if (!schema) {
continue;
}
const cleanedSchema = JSON.parse(JSON.stringify(schema));
const kind = manifest.spec.names.kind;
const typeName = `K8S${kind}${firstUpsercase(version.name)}`;
const jsonLocation = join(root, `${typeName}.json`);
await writeFile(jsonLocation, JSON.stringify(schema, null, 2));
const file = await compile(cleanedSchema, typeName, {
declareExternallyReferenced: true,
additionalProperties: false,
$refOptions: {
continueOnError: true,
},
});
const fileLocation = join(root, `${typeName}.ts`);
await writeFile(fileLocation, file, 'utf8');
} catch (err) {
console.error(err);
console.error(`${manifest.metadata?.name} ${version.name} failed`);
}
}
}