Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kubernetes pod enter container action #298

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/backend/controllers/kubernetes/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func (c *KubePodController) List() {
deployment := c.Input().Get("deployment")
statefulset := c.Input().Get("statefulset")
daemonSet := c.Input().Get("daemonSet")
podName := c.Input().Get("pod")
job := c.Input().Get("job")
manager, err := client.Manager(cluster)
if err == nil {
Expand All @@ -117,6 +118,10 @@ func (c *KubePodController) List() {
result, err = pod.GetPodsByDaemonSet(manager.CacheFactory, namespace, daemonSet)
} else if job != "" {
result, err = pod.GetPodsByJob(manager.CacheFactory, namespace, job)
} else if podName != "" {
var podInfo *pod.Pod
podInfo, err = pod.GetPodByName(manager.Client, namespace, podName)
result = []*pod.Pod{podInfo}
} else {
err = fmt.Errorf("unknown resource type. ")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

<wayne-list-pod
[resources]="resources"
[cluster]="cluster"
[showState]="showState"
(delete)="onDeleteResourceEvent($event)"
(edit)="onEditResourceEvent($event)"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ConfirmationDialogService } from '../../../shared/confirmation-dialog/confirmation-dialog.service';
import { MessageHandlerService } from '../../../shared/message-handler/message-handler.service';
import { ClusterService } from '../../../shared/client/v1/cluster.service';
import { AuthService } from '../../../shared/auth/auth.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
<button class="action-item" (click)="onEditEvent(obj)">{{'ADMIN.KUBERNETES.ACTION.EDIT' | translate}}</button>
<button class="action-item" (click)="onDeleteEvent(obj)">{{'ADMIN.KUBERNETES.ACTION.DELETE' | translate}}</button>
<button class="action-item" (click)="onForceDeleteEvent(obj)">{{'ADMIN.KUBERNETES.ACTION.FORCEDELETE' | translate}}</button>
<button class="action-item" (click)="enterContainer(obj)">{{'ADMIN.KUBERNETES.ACTION.ENTER_CONTAINER' | translate}}</button>
<button class="action-item" (click)="podLog(obj)">{{'ADMIN.KUBERNETES.ACTION.LOG' | translate}}</button>
</clr-dg-action-overflow>
<clr-dg-cell> {{ obj.metadata.name }} </clr-dg-cell>
<clr-dg-cell class="col-version">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,24 @@ import { KubePod } from '../../../../shared/model/v1/kubernetes/kubepod';
export class ListPodComponent extends KubernetesListResource {
@Input() resources: any[];
@Input() showState: object;
@Input() cluster: string;

constructor(public tplDetailService: TplDetailService) {
super(tplDetailService);
}

enterContainer(pod: KubePod): void {
const url = `portal/namespace/0/app/0/pod` +
`/${pod.metadata.name}/pod/${pod.metadata.name}/terminal/${this.cluster}/${pod.metadata.namespace}`;
window.open(url, '_blank');
}

podLog(pod: KubePod): void {
const url = `portal/logging/namespace/0/app/0/pod/${pod.metadata.name}` +
`/pod/${pod.metadata.name}/${this.cluster}/${pod.metadata.namespace}`;
window.open(url, '_blank');
}

// getPodStatus returns the pod state
getPodStatus(pod: KubePod): string {
// Terminating
Expand Down
24 changes: 13 additions & 11 deletions src/frontend/src/app/shared/list-pod/list-pod.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { AuthService } from '../auth/auth.service';
styleUrls: ['list-pod.scss']
})

export class ListPodComponent implements OnDestroy {
export class ListPodComponent implements OnDestroy {
@Input() Type: string;
checkOnGoing = false;
isSubmitOnGoing = false;
Expand All @@ -38,7 +38,7 @@ export class ListPodComponent implements OnDestroy {
timeComparator = new TimeComparator();
stateComparator = new StateComparator();
currentCluster: string;
deployment: string;
resourceName: string;
logSource: string;
timer: any;
whetherHotReflash = true;
Expand Down Expand Up @@ -87,9 +87,9 @@ export class ListPodComponent implements OnDestroy {
clearInterval(this.timer);
}

openModal(cluster: string, deployment: string) {
openModal(cluster: string, resourceName: string) {
this.currentCluster = cluster;
this.deployment = deployment;
this.resourceName = resourceName;
this.pods = null;
this.logSource = null;
this.modalOpened = true;
Expand Down Expand Up @@ -125,12 +125,14 @@ export class ListPodComponent implements OnDestroy {
if (!this.modalOpened) {
clearInterval(this.timer);
}
if (this.whetherHotReflash) { this.refresh(); }
if (this.whetherHotReflash) {
this.refresh();
}
}, 5000);
}

refresh() {
this.podClient.listByResouce(this.appId, this.currentCluster, this.cacheService.kubeNamespace, this.Type, this.deployment).subscribe(
this.podClient.listByResouce(this.appId, this.currentCluster, this.cacheService.kubeNamespace, this.Type, this.resourceName).subscribe(
response => {
const pods = response.data;
this.inventory.size = pods.length;
Expand Down Expand Up @@ -159,7 +161,7 @@ export class ListPodComponent implements OnDestroy {
enterContainer(pod: Pod): void {
const appId = this.route.parent.snapshot.params['id'];
const url = `portal/namespace/${this.cacheService.namespaceId}/app/${appId}/${this.Type}` +
`/${this.deployment}/pod/${pod.name}/terminal/${this.currentCluster}/${this.cacheService.kubeNamespace}`;
`/${this.resourceName}/pod/${pod.name}/terminal/${this.currentCluster}/${this.cacheService.kubeNamespace}`;
window.open(url, '_blank');
}

Expand All @@ -174,17 +176,17 @@ export class ListPodComponent implements OnDestroy {
if (this.logSource === undefined) {
this.messageHandlerService.showInfo('缺少机房信息,请联系管理员');
}
const kubeToolCmd = `kubetool log --source ${this.logSource === undefined ? '' : this.logSource} --${this.Type} ${this.deployment} ` +
`--pod=${pod.name} --layout=log`;
const kubeToolCmd = `kubetool log --source ${this.logSource === undefined ? '' : this.logSource} ` +
` --${this.Type} ${this.resourceName} --pod=${pod.name} --layout=log`;
this.copyService.copy(kubeToolCmd);
this.switchCopyButton();
}


podLog(pod: Pod): void {
const appId = this.route.parent.snapshot.params['id'];
const url = `portal/logging/namespace/${this.cacheService.namespaceId}/app/${appId}/${this.Type}/${this.deployment}` +
`/pod/${pod.name}/${this.currentCluster}/${this.cacheService.kubeNamespace}`;
const url = `portal/logging/namespace/${this.cacheService.namespaceId}/app/${appId}/${this.Type}/${this.resourceName}` +
`/pod/${pod.name}/${this.currentCluster}/${this.cacheService.kubeNamespace}`;
window.open(url, '_blank');
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/src/assets/i18n/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,9 @@
"MIGRATION": "迁移",
"DELETE": "删除",
"FORCEDELETE": "强制删除",
"REFRESH": "刷新"
"REFRESH": "刷新",
"ENTER_CONTAINER": "进入容器",
"LOG": "查看日志"
},
"LABEL": {
"NAMESPACE": "命名空间:"
Expand Down