Skip to content

Commit

Permalink
updating kubernetes client & some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
asere authored and asere committed Aug 28, 2023
1 parent f9a4abd commit 7eeccf8
Show file tree
Hide file tree
Showing 7 changed files with 5,740 additions and 5,250 deletions.
10,617 changes: 5,547 additions & 5,070 deletions BackEnd/package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion BackEnd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"license": "MIT",
"dependencies": {
"@kubernetes/client-node": "^0.13.2",
"@kubernetes/client-node": "^0.18.1",
"archiver": "^5.2.0",
"axios": "^0.24.0",
"child_process": "^1.0.2",
Expand All @@ -43,6 +43,7 @@
"passport-local": "1.0.0",
"rimraf": "^3.0.2",
"slug": "4.0.2",
"typescript": "^5.2.2",
"unzipper": "^0.10.11"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions BackEnd/src/controllers/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export function serverAPI(cloud: CloudService) {
server.author = user;
log_functions.create('bin', 'post /server/', log_message.user_server_created, user, server);
return server.save().then(async function() {
await cloud.createContainer(server.slug)
await copyObjects(cloud, env.OS_DEFAULT_CONTAINER, server.slug)
await cloud.createContainer(server.slug as string)
await copyObjects(cloud, env.OS_DEFAULT_CONTAINER, server.slug as string)

log_functions.create('general', 'post /server/',
log_message.user_swift_created, user, server);
Expand Down
14 changes: 10 additions & 4 deletions BackEnd/src/lib/server_functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const k8sApiDeploy = kc.makeApiClient(k8s.AppsV1Api);
const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
const k8sApiIngress = kc.makeApiClient(k8s.ExtensionsV1beta1Api);
const k8sApiIngress = kc.makeApiClient(k8s.NetworkingV1Api);

k8sApiIngress.defaultHeaders = {
'Content-Type': 'application/strategic-merge-patch+json',
Expand Down Expand Up @@ -204,12 +204,18 @@ function createObjectService(slug : string) {
export function createObjectRule(slug : string, username : string) {
return {
// TODO: remove hard coded URL
host: username + '.' + slug + '.learn-ocaml.org',
host: slug + "-" + username + ".learn-ocaml.org",
http: {
paths: [{
path: "/",
pathType: "Prefix",
backend: {
serviceName: slug,
servicePort: 80
service: {
name: slug,
port: {
number: 80
}
}
}
}]
}
Expand Down
4 changes: 2 additions & 2 deletions BackEnd/src/lib/upload_functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export async function createArchiveFromDirectory(source : string, dest : string,
var files = read(source)
.map((file : string) =>
[path.join(source, file), path.join(dest, file)]);
if (files === []) {
if (files.length == 0) {
throw 'empty files list';
}
await createArchive(files, format, archive_name);
Expand Down Expand Up @@ -321,7 +321,7 @@ export function download_from_url(file_url : any, dest_path : any) {
export function delete_useless_files(useless : any, path : any,
tabOfName : any, files : any) {
return new Promise(function (resolve, reject) {
if (useless === [] || useless === undefined || useless === null) {
if (!Array.isArray(useless) || useless.length == 0) {
return resolve('nothing to delete');
}
//console.log('tabOfName before filter : ' + tabOfName);
Expand Down
47 changes: 25 additions & 22 deletions BackEnd/src/models/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,31 @@ var ServerSchema = new mongoose.Schema({
author: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
token: String,
url: String
}, { timestamps: true });
}, {
timestamps: true,
methods: {
slugify() {
// this.slug = slug(this.title) + '-' + (Math.random() * Math.pow(36, 6) | 0).toString(36);
(this as any).slug = slug((this as any).title);
},

toJSONFor(user) {
return {
slug: (this as any).slug,
title: (this as any).title,
description: (this as any).description,
body: (this as any).body,
createdAt: (this as any).createdAt,
updatedAt: (this as any).updatedAt,
author: (this as any).author.toProfileJSONFor(user),
active: (this as any).active,
volume: (this as any).volume,
token: (this as any).token,
url: (this as any).url
};
}
}
});

ServerSchema.plugin(uniqueValidator, { message: 'is already taken' });

Expand All @@ -26,25 +50,4 @@ ServerSchema.pre('validate', function (next) {
next();
});

ServerSchema.methods.slugify = function () {
// this.slug = slug(this.title) + '-' + (Math.random() * Math.pow(36, 6) | 0).toString(36);
(this as any).slug = slug((this as any).title);
};

ServerSchema.methods.toJSONFor = function (user) {
return {
slug: (this as any).slug,
title: (this as any).title,
description: (this as any).description,
body: (this as any).body,
createdAt: (this as any).createdAt,
updatedAt: (this as any).updatedAt,
author: (this as any).author.toProfileJSONFor(user),
active: (this as any).active,
volume: (this as any).volume,
token: (this as any).token,
url: (this as any).url
};
};

export const Server = mongoose.model('Server', ServerSchema);
Loading

0 comments on commit 7eeccf8

Please sign in to comment.