From 64be404fbb76bff6185ede5e22c8411a678c274c Mon Sep 17 00:00:00 2001 From: n313893254 Date: Fri, 1 Jun 2018 15:46:47 +0800 Subject: [PATCH] Windows support --- .../cluster-driver/driver-rke/component.js | 75 ++++++++++++++++++- .../cluster-driver/driver-rke/template.hbs | 66 ++++++++++++++-- .../components/container-shell/component.js | 9 ++- translations/en-us.yaml | 9 +++ 4 files changed, 149 insertions(+), 10 deletions(-) diff --git a/lib/shared/addon/components/cluster-driver/driver-rke/component.js b/lib/shared/addon/components/cluster-driver/driver-rke/component.js index b684be25a..94b41148d 100644 --- a/lib/shared/addon/components/cluster-driver/driver-rke/component.js +++ b/lib/shared/addon/components/cluster-driver/driver-rke/component.js @@ -98,6 +98,9 @@ export default InputTextFile.extend(ClusterDriver, { worker: true, defaultDockerRootDir: null, + windowsEnable: null, + isLinux: true, + windowsSupport: false, isNew: equal('mode', 'new'), isEdit: equal('mode', 'edit'), notView: or('isNew', 'isEdit'), @@ -145,6 +148,16 @@ export default InputTextFile.extend(ClusterDriver, { let defaultCluster = globalStore.createRecord({ type: 'cluster' }) set(this, 'defaultDockerRootDir', defaultCluster.dockerRootDir) + + if (!get(this, 'isEdit')) { + this.windowsSupportChange() + } + + if (get(this, 'isEdit')) { + if (get(this, 'config.network.options.flannel_backend_type')) { + set(this, 'windowsSupport', true) + } + } }); }, @@ -186,8 +199,9 @@ export default InputTextFile.extend(ClusterDriver, { strategy: 'x509', }), network: globalStore.createRecord({ - type: 'networkConfig', - plugin: 'canal', + type: 'networkConfig', + plugin: 'canal', + options: { flannel_backend_type: null, }, }), ingress: globalStore.createRecord({ type: 'ingressConfig', @@ -231,6 +245,43 @@ export default InputTextFile.extend(ClusterDriver, { } }), + windowsSupportChange: observer('windowsSupport', function() { + const windowsSupport = get(this, 'windowsSupport') + + if (windowsSupport) { + let res = NETWORKCHOICES.filter((n) => n.value === 'flannel') + + setProperties(this, { + networkContent: res, + 'config.network.plugin': 'flannel', + 'config.network.options.flannel_backend_type': 'host-gw', + }) + } else { + setProperties(this, { + networkContent: NETWORKCHOICES, + 'config.network.options.flannel_backend_type': null, + }) + } + }), + + isLinuxChanged: observer('isLinux', function() { + if (get(this, 'nodeWhich') !== 'custom') { + return + } + const mode = get(this, 'mode') + const isLinux = get(this, 'isLinux') + + if (mode === 'edit') { + if (!isLinux) { + setProperties(this, { + controlplane: false, + etcd: false, + worker: true, + }) + } + } + }), + versionChoices: computed('initialVersion', `settings.${ C.SETTING.VERSIONS_K8S }`, 'config.kubernetesVersion', function() { const versions = JSON.parse(get(this, `settings.${ C.SETTING.VERSIONS_K8S }`) || '{}'); @@ -296,7 +347,7 @@ export default InputTextFile.extend(ClusterDriver, { return cur - orig; }), - command: computed('labels', 'token.nodeCommand', 'etcd', 'controlplane', 'worker', 'address', 'internalAddress', 'nodeName', function() { + command: computed('labels', 'token.nodeCommand', 'token.windowsNodeCommand', 'etcd', 'controlplane', 'worker', 'address', 'internalAddress', 'nodeName', 'isLinux', function() { let out = get(this, 'token.nodeCommand'); if ( !out ) { @@ -333,6 +384,24 @@ export default InputTextFile.extend(ClusterDriver, { out += ` --label ${ key }=${ labels[key] }`; }); + if (!get(this, 'isLinux')) { + out = get(this, 'token.windowsNodeCommand') || '' + out = out.replace('--isolation hyperv ', '') + let addressCmd = '' + + if (address) { + addressCmd += ` -address ${ address }` + } + + if (internalAddress) { + addressCmd += ` -internalAddress ${ internalAddress }` + } + + if (addressCmd) { + out = out.replace(`; if($?)`, `${ addressCmd }; if($?)`) + } + } + return out; }), diff --git a/lib/shared/addon/components/cluster-driver/driver-rke/template.hbs b/lib/shared/addon/components/cluster-driver/driver-rke/template.hbs index 1664604bb..2c8d61766 100644 --- a/lib/shared/addon/components/cluster-driver/driver-rke/template.hbs +++ b/lib/shared/addon/components/cluster-driver/driver-rke/template.hbs @@ -35,6 +35,25 @@ {{copy-to-clipboard tooltipText="" buttonText="copyToClipboard.tooltip" clipboardText=value class="with-clip"}} {{else}} + {{#if (eq nodeWhich 'custom')}} +
+
+ +
+ +
+
+ +
+
+
+ {{/if}}
@@ -48,7 +67,7 @@ {{new-select classNames="form-control" - content=networkChoices + content=networkContent localizedLabel=true value=cluster.rancherKubernetesEngineConfig.network.plugin disabled=isEdit @@ -201,8 +220,35 @@ {{/if}} {{#if (and isCustom (eq step 2)) }} - {{#accordion-list showExpandAll=false as |al expandFn|}} + {{#if windowsSupport}} + {{#accordion-list-item + title=(t 'clusterNew.rke.system.title') + detail=(t 'clusterNew.rke.system.detail') + expandOnInit=true + expandAll=al.expandAll + expand=(action expandFn) + }} +
+
+
+ +
+
+
+
+ +
+
+
+ {{/accordion-list-item}} + {{/if}} {{#accordion-list-item title=(t 'clusterNew.rke.role.pageheader') detail=(t 'clusterNew.rke.info.text') @@ -225,13 +271,13 @@
  • - +
    - +
    - +
    {{#advanced-section advanced=advanced}} @@ -343,7 +389,7 @@
  • - {{t 'clusterNew.rke.command.instructions'}} + {{t (if isLinux 'clusterNew.rke.command.instructions' 'clusterNew.rke.command.winInstructions') htmlSafe=true}} {{!--

    {{t 'clusterNew.rke.labels.detail'}}

    --}}
    • @@ -364,6 +410,14 @@ {{/accordion-list-item}} + {{#if isLinux}} + {{form-user-labels + setLabels=(action 'setLabels') + expandAll=al.expandAll + expand=(action expandFn) + detailKey="formUserLabels.nodeDetail" + }} + {{/if}} {{/accordion-list}} {{#if newNodeCount}} diff --git a/lib/shared/addon/components/container-shell/component.js b/lib/shared/addon/components/container-shell/component.js index 1800bd677..d31225e3a 100644 --- a/lib/shared/addon/components/container-shell/component.js +++ b/lib/shared/addon/components/container-shell/component.js @@ -90,7 +90,14 @@ export default Component.extend(ThrottledResize, { url = `${ scheme }${ window.location.host }/k8s/clusters/${ clusterId }/api/v1/namespaces/${ namespaceId }/pods/${ podName }/exec`; url += `?container=${ encodeURIComponent(containerName) }&stdout=1&stdin=1&stderr=1&tty=1`; - const command = get(instance, 'command') || DEFAULT_COMMAND; + let command = get(instance, 'command') || DEFAULT_COMMAND; + + const { node } = instance || {} + const system = node.info && node.info.os && node.info.os.operatingSystem || '' + + if (system.startsWith('Windows')) { + command = ['cmd'] + } command.forEach((c) => { url += `&command=${ encodeURIComponent(c) }`; diff --git a/translations/en-us.yaml b/translations/en-us.yaml index 7304a6aac..499cedbdb 100644 --- a/translations/en-us.yaml +++ b/translations/en-us.yaml @@ -2078,6 +2078,7 @@ clusterNew: text: Editing node options will update the command you will run on your existing machines command: instructions: 'Run this command on one or more existing machines already running a supported version of Docker.' + winInstructions: 'Run this command in CMD on one or more existing machines already running a supported version of Docker and windows server version more than 1803.' auth: label: Auth Provider x509: x509 @@ -2099,6 +2100,8 @@ clusterNew: calico: cloudProvider: label: Cloud Provider + type: + info: Only support "host-gw" backend ingress: label: Nginx Ingress monitoring: @@ -2159,6 +2162,12 @@ clusterNew: worker: Please select at least one node to use as a worker. dockerRootDir: placeholder: Default directory is {dir}. + system: + title: Node Operating System + detail: The OS of the node which will be added into the cluster + windowsSupport: + label: Windows Support (Experimental) + disabled: Not support {plugin} network provider. custom: label: Custom shortLabel: Custom