Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
WIP: Kubernetes terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
nwmac committed Jun 2, 2020
1 parent fac7061 commit dedfe8e
Show file tree
Hide file tree
Showing 13 changed files with 230 additions and 146 deletions.
4 changes: 4 additions & 0 deletions custom-src/deploy/kubernetes/custom-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ function custom_image_build() {
# Build and push an image for the Helm Repo Sync Tool
log "-- Building/publishing Monocular Chart Repo Sync Tool"
patchAndPushImage stratos-chartsync Dockerfile "${STRATOS_PATH}/src/jetstream/plugins/monocular/chart-repo"

# Build and push an image for the Kubernetes Terminal
log "-- Building/publishing Kubernetes Terminal"
patchAndPushImage stratos-kube-terminal Dockerfile.kubeconsole "${STRATOS_PATH}/deploy/containers/kube-terminal"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<app-page-header [breadcrumbs]="breadcrumbs$ | async">
<h1>Kubernetes Console</h1>
<h1>Kubernetes Terminal</h1>
<div class="page-header-right">
<span>
<button mat-icon-button matTooltip="Disconnect" name="stop" *ngIf="sshViewer.isConnected" (click)="sshViewer.disconnect()" [disabled]="sshViewer.attemptingConnection">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ export class KubeConsoleComponent implements OnInit {
tap(() => this.connectionStatus.next(1)),
switchMap(getResponse => getResponse(this.sshInput)),
catchError((e: Error) => {
console.log(e.message);
if (e.message !== normalClosureMessage) {
this.errorMessage = 'Error connecting to web socket';
this.errorMessage = 'Error launching Kubernetes Terminal';
}
return [];
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<span class="kube-details__button">View Dashboard</span>
</button>
<button [routerLink]="kubeConsoleLink" mat-button>
<mat-icon>dashboard</mat-icon>
<span class="kube-details__button">Open Console</span>
<mat-icon>desktop_windows</mat-icon>
<span class="kube-details__button">Open Terminal</span>
</button>
</app-page-sub-nav>

Expand Down
18 changes: 0 additions & 18 deletions deploy/Dockerfile.kubeconsole.yml

This file was deleted.

40 changes: 40 additions & 0 deletions deploy/containers/kube-terminal/Dockerfile.kubeconsole
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM splatform/stratos-bk-build-base:leap15_1 as terminal-builder
USER root
WORKDIR /root

#RUN zypper in -y tar

# Kubectl versions
RUN curl -L -o kubectl_1.18 https://storage.googleapis.com/kubernetes-release/release/v1.18.2/bin/linux/amd64/kubectl
RUN curl -L -o kubectl_1.17 https://storage.googleapis.com/kubernetes-release/release/v1.17.5/bin/linux/amd64/kubectl
#RUN curl -L -o kubectl_1.16 https://storage.googleapis.com/kubernetes-release/release/v1.16.9/bin/linux/amd64/kubectl
#RUN curl -L -o kubectl_1.15 https://storage.googleapis.com/kubernetes-release/release/v1.15.11/bin/linux/amd64/kubectl
RUN curl -L -o kubectl_1.14 https://storage.googleapis.com/kubernetes-release/release/v1.14.10/bin/linux/amd64/kubectl

# Tar each one up, to save space in the image
RUN gzip kubectl_1.18
RUN gzip kubectl_1.17
RUN gzip kubectl_1.14

# Fetch Helm 3 package
RUN curl -L -o helm.tar.gz https://get.helm.sh/helm-v3.1.2-linux-amd64.tar.gz && \
tar -xvf helm.tar.gz --strip-components=1 && \
gzip helm

RUN ls -al

FROM splatform/stratos-bk-init-base:leap15_1

RUN zypper in -y gzip

RUN mkdir /stratos

# Copy the various kubectl versions

COPY --from=terminal-builder /root/helm.gz /stratos/helm.gz
COPY --from=terminal-builder /root/kubectl* /stratos/

ADD ./kubeconsole.bashrc /root/.bashrc
WORKDIR /root

CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait"
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,42 @@ RESET="\033[0m"
BOLD="\033[1m"
DIM="\033[2m"

echo -e "${BOLD}${GREEN}SUSE Cloud Application Platform${RESET}"
echo -e "${BOLD}${GREEN}SUSE Stratos Console${RESET}"
echo ""
echo -e "${CYAN}Kubernetes Console${RESET}"
echo -e "${CYAN}Kubernetes Terminal${RESET}"
echo ""

# Unpack helm comand
gunzip /stratos/helm.gz

# Need to choose appropriate kubectl version
pushd /stratos > /dev/null
# Default to the newwest version that we have
USE=$(ls kubectl_* | sort -r | head -n1)
popd > /dev/null

# If env var KUBERNETES_VERSION is set, then use it (major.minor only)
if [ -n "${KUBERNETES_VERSION}" ]; then
VERSION="kubectl_${KUBERNETES_VERSION}.gz"
if [ -f "/stratos/${VERSION}" ]; then
USE=${VERSION}
fi
fi

gunzip /stratos/${USE}
VER=${USE::-3}
mv /stratos/${VER} /stratos/kubectl
chmod +x /stratos/kubectl
export PATH=/stratos:$PATH

export KUBECONFIG=/root/.stratos/kubeconfig
export PS1="\033[92mstratos>\033[0m"
alias k=kubectl

helm init --client-only > /dev/null
helm repo remove local > /dev/null
helm repo remove stable > /dev/null
# Helm shell completion
source <(helm completion bash)

#helm repo remove stable > /dev/null

if [ -f "/root/.stratos/helm-setup" ]; then
echo "Setting up Helm repositories ..."
Expand All @@ -26,7 +50,6 @@ if [ -f "/root/.stratos/helm-setup" ]; then
echo ""
fi


if [ -f "/root/.stratos/history" ]; then
cat /root/.stratos/history > /root/.bash_history
fi
Expand Down
4 changes: 4 additions & 0 deletions deploy/kubernetes/console/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ spec:
env:
- name: STRATOS_HELM_RELEASE
value: "{{ .Release.Name }}"
- name: STRATOS_KUBERNETES_NAMESPACE
value: "{{ .Release.Namespace }}"
- name: STRATOS_KUBERNETES_TERMINAL_IMAGE
value: "{{.Values.kube.registry.hostname}}/{{.Values.kube.organization}}/stratos-kube-terminal:{{.Values.consoleVersion}}"
- name: DB_USER
valueFrom:
secretKeyRef:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="ssh-viewer">
<div class="ssh-viewer__overlay" *ngIf="!message && (errorMessage || !isConnected)">
<div class="ssh-viewer__error" *ngIf="errorMessage">
Error occurred establishing SSH connection
{{ errorMessage || 'Error occurred establishing SSH connection' }}
</div>
<div class="ssh-viewer__disconnected" *ngIf="!errorMessage && !isConnected && !isConnecting">
Disconnected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ export class SshViewerComponent implements OnInit, OnDestroy {
for (const c of data.split(' ')) {
this.xterm.write(String.fromCharCode(parseInt(c, 16)));
}
} else {
console.log('Error')
const eMsg = this.errorMessage;
//this.disconnect();
this.errorMessage = eMsg;
}
},
(err) => {
Expand All @@ -146,6 +151,11 @@ export class SshViewerComponent implements OnInit, OnDestroy {
for (let i = 4; i < chars.length - 1; i++) {
title += String.fromCharCode(parseInt(chars[i], 16));
}
if (title.length > 0 && title.charAt(0) === '!') {
this.errorMessage = title.substr(1);
console.log(this.errorMessage);
return true;
}
this.message = title;
}
return false;
Expand Down
9 changes: 7 additions & 2 deletions src/jetstream/plugins/kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ import (
log "github.com/sirupsen/logrus"

"github.com/cloudfoundry-incubator/stratos/src/jetstream/plugins/kubernetes/auth"

"github.com/cloudfoundry-incubator/stratos/src/jetstream/plugins/kubernetes/terminal"
)

// KubernetesSpecification is the endpoint that adds Kubernetes support to the backend
type KubernetesSpecification struct {
portalProxy interfaces.PortalProxy
endpointType string
kubeTerminal *terminal.KubeTerminal
}

type KubeStatus struct {
Expand Down Expand Up @@ -53,8 +56,10 @@ const (
kubeDashboardPluginConfigSetting = "kubeDashboardEnabled"
)

// Init creates a new instance of the Kubernetes plugin
func Init(portalProxy interfaces.PortalProxy) (interfaces.StratosPlugin, error) {
return &KubernetesSpecification{portalProxy: portalProxy, endpointType: kubeEndpointType}, nil
kubeTerminal := terminal.NewKubeTerminal(portalProxy)
return &KubernetesSpecification{portalProxy: portalProxy, endpointType: kubeEndpointType, kubeTerminal: kubeTerminal}, nil
}

func (c *KubernetesSpecification) GetEndpointPlugin() (interfaces.EndpointPlugin, error) {
Expand Down Expand Up @@ -160,7 +165,7 @@ func (c *KubernetesSpecification) AddSessionGroupRoutes(echoGroup *echo.Group) {
echoGroup.GET("/helm/releases/:endpoint/:namespace/:name", c.GetRelease)

// Kube Terminal
echoGroup.GET("/kubeconsole/:guid", c.KubeConsole)
echoGroup.GET("/kubeconsole/:guid", c.KubeTerminal)

}

Expand Down
Loading

0 comments on commit dedfe8e

Please sign in to comment.