-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wg102
committed
Sep 17, 2020
1 parent
22bdc13
commit 2095188
Showing
19 changed files
with
407 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,143 @@ | ||
import { Component, OnInit } from "@angular/core"; | ||
import { NamespaceService } from "../services/namespace.service"; | ||
import { KubernetesService } from "src/app/services/kubernetes.service"; | ||
|
||
import { Subscription } from "rxjs"; | ||
import { isEqual } from "lodash"; | ||
import { first } from "rxjs/operators"; | ||
|
||
import { ExponentialBackoff } from "src/app/utils/polling"; | ||
import { MatDialog } from "@angular/material/dialog"; | ||
import { ConfirmDialogComponent } from "./confirm-dialog/confirm-dialog.component"; | ||
import { Pvc, Volume, Resource } from "../utils/types"; | ||
|
||
|
||
@Component({ | ||
selector: "app-main-table", | ||
templateUrl: "./main-table.component.html", | ||
styleUrls: ["./main-table.component.scss"] | ||
}) | ||
export class MainTableComponent implements OnInit { | ||
currNamespace = ""; | ||
namespaces = []; | ||
currNamespace: string; | ||
resources = []; | ||
usedPVCs: Set<string> = new Set<string>(); | ||
pvcs: Volume[] = []; | ||
customPvcs: Pvc[] = []; | ||
|
||
subscriptions = new Subscription(); | ||
poller: ExponentialBackoff; | ||
|
||
constructor( | ||
public ns: NamespaceService, | ||
private k8s: KubernetesService, | ||
private dialog: MatDialog | ||
) {} | ||
|
||
ngOnInit() { | ||
this.poller = new ExponentialBackoff({ interval: 2000, retries: 3 }); | ||
const resourcesSub = this.poller.start().subscribe(() => { | ||
if (!this.currNamespace) { | ||
return; | ||
} | ||
|
||
let getVolumes = this.k8s.getVolumes(this.currNamespace).toPromise().then( | ||
pvcs => { | ||
if(isEqual(this.pvcs, pvcs)){ | ||
return; | ||
} | ||
this.pvcs = pvcs; | ||
} | ||
); | ||
|
||
let getResource = this.k8s.getResource(this.currNamespace).toPromise().then( | ||
resources => { | ||
if (isEqual(this.resources, resources)){ | ||
return; | ||
} | ||
this.resources = resources; | ||
this.usedPVCs.clear(); | ||
this.resources.forEach(res => {this.usedPVCs.add(res.volumes.forEach(element => {this.usedPVCs.add(element);}))}) | ||
}); | ||
|
||
Promise.all([getVolumes, getResource]) | ||
.then(val => { | ||
this.customPvcs = []; | ||
this.pvcs.forEach(vol => { | ||
this.customPvcs.push({pvc:vol, ismounted:this.usedPVCs.has(vol.name)}); | ||
}); | ||
}); | ||
}); | ||
|
||
// Keep track of the selected namespace | ||
const namespaceSub = this.ns | ||
.getSelectedNamespace() | ||
.subscribe(namespace => { | ||
this.currNamespace = namespace; | ||
this.poller.reset(); | ||
}); | ||
|
||
this.subscriptions.add(resourcesSub); | ||
this.subscriptions.add(namespaceSub); | ||
} | ||
|
||
deleteResource(rsrc: Resource): void { | ||
const dialogRef = this.dialog.open(ConfirmDialogComponent, { | ||
width: "fit-content", | ||
data: { | ||
title: "You are about to delete Notebook Server: " + rsrc.name, | ||
message: | ||
"Are you sure you want to delete this Notebook Server? " + | ||
"Your data might be lost if the Server is not backed by persistent storage.", | ||
yes: "delete", | ||
no: "cancel" | ||
} | ||
}); | ||
|
||
dialogRef | ||
.afterClosed() | ||
.pipe(first()) | ||
.subscribe(result => { | ||
if (!result || result !== "delete") { | ||
return; | ||
} | ||
|
||
this.k8s | ||
.deleteResource(rsrc.namespace, rsrc.name) | ||
.pipe(first()) | ||
.subscribe(r => { | ||
this.poller.reset(); | ||
}); | ||
}); | ||
} | ||
|
||
deletePvc(p: Pvc): void { | ||
const dialogRef = this.dialog.open(ConfirmDialogComponent, { | ||
width: "fit-content", | ||
data: { | ||
title: "You are about to delete the PVC: " + p.pvc.name, | ||
message: | ||
"Are you sure you want to delete this Persistent Volume Claim? ", | ||
yes: "delete", | ||
no: "cancel" | ||
} | ||
}); | ||
|
||
dialogRef | ||
.afterClosed() | ||
.pipe(first()) | ||
.subscribe(result => { | ||
if (result !== "delete") { | ||
return; | ||
} | ||
|
||
constructor(public ns: NamespaceService) {} | ||
this.k8s | ||
.deletePersistentStorageClaim(p.pvc.namespace, p.pvc.name) | ||
.pipe(first()) | ||
.subscribe(r => { | ||
this.poller.reset(); | ||
}); | ||
}); | ||
} | ||
|
||
ngOnInit() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 0 additions & 86 deletions
86
frontend/src/app/main-table/resource-table/resource-table.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +0,0 @@ | ||
.card { | ||
width: 900px; | ||
padding: 0px; | ||
border-radius: 5px; | ||
background: white; | ||
} | ||
|
||
table { | ||
width: 100%; | ||
} | ||
|
||
.header { | ||
display: flex; | ||
align-items: center; | ||
padding: 0px 16px 0px 16px; | ||
height: 64px; | ||
} | ||
|
||
.header p { | ||
font-weight: 400; | ||
font-size: 20px; | ||
} | ||
|
||
.cdk-column-actions { | ||
text-align: center; | ||
} | ||
|
||
.mat-icon { | ||
line-height: 0.85; | ||
} | ||
|
||
td.mat-cell:last-of-type, | ||
td.mat-footer-cell:last-of-type, | ||
th.mat-header-cell:last-of-type { | ||
padding-right: 0px; | ||
} | ||
|
||
.inline { | ||
display: inline-block; | ||
} | ||
|
||
// Status Icons | ||
.running { | ||
color: green; | ||
} | ||
|
||
.warning { | ||
color: orange; | ||
} | ||
|
||
.error { | ||
color: red; | ||
} | ||
|
||
.status { | ||
display: inline-flex; | ||
vertical-align: middle; | ||
} | ||
|
||
.delete { | ||
color: red; | ||
} | ||
|
||
// Flex | ||
.parent { | ||
display: flex; | ||
} | ||
|
||
.spacer { | ||
flex-grow: 1; | ||
} | ||
|
||
th, | ||
td { | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} | ||
|
||
td.mat-column-image, | ||
td.mat-column-name { | ||
max-width: 200px; | ||
} | ||
|
||
td.mat-column-cpu { | ||
width: 40px; | ||
} | ||
Oops, something went wrong.