Skip to content

Commit f3eb3cd

Browse files
committed
feat: Improve local dev setup
* Add Azure auth support to API server * Proxy front-end API calls to local API's default port * Stop front-end from unnecessarily polling namespaces * Use text field for active namespace when front-end not hooked up to the central dashboard * Stop namespace service from defaulting to "kubeflow" namespace
1 parent b7ee560 commit f3eb3cd

File tree

10 files changed

+109
-57
lines changed

10 files changed

+109
-57
lines changed

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"scripts": {
55
"ng": "ng",
66
"format": "prettier --write './**/*.{ts,html,css}'",
7-
"start": "ng serve --base-href /jupyter/ --deploy-url /jupyter/",
7+
"start": "ng serve --base-href /jupyter/ --deploy-url /jupyter/ --proxy-config proxy.config.js",
88
"build": "ng build --base-href /jupyter/ --deploy-url /jupyter/",
99
"test": "ng test",
1010
"lint": "ng lint",

frontend/proxy.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const PROXY_CONFIG = {
2+
'/api/*': {
3+
target: 'http://localhost:5000',
4+
secure: false,
5+
changeOrigin: true,
6+
logLevel: 'debug',
7+
bypass: function (req) {
8+
const uidHeader = process.env.KF_USER_ID;
9+
if (uidHeader) {
10+
req.headers['kubeflow-userid'] = uidHeader;
11+
}
12+
},
13+
},
14+
};
15+
16+
module.exports = PROXY_CONFIG;
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
<!-- Namespaces Selector -->
22
<mat-form-field>
33
<mat-label>Select Namespace</mat-label>
4-
<mat-select
4+
<input
5+
matInput
56
[(ngModel)]="currNamespace"
67
name="namespacesSelect"
7-
(selectionChange)="namespaceChanged($event.value)"
8-
>
9-
<mat-option *ngFor="let namespace of namespaces" [value]="namespace">
10-
{{ namespace }}
11-
</mat-option>
12-
</mat-select>
8+
(keyup.enter)="namespaceChanged(currNamespace)"
9+
/>
1310
</mat-form-field>
11+
<button
12+
mat-button
13+
color="accent"
14+
class="margin"
15+
(click)="namespaceChanged(currNamespace)"
16+
>
17+
Update
18+
</button>
Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { Component, OnInit, OnDestroy } from "@angular/core";
2-
import { first } from "rxjs/operators";
32
import { NamespaceService } from "src/app/services/namespace.service";
4-
import { KubernetesService } from "src/app/services/kubernetes.service";
5-
import { ExponentialBackoff } from "src/app/utils/polling";
63
import { Subscription } from "rxjs";
74

85
@Component({
@@ -11,51 +8,26 @@ import { Subscription } from "rxjs";
118
styleUrls: ["./namespace-select.component.scss"]
129
})
1310
export class NamespaceSelectComponent implements OnInit, OnDestroy {
14-
namespaces = [];
1511
currNamespace: string;
16-
private poller: ExponentialBackoff;
17-
private subscriptions = new Subscription();
1812

19-
constructor(
20-
private namespaceService: NamespaceService,
21-
private k8s: KubernetesService
22-
) {
23-
this.poller = new ExponentialBackoff();
24-
}
25-
26-
ngOnInit() {
27-
// Keep track of the selected namespace
28-
this.namespaceService.getSelectedNamespace().subscribe(namespace => {
29-
this.currNamespace = namespace;
30-
});
31-
32-
// Poll untill you get existing Namespaces
33-
const nsSub = this.poller.start().subscribe(() => {
34-
this.k8s.getNamespaces().subscribe(namespaces => {
35-
this.namespaces = namespaces;
36-
37-
if (
38-
this.currNamespace === undefined ||
39-
this.currNamespace.length === 0
40-
) {
41-
return;
42-
}
43-
44-
// stop polling
45-
this.namespaceService.updateSelectedNamespace(this.currNamespace);
46-
this.poller.stop();
47-
this.subscriptions.unsubscribe();
48-
});
49-
});
13+
private currNamespaceSub: Subscription;
5014

51-
this.subscriptions.add(nsSub);
52-
}
15+
constructor(private namespaceService: NamespaceService) { }
5316

54-
ngOnDestroy() {
55-
this.subscriptions.unsubscribe();
17+
ngOnInit() {
18+
this.currNamespaceSub = this.namespaceService
19+
.getSelectedNamespace()
20+
.subscribe(namespace => this.currNamespace = namespace);
5621
}
5722

5823
namespaceChanged(namespace: string) {
24+
if ("string" !== typeof namespace) {
25+
return;
26+
}
5927
this.namespaceService.updateSelectedNamespace(namespace);
6028
}
29+
30+
ngOnDestroy() {
31+
this.currNamespaceSub.unsubscribe();
32+
}
6133
}

frontend/src/app/main-table/resource-table/resource-table.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class ResourceTableComponent implements OnInit {
5252
this.dataSource.sort = this.sort;
5353

5454
// Create the exponential backoff poller
55-
this.poller = new ExponentialBackoff({ interval: 1000, retries: 3 });
55+
this.poller = new ExponentialBackoff({ interval: 2000, retries: 3 });
5656
const resourcesSub = this.poller.start().subscribe(() => {
5757
// NOTE: We are using both the 'trackBy' feature in the Table for performance
5858
// and also detecting with lodash if the new data is different from the old

frontend/src/app/services/namespace.service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ export class NamespaceService {
3030
cdeh.onNamespaceSelected = this.updateSelectedNamespace.bind(this);
3131
}
3232
);
33-
} else {
34-
this.updateSelectedNamespace("kubeflow");
3533
}
3634
});
3735
}

frontend/src/environments/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
export const environment = {
66
production: false,
7-
apiUrl: "http://localhost:5000",
7+
apiUrl: "",
88
resource: "notebooks",
99
ui: "default",
1010
rokUrl: ""

go.mod

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,34 @@ module github.com/StatCan/jupyter-apis
33
go 1.14
44

55
require (
6+
github.com/Azure/go-autorest/autorest v0.11.4 // indirect
7+
github.com/Azure/go-autorest/autorest/adal v0.9.2 // indirect
68
github.com/StatCan/kubeflow-controller v0.0.0-20200811133651-33215007413e
79
github.com/andanhm/go-prettytime v1.0.0
810
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef // indirect
911
github.com/golang/protobuf v1.4.2 // indirect
12+
github.com/google/gofuzz v1.2.0 // indirect
1013
github.com/gorilla/handlers v1.4.2
1114
github.com/gorilla/mux v1.7.4
1215
github.com/hashicorp/golang-lru v0.5.4 // indirect
1316
github.com/imdario/mergo v0.3.10 // indirect
1417
github.com/json-iterator/go v1.1.10 // indirect
1518
github.com/kr/pretty v0.2.0 // indirect
16-
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 // indirect
17-
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
19+
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de // indirect
20+
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc // indirect
1821
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
22+
golang.org/x/sys v0.0.0-20200817155316-9781c653f443 // indirect
1923
golang.org/x/text v0.3.3 // indirect
2024
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
25+
google.golang.org/appengine v1.6.6 // indirect
26+
google.golang.org/protobuf v1.25.0 // indirect
2127
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
2228
gopkg.in/inf.v0 v0.9.1
2329
gopkg.in/yaml.v2 v2.3.0
2430
k8s.io/api v0.18.6
25-
k8s.io/apimachinery v0.18.6
31+
k8s.io/apimachinery v0.18.8
2632
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
27-
k8s.io/utils v0.0.0-20200603063816-c1c6865ac451 // indirect
33+
k8s.io/utils v0.0.0-20200815180417-3bc9d57fc792 // indirect
2834
)
2935

3036
replace k8s.io/client-go => k8s.io/client-go v0.18.6

0 commit comments

Comments
 (0)