Skip to content

Commit

Permalink
remove harbor, towards cloudImg impl
Browse files Browse the repository at this point in the history
  • Loading branch information
QcFe committed Mar 11, 2025
1 parent 82f88da commit 4997d13
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 52 deletions.
6 changes: 0 additions & 6 deletions qlkube/deploy/qlkube/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,10 @@ spec:
- name: configuration
mountPath: "{{ .Values.configuration.mountPath }}/{{ .Values.configuration.wrappers.fileName }}"
subPath: "{{ .Values.configuration.wrappers.fileName }}"
- name: harbor-token
mountPath: "/var/run/secrets/harbor_token.json"
subPath: "harbor_token.json"
volumes:
- name: configuration
configMap:
name: "{{ include "qlkube.fullname" . }}"
- name: harbor-token
secret:
secretName: {{ include "qlkube.fullname" . }}-harbor-token
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
Expand Down
10 changes: 0 additions & 10 deletions qlkube/deploy/qlkube/templates/secret-harbor.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions qlkube/deploy/qlkube/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,3 @@ resources:
memory: 250Mi

rbacResourcesName: crownlabs-qlkube

harborToken: {}
29 changes: 10 additions & 19 deletions qlkube/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const repl = require('repl');
const { setupSubscriptions } = require('./decorateSubscription');
const { getOpenApiSpec } = require('./oas');
const { decorateOpenapi } = require('./decorateOpenapi');
const { joinSchemas } = require('./joinSchemas');
const { createSchema, createHarborSchema } = require('./schema');
const { createSchema, oasToGraphQlSchema, joinSchemas } = require('./schema');
const { subscriptions } = require('./subscriptions');
const { kinformer } = require('./informer');
const { getBearerToken, logger } = require('./utils');
Expand All @@ -35,29 +34,21 @@ async function main() {
'utf8',
)
: '';
const registryUrl = inCluster ? 'http://cloudimg-registry' : 'http://localhost:8002';

const oas = await getOpenApiSpec(kubeApiUrl, ['openapi/v2'], inClusterToken);
const targetOas = decorateOpenapi(oas);

let kubeSchema = await createSchema(targetOas, kubeApiUrl, inClusterToken);
kubeSchema = setupSubscriptions(subscriptions, kubeSchema);

const harborToken = JSON.parse(
await fs.readFile(
inCluster ? '/var/run/secrets/harbor_token.json' : './.harbor_token.json',
'utf8',
),
);

const harborApiUrl = 'https://harbor.crownlabs.polito.it';

const harborOas = await getOpenApiSpec(harborApiUrl, ['swagger2.json'], harborToken);
const harborSchema = await createHarborSchema(
harborOas,
harborApiUrl,
harborToken,
);
const registryOas = await getOpenApiSpec(registryUrl, ['docs/openapi.json']);
const registrySchema = (await oasToGraphQlSchema(registryOas, registryUrl, null, true)).schema;

const schema = joinSchemas(kubeSchema, harborSchema);
const schema = joinSchemas([
{ schema: kubeSchema },
{ schema: registrySchema, prefix: 'reg' },
]);

const app = express();
const httpServer = createServer(app);
Expand Down Expand Up @@ -195,7 +186,7 @@ async function main() {
url: `http://localhost:${PORT}/`,
subscriptions: `ws://localhost:${PORT}/subscription`,
}, '🚀 Server ready');
global.harborSchema = harborSchema;
global.registrySchema = registrySchema;
global.kubeSchema = kubeSchema;
repl.start('> ');
});
Expand Down
48 changes: 33 additions & 15 deletions qlkube/src/schema.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
const { createGraphQLSchema } = require('openapi-to-graphql');
const { stitchSchemas } = require('@graphql-tools/stitch');
const { RenameRootFields } = require('@graphql-tools/wrap');
const { RenameRootTypes } = require('@graphql-tools/wrap');
const { decorateBaseSchema } = require('./decorateBaseSchema');
const { wrappers } = require('./wrappers');

exports.createHarborSchema = async (oas, harborApiUrl, token) => {
const { schema } = await createGraphQLSchema(oas, {
baseUrl: `${harborApiUrl}/api/v2.0`,
viewer: false,
requestOptions: {
headers: (_method, _path, _title, _resolverParams) => ({
Authorization: `Basic ${btoa(`${token.name}:${token.secret}`)}`,
}),
},
});
return schema;
const basicHeaders = {
'Content-Type': 'application/json',
};

async function oasToGraphQlSchema(oas, kubeApiUrl, token) {
async function oasToGraphQlSchema(oas, baseUrl, token, operationIdFieldNames) {
const schema = await createGraphQLSchema(oas, {
baseUrl: kubeApiUrl,
baseUrl,
viewer: false,
headers: {
headers: token ? {
Authorization: `Bearer ${token}`,
},
...basicHeaders,
} : basicHeaders,
tokenJSONpath: '$.token',
simpleEnumValues: true,
operationIdFieldNames,
});
return schema;
}
Expand All @@ -47,3 +43,25 @@ exports.createSchema = async (oas, kubeApiUrl, token) => {

return baseSchema;
};

exports.oasToGraphQlSchema = oasToGraphQlSchema;

/**
* stitch schemas by merging them, possibly prefixing root fields
* schemas is an object like { schema, prefix? }
*
* @param {GraphQLSchema[]} schemas
* @returns
*/
module.exports.joinSchemas = (schemas) => {
const subschemas = schemas.map(({ schema, prefix }) => ({
schema,
transforms: prefix ? [
new RenameRootFields((operation, name, _field) => `${prefix}_${name}`),
new RenameRootTypes((name) => `${prefix}_${name}`),
] : [],
}));

const schema = stitchSchemas({ subschemas });
return schema;
};

0 comments on commit 4997d13

Please sign in to comment.