Merge pull request #1388 from westlywright/tech-preview

kube popout shell
This commit is contained in:
Vincent Fiduccia 2017-10-06 15:06:39 -07:00 committed by GitHub
commit fb6117b16e
11 changed files with 76 additions and 10 deletions

1
.gitignore vendored
View File

@ -28,6 +28,7 @@ jsconfig.json
GPATH
GRTAGS
GTAGS
*.code-workspace
*.swp

View File

@ -98,7 +98,7 @@ export default Ember.Component.extend(NewOrEdit, {
if ( !this.get('launchConfig.metadata') ) {
this.set('launchConfig.metadata', {});
};
}
if ( this.get('isService') && !this.get('isSidekick') ) {
this.setProperties({

View File

@ -2,4 +2,5 @@ import Ember from 'ember';
import Console from 'ui/mixins/console';
export default Ember.Controller.extend(Console, {
command: null,
});

View File

@ -1,10 +1,33 @@
import Ember from 'ember';
import C from 'ui/utils/constants';
export default Ember.Route.extend({
projects: Ember.inject.service(),
k8s: Ember.inject.service(),
model: function(params) {
let store = this.get('store');
if (params.kubernetes) {
return this.get('k8s').getInstanceToConnect();
}
return store.find('container', params.instanceId).then((response) => {
return response;
});
},
setupController(controller, model) {
this._super(controller, model);
if (controller.get('kubernetes')) {
controller.set('command', Ember.computed('model.labels', function() {
var labels = this.get('model.labels')||{};
if ( labels[C.LABEL.K8S_TOKEN]+'' === 'true' ) {
return [
'kubectl-shell.sh',
this.get('cookies').get(C.COOKIE.TOKEN) || 'unauthorized'
];
} else {
return ['/bin/bash','-l','-c','echo "# Run kubectl commands inside here\n# e.g. kubectl get rc\n"; TERM=xterm-256color /bin/bash'];
}
}));
}
}
});

View File

@ -1,6 +1,7 @@
<div class="shell-popup">
{{#container-shell
instance=model
command=command
showProtip=false
cols=80
rows=24

View File

@ -30,8 +30,15 @@ export default Ember.Controller.extend({
window.open(this.get('k8s.kubernetesDashboard'),'_blank');
},
kubectl() {
kubectl(e) {
if (e.metaKey) {
let proj = this.get('projects.current.id');
Ember.run.later(() => {
window.open(`//${window.location.host}/env/${proj}/infra/console?kubernetes=true&isPopup=true`, '_blank', "toolbars=0,width=900,height=700,left=200,top=200");
});
} else {
this.get('modalService').toggleModal('modal-kubectl');
}
},
kubeconfig() {

View File

@ -27,7 +27,8 @@
<p>{{t 'k8sAdvancedTab.shell.detail' htmlSafe=true}}</p>
<div class="links" style="top: auto; bottom: 47px;">
<button class="btn bg-primary icon-btn ml-10" {{action "kubectl"}}>
<button class="btn bg-primary icon-btn ml-10" onClick={{action "kubectl" allowedKeys="meta"}}>
<span class="darken"><i class="icon icon-terminal"></i></span>
<span>{{t 'k8sAdvancedTab.shell.button'}}</span>
</button>

View File

@ -2,7 +2,7 @@ import Ember from 'ember';
export default Ember.Mixin.create({
application : Ember.inject.controller(),
queryParams : ['instanceId'],
queryParams : ['instanceId', 'kubernetes'],
instanceId : null,
model : null,

View File

@ -180,12 +180,18 @@ var Stack = Resource.extend(StateCounts, {
return false;
}
var count = this.get('services.length') || 0;
if ( count === 0 ) {
var services = this.get('services');
var containers = this.get('instances').filter((inst) => {
return inst.get('serviceId') === null;
});
var countS = (services.length || 0);
var countC = (containers.length || 0);
if ( (countS + countC) === 0 ) {
return false;
}
return this.get('services').filterBy('actionLinks.deactivate').get('length') > 0;
return services.filterBy('actionLinks.deactivate').get('length') > 0 && containers.filterBy('actionLinks.stop').get('length');
}.property('services.@each.state','actionLinks.stopall'),
canViewConfig: function() {

View File

@ -26,7 +26,7 @@ export default Ember.Controller.extend(NewOrEdit, {
},
},
testNames: function(el, idx, ary) {
testNames: function(el/*, idx , ary */) {
let error = false;
if (el.includes('compose')) {
if (el !== 'rancher-compose.yml' || el !== 'docker-compose.yml') {

View File

@ -4,6 +4,7 @@ import C from 'ui/utils/constants';
export default Ember.Service.extend({
store: Ember.inject.service('store'),
userStore: Ember.inject.service('user-store'),
projects: Ember.inject.service(),
kubernetesDashboard: function() {
@ -54,4 +55,29 @@ export default Ember.Service.extend({
message: err.body.stdErr.split(/\n/),
});
},
getInstanceToConnect() {
let systemProject = this.get('projects.current.cluster.systemProject');
let inst;
if ( !systemProject ) {
return Ember.RSVP.reject('Unable to locate system environment');
}
return this.get('userStore').rawRequest({
url: systemProject.links.instances,
}).then((res) => {
inst = res.body.data.find((c) => {
return c.state === 'running'
&& c.labels
&& c.labels[C.LABEL.K8S_KUBECTL]+'' === 'true';
});
if ( inst ) {
return this.get('store').createRecord(inst);
} else {
return Ember.RSVP.reject('Unable to find running kubectl container');
}
});
},
});