diff --git a/app/models/storageclass.js b/app/models/storageclass.js index 8e3d4ff00..1eeac7792 100644 --- a/app/models/storageclass.js +++ b/app/models/storageclass.js @@ -19,6 +19,7 @@ registerProvisioner('azure-file', 'kubernetes.io/azure-file', true); registerProvisioner('portworx-volume','kubernetes.io/portworx-volume', true); registerProvisioner('scaleio', 'kubernetes.io/scaleio', true); registerProvisioner('storageos', 'kubernetes.io/storageos', true); +registerProvisioner('longhorn', 'rancher.io/longhorn', true); export function registerProvisioner(name, provisioner, component) { if ( component === true ) { diff --git a/app/models/volume.js b/app/models/volume.js index b3cd7d593..30c5304b6 100644 --- a/app/models/volume.js +++ b/app/models/volume.js @@ -3,7 +3,7 @@ import { inject as service } from '@ember/service'; import Resource from 'ember-api-store/models/resource'; const SOURCES = []; -// name/component field component ephemeral persistent +// name/component field component ephemeral persistent driver registerSource('aws-ebs', 'awsElasticBlockStore', true, true, true); registerSource('azure-disk', 'azureDisk', true, true, true); registerSource('azure-file', 'azureFile', true, true, true); @@ -14,6 +14,7 @@ registerSource('config-map', 'configMap', true, true, f registerSource('empty-dir', 'emptyDir', true, true, false); registerSource('fc', 'fc', true, true, true); registerSource('flex-volume', 'flexVolume', true, true, true); +registerSource('flex-volume-longhorn', 'flexVolume', true, true, true, 'rancher.io/longhorn'); registerSource('flocker', 'flocker', true, true, true); registerSource('gce-pd', 'gcePersistentDisk', true, true, true); //registerSource('git-repo', 'gitRepo', true, true, false); @@ -33,7 +34,7 @@ registerSource('secret', 'secret', true, true, f registerSource('storageos', 'storageos', true, true, true); registerSource('vsphere-volume', 'vsphereVolume', true, true, true); -export function registerSource(name, field, component, ephemeral=true, persistent=true) { +export function registerSource(name, field, component, ephemeral=true, persistent=true, driver='') { if ( component === true ) { component = name; } @@ -46,6 +47,7 @@ export function registerSource(name, field, component, ephemeral=true, persisten SOURCES.push({ name: name, value: field, + driver, component: component, ephemeral: !!ephemeral, persistent: !!persistent, @@ -91,14 +93,29 @@ var Volume = Resource.extend({ return get(this, key); } }), - - displaySource: computed('configName','intl.locale', function() { - const intl = get(this, 'intl'); + sourceName: computed('configName', function(){ const key = get(this, 'configName'); - const entry = SOURCES.findBy('value', key); - - if ( key ) { - return intl.t(`volumeSource.${entry.name}.title`); + if ( !key ) { + return + } + let entry; + let driver = get(this, key).driver; + entry = SOURCES.findBy('value', key); + if(key === 'flexVolume' && driver){ + let specialSource = SOURCES.findBy('driver', driver); + if(specialSource){ + entry = specialSource; + } + } + if(entry){ + return entry.name; + } + }), + displaySource: computed('sourceName','intl.locale', function() { + const intl = get(this, 'intl'); + const sourceName = get(this, 'sourceName'); + if ( sourceName ) { + return intl.t(`volumeSource.${sourceName}.title`); } }), diff --git a/lib/shared/addon/components/cru-persistent-volume/component.js b/lib/shared/addon/components/cru-persistent-volume/component.js index cf5092b27..2e6147b56 100644 --- a/lib/shared/addon/components/cru-persistent-volume/component.js +++ b/lib/shared/addon/components/cru-persistent-volume/component.js @@ -35,12 +35,7 @@ export default Component.extend(ViewNewEdit, { set(this, 'capacity', 10); } else { - const configName = get(this,'primaryResource.configName'); - const sources = getSources('persistent'); - const entry = sources.findBy('value', configName); - if ( entry ) { - set(this, 'sourceName', entry.name); - } + set(this, 'sourceName', get(this,'primaryResource.sourceName')); const capacity = get(this, 'primaryResource.capacity.storage'); if ( capacity ) { diff --git a/lib/shared/addon/components/cru-volume/component.js b/lib/shared/addon/components/cru-volume/component.js index 432977813..7bb4514b5 100644 --- a/lib/shared/addon/components/cru-volume/component.js +++ b/lib/shared/addon/components/cru-volume/component.js @@ -32,12 +32,7 @@ export default Component.extend(ViewNewEdit, { }.property('scope'), didReceiveAttrs() { - const configName = get(this,'primaryResource.configName'); - const sources = getSources('ephemeral'); - const entry = sources.findBy('value', configName); - if ( entry ) { - set(this, 'sourceName', entry.name); - } + set(this, 'sourceName', get(this,'primaryResource.sourceName')); }, willSave() { diff --git a/lib/shared/addon/components/storage-class/provisioner-longhorn/component.js b/lib/shared/addon/components/storage-class/provisioner-longhorn/component.js new file mode 100644 index 000000000..b6f2bd4ee --- /dev/null +++ b/lib/shared/addon/components/storage-class/provisioner-longhorn/component.js @@ -0,0 +1,12 @@ +import Component from '@ember/component'; +import layout from './template'; +import StorageClassProvisioner from 'shared/mixins/storage-class-provisioner'; + +const FIELDS = ['numberOfReplicas', 'staleReplicaTimeout', 'fromBackup']; + +export default Component.extend(StorageClassProvisioner, { + layout, + + provisioner: 'longhorn', + fields: FIELDS, +}); diff --git a/lib/shared/addon/components/storage-class/provisioner-longhorn/template.hbs b/lib/shared/addon/components/storage-class/provisioner-longhorn/template.hbs new file mode 100644 index 000000000..e80e6de2f --- /dev/null +++ b/lib/shared/addon/components/storage-class/provisioner-longhorn/template.hbs @@ -0,0 +1,12 @@ +{{#each fieldsGroup as |fields|}} +
+ {{#each fields as |field|}} +
+ + {{#input-or-display editable=editing value=(get model field)}} + {{input type="text" value=(get model field) classNames="form-control" placeholder=(t (concat 'cruStorageClass.' provisioner '.' field '.placeholder'))}} + {{/input-or-display}} +
+ {{/each}} +
+{{/each}} \ No newline at end of file diff --git a/lib/shared/addon/components/volume-source/source-flex-volume-longhorn/component.js b/lib/shared/addon/components/volume-source/source-flex-volume-longhorn/component.js new file mode 100644 index 000000000..2c1fc0c8f --- /dev/null +++ b/lib/shared/addon/components/volume-source/source-flex-volume-longhorn/component.js @@ -0,0 +1,21 @@ +import { get, set } from '@ember/object'; +import Component from '@ember/component'; +import layout from './template'; +import VolumeSource from 'shared/mixins/volume-source'; + +export default Component.extend(VolumeSource, { + layout, + field: 'flexVolume', + fieldType: 'flexVolumeSource', + init() { + this._super(); + get(this, 'config.driver')||set(this, 'config.driver', 'rancher.io/longhorn'); + get(this, 'config.options')||set(this, 'config.options', { + size: "2Gi", + numberOfReplicas: "3", + staleReplicaTimeout: "20", + fromBackup: "" + }); + get(this, 'config.secretRef')||set(this, 'config.secretRef',{}); + } +}); diff --git a/lib/shared/addon/components/volume-source/source-flex-volume-longhorn/template.hbs b/lib/shared/addon/components/volume-source/source-flex-volume-longhorn/template.hbs new file mode 100644 index 000000000..3d7d0b2d2 --- /dev/null +++ b/lib/shared/addon/components/volume-source/source-flex-volume-longhorn/template.hbs @@ -0,0 +1,55 @@ +
+
+ + {{#input-or-display editable=false value=config.driver}} + {{input type="text" value=config.driver classNames="form-control" placeholder=(t 'cruPersistentVolume.flexVolume.driver.placeholder')}} + {{/input-or-display}} +
+ +
+ + {{#input-or-display editable=editing value=config.fsType}} + {{input type="text" value=config.fsType classNames="form-control" placeholder=(t 'cruPersistentVolume.flexVolume.fsType.placeholder')}} + {{/input-or-display}} +
+
+ +
+
+ {{form-key-value + initialMap=config.options + editing=editing + header=(t 'cruPersistentVolume.flexVolume.options.label') + addActionLabel="cruPersistentVolume.flexVolume.options.addActionLabel" + changed=(action (mut config.options)) + }} +
+ +
+ + {{#if editing}} +
+ + +
+ {{else}} +
+ {{config.readOnly}} +
+ {{/if}} +
+ +
+ +
+
+ + {{#input-or-display editable=editing value=config.secretRef.name}} + {{input type="text" value=config.secretRef.name classNames="form-control" placeholder=(t 'cruPersistentVolume.flexVolume.secretRef.placeholder')}} + {{/input-or-display}} +
+
\ No newline at end of file diff --git a/lib/shared/addon/components/volume-source/source-flex-volume/component.js b/lib/shared/addon/components/volume-source/source-flex-volume/component.js index f57742a19..1442fe05e 100644 --- a/lib/shared/addon/components/volume-source/source-flex-volume/component.js +++ b/lib/shared/addon/components/volume-source/source-flex-volume/component.js @@ -1,9 +1,13 @@ import Component from '@ember/component'; import layout from './template'; import VolumeSource from 'shared/mixins/volume-source'; +import { set, get } from '@ember/object'; export default Component.extend(VolumeSource, { layout, field: 'flexVolume', fieldType: 'flexVolumeSource', + didInsertElement() { + get(this, 'config.secretRef')||set(this, 'config.secretRef',{}); + } }); diff --git a/lib/shared/app/components/storage-class/provisioner-longhorn/component.js b/lib/shared/app/components/storage-class/provisioner-longhorn/component.js new file mode 100644 index 000000000..c7d8430d3 --- /dev/null +++ b/lib/shared/app/components/storage-class/provisioner-longhorn/component.js @@ -0,0 +1 @@ +export { default } from 'shared/components/storage-class/provisioner-longhorn/component'; diff --git a/lib/shared/app/components/volume-source/source-flex-volume-longhorn/component.js b/lib/shared/app/components/volume-source/source-flex-volume-longhorn/component.js new file mode 100644 index 000000000..2028948a5 --- /dev/null +++ b/lib/shared/app/components/volume-source/source-flex-volume-longhorn/component.js @@ -0,0 +1 @@ +export { default } from 'shared/components/volume-source/source-flex-volume-longhorn/component'; diff --git a/translations/en-us.yaml b/translations/en-us.yaml index 168826dad..be3147546 100644 --- a/translations/en-us.yaml +++ b/translations/en-us.yaml @@ -2535,6 +2535,16 @@ cruStorageClass: fsType: label: Filesystem Type placeholder: "e.g. ext4" + longhorn: + numberOfReplicas: + label: Number Of Relicas + placeholder: "e.g. 3" + staleReplicaTimeout: + label: Stale Replica Timeout + placeholder: "e.g. 30" + fromBackup: + label: From Backup + placeholder: "" quobyte: quobyteAPIServer: label: Quobyte API Server @@ -5419,6 +5429,8 @@ storageClass: title: Gluster Volume local: title: Local Node Disk + longhorn: + title: Longhorn portworx-volume: title: Portworx Volume quobyte: @@ -5453,6 +5465,8 @@ volumeSource: title: Fibre Channel flex-volume: title: Flex Volume + flex-volume-longhorn: + title: Longhorn flocker: title: Flocker gce-pd: