Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nwmac committed Mar 19, 2019
1 parent 3439dbe commit 766aac3
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@ src/frontend/packages/core/src/index.html
# Prebuild package

stratos-frontend-prebuild.zip

src/frontend/assets
src/frontend/sass
2 changes: 1 addition & 1 deletion custom-src/frontend/app/custom/custom-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const kubernetes: Routes = [
text: 'Helm',
matIcon: 'helm',
matIconFont: 'stratos-icons',
position: 60,
position: 65,
requiresEndpointType: 'helm'
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
<app-page-header [tabs]="tabLinks">
<h1>{{ (kubeEndpointService.endpoint$ | async)?.entity.name }}</h1>
<app-page-header [breadcrumbs]="breadcrumbs$ | async" [tabs]="tabLinks">
<h1>Dashboard</h1>
<div class="page-header-right" [ngClass]="{'kube-dashboard__hidden': isLoading$ | async }">
<span>
<!--
<mat-form-field floatLabel="never">
<input matInput [(ngModel)]="searchTerms" name="searchTerms" placeholder="Search" (keyup)="onKey($event)">
</mat-form-field>
-->
<button mat-icon-button (click)="toggle()" *ngIf="expanded">
<mat-icon matTooltip="Collapse">expand_less</mat-icon>
</button>
<button mat-icon-button (click)="toggle()" *ngIf="!expanded">
<mat-icon matTooltip="Expand">expand_more</mat-icon>
</button>
<!--
<button mat-icon-button (click)="create()">
<mat-icon matTooltip="Create">add</mat-icon>
</button>
-->
</span>
</div>
</app-page-header>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { BehaviorSubject } from 'rxjs';
import { BehaviorSubject, Observable } from 'rxjs';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
import { Component, OnInit, ViewChild, ElementRef, Renderer2 } from '@angular/core';
import { KubernetesEndpointService } from '../services/kubernetes-endpoint.service';
import { BaseKubeGuid } from '../kubernetes-page.types';
import { ActivatedRoute } from '@angular/router';
import { KubernetesService } from '../services/kubernetes.service';
import { IHeaderBreadcrumb } from '../../../shared/components/page-header/page-header.types';
import { map } from 'rxjs/operators';

@Component({
selector: 'app-kubernetes-dashboard',
Expand Down Expand Up @@ -38,6 +40,8 @@ export class KubernetesDashboardTabComponent implements OnInit {

href = '';

public breadcrumbs$: Observable<IHeaderBreadcrumb[]>;

constructor(public kubeEndpointService: KubernetesEndpointService, private sanitizer: DomSanitizer, public renderer: Renderer2) { }

ngOnInit() {
Expand All @@ -50,6 +54,15 @@ export class KubernetesDashboardTabComponent implements OnInit {
this.href = href;
this.source = this.sanitizer.bypassSecurityTrustResourceUrl(`/pp/v1/kubedash/${guid}/`);
console.log(window.location);

this.breadcrumbs$ = this.kubeEndpointService.endpoint$.pipe(
map(endpoint => ([{
breadcrumbs: [
{ value: endpoint.entity.name, routerLink: `/kubernetes/${endpoint.entity.guid}` },
]
}])
)
);
}

iframeLoaded() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { KubernetesService } from '../services/kubernetes.service';
export class KubernetesTabBaseComponent implements OnInit {

tabLinks = [
{ link: 'summary', label: 'Summary' },
{ link: 'nodes', label: 'Nodes' },
{ link: 'namespaces', label: 'Namespaces' },
{ link: 'pods', label: 'Pods' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { KubernetesNodeMetricsComponent } from './kubernetes-node/kubernetes-nod
import { KubernetesNamespaceComponent } from './kubernetes-namespace/kubernetes-namespace.component';
import { KubernetesNamespacePodsComponent } from './kubernetes-namespace/kubernetes-namespace-pods/kubernetes-namespace-pods.component';
import { KubernetesDashboardTabComponent } from './kubernetes-dashboard/kubernetes-dashboard.component';
import { KubernetesSummaryTabComponent } from './tabs/kubernetes-summary-tab/kubernetes-summary.component';

const kubernetes: Routes = [{
path: '',
component: KubernetesComponent
Expand Down Expand Up @@ -120,9 +122,13 @@ const kubernetes: Routes = [{
children: [
{
path: '',
redirectTo: 'nodes',
redirectTo: 'summary',
pathMatch: 'full'
},
{
path: 'summary',
component: KubernetesSummaryTabComponent
},
{
path: 'nodes',
component: KubernetesNodesTabComponent
Expand Down
1 change: 0 additions & 1 deletion src/jetstream/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ func (p *portalProxy) urlCheckMiddleware(h echo.HandlerFunc) echo.HandlerFunc {

func (p *portalProxy) setStaticCacheContentMiddleware(h echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
log.Debug("setStaticContentHeadersMiddleware")
c.Response().Header().Set("cache-control", "no-cache")
return h(c)
}
Expand Down
38 changes: 17 additions & 21 deletions src/jetstream/plugins/kubernetes/kube_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func normalizeLocation(location *url.URL) *url.URL {
}

func (k *KubernetesSpecification) kubeDashboardTest(c echo.Context) error {
log.Info("kubeDashboardTest request")
log.Debug("kubeDashboardTest request")

// c.Response().Header().Set("X-FRAME-OPTIONS", "sameorigin")

Expand All @@ -104,16 +104,13 @@ func (k *KubernetesSpecification) kubeDashboardTest(c echo.Context) error {

var p = k.portalProxy

log.Info(userGUID)
log.Info(cnsiGUID)

log.Info(c.Request().RequestURI)
log.Debug(c.Request().RequestURI)

var prefix = "/pp/v1/kubedash/" + cnsiGUID + "/"

path := c.Request().RequestURI[len(prefix):]

log.Info(path)
log.Debug(path)

cnsiRecord, err := p.GetCNSIRecord(cnsiGUID)
if err != nil {
Expand All @@ -128,18 +125,18 @@ func (k *KubernetesSpecification) kubeDashboardTest(c echo.Context) error {
return errors.New("Could not get token")
}

log.Info(tokenRec.AuthToken)
log.Info(tokenRec.AuthType)
log.Debug(tokenRec.AuthToken)
log.Debug(tokenRec.AuthType)

// Make the info call to the SSH endpoint info
// Currently this is not cached, so we must get it each time
apiEndpoint := cnsiRecord.APIEndpoint
log.Info(apiEndpoint)
log.Debug(apiEndpoint)
// target := fmt.Sprintf("%s/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/", apiEndpoint)
//target := fmt.Sprintf("%s/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/", apiEndpoint)
// target := http://localhost:8001/api/v1/namespaces/kube-system/services/kubernetes-dashboard/proxy
target := fmt.Sprintf("%s/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/%s", apiEndpoint, path)
log.Info(target)
log.Debug(target)
targetURL, _ := url.Parse(target)
targetURL = normalizeLocation(targetURL)

Expand All @@ -148,12 +145,12 @@ func (k *KubernetesSpecification) kubeDashboardTest(c echo.Context) error {
return errors.New("Could not get config for this auth type")
}

log.Info("Config")
log.Info(config.Host)
log.Info("Making request")
log.Debug("Config")
log.Debug(config.Host)
log.Debug("Making request")
req := c.Request()
w := c.Response().Writer
log.Infof("%v+", req)
log.Debugf("%v+", req)

// if h.tryUpgrade(w, req) {
// return
Expand Down Expand Up @@ -181,7 +178,6 @@ func (k *KubernetesSpecification) kubeDashboardTest(c echo.Context) error {
if len(req.URL.RawQuery) > 0 {
queryPart = "?" + req.URL.RawQuery
}
log.Warn("REDIRECT")
w.Header().Set("Location", req.URL.Path+"/"+queryPart)
w.WriteHeader(http.StatusMovedPermanently)
return nil
Expand All @@ -205,21 +201,21 @@ func (k *KubernetesSpecification) kubeDashboardTest(c echo.Context) error {
proxy.Transport = transport
proxy.FlushInterval = defaultFlushInterval
proxy.ModifyResponse = func(response *http.Response) error {
log.Infof("GOT PROXY RESPONSE: %s", loc.String())
log.Infof("%d", response.StatusCode)
log.Info(response.Header.Get("Content-Type"))
log.Debugf("GOT PROXY RESPONSE: %s", loc.String())
log.Debugf("%d", response.StatusCode)
log.Debug(response.Header.Get("Content-Type"))

log.Infof("%v+", response.Header)
log.Debugf("%v+", response.Header)
response.Header.Del("X-FRAME-OPTIONS")
response.Header.Set("X-FRAME-OPTIONS", "sameorigin")
log.Info("%v+", response)
log.Debug("%v+", response)
return nil
}

// Note that ServeHttp is non blocking and uses a go routine under the hood
proxy.ServeHTTP(w, newReq)

log.Infof("Finsihed proxying request: %s", target)
log.Debugf("Finsihed proxying request: %s", target)

return nil
}
56 changes: 56 additions & 0 deletions src/jetstream/plugins/kubernetes/list_releases.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package kubernetes

import (
"net/url"

"github.com/labstack/echo"
log "github.com/sirupsen/logrus"

Expand All @@ -12,6 +14,19 @@ import (
"github.com/cloudfoundry-incubator/stratos/src/jetstream/repository/interfaces"
)

type kubeReleasesData struct {
Endpoint string `json:"endpoint"`
Name string `json:"releaseName"`
Namespace string `json:"releaseNamespace"`
Chart struct {
Name string `json:"chartName"`
Repository string `json:"repo"`
Version string `json:"version"`
} `json:"chart"`
}

type kubeReleasesResponse map[string]kubeReleasesData

// ListReleases will list the helm releases for all endpoints
func (c *KubernetesSpecification) ListReleases(ec echo.Context) error {

Expand Down Expand Up @@ -51,3 +66,44 @@ func (c *KubernetesSpecification) listReleases(ep *interfaces.ConnectedEndpoint,
response.Result = res
done <- response
}

// ListReleases will list the helm releases for all endpoints
func (c *KubernetesSpecification) aListReleases(ec echo.Context) error {

// Need to get a config object for the target endpoint
// endpointGUID := ec.Param("endpoint")
userID := ec.Get("user_id").(string)

// Get the config maps directly - don't go via Tiller

requests := c.makeKubeProxyRequest(userID, "GET", "/api/v1/configmaps?labelSelector=OWNER%3DTILLER")
responses, _ := c.portalProxy.DoProxyRequest(requests)
return c.portalProxy.SendProxiedResponse(ec, responses)
}

func (c *KubernetesSpecification) makeKubeProxyRequest(userID, method, uri string) []interfaces.ProxyRequestInfo {

var p = c.portalProxy
eps, err := p.ListEndpointsByUser(userID)
if err != nil {
return nil
}

// Construct the metadata for proxying
requests := make([]interfaces.ProxyRequestInfo, 0)
for _, endpoint := range eps {
if endpoint.CNSIType == "k8s" {
req := interfaces.ProxyRequestInfo{}
req.UserGUID = userID
req.ResultGUID = endpoint.GUID
req.EndpointGUID = endpoint.GUID
req.Method = method

uri, _ := url.Parse(uri)
req.URI = uri
requests = append(requests, req)
}
}

return requests
}

0 comments on commit 766aac3

Please sign in to comment.