mirror of https://github.com/rancher/ui.git
144 lines
3.6 KiB
JavaScript
144 lines
3.6 KiB
JavaScript
import Component from '@ember/component';
|
|
import { computed, get, observer, set } from '@ember/object';
|
|
import { alias, equal } from '@ember/object/computed';
|
|
import { inject as service } from '@ember/service';
|
|
import { isEmpty } from '@ember/utils';
|
|
import { resolve } from 'rsvp';
|
|
import ClusterDriver from 'shared/mixins/cluster-driver';
|
|
import layout from './template';
|
|
|
|
export default Component.extend(ClusterDriver, {
|
|
globalStore: service(),
|
|
growl: service(),
|
|
settings: service(),
|
|
intl: service(),
|
|
|
|
layout,
|
|
configField: 'importedConfig',
|
|
step: 1,
|
|
nodeForInfo: null,
|
|
isDockerCluster: false,
|
|
|
|
isEdit: equal('mode', 'edit'),
|
|
isView: equal('mode', 'view'),
|
|
clusterState: alias('model.originalCluster.state'),
|
|
isK3sCluster: equal('model.cluster.driver', 'k3s'),
|
|
isRke2Cluster: equal('model.cluster.driver', 'rke2'),
|
|
|
|
nodes: computed.reads('model.cluster.masterNodes'),
|
|
|
|
didReceiveAttrs() {
|
|
if ( get(this, 'isEdit') ) {
|
|
if (this.isK3sCluster) {
|
|
set(this, 'configField', 'k3sConfig');
|
|
|
|
if (this.model.cluster.masterNodes.length === 1) {
|
|
set(this, 'nodeForInfo', this.model.cluster.masterNodes.firstObject);
|
|
}
|
|
|
|
if (isEmpty(this.model.cluster.k3sConfig)) {
|
|
set(this, 'isDockerCluster', true);
|
|
}
|
|
} else if (this.isRke2Cluster) {
|
|
set(this, 'configField', 'rke2Config');
|
|
|
|
if (this.model.cluster.masterNodes.length === 1) {
|
|
set(this, 'nodeForInfo', this.model.cluster.masterNodes.firstObject);
|
|
}
|
|
|
|
if (isEmpty(this.model.cluster.rke2Config)) {
|
|
set(this, 'model.cluster.rke2Config', this.globalStore.createRecord({
|
|
type: 'rke2Config',
|
|
kubernetesVersion: this.cluster.version.gitVersion
|
|
}));
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
actions: {
|
|
setActiveNodeForInfo(selection) {
|
|
const node = selection ? this.nodes.findBy('id', selection.id) : null;
|
|
|
|
set(this, 'nodeForInfo', node);
|
|
},
|
|
},
|
|
|
|
clusterChanged: observer('originalCluster.state', function() {
|
|
if ( get(this, 'step') >= 2 ) {
|
|
const state = get(this, 'originalCluster.state')
|
|
|
|
if ( !['pending', 'initializing', 'active'].includes(state) ) {
|
|
if (this.close) {
|
|
this.close();
|
|
}
|
|
}
|
|
}
|
|
}),
|
|
|
|
nodeInfoId: computed({
|
|
get() {
|
|
const { nodeForInfo } = this;
|
|
|
|
if (isEmpty(nodeForInfo)) {
|
|
return null;
|
|
} else {
|
|
return nodeForInfo.id
|
|
}
|
|
},
|
|
|
|
set(key, value) {
|
|
const { nodeForInfo } = this;
|
|
|
|
if (!isEmpty(nodeForInfo)) {
|
|
set(nodeForInfo, 'id', value);
|
|
}
|
|
|
|
return value;
|
|
},
|
|
}),
|
|
|
|
nodesOptions: computed('nodes.@each.state', function() {
|
|
return this.nodes.map((node) => ( {
|
|
id: node.id,
|
|
displayName: node.displayName
|
|
} ));
|
|
}),
|
|
|
|
willSave() {
|
|
const {
|
|
configField: field,
|
|
config
|
|
} = this;
|
|
let errors = [];
|
|
|
|
if (field === 'k3sConfig' && !isEmpty(config)) {
|
|
if (config.k3supgradeStrategy) {
|
|
// doesn't work because missing deep validation
|
|
// errors = config.k3supgradeStrategy.validationErrors();
|
|
if (config.k3supgradeStrategy.serverConcurrency <= 0 || config.k3supgradeStrategy.workerConcurrency <= 0) {
|
|
errors.push(this.intl.t('clusterNew.k3simport.errors.concurrency.negative'))
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!isEmpty(errors)) {
|
|
set(this, 'errors', errors);
|
|
|
|
return false;
|
|
}
|
|
|
|
return this._super();
|
|
},
|
|
|
|
doneSaving() {
|
|
return this.loadToken();
|
|
},
|
|
|
|
loadToken() {
|
|
set(this, 'step', 2);
|
|
|
|
return resolve();
|
|
}
|
|
});
|