Skip to content

Commit

Permalink
feat(console): adjust kubectl dialog (tkestack#953)
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-hnny committed Nov 30, 2020
1 parent 5211c56 commit ca31bc3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 51 deletions.
33 changes: 30 additions & 3 deletions web/console/helpers/downloadCrt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,34 @@ export function downloadKubeconfig(crtText, filename = 'kubeconfig') {
downloadText(crtText, filename, 'applicatoin/octet-stream;charset=utf-8;');
}

export function getKubectlConfig({ caCert, token, host, clusterId }) {
const config = `apiVersion: v1\nclusters:\n- cluster:\n certificate-authority-data: ${caCert}\n server: ${host}\n name: ${clusterId}\ncontexts:\n- context:\n cluster: ${clusterId}\n user: ${clusterId}-admin\n name: ${clusterId}-context-default\ncurrent-context: ${clusterId}-context-default\nkind: Config\npreferences: {}\nusers:\n- name: ${clusterId}-admin\n user:\n token: ${token}\n`;
return config;
export function getKubectlConfig({ caCert, token, host, clusterId, clientKey, clientCert }) {
const user = Object.entries({
token: token,
'client-key-data': clientKey,
'client-certificate-data': clientCert
})
.filter(([key, value]) => value)
.map(([key, value]) => `${key}: ${value}`)
.join('\n ');

return `
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: ${caCert}
server: ${host}
name: ${clusterId}
contexts:
- context:
cluster: ${clusterId}
user: ${clusterId}-admin
name: ${clusterId}-context-default
current-context: ${clusterId}-default
kind: Config
preferences: {}
users:
- name: ${clusterId}-admin
user:
${user}
`.trim();
}
4 changes: 3 additions & 1 deletion web/console/src/modules/cluster/actions/clusterActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ const restActions = {
name: response.records[0].metadata.name,
clusterName: response.records[0].clusterName,
caCert: response.records[0].caCert,
token: response.records[0].token
token: response.records[0].token,
clientKey: response.records[0].clientKey,
clientCert: response.records[0].clientCert
}
});
}
Expand Down
49 changes: 3 additions & 46 deletions web/console/src/modules/cluster/components/KubectlDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export class KubectlDialog extends React.Component<RootProps, any> {
caCert: clustercredential.caCert,
token: clustercredential.token,
host: getHost(clusterInfo),
clusterId: clustercredential.clusterName
clusterId: clustercredential.clusterName,
clientKey: clustercredential.clientKey,
clientCert: clustercredential.clientCert
});

return kuberctlDialog ? (
Expand All @@ -67,51 +69,6 @@ export class KubectlDialog extends React.Component<RootProps, any> {
);
})}
</FormPanel.Item>
<FormPanel.Item label={t('Token')}>
<div className="rich-textarea hide-number">
<Clip target={'#token'} className="copy-btn">
{t('复制')}
</Clip>
<div className="rich-content" contentEditable={false}>
<p
className="rich-text"
id="token"
style={{ width: '475px', whiteSpace: 'pre-wrap', height: '25px', marginTop: '0px' }}
>
{clustercredential.token}
</p>
</div>
</div>
</FormPanel.Item>
<FormPanel.Item label={t('集群CA证书')}>
<div className="rich-textarea hide-number">
<Clip target={'#certificationAuthority'} className="copy-btn">
{t('复制')}
</Clip>
<a
href="javascript:void(0)"
onClick={e => downloadCrt(clustercredential.caCert ? window.atob(clustercredential.caCert) : '')}
className="copy-btn"
style={{ right: '50px' }}
>
{t('下载')}
</a>
<div className="rich-content" contentEditable={false}>
<p
className="rich-text"
id="certificationAuthority"
style={{
width: '480px',
whiteSpace: 'pre-wrap',
overflow: 'auto',
height: '64px'
}}
>
{clustercredential.caCert && window.atob(clustercredential.caCert)}
</p>
</div>
</div>
</FormPanel.Item>

<FormPanel.Item label="Kubeconfig">
<div className="rich-textarea hide-number">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ export class ClusterTablePanel extends React.Component<RootProps, State> {
{/* {cluster.status.phase !== 'Running' && cluster.status.phase !== 'Terminating' && renderConditions()} */}
{renderDeleteButton()}
{renderKuberctlButton()}
{/* {cluster.spec.type === 'Imported' && renderUpdateTokenButton()} */}
{cluster.spec.type === 'Imported' && renderUpdateTokenButton()}
{renderMoreButton()}
</React.Fragment>
Expand Down
4 changes: 3 additions & 1 deletion web/console/src/modules/cluster/models/Clustercredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ export interface Clustercredential {
name: string;
clusterName: string;
caCert: string;
token: string;
token?: string;
clientKey?: string;
clientCert?: string;
}

0 comments on commit ca31bc3

Please sign in to comment.