|
| 1 | +import React from 'react'; |
| 2 | +import styles from './styles.module.css'; |
| 3 | +import CodeBlock from '@theme/CodeBlock' |
| 4 | +import {Form, Input, InputNumber, Switch} from "antd"; |
| 5 | + |
| 6 | +class Comparison extends React.Component { |
| 7 | + constructor(props) { |
| 8 | + super(props); |
| 9 | + |
| 10 | + this.state = { |
| 11 | + name: "nginx", |
| 12 | + replicas: "3", |
| 13 | + version: "1.14.2", |
| 14 | + port: "80", |
| 15 | + service: false, |
| 16 | + }; |
| 17 | + } |
| 18 | + |
| 19 | + render() { |
| 20 | + const k8sDplString = 'apiVersion: apps/v1\n' + |
| 21 | + 'kind: Deployment\n' + |
| 22 | + 'metadata:\n' + |
| 23 | + ' name: ' + this.state.name + '\n' + |
| 24 | + ' labels:\n' + |
| 25 | + ' app: ' + this.state.name + '\n' + |
| 26 | + 'spec:\n' + |
| 27 | + ' replicas: ' + this.state.replicas + '\n' + |
| 28 | + ' selector:\n' + |
| 29 | + ' matchLabels:\n' + |
| 30 | + ' app: ' + this.state.name + '\n' + |
| 31 | + ' template:\n' + |
| 32 | + ' metadata:\n' + |
| 33 | + ' labels:\n' + |
| 34 | + ' app: ' + this.state.name + '\n' + |
| 35 | + ' spec:\n' + |
| 36 | + ' containers:\n' + |
| 37 | + ' - name: ' + this.state.name + '\n' + |
| 38 | + ' image: ' + this.state.name + ':' + this.state.version + '\n' + |
| 39 | + ' ports:\n' + |
| 40 | + ' - containerPort: ' + this.state.port |
| 41 | + |
| 42 | + const k8sSvcString = '---\n' + |
| 43 | + 'apiVersion: v1\n' + |
| 44 | + 'kind: Service\n' + |
| 45 | + 'metadata:\n' + |
| 46 | + ' name: ' + this.state.name + '\n' + |
| 47 | + 'spec:\n' + |
| 48 | + ' ports:\n' + |
| 49 | + ' - protocol: TCP\n' + |
| 50 | + ' port: ' + this.state.port + '\n' + |
| 51 | + ' targetPort: 9376' |
| 52 | + |
| 53 | + const onNameChange = (event) => { |
| 54 | + this.setState({ |
| 55 | + name: event.target.value, |
| 56 | + replicas: this.state.replicas, |
| 57 | + version: this.state.version, |
| 58 | + port: this.state.port, |
| 59 | + service: this.state.service, |
| 60 | + }) |
| 61 | + } |
| 62 | + |
| 63 | + const onReplicasChange = (replicas) => { |
| 64 | + this.setState({ |
| 65 | + name: this.state.name, |
| 66 | + replicas: replicas, |
| 67 | + version: this.state.version, |
| 68 | + port: this.state.port, |
| 69 | + service: this.state.service, |
| 70 | + }) |
| 71 | + } |
| 72 | + |
| 73 | + const onVersionChange = (event) => { |
| 74 | + this.setState({ |
| 75 | + name: this.state.name, |
| 76 | + replicas: this.state.replicas, |
| 77 | + version: event.target.value, |
| 78 | + port: this.state.port, |
| 79 | + service: this.state.service, |
| 80 | + }) |
| 81 | + } |
| 82 | + |
| 83 | + const onPortChange = (port) => { |
| 84 | + this.setState({ |
| 85 | + name: this.state.name, |
| 86 | + replicas: this.state.replicas, |
| 87 | + version: this.state.version, |
| 88 | + port: port, |
| 89 | + service: this.state.service, |
| 90 | + }) |
| 91 | + } |
| 92 | + |
| 93 | + const onNeedService = (service) => { |
| 94 | + this.setState({ |
| 95 | + name: this.state.name, |
| 96 | + replicas: this.state.replicas, |
| 97 | + version: this.state.version, |
| 98 | + port: this.state.port, |
| 99 | + service: service, |
| 100 | + }) |
| 101 | + } |
| 102 | + |
| 103 | + const getManifest = () => { |
| 104 | + var manifest = k8sDplString; |
| 105 | + |
| 106 | + if (this.state.service) { |
| 107 | + manifest += '\n' + k8sSvcString; |
| 108 | + } |
| 109 | + |
| 110 | + return manifest |
| 111 | + } |
| 112 | + |
| 113 | + return ( |
| 114 | + <div className={styles.all}> |
| 115 | + <div className={styles.yaml}> |
| 116 | + <CodeBlock |
| 117 | + language={'yaml'} |
| 118 | + showLineNumbers={true} |
| 119 | + > |
| 120 | + {getManifest()} |
| 121 | + </CodeBlock> |
| 122 | + </div> |
| 123 | + <div className={styles.ui}> |
| 124 | + <h1 className="hero__title">Simple deployment</h1> |
| 125 | + <p className="hero__subtitle">Cyclops gives you a UI containing fields you define yourself to manage your |
| 126 | + K8s workloads</p> |
| 127 | + <Form labelAlign={"left"}> |
| 128 | + <Form.Item |
| 129 | + label="Name" |
| 130 | + style={{display: 'block'}} |
| 131 | + > |
| 132 | + <Input defaultValue={'nginx'} onChange={onNameChange}/> |
| 133 | + </Form.Item> |
| 134 | + <Form.Item |
| 135 | + label="Replicas" |
| 136 | + style={{display: 'block'}} |
| 137 | + > |
| 138 | + <InputNumber defaultValue={'3'} onChange={onReplicasChange}/> |
| 139 | + </Form.Item> |
| 140 | + <Form.Item |
| 141 | + label="Version" |
| 142 | + style={{display: 'block'}} |
| 143 | + > |
| 144 | + <Input defaultValue={'1.14.2'} onChange={onVersionChange}/> |
| 145 | + </Form.Item> |
| 146 | + <Form.Item |
| 147 | + label="Port" |
| 148 | + style={{display: 'block'}} |
| 149 | + > |
| 150 | + <InputNumber defaultValue={'80'} onChange={onPortChange}/> |
| 151 | + </Form.Item> |
| 152 | + <Form.Item |
| 153 | + label="Need service" |
| 154 | + style={{display: 'block'}} |
| 155 | + > |
| 156 | + <Switch defaultValue={'false'} onChange={onNeedService}/> |
| 157 | + </Form.Item> |
| 158 | + </Form> |
| 159 | + </div> |
| 160 | + </div> |
| 161 | + ); |
| 162 | + } |
| 163 | +} |
| 164 | + |
| 165 | +export default Comparison; |
0 commit comments