Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Kubeconfig via file #122

Merged
merged 1 commit into from
Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/components/settings/clusters/kubeconfig/KubeconfigPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ const KubeconfigPage: React.FunctionComponent<IKubeconfigPageProps> = ({ history
setKubeconfig(event.target.value);
};

const handleKubeconfigFile = async (event) => {
const files: FileList = event.target.files;

if (files.length === 1) {
const reader = new FileReader();
reader.readAsText(files[0], 'UTF-8');
reader.onload = (e) => {
if (e.target && e.target.result) {
setKubeconfig(e.target.result as string);
}
};
reader.onerror = () => {
setError(`Could not read ${files[0].name}`);
};
}
};

const addClusters = () => {
if (kubeconfig === '') {
setError('Kubeconfig is required');
Expand Down Expand Up @@ -130,6 +147,15 @@ const KubeconfigPage: React.FunctionComponent<IKubeconfigPageProps> = ({ history
</IonHeader>
<IonContent>
<IonList lines="full">
<div className="select-kubeconfig-wrapper">
<IonButton expand="block">
<input id="file" hidden type="file" onChange={handleKubeconfigFile} />
<label htmlFor="file" className="select-kubeconfig">
Select Kubeconfig
</label>
</IonButton>
</div>

<IonItem>
<IonLabel position="stacked">Kubeconfig</IonLabel>
<IonTextarea autoGrow={true} value={kubeconfig} onInput={handleKubeconfig} />
Expand Down
10 changes: 10 additions & 0 deletions src/theme/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,13 @@ ion-avatar {
width: 368px;
}

/* Select Kubeconfig
Customization for the file input to import a Kubeconfig file */
.select-kubeconfig-wrapper {
padding: 16px;
}

.select-kubeconfig {
width: 100%;
cursor: pointer;
}
1 change: 0 additions & 1 deletion src/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export const readSettings = (): IAppSettings => {

if (settingsFromStorage) {
const settings = JSON.parse(settingsFromStorage);
console.log(settings);
return {
darkMode: settings.hasOwnProperty('darkMode') ? settings.darkMode : DEFAULT_SETTINGS.darkMode,
timeout: settings.timeout ? settings.timeout : DEFAULT_SETTINGS.timeout,
Expand Down