├── .eslintrc.js ├── .github └── workflows │ └── build-extension-charts.yml ├── .gitignore ├── .nvmrc ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── babel.config.js ├── package.json ├── pkg └── capi │ ├── README.md │ ├── assets │ └── images │ │ └── providers │ │ ├── docker.svg │ │ ├── kubeadm.svg │ │ ├── vsphere-black.svg │ │ └── vsphere.svg │ ├── babel.config.js │ ├── components │ ├── AutoImport.vue │ ├── CCVariables │ │ ├── Variable.vue │ │ └── index.vue │ ├── CardGrid.vue │ ├── ClusterClassCard │ │ ├── ClusterCardField.vue │ │ └── index.vue │ ├── ClusterListBanner.vue │ └── ExperimentalBanner.vue │ ├── config │ ├── capi.ts │ └── query-params.ts │ ├── edit │ ├── cluster.x-k8s.io.cluster │ │ ├── ClusterConfig.vue │ │ ├── ControlPlaneEndpointSection.vue │ │ ├── ControlPlaneSection.vue │ │ ├── NetworkSection.vue │ │ ├── WorkerItem.vue │ │ └── index.vue │ └── turtles-capi.cattle.io.capiprovider │ │ ├── ProviderConfig.vue │ │ └── index.vue │ ├── formatters │ └── AutoImportState.vue │ ├── index.ts │ ├── l10n │ └── en-us.yaml │ ├── models │ ├── cluster.x-k8s.io.cluster.js │ ├── cluster.x-k8s.io.clusterclass.js │ └── turtles-capi.cattle.io.capiprovider.js │ ├── package.json │ ├── pages │ └── index.vue │ ├── routes │ └── capi-routing.ts │ ├── tsconfig.json │ ├── types │ └── capi.ts │ ├── util │ ├── auto-import.ts │ └── validators.ts │ └── vue.config.js ├── tsconfig.json ├── vue.config.js ├── vuex.d.ts └── yarn.lock /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | browser: true, 5 | node: true 6 | }, 7 | globals: { NodeJS: true, Timer: true }, 8 | extends: [ 9 | 'standard', 10 | 'eslint:recommended', 11 | 'plugin:cypress/recommended', 12 | 'plugin:vue/vue3-recommended', 13 | ], 14 | // add your custom rules here 15 | rules: { 16 | 'dot-notation': 'off', 17 | 'generator-star-spacing': 'off', 18 | 'guard-for-in': 'off', 19 | 'linebreak-style': 'off', 20 | 'new-cap': 'off', 21 | 'no-empty': 'off', 22 | 'no-extra-boolean-cast': 'off', 23 | 'no-new': 'off', 24 | 'no-plusplus': 'off', 25 | 'no-useless-escape': 'off', 26 | 'nuxt/no-cjs-in-config': 'off', 27 | 'semi-spacing': 'off', 28 | 'space-in-parens': 'off', 29 | strict: 'off', 30 | 'unicorn/no-new-buffer': 'off', 31 | 'vue/html-self-closing': 'off', 32 | 'vue/no-unused-components': 'warn', 33 | 'vue/no-v-html': 'off', 34 | 'wrap-iife': 'off', 35 | 'vue/no-v-for-template-key': 'off', 36 | 'array-bracket-spacing': 'warn', 37 | 'arrow-parens': 'warn', 38 | 'arrow-spacing': ['warn', { before: true, after: true }], 39 | 'block-spacing': ['warn', 'always'], 40 | 'brace-style': ['warn', '1tbs'], 41 | 'comma-dangle': ['warn', 'only-multiline'], 42 | 'comma-spacing': 'warn', 43 | curly: 'warn', 44 | eqeqeq: 'warn', 45 | 'func-call-spacing': ['warn', 'never'], 46 | 'implicit-arrow-linebreak': 'warn', 47 | indent: ['warn', 2], 48 | 'keyword-spacing': 'warn', 49 | 'lines-between-class-members': ['warn', 'always', { exceptAfterSingleLine: true }], 50 | 'multiline-ternary': ['warn', 'never'], 51 | 'newline-per-chained-call': ['warn', { ignoreChainWithDepth: 4 }], 52 | 'no-caller': 'warn', 53 | 'no-cond-assign': ['warn', 'except-parens'], 54 | 'no-console': 'warn', 55 | 'no-debugger': 'warn', 56 | 'no-eq-null': 'warn', 57 | 'no-eval': 'warn', 58 | 'no-trailing-spaces': 'warn', 59 | 'no-undef': 'warn', 60 | 'no-unused-vars': 'warn', 61 | 'no-whitespace-before-property': 'warn', 62 | 'object-curly-spacing': ['warn', 'always'], 63 | 'object-property-newline': 'warn', 64 | 'object-shorthand': 'warn', 65 | 'padded-blocks': ['warn', 'never'], 66 | 'prefer-arrow-callback': 'warn', 67 | 'prefer-template': 'warn', 68 | 'quote-props': 'warn', 69 | 'rest-spread-spacing': 'warn', 70 | semi: ['warn', 'always'], 71 | 'space-before-function-paren': ['warn', 'never'], 72 | 'space-infix-ops': 'warn', 73 | 'spaced-comment': 'warn', 74 | 'switch-colon-spacing': 'warn', 75 | 'template-curly-spacing': ['warn', 'always'], 76 | 'yield-star-spacing': ['warn', 'both'], 77 | 78 | 'key-spacing': ['warn', { 79 | align: { 80 | beforeColon: false, 81 | afterColon: true, 82 | on: 'value', 83 | mode: 'minimum' 84 | }, 85 | multiLine: { 86 | beforeColon: false, 87 | afterColon: true 88 | }, 89 | }], 90 | 91 | 'object-curly-newline': ['warn', { 92 | ObjectExpression: { 93 | multiline: true, 94 | minProperties: 3 95 | }, 96 | ObjectPattern: { 97 | multiline: true, 98 | minProperties: 4 99 | }, 100 | ImportDeclaration: { 101 | multiline: true, 102 | minProperties: 5 103 | }, 104 | ExportDeclaration: { 105 | multiline: true, 106 | minProperties: 3 107 | } 108 | }], 109 | 110 | 'padding-line-between-statements': [ 111 | 'warn', 112 | { 113 | blankLine: 'always', 114 | prev: '*', 115 | next: 'return', 116 | }, 117 | { 118 | blankLine: 'always', 119 | prev: 'function', 120 | next: 'function', 121 | }, 122 | // This configuration would require blank lines after every sequence of variable declarations 123 | { 124 | blankLine: 'always', 125 | prev: ['const', 'let', 'var'], 126 | next: '*' 127 | }, 128 | { 129 | blankLine: 'any', 130 | prev: ['const', 'let', 'var'], 131 | next: ['const', 'let', 'var'] 132 | } 133 | ], 134 | 135 | quotes: [ 136 | 'warn', 137 | 'single', 138 | { 139 | avoidEscape: true, 140 | allowTemplateLiterals: true 141 | }, 142 | ], 143 | 144 | 'space-unary-ops': [ 145 | 'warn', 146 | { 147 | words: true, 148 | nonwords: false, 149 | } 150 | ], 151 | 152 | // FIXME: The following is disabled due to new linter and old JS code. These should all be enabled and underlying issues fixed 153 | 'vue/order-in-components': 'off', 154 | 'vue/no-lone-template': 'off', 155 | 'vue/v-slot-style': 'off', 156 | 'vue/component-tags-order': 'off', 157 | 'vue/no-mutating-props': 'off', 158 | '@typescript-eslint/no-unused-vars': 'off', 159 | 'array-callback-return': 'off', 160 | }, 161 | overrides: [ 162 | { 163 | files: ['*.js'], 164 | rules: { 165 | // FIXME: The following is disabled due to new linter and old JS code. These should all be enabled and underlying issues fixed 166 | 'prefer-regex-literals': 'off', 167 | 'vue/component-definition-name-casing': 'off', 168 | 'no-unreachable-loop': 'off', 169 | 'computed-property-spacing': 'off', 170 | } 171 | } 172 | ] 173 | }; 174 | -------------------------------------------------------------------------------- /.github/workflows/build-extension-charts.yml: -------------------------------------------------------------------------------- 1 | name: Build and Release Extension Charts 2 | 3 | on: 4 | workflow_dispatch: 5 | release: 6 | types: [prereleased, released] 7 | 8 | defaults: 9 | run: 10 | shell: bash 11 | working-directory: ./ 12 | 13 | jobs: 14 | build-extension-charts: 15 | uses: rancher/dashboard/.github/workflows/build-extension-charts.yml@shell-pkg-v3.0.2-rc.2 16 | permissions: 17 | actions: write 18 | contents: write 19 | deployments: write 20 | pages: write 21 | with: 22 | target_branch: gh-pages 23 | tagged_release: ${{ github.ref_name }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Node template 3 | # Logs 4 | logs 5 | *.log 6 | npm-debug.log* 7 | yarn-debug.log* 8 | yarn-error.log* 9 | package-lock.json 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | *.pid.lock 16 | 17 | # Directory for instrumented libs generated by jscoverage/JSCover 18 | lib-cov 19 | 20 | # Coverage directory used by tools like istanbul 21 | coverage 22 | 23 | # nyc test coverage 24 | .nyc_output 25 | 26 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 27 | .grunt 28 | 29 | # Bower dependency directory (https://bower.io/) 30 | bower_components 31 | 32 | # node-waf configuration 33 | .lock-wscript 34 | 35 | # Compiled binary addons (https://nodejs.org/api/addons.html) 36 | build/Release 37 | 38 | # Dependency directories 39 | node_modules/ 40 | jspm_packages/ 41 | 42 | # TypeScript v1 declaration files 43 | typings/ 44 | 45 | # Optional npm cache directory 46 | .npm 47 | 48 | # Optional eslint cache 49 | .eslintcache 50 | 51 | # Optional REPL history 52 | .node_repl_history 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # parcel-bundler cache (https://parceljs.org/) 61 | .cache 62 | 63 | 64 | # IDE / Editor 65 | .idea 66 | .editorconfig 67 | *.org 68 | *.tern-port 69 | 70 | # Service worker 71 | sw.* 72 | 73 | # Mac OSX 74 | .DS_Store 75 | 76 | # Storybook 77 | storybook-static/ 78 | 79 | # Packages 80 | dist-pkg 81 | tmp 82 | 83 | # Others 84 | .todo 85 | 86 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 20 -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "node_modules/typescript/lib" 3 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # capi-ui-extension 2 | Rancher Extension used in [rancher/dashboard](https://github.com/rancher/dashboard) for [Rancher Turtles](https://turtles.docs.rancher.com/turtles/v0.16/en/getting-started/install-rancher-turtles/using_rancher_dashboard.html) CAPI Provisioning UI. 3 | 4 | ## Running for Development 5 | This is what you probably want to get started. 6 | ```bash 7 | # Install dependencies 8 | yarn install 9 | 10 | # For development, serve with hot reload at https://localhost:8005 11 | # using the endpoint for your Rancher API 12 | API=https://your-rancher yarn dev 13 | # or put the variable into a .env file 14 | # Goto https://localhost:8005 15 | ``` 16 | 17 | ## Updating @shell package 18 | This is about updating the @shell package which is the base from rancher/dashboard 19 | ```bash 20 | # Update 21 | yarn create @rancher/update 22 | ``` 23 | 24 | ## Building the extension for production 25 | Bump the app version on `package.json` file, then run: 26 | ```bash 27 | # Build for production 28 | ./scripts/publish -g 29 | # add flag -f if you need to overwrite an existing version 30 | 31 | 32 | # If you need to test the built extension 33 | yarn serve-pkgs 34 | ``` 35 | 36 | ## Installing released versions of the CAPI UI 37 | NOTE: This UI is currently in tech preview. Follow instructions [here](https://turtles.docs.rancher.com/turtles/v0.16/en/getting-started/install-rancher-turtles/using_rancher_dashboard.html#_capi_ui_extension_installation) to install the capi ui. 38 | 39 | 40 | 41 | License 42 | ======= 43 | Check CAPI UI Apache License details [here](LICENSE)# capi-ui-extension -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = require('@rancher/shell/babel.config.js'); 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "capi-ui", 3 | "description": "UI for CAPI cluster provisioning using the Rancher Turtles extension", 4 | "version": "0.8.3-rc1", 5 | "private": false, 6 | "engines": { 7 | "node": ">=20" 8 | }, 9 | "dependencies": { 10 | "@rancher/components": "^0.3.0-alpha.1", 11 | "@rancher/shell": "3.0.5-rc.2", 12 | "@types/lodash": "4.14.196", 13 | "cache-loader": "4.1.0", 14 | "color": "4.2.3", 15 | "core-js": "3.21.1", 16 | "css-loader": "6.7.3", 17 | "ip": "2.0.1", 18 | "node-polyfill-webpack-plugin": "3.0.0", 19 | "semver": "7.5.4" 20 | }, 21 | "resolutions": { 22 | "**/webpack": "5", 23 | "@types/node": "16.4.3", 24 | "glob": "7.2.3" 25 | }, 26 | "scripts": { 27 | "dev": "NODE_ENV=dev ./node_modules/.bin/vue-cli-service serve", 28 | "build": "./node_modules/.bin/vue-cli-service build", 29 | "clean": "./node_modules/@rancher/shell/scripts/clean", 30 | "build-pkg": "./node_modules/@rancher/shell/scripts/build-pkg.sh", 31 | "serve-pkgs": "./node_modules/@rancher/shell/scripts/serve-pkgs", 32 | "publish-pkgs": "./node_modules/@rancher/shell/scripts/extension/publish", 33 | "parse-tag-name": "./node_modules/@rancher/shell/scripts/extension/parse-tag-name", 34 | "migrate": "node ./scrips/vue-migrate.js" 35 | }, 36 | "devDependencies": { 37 | "eslint-plugin-cypress": "2.12.1", 38 | "eslint-plugin-import": "2.23.4", 39 | "eslint-plugin-jest": "24.4.0", 40 | "eslint-plugin-node": "11.1.0", 41 | "eslint-plugin-promise": "7.2.1", 42 | "eslint-plugin-vue": "9.10.0" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /pkg/capi/README.md: -------------------------------------------------------------------------------- 1 | # CAPI Provisioning 2 | 3 | 4 | ### **The CAPI UI extension is in tech preview.** 5 | 6 | Create clusters using the Cluster API and automatically import them into Rancher. The Turtles chart must be installed in the local Rancher cluster for the CAPI UI extension to work. Read more about the Rancher Turtles project [here](https://turtles.docs.rancher.com/turtles/next/en/index.html). -------------------------------------------------------------------------------- /pkg/capi/assets/images/providers/docker.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pkg/capi/assets/images/providers/kubeadm.svg: -------------------------------------------------------------------------------- 1 | kubeadm-icon-color -------------------------------------------------------------------------------- /pkg/capi/assets/images/providers/vsphere-black.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /pkg/capi/assets/images/providers/vsphere.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /pkg/capi/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./.shell/pkg/babel.config.js'); 2 | -------------------------------------------------------------------------------- /pkg/capi/components/AutoImport.vue: -------------------------------------------------------------------------------- 1 | 44 | 45 | 57 | -------------------------------------------------------------------------------- /pkg/capi/components/CCVariables/Variable.vue: -------------------------------------------------------------------------------- 1 | 165 | 166 | 205 | 219 | -------------------------------------------------------------------------------- /pkg/capi/components/CCVariables/index.vue: -------------------------------------------------------------------------------- 1 | 205 | 206 | 230 | 231 | 256 | -------------------------------------------------------------------------------- /pkg/capi/components/CardGrid.vue: -------------------------------------------------------------------------------- 1 | 53 | 54 | 78 | 79 | 91 | -------------------------------------------------------------------------------- /pkg/capi/components/ClusterClassCard/ClusterCardField.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 31 | 32 | 49 | -------------------------------------------------------------------------------- /pkg/capi/components/ClusterClassCard/index.vue: -------------------------------------------------------------------------------- 1 | 60 | 61 | 105 | 106 | 185 | -------------------------------------------------------------------------------- /pkg/capi/components/ClusterListBanner.vue: -------------------------------------------------------------------------------- 1 | 33 | 34 | 41 | -------------------------------------------------------------------------------- /pkg/capi/components/ExperimentalBanner.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 18 | -------------------------------------------------------------------------------- /pkg/capi/config/capi.ts: -------------------------------------------------------------------------------- 1 | import { CAPI as RANCHER_CAPI } from '@shell/config/types'; 2 | import { CAPI as TURTLES_CAPI } from '../types/capi'; 3 | 4 | const CLUSTER_MGMT_PRODUCT = 'manager'; 5 | 6 | export function init($plugin: any, store: any) { 7 | const { 8 | basicType, 9 | weightType, 10 | weightGroup, 11 | virtualType, 12 | // headers, 13 | } = $plugin.DSL(store, CLUSTER_MGMT_PRODUCT); 14 | 15 | virtualType({ 16 | label: 'CAPI Turtles', 17 | icon: 'gear', 18 | name: 'capi-dashboard', 19 | namespaced: false, 20 | weight: 99, 21 | route: { 22 | name: `c-cluster-${ CLUSTER_MGMT_PRODUCT }-capi`, 23 | params: { cluster: '_' } 24 | }, 25 | overview: true, 26 | exact: true, 27 | }); 28 | 29 | // Interestingly, types can only appear in one place, so by adding machine deployment 30 | // and others here, they will no longer show up in the Advanced section, which is 31 | // quite nice for this use case 32 | basicType([ 33 | 'capi-dashboard', 34 | RANCHER_CAPI.CAPI_CLUSTER, 35 | TURTLES_CAPI.CLUSTER_CLASS, 36 | TURTLES_CAPI.PROVIDER, 37 | // keep this page hidden under 'advanced' still as it may fail to load in Rancher <=2.8.0, see https://github.com/rancher/dashboard/issues/9973 38 | // RANCHER_CAPI.MACHINE, 39 | RANCHER_CAPI.MACHINE_SET, 40 | RANCHER_CAPI.MACHINE_DEPLOYMENT, 41 | ], 'CAPITurtles'); 42 | 43 | weightType(RANCHER_CAPI.CAPI_CLUSTER, 10, true); 44 | 45 | // Ensure CAPI group appears before the Advanced group 46 | weightGroup('CAPITurtles', 10, true); 47 | } 48 | -------------------------------------------------------------------------------- /pkg/capi/config/query-params.ts: -------------------------------------------------------------------------------- 1 | export const PROVIDER_TYPE = 'category'; 2 | -------------------------------------------------------------------------------- /pkg/capi/edit/cluster.x-k8s.io.cluster/ClusterConfig.vue: -------------------------------------------------------------------------------- 1 | 382 | 557 | 579 | -------------------------------------------------------------------------------- /pkg/capi/edit/cluster.x-k8s.io.cluster/ControlPlaneEndpointSection.vue: -------------------------------------------------------------------------------- 1 | 59 | 91 | 114 | -------------------------------------------------------------------------------- /pkg/capi/edit/cluster.x-k8s.io.cluster/ControlPlaneSection.vue: -------------------------------------------------------------------------------- 1 | 36 | 50 | 65 | -------------------------------------------------------------------------------- /pkg/capi/edit/cluster.x-k8s.io.cluster/NetworkSection.vue: -------------------------------------------------------------------------------- 1 | 75 | 135 | 161 | -------------------------------------------------------------------------------- /pkg/capi/edit/cluster.x-k8s.io.cluster/WorkerItem.vue: -------------------------------------------------------------------------------- 1 | 149 | 252 | 266 | -------------------------------------------------------------------------------- /pkg/capi/edit/cluster.x-k8s.io.cluster/index.vue: -------------------------------------------------------------------------------- 1 | 80 | 81 | 126 | -------------------------------------------------------------------------------- /pkg/capi/edit/turtles-capi.cattle.io.capiprovider/ProviderConfig.vue: -------------------------------------------------------------------------------- 1 | 275 | 276 | 463 | 464 | 471 | -------------------------------------------------------------------------------- /pkg/capi/edit/turtles-capi.cattle.io.capiprovider/index.vue: -------------------------------------------------------------------------------- 1 | 172 | 173 | 227 | 228 | 239 | -------------------------------------------------------------------------------- /pkg/capi/formatters/AutoImportState.vue: -------------------------------------------------------------------------------- 1 | 26 | 27 | 34 | -------------------------------------------------------------------------------- /pkg/capi/index.ts: -------------------------------------------------------------------------------- 1 | import { importTypes } from '@rancher/auto-import'; 2 | import { 3 | ActionLocation, IPlugin, PanelLocation, TableColumnLocation, TabLocation 4 | } from '@shell/core/types'; 5 | import { _CLONE, _CREATE, _EDIT } from '@shell/config/query-params'; 6 | import { MANAGEMENT, CAPI as RANCHER_CAPI } from '@shell/config/types'; 7 | import { LABELS, CAPI as TURTLES_CAPI } from './types/capi'; 8 | import capiRouting from './routes/capi-routing'; 9 | import toggleAutoImport from './util/auto-import'; 10 | 11 | // Init the package 12 | export default function(plugin: any): void { 13 | // Auto-import model, detail, edit from the folders 14 | importTypes(plugin); 15 | 16 | // Provide plugin metadata from package.json 17 | plugin.metadata = require('./package.json'); 18 | 19 | plugin.addProduct(require('./config/capi')); 20 | 21 | // Add Vue Routes 22 | plugin.addRoutes(capiRouting); 23 | 24 | // add tab to namespace edit 25 | plugin.addTab( 26 | TabLocation.RESOURCE_DETAIL, 27 | { 28 | resource: ['namespace'], 29 | cluster: ['local'], 30 | mode: [_CREATE, _CLONE, _EDIT, 'config'] 31 | }, 32 | { 33 | name: 'capi-auto-import', 34 | labelKey: 'capi.autoImport.label', 35 | weight: -5, 36 | showHeader: true, 37 | component: () => import('./components/AutoImport.vue') 38 | } 39 | ); 40 | 41 | // add enable auto-import action to namespace table 42 | plugin.addAction(ActionLocation.TABLE, 43 | { path: [{ urlPath: '/c/local/explorer/projectsnamespaces', exact: true }, { urlPath: 'cluster.x-k8s.io.cluster', endsWith: true }] }, 44 | { 45 | labelKey: 'capi.autoImport.enableAction', 46 | icon: 'icon-plus', 47 | enabled(target: any) { 48 | const isProject = target.type === MANAGEMENT.PROJECT; 49 | 50 | return !isProject && target?.metadata?.labels?.[LABELS.AUTO_IMPORT] !== 'true'; 51 | }, 52 | invoke(opts, resources = []) { 53 | resources.forEach((ns) => { 54 | toggleAutoImport(ns); 55 | }); 56 | } 57 | }); 58 | 59 | // add disable auto-import action to namespace table 60 | plugin.addAction(ActionLocation.TABLE, 61 | { path: [{ urlPath: '/c/local/explorer/projectsnamespaces', exact: true }, { urlPath: 'cluster.x-k8s.io.cluster', endsWith: true }] }, 62 | { 63 | labelKey: 'capi.autoImport.disableAction', 64 | icon: 'icon-minus', 65 | enabled(target: any) { 66 | const isProject = target.type === MANAGEMENT.PROJECT; 67 | 68 | return !isProject && target?.metadata?.labels?.[LABELS.AUTO_IMPORT] === 'true'; 69 | }, 70 | invoke(opts, resources = []) { 71 | resources.forEach((ns) => { 72 | toggleAutoImport(ns); 73 | }); 74 | } 75 | }); 76 | 77 | // add column to namespace table 78 | plugin.addTableColumn( 79 | TableColumnLocation.RESOURCE, 80 | { path: [{ urlPath: '/c/local/explorer/projectsnamespaces', exact: true }] }, 81 | { 82 | name: 'capi-auto-import', 83 | labelKey: 'capi.autoImport.label', 84 | getValue: (row: any) => { 85 | return row?.labels?.[LABELS.AUTO_IMPORT] === 'true'; 86 | }, 87 | width: 200, 88 | align: 'center', 89 | formatter: 'AutoImportState' 90 | } 91 | ); 92 | 93 | // add warning to cluster mgmt resource list 94 | plugin.addPanel(PanelLocation.RESOURCE_LIST, 95 | { resource: ['provisioning.cattle.io.cluster'] }, 96 | { component: () => import('./components/ClusterListBanner.vue') } 97 | ); 98 | 99 | plugin.addPanel(PanelLocation.RESOURCE_LIST, 100 | { 101 | resource: [RANCHER_CAPI.CAPI_CLUSTER, 102 | TURTLES_CAPI.CLUSTER_CLASS, 103 | TURTLES_CAPI.PROVIDER, 104 | RANCHER_CAPI.MACHINE, 105 | RANCHER_CAPI.MACHINE_SET, 106 | RANCHER_CAPI.MACHINE_DEPLOYMENT] 107 | }, 108 | { component: () => import('./components/ExperimentalBanner.vue') } 109 | ); 110 | 111 | plugin.addPanel(PanelLocation.DETAILS_MASTHEAD, 112 | { 113 | resource: [RANCHER_CAPI.CAPI_CLUSTER, 114 | TURTLES_CAPI.CLUSTER_CLASS, 115 | TURTLES_CAPI.PROVIDER, 116 | RANCHER_CAPI.MACHINE, 117 | RANCHER_CAPI.MACHINE_SET, 118 | RANCHER_CAPI.MACHINE_DEPLOYMENT] 119 | }, 120 | { component: () => import('./components/ExperimentalBanner.vue') } 121 | ); 122 | } 123 | -------------------------------------------------------------------------------- /pkg/capi/l10n/en-us.yaml: -------------------------------------------------------------------------------- 1 | action: 2 | createCluster: Create Cluster 3 | capi: 4 | installation: 5 | title: Rancher Turtles 6 | description: The Rancher Turtles operator allows users to import CAPI-provisioned clusters into Rancher. 7 | turtlesNeeded: Either the user doesn't have permission to run the Turtles extension or the Turtles operator isn't installed. To learn how to install the Rancher Turtles extension, read the documentation. 8 | autoImport: 9 | label: CAPI Auto-Import 10 | checkbox: 11 | label: Automatically import CAPI clusters created in this namespace 12 | enableAction: Enable CAPI Auto-Import 13 | disableAction: Disable CAPI Auto-Import 14 | warnings: 15 | embeddedFeatureFlag: "It looks like the Rancher-managed cluster API feature is disabled. To provision and manage RKE2 clusters you must either enable the embedded-cluster-api feature flag or install the Rancher Turtles extension." 16 | cluster: 17 | steps: 18 | clusterClass: 19 | title: Cluster Class 20 | label: Cluster Class 21 | description: "" 22 | configuration: 23 | title: Configuration 24 | label: Configuration 25 | description: "" 26 | variables: 27 | title: Variables 28 | label: Variables 29 | description: "" 30 | secret: 31 | reuse: Use existing credential 32 | create: Create new credential 33 | topology: 34 | controlPlane: 35 | title: Control Plane 36 | replicas: Replicas 37 | providerConfig: 38 | title: Infrastructure 39 | clusterClass: 40 | title: Cluster Class 41 | label: Cluster Class 42 | description: Cluster Class Description 43 | variables: 44 | title: Variables 45 | version: 46 | title: Kubernetes Version 47 | networking: 48 | title: Networking 49 | apiServerPort: API Server Port 50 | serviceDomain: Service Domain 51 | pods: 52 | title: Pod CIDR Blocks 53 | add: Add Pod CIDR Block 54 | services: 55 | title: Service VIP CIDR Blocks 56 | add: Add Service VIP CIDR Block 57 | cidrplaceholder: e.g. 192.168.0.0/16 58 | 59 | controlPlaneEndpoint: 60 | title: Control Plane Endpoint 61 | host: Host 62 | port: Port 63 | workers: 64 | title: Workers 65 | class: Class 66 | name: Name 67 | replicas: Replicas 68 | machineDeployments: 69 | title: Machine Deployments 70 | add: Add Machine Deployment 71 | machinePools: 72 | title: Machine Pools 73 | add: Add Machine Pool 74 | labels: 75 | title: Labels & Annotations 76 | autoimport: 77 | label: Auto-import cluster into Rancher 78 | clusterClassCard: 79 | title: "Cluster Class Name: {name}" 80 | controlPlaneName: Control Plane Name 81 | controlPlaneKind: Control Plane Kind 82 | controlPlaneNamespace: Control Plane Namespace 83 | machineDeploymentsCount: |- 84 | {count, plural, 85 | one {{count} Machine Deployment } 86 | other {{count} Machine Deployments } 87 | } 88 | machinePoolsCount: |- 89 | {count, plural, 90 | one {{count} Machine Pool } 91 | other {{count} Machine Pools } 92 | } 93 | experimental: "The Rancher CAPI UI extension is currently in tech preview." 94 | provider: 95 | title: Provider 96 | label: Provider 97 | placeholder: eg. custom-provider 98 | banner: Editing configuration will affect all clusters that are using this provider and may cause errors. 99 | name: 100 | label: Name 101 | placeholder: Provider name 102 | description: 103 | label: Description 104 | placeholder: Any text you want that better describes this provider 105 | type: 106 | label: Provider type 107 | infrastructure: 108 | label: Infrastructure 109 | bootstrap: 110 | label: Bootstrap 111 | controlPlane: 112 | label: Control Plane 113 | addon: 114 | label: Add-On 115 | ipam: 116 | label: IPAM 117 | runtimeextension: 118 | label: Runtime Extension 119 | core: 120 | label: Core 121 | custom: 122 | label: Custom 123 | version: 124 | label: Version 125 | placeholder: eg. v1.0.0 126 | tooltip: If unspecified, the latest version will be used. 127 | fetchConfigURL: 128 | label: URL 129 | placeholder: https://github.com/example/releases/latest/client.yaml 130 | cloudCredential: 131 | title: Cloud Credential 132 | toggle: Use a Rancher cloud credential to configure access for all {provider} CAPI clusters 133 | features: 134 | title: Features 135 | clusterResourceSet: Enable cluster resource set 136 | clusterTopology: Enable cluster topology 137 | machinePool: Enable machine pool 138 | variables: 139 | title: Variables 140 | add: Add 141 | secret: 142 | title: Secret Configuration 143 | create: Create new secret 144 | reuse: Use core provider secret 145 | data: Data 146 | label: Secret Name 147 | providerDisplayNames: 148 | digitalocean: Digital Ocean 149 | aws: Amazon 150 | azure: Azure 151 | docker: Docker 152 | gcp: Google Cloud Platform 153 | vsphere: vSphere 154 | kubeadm: Kubeadm 155 | rke2: RKE2 156 | 157 | nav: 158 | group: 159 | CAPITurtles: CAPI 160 | 161 | typeLabel: 162 | cluster.x-k8s.io.cluster: |- 163 | {count, plural, 164 | one { Cluster } 165 | other { Clusters } 166 | } 167 | turtles-capi.cattle.io.capiprovider: |- 168 | {count, plural, 169 | one { Provider } 170 | other { Providers } 171 | } 172 | cluster.x-k8s.io.machineset: |- 173 | {count, plural, 174 | one { Machine Set} 175 | other { Machine Sets } 176 | } 177 | cluster.x-k8s.io.machinedeployment: |- 178 | {count, plural, 179 | one { Machine Deployment} 180 | other { Machine Deployments } 181 | } 182 | cluster.x-k8s.io.clusterclass: |- 183 | {count, plural, 184 | one { Cluster Class} 185 | other { Cluster Classes} 186 | } 187 | validation: 188 | exclusiveMaxValue: '"{key}" must be less than {maximum}.' 189 | exclusiveMinValue: '"{key}" must be greater than {minimum}.' 190 | maxItems: |- 191 | {maxItems, plural, 192 | one {"{key}" may contain no more than {maxItems} item.} 193 | other {"{key}" may contain no more than {maxItems} items.} 194 | } 195 | minItems: |- 196 | {minItems, plural, 197 | one {"{key}" must contain at least {minItems} item.} 198 | other {"{key}" must contain at least {minItems} items.} 199 | } 200 | pattern: '"{key}" must match the pattern {pattern}.' 201 | stringFormat: '"{key}" must be a valid {format}.' 202 | uniqueItems: '"{key}" may not contain duplicate elements.' 203 | version: "Version format should be in the semver format prefixed with 'v'. Example: v1.9.3" 204 | name: Name is required and must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character. 205 | port: Port value must be a number. 206 | url: '"Value" must be a valid URL.' 207 | error: 208 | clusterClassNotFound: Could not find corresponding cluster class. Please check that cluster class exists and is valid. 209 | -------------------------------------------------------------------------------- /pkg/capi/models/cluster.x-k8s.io.cluster.js: -------------------------------------------------------------------------------- 1 | import SteveModel from '@shell/plugins/steve/steve-class'; 2 | import { 3 | _YAML, 4 | AS, 5 | } from '@shell/config/query-params'; 6 | 7 | export default class CapiCluster extends SteveModel { 8 | get canEditYaml() { 9 | return false; 10 | } 11 | 12 | get canUpdate() { 13 | return false; 14 | } 15 | 16 | get detailLocation() { 17 | const location = super._detailLocation; 18 | 19 | return { ...location, query: { [AS]: _YAML } }; 20 | } 21 | 22 | get _availableActions() { 23 | const out = super._availableActions; 24 | 25 | return out.filter((action) => action.action !== 'goToEdit' && action.action !== 'goToViewConfig'); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /pkg/capi/models/cluster.x-k8s.io.clusterclass.js: -------------------------------------------------------------------------------- 1 | import SteveModel from '@shell/plugins/steve/steve-class'; 2 | import { CAPI, MANAGEMENT, LOCAL_CLUSTER } from '@shell/config/types'; 3 | import { BLANK_CLUSTER, QUERY_PARAMS } from '../types/capi'; 4 | 5 | export default class ClusterClass extends SteveModel { 6 | get _availableActions() { 7 | const out = super._availableActions; 8 | 9 | out.unshift({ 10 | action: 'goToCreateCluster', 11 | label: this.t('action.createCluster'), 12 | icon: 'icon icon-plus', 13 | enabled: true 14 | }); 15 | 16 | return out; 17 | } 18 | 19 | goToCreateCluster() { 20 | const escapedID = escape(this.id); 21 | const location = { 22 | name: 'c-cluster-product-resource-create', 23 | params: { 24 | cluster: BLANK_CLUSTER, 25 | product: 'manager', 26 | resource: CAPI.CAPI_CLUSTER 27 | }, 28 | query: { [QUERY_PARAMS.CLASS]: escapedID } 29 | }; 30 | 31 | this.currentRouter().push(location); 32 | } 33 | 34 | saveYaml(yaml) { 35 | const localCluster = this.$rootGetters['management/byId'](MANAGEMENT.CLUSTER, LOCAL_CLUSTER); 36 | 37 | return localCluster.doAction('apply', { yaml }); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /pkg/capi/models/turtles-capi.cattle.io.capiprovider.js: -------------------------------------------------------------------------------- 1 | import SteveModel from '@shell/plugins/steve/steve-class'; 2 | 3 | export default class CapiProvider extends SteveModel { 4 | get canEditYaml() { 5 | return false; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /pkg/capi/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "capi", 3 | "description": "UI for CAPI cluster provisioning", 4 | "version": "0.8.3-rc1", 5 | "private": false, 6 | "rancher": { 7 | "annotations": { 8 | "catalog.cattle.io/rancher-version": ">= 2.10.0-0", 9 | "catalog.cattle.io/display-name": "CAPI UI", 10 | "catalog.cattle.io/ui-extensions-version": ">= 3.0.0 < 4.0.0", 11 | "catalog.cattle.io/certified": "rancher" 12 | } 13 | }, 14 | "scripts": { 15 | "dev": "./node_modules/.bin/nuxt dev", 16 | "nuxt": "./node_modules/.bin/nuxt" 17 | }, 18 | "engines": { 19 | "node": ">=20" 20 | }, 21 | "devDependencies": { 22 | "@vue/cli-plugin-babel": "5.0.8", 23 | "@vue/cli-service": "5.0.8", 24 | "@vue/cli-plugin-typescript": "5.0.8" 25 | }, 26 | "browserslist": [ 27 | "> 1%", 28 | "last 2 versions", 29 | "not dead" 30 | ] 31 | } -------------------------------------------------------------------------------- /pkg/capi/pages/index.vue: -------------------------------------------------------------------------------- 1 | 41 | 42 | 67 | 68 | 87 | -------------------------------------------------------------------------------- /pkg/capi/routes/capi-routing.ts: -------------------------------------------------------------------------------- 1 | import Dashboard from '../pages/index.vue'; 2 | 3 | const routes = [ 4 | { 5 | name: 'c-cluster-manager-capi', 6 | path: '/c/:cluster/manager/capi', 7 | component: Dashboard, 8 | }, 9 | ]; 10 | 11 | export default routes; 12 | -------------------------------------------------------------------------------- /pkg/capi/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowJs": true, 4 | "target": "esnext", 5 | "module": "esnext", 6 | // "strict": true, //this causes problems with vuex typing eg "property $store does not exist on type..." 7 | "jsx": "preserve", 8 | "importHelpers": true, 9 | "moduleResolution": "node", 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "sourceMap": true, 14 | "baseUrl": ".", 15 | "preserveSymlinks": true, 16 | "typeRoots": [ 17 | "../../node_modules", 18 | "../../node_modules/@rancher/shell/types" 19 | ], 20 | "types": [ 21 | "node", 22 | "webpack-env", 23 | "@types/node", 24 | "@types/lodash", 25 | "rancher", 26 | "shell" 27 | ], 28 | "lib": [ 29 | "esnext", 30 | "dom", 31 | "dom.iterable", 32 | "scripthost" 33 | ], 34 | "paths": { 35 | "@shell/*": [ 36 | "../../node_modules/@rancher/shell/*" 37 | ], 38 | "@components/*": [ 39 | "@rancher/components/*" 40 | ] 41 | } 42 | }, 43 | "include": [ 44 | "**/*.ts", 45 | "**/*.d.ts", 46 | "**/*.tsx", 47 | ], 48 | "exclude": [ 49 | "node_modules", 50 | ] 51 | } 52 | -------------------------------------------------------------------------------- /pkg/capi/types/capi.ts: -------------------------------------------------------------------------------- 1 | export const CAPI_PRODUCT_NAME = 'capi-turtles'; 2 | 3 | export const QUERY_PARAMS = { CLASS: 'class' }; 4 | 5 | export const BLANK_CLUSTER = '_'; 6 | 7 | export const LABELS = { AUTO_IMPORT: 'cluster-api.cattle.io/rancher-auto-import' }; 8 | 9 | export const RANCHER_TURTLES_SYSTEM_NAMESPACE = 'capi-system'; 10 | export const RANCHER_TURTLES_SYSTEM_NAME = 'capi-env-variables'; 11 | 12 | export const CAPI = { 13 | CLUSTER: 'cluster.x-k8s.io.cluster', 14 | CLUSTER_CLASS: 'cluster.x-k8s.io.clusterclass', 15 | PROVIDER: 'turtles-capi.cattle.io.capiprovider', 16 | }; 17 | 18 | export const CP_VERSIONS = { 19 | KThreesControlPlaneTemplate: ['k3s1', 'k3s2'], 20 | RKE2ControlPlaneTemplate: ['rke2r1', 'rke2r2'] 21 | }; 22 | 23 | export const CREDENTIALS_UPDATE_REQUIRED = ['aks']; 24 | export const CREDENTIALS_NOT_REQUIRED = ['docker']; 25 | 26 | export const PROVIDER_TYPES = [ 27 | { 28 | name: 'aws', type: 'infrastructure', disabled: false, credential: 'aws', credentialRequired: true 29 | }, 30 | { 31 | name: 'azure', type: 'infrastructure', disabled: false, credential: 'azure', credentialRequired: false 32 | }, 33 | { 34 | name: 'digitalocean', type: 'infrastructure', disabled: false, credential: 'digitalocean', credentialRequired: true 35 | }, 36 | { 37 | name: 'docker', type: 'infrastructure', disabled: false 38 | }, 39 | { 40 | name: 'gcp', type: 'infrastructure', disabled: false, credential: 'gcp', credentialRequired: true 41 | }, 42 | { 43 | name: 'vsphere', type: 'infrastructure', disabled: false, credential: 'vmwarevsphere', credentialRequired: true 44 | }, 45 | { 46 | name: 'rke2', type: 'bootstrap', disabled: false 47 | }, 48 | { 49 | name: 'rke2', type: 'controlPlane', disabled: false 50 | }, 51 | { 52 | name: 'kubeadm', type: 'bootstrap', disabled: false 53 | }, 54 | { 55 | name: 'kubeadm', type: 'controlPlane', disabled: false 56 | }, 57 | { 58 | name: 'custom', type: 'custom', disabled: false 59 | }, 60 | ]; 61 | -------------------------------------------------------------------------------- /pkg/capi/util/auto-import.ts: -------------------------------------------------------------------------------- 1 | import { LABELS } from '../types/capi'; 2 | 3 | export default function(resource: any) { 4 | if (resource?.metadata?.labels?.[LABELS.AUTO_IMPORT] === 'true') { 5 | delete resource.metadata.labels[LABELS.AUTO_IMPORT]; 6 | } else { 7 | if (!resource.metadata.labels) { 8 | resource.metadata.labels = {}; 9 | } 10 | resource.metadata.labels[LABELS.AUTO_IMPORT] = 'true'; 11 | } 12 | try { 13 | resource.save(); 14 | } catch (err) { 15 | const title = resource.t('resource.errors.update', { name: resource.name }); 16 | 17 | resource.$dispatch('growl/error', { 18 | title, message: err, timeout: 5000 19 | }, { root: true }); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /pkg/capi/util/validators.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Validator, 3 | ValidationOptions, 4 | } from "@shell/utils/validators/formRules"; 5 | import { Translation } from "@shell/types/t"; 6 | import isEmpty from "lodash/isEmpty"; 7 | import { isIpv4 } from "@shell/utils/string"; 8 | import { isValidCIDR, isValidMac } from "@shell/utils/validators/cidr"; 9 | import formRulesGenerator from "@shell/utils/validators/formRules/index"; 10 | import { CP_VERSIONS } from "./../types/capi"; 11 | import semver from "semver"; 12 | 13 | /** 14 | * 15 | * @param t this.$store.getters[i18n/t] 16 | * @param param1 param1.key should be the (already localized) label of the field being validated 17 | * @param openAPIV3Schema cluster class variable schema.openapiv3schema 18 | * 19 | * @returns an array of validator functions that work with the form-validation mixin. These can be supplied to any component wth the labeled-form-element mixin using the rules prop 20 | */ 21 | export const openAPIV3SchemaValidators = function ( 22 | t: Translation, 23 | { key = "Value" }: ValidationOptions, 24 | openAPIV3Schema: any 25 | ): Validator[] { 26 | const { 27 | exclusiveMinimum, 28 | exclusiveMaximum, 29 | maxItems, 30 | maxLength, 31 | maximum, 32 | minItems, 33 | minLength, 34 | minimum, 35 | pattern, 36 | uniqueItems, 37 | required: requiredFields, 38 | format, 39 | } = openAPIV3Schema; 40 | 41 | const out = [] as any[]; 42 | 43 | if (maximum) { 44 | if (exclusiveMaximum) { 45 | out.push((val: string | number) => 46 | Number(val) >= Number(maximum) 47 | ? t("validation.exclusiveMaxValue", { key, maximum }) 48 | : undefined 49 | ); 50 | } else { 51 | out.push((val: string | number) => 52 | Number(val) > Number(maximum) 53 | ? t("validation.maxValue", { key, max: maximum }) 54 | : undefined 55 | ); 56 | } 57 | } 58 | 59 | if (minimum !== undefined) { 60 | if (exclusiveMinimum) { 61 | out.push((val: string | number) => 62 | Number(val) <= Number(minimum) 63 | ? t("validation.exclusiveMinValue", { key, minimum }) 64 | : undefined 65 | ); 66 | } else { 67 | out.push((val: string | number) => 68 | Number(val) < Number(minimum) 69 | ? t("validation.minValue", { key, min: minimum }) 70 | : undefined 71 | ); 72 | } 73 | } 74 | if (minLength !== undefined) { 75 | out.push((val: string) => 76 | val && val.length < Number(minLength) 77 | ? t("validation.minLength", { key, min: minLength }) 78 | : undefined 79 | ); 80 | } 81 | if (maxLength) { 82 | out.push((val: string) => 83 | val && val.length > Number(maxLength) 84 | ? t("validation.maxLength", { key, max: maxLength }) 85 | : undefined 86 | ); 87 | } 88 | if (maxItems) { 89 | out.push((val: any[]) => 90 | val && val.length > maxItems 91 | ? t("validation.maxItems", { key, maxItems }) 92 | : undefined 93 | ); 94 | } 95 | 96 | if (minItems !== undefined) { 97 | out.push((val: any[]) => 98 | val && val.length < minItems 99 | ? t("validation.minItems", { key, minItems }) 100 | : undefined 101 | ); 102 | } 103 | 104 | if (pattern) { 105 | out.push( 106 | regexValidator( 107 | t("validation.pattern", { key, pattern }), 108 | new RegExp(pattern) 109 | ) 110 | ); 111 | } 112 | 113 | if (format && stringFormatValidators(t, { key }, format)) { 114 | out.push(stringFormatValidators(t, { key }, format)); 115 | } 116 | 117 | if (uniqueItems) { 118 | out.push((val: any[]) => 119 | val && val.filter((item, index) => val.indexOf(item) !== index).length 120 | ? t("validation.uniqueItems", { key }) 121 | : undefined 122 | ); 123 | } 124 | 125 | if (requiredFields) { 126 | out.push((val: any) => 127 | requiredFields.find((key: string) => val[key] === undefined) 128 | ? t("validation.requiredFields", { 129 | key, 130 | requiredFields: requiredFields.toString(), 131 | }) 132 | : undefined 133 | ); 134 | } 135 | 136 | return out; 137 | }; 138 | 139 | const regexValidator = function ( 140 | errorMessage: string, 141 | regexp: RegExp 142 | ): Validator { 143 | return (val: string) => 144 | val && !val.match(regexp) ? errorMessage : undefined; 145 | }; 146 | 147 | // strings can be evaluated against regular expressions by defining 'pattern' or validated against a common set of regexp using 'format' 148 | /** 149 | * 150 | * @param t this.$store.getters[i18n/t] 151 | * @param param1 param1.key should be the (already localized) label of the field being validated 152 | * @param format one of a set list of string formats defined here https://github.com/kubernetes/apiextensions-apiserver/blob/master/pkg/apiserver/validation/formats.go 153 | * 154 | * @returns a form validator for the string format, OR undefined if the format specified is invalid or a format we're not validating for practical reasons 155 | */ 156 | const stringFormatValidators = function ( 157 | t: Translation, 158 | { key = "Value" }: ValidationOptions, 159 | format: string 160 | ): Validator | undefined { 161 | const formRules = formRulesGenerator(t, { key }); 162 | const errorMessage = t("validation.stringFormat", { key, format }); 163 | 164 | // there are actually 24 formats in total validated on the backend with some odd options eg ISBN, creditcard 165 | // this subset of formats are the most universal, which we can be confident we are validating correctly 166 | switch (format) { 167 | case "hostname": 168 | return (val: string) => formRules.wildcardHostname(val); 169 | case "ipv4": 170 | return (val: string) => (val && !isIpv4(val) ? errorMessage : undefined); 171 | case "cidr": 172 | return (val: string) => 173 | (val && !isValidCIDR(val)) || val === '' ? errorMessage : undefined; 174 | case "mac": 175 | return (val: string) => 176 | val && !isValidMac(val) ? errorMessage : undefined; 177 | case "uuid": 178 | return regexValidator( 179 | errorMessage, 180 | /^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i 181 | ); 182 | case "uuid3": 183 | return regexValidator( 184 | errorMessage, 185 | /^[0-9a-f]{8}-?[0-9a-f]{4}-?3[0-9a-f]{3}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i 186 | ); 187 | case "uuid4": 188 | return regexValidator( 189 | errorMessage, 190 | /^[0-9a-f]{8}-?[0-9a-f]{4}-?4[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12}$/i 191 | ); 192 | case "uuid5": 193 | return regexValidator( 194 | errorMessage, 195 | /^[0-9a-f]{8}-?[0-9a-f]{4}-?5[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12}$/i 196 | ); 197 | default: 198 | return undefined; 199 | } 200 | }; 201 | 202 | export const isDefined = (val: any) => val || val === false || !isEmpty(val); 203 | 204 | export const versionValidator = function ( 205 | t: Translation, 206 | type: string 207 | ): Validator { 208 | return (version: string) => { 209 | try { 210 | if (!version || !version.startsWith("v")) { 211 | return t("validation.version"); 212 | } 213 | 214 | const validBuilds = CP_VERSIONS[type as keyof typeof CP_VERSIONS]; 215 | 216 | const parsedVersion = semver.parse(version); 217 | if (validBuilds) { 218 | return validBuilds.includes(parsedVersion?.build?.[0]) 219 | ? "" 220 | : t("validation.version"); 221 | } 222 | return parsedVersion ? "" : t("validation.version"); 223 | } catch { 224 | return t("validation.version"); 225 | } 226 | }; 227 | }; 228 | 229 | export const hostValidator = function (t: Translation): Validator { 230 | return stringFormatValidators(t, { key: "Host" }, "hostname"); 231 | }; 232 | 233 | export const portValidator = function (t: Translation): Validator { 234 | return (val: number) => 235 | val && isNaN(val) ? t("validation.port") : undefined; 236 | }; 237 | 238 | export const cidrValidator = function (t: Translation): Validator { 239 | return stringFormatValidators(t, { key: "Value" }, "cidr"); 240 | }; 241 | 242 | export const urlValidator = function (t: Translation): Validator { 243 | return (val: string) => 244 | val && !val.match(/^https?:\/\/(.*)$/) ? t("validation.url") : undefined; 245 | }; 246 | 247 | export const providerVersionValidator = function (t: Translation): Validator { 248 | return (val: string) => 249 | val && 250 | !val.match( 251 | /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ 252 | ) 253 | ? t("validation.version") 254 | : undefined; 255 | }; 256 | 257 | export const providerNameValidator = function (t: Translation): Validator { 258 | return (val: string) => 259 | !val || 260 | !val.match( 261 | /^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$/ 262 | ) 263 | ? t("validation.name") 264 | : undefined; 265 | }; 266 | -------------------------------------------------------------------------------- /pkg/capi/vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./.shell/pkg/vue.config')(__dirname); 2 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2018", 4 | "module": "ESNext", 5 | "moduleResolution": "Node", 6 | "lib": [ 7 | "ESNext", 8 | "ESNext.AsyncIterable", 9 | "DOM" 10 | ], 11 | "esModuleInterop": true, 12 | "allowJs": true, 13 | "sourceMap": true, 14 | "strict": true, 15 | "noEmit": true, 16 | "baseUrl": ".", 17 | "paths": { 18 | "~/*": [ 19 | "./*" 20 | ], 21 | "@/*": [ 22 | "./*" 23 | ], 24 | "@shell/*": [ 25 | "./node_modules/@rancher/shell/*" 26 | ] 27 | }, 28 | "typeRoots": [ 29 | "./node_modules", 30 | "./node_modules/@rancher/shell/types" 31 | ], 32 | "types": [ 33 | "@types/node", 34 | "cypress", 35 | "rancher", 36 | "shell" 37 | ] 38 | }, 39 | "exclude": [ 40 | "node_modules" 41 | ] 42 | } -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | const config = require('@rancher/shell/vue.config'); 2 | 3 | module.exports = config(__dirname, { 4 | excludes: [], 5 | // excludes: ['fleet', 'example'] 6 | }); 7 | -------------------------------------------------------------------------------- /vuex.d.ts: -------------------------------------------------------------------------------- 1 | // vuex.d.ts 2 | import { Store } from 'vuex'; 3 | 4 | declare module '@vue/runtime-core' { 5 | // declare your own store states 6 | interface State { 7 | [key:string]: any 8 | } 9 | 10 | // provide typings for `this.$store` 11 | interface ComponentCustomProperties { 12 | $store: Store 13 | } 14 | } 15 | --------------------------------------------------------------------------------