mirror of
https://github.com/frosch95/K8sFileBrowser.git
synced 2026-04-11 21:08:22 +02:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d03c88261 | |||
| a696152667 | |||
| 491127d460 | |||
| 551b77f5a1 | |||
| 7932583d9d |
@@ -75,8 +75,7 @@
|
||||
"Clean",
|
||||
"Publish",
|
||||
"PublishLinux",
|
||||
"PublishWin",
|
||||
"Restore"
|
||||
"PublishWin"
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -89,8 +88,7 @@
|
||||
"Clean",
|
||||
"Publish",
|
||||
"PublishLinux",
|
||||
"PublishWin",
|
||||
"Restore"
|
||||
"PublishWin"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
Accent="#677696"
|
||||
RegionColor="#282c34"
|
||||
ErrorText="Red"
|
||||
AltHigh="#282c34"
|
||||
AltHigh="#343a45"
|
||||
AltMediumLow="#2c313c"
|
||||
ListLow="#21252b"
|
||||
ListMedium="#2c313c"
|
||||
|
||||
@@ -4,30 +4,39 @@ using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Concurrency;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using K8sFileBrowser.Models;
|
||||
using K8sFileBrowser.Services;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.Fody.Helpers;
|
||||
using Serilog;
|
||||
|
||||
namespace K8sFileBrowser.ViewModels;
|
||||
|
||||
public class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
private ObservableAsPropertyHelper<IEnumerable<ClusterContext>> _clusterContexts = null!;
|
||||
public IEnumerable<ClusterContext> ClusterContexts => _clusterContexts.Value;
|
||||
|
||||
#region Properties
|
||||
|
||||
[Reactive]
|
||||
public string? Version { get; set; } = null!;
|
||||
|
||||
[Reactive]
|
||||
public IEnumerable<ClusterContext> ClusterContexts { get; set; } = null!;
|
||||
|
||||
[Reactive]
|
||||
public ClusterContext? SelectedClusterContext { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public IEnumerable<Namespace> Namespaces { get; set; }
|
||||
public IEnumerable<Namespace> Namespaces { get; set; } = null!;
|
||||
|
||||
[Reactive]
|
||||
public Namespace? SelectedNamespace { get; set; }
|
||||
|
||||
private ObservableAsPropertyHelper<IEnumerable<Pod>> _pods = null!;
|
||||
public IEnumerable<Pod> Pods => _pods.Value;
|
||||
[Reactive]
|
||||
public IEnumerable<Pod> Pods { get; set; } = null!;
|
||||
|
||||
[Reactive]
|
||||
public Pod? SelectedPod { get; set; }
|
||||
@@ -38,8 +47,8 @@ public class MainWindowViewModel : ViewModelBase
|
||||
[Reactive]
|
||||
public Container? SelectedContainer { get; set; }
|
||||
|
||||
private ObservableAsPropertyHelper<IEnumerable<FileInformation>> _fileInformation = null!;
|
||||
public IEnumerable<FileInformation> FileInformation => _fileInformation.Value;
|
||||
[Reactive]
|
||||
public IEnumerable<FileInformation> FileInformation { get; set; } = null!;
|
||||
|
||||
[Reactive]
|
||||
public FileInformation? SelectedFile { get; set; }
|
||||
@@ -48,21 +57,26 @@ public class MainWindowViewModel : ViewModelBase
|
||||
public string? SelectedPath { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public Message Message { get; set; }
|
||||
public Message Message { get; set; } = null!;
|
||||
|
||||
#endregion Properties
|
||||
|
||||
#region Commands
|
||||
|
||||
public ReactiveCommand<Unit, Unit> DownloadCommand { get; private set; } = null!;
|
||||
public ReactiveCommand<Unit, Unit> DownloadLogCommand { get; private set; } = null!;
|
||||
public ReactiveCommand<Unit, Unit> ParentCommand { get; private set; } = null!;
|
||||
public ReactiveCommand<Unit, Unit> OpenCommand { get; private set; } = null!;
|
||||
|
||||
private ReactiveCommand<Namespace, IEnumerable<Pod>> GetPodsForNamespace { get; set; } = null!;
|
||||
|
||||
#endregion Commands
|
||||
|
||||
public MainWindowViewModel()
|
||||
{
|
||||
//TODO: use dependency injection to get the kubernetes service
|
||||
IKubernetesService kubernetesService = new KubernetesService();
|
||||
|
||||
Version = Assembly.GetExecutingAssembly().GetName().Version?.ToString();
|
||||
|
||||
// commands
|
||||
ConfigureOpenDirectoryCommand();
|
||||
ConfigureDownloadFileCommand(kubernetesService);
|
||||
@@ -81,68 +95,25 @@ public class MainWindowViewModel : ViewModelBase
|
||||
InitiallyLoadContexts(kubernetesService);
|
||||
}
|
||||
|
||||
#region Property Subscriptions
|
||||
|
||||
private void InitiallyLoadContexts(IKubernetesService kubernetesService)
|
||||
{
|
||||
// load the cluster contexts when the view model is created
|
||||
var loadContexts = ReactiveCommand
|
||||
.Create<Unit, IEnumerable<ClusterContext>>(_ => kubernetesService.GetClusterContexts());
|
||||
_clusterContexts = loadContexts.Execute().ToProperty(
|
||||
this, x => x.ClusterContexts, scheduler: RxApp.MainThreadScheduler);
|
||||
loadContexts.Execute()
|
||||
.Throttle(new TimeSpan(10))
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(x =>
|
||||
{
|
||||
ResetNamespaces();
|
||||
ClusterContexts = x;
|
||||
|
||||
// select the current cluster context
|
||||
SelectedClusterContext = ClusterContexts
|
||||
.FirstOrDefault(x => x.Name == kubernetesService.GetCurrentContext());
|
||||
}
|
||||
|
||||
private void RegisterResetPath()
|
||||
{
|
||||
// reset the path when the pod or namespace changes
|
||||
this.WhenAnyValue(c => c.SelectedPod, c => c.SelectedNamespace)
|
||||
.Throttle(new TimeSpan(10))
|
||||
.ObserveOn(RxApp.TaskpoolScheduler)
|
||||
.Subscribe(_ => SelectedPath = "/");
|
||||
}
|
||||
|
||||
private void RegisterReadContainers()
|
||||
{
|
||||
// read the file information when the path changes
|
||||
this
|
||||
.WhenAnyValue(c => c.SelectedPod, c => c.SelectedNamespace)
|
||||
.Throttle(new TimeSpan(10))
|
||||
.Select(x => x.Item2 == null || x.Item1 == null
|
||||
? new List<Container>()
|
||||
: x.Item1.Containers.Select(c => new Container {Name = c}))
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe( x => Containers = x);
|
||||
|
||||
this.WhenAnyValue(x => x.Containers)
|
||||
.Throttle(new TimeSpan(10))
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(x => SelectedContainer = x?.FirstOrDefault());
|
||||
}
|
||||
|
||||
private void RegisterReadFiles(IKubernetesService kubernetesService)
|
||||
{
|
||||
// read the file information when the path changes
|
||||
_fileInformation = this
|
||||
.WhenAnyValue(c => c.SelectedPath, c => c.SelectedPod, c => c.SelectedNamespace, c => c.SelectedContainer)
|
||||
.Throttle(new TimeSpan(10))
|
||||
.Select(x => x.Item3 == null || x.Item2 == null || x.Item1 == null || x.Item4 == null
|
||||
? new List<FileInformation>()
|
||||
: GetFileInformation(kubernetesService, x.Item1, x.Item2, x.Item3, x.Item4))
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.ToProperty(this, x => x.FileInformation);
|
||||
}
|
||||
|
||||
private void RegisterReadPods()
|
||||
{
|
||||
// read the pods when the namespace changes
|
||||
_pods = this
|
||||
.WhenAnyValue(c => c.SelectedNamespace)
|
||||
.Throttle(new TimeSpan(10))
|
||||
.SelectMany(ns => GetPodsForNamespace.Execute(ns!))
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.ToProperty(this, x => x.Pods);
|
||||
.FirstOrDefault(c => c.Name == kubernetesService.GetCurrentContext());
|
||||
});
|
||||
}
|
||||
|
||||
private void RegisterReadNamespaces(IKubernetesService kubernetesService)
|
||||
@@ -153,16 +124,82 @@ public class MainWindowViewModel : ViewModelBase
|
||||
.Throttle(new TimeSpan(10))
|
||||
.SelectMany(context => GetClusterContextAsync(context, kubernetesService))
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(ns => Namespaces = ns);
|
||||
.Subscribe(ns =>
|
||||
{
|
||||
ResetPods();
|
||||
Namespaces = ns;
|
||||
});
|
||||
}
|
||||
|
||||
private void RegisterReadPods()
|
||||
{
|
||||
// read the pods when the namespace changes
|
||||
this
|
||||
.WhenAnyValue(c => c.SelectedNamespace)
|
||||
.Throttle(new TimeSpan(10))
|
||||
.Where(x => x != null)
|
||||
.SelectMany(ns => GetPodsForNamespace.Execute(ns!))
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(x =>
|
||||
{
|
||||
ResetContainers();
|
||||
Pods = x;
|
||||
});
|
||||
}
|
||||
|
||||
private void RegisterReadContainers()
|
||||
{
|
||||
// read the file information when the path changes
|
||||
this
|
||||
.WhenAnyValue(c => c.SelectedPod)
|
||||
.Throttle(new TimeSpan(10))
|
||||
.Where(x => x != null)
|
||||
.Select(x => x!.Containers.Select(c => new Container {Name = c}))
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe( x =>
|
||||
{
|
||||
ResetPath();
|
||||
Containers = x;
|
||||
});
|
||||
|
||||
this.WhenAnyValue(x => x.Containers)
|
||||
.Throttle(new TimeSpan(10))
|
||||
.Where(x => !x.IsNullOrEmpty())
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(x => SelectedContainer = x?.FirstOrDefault());
|
||||
}
|
||||
|
||||
private void RegisterResetPath()
|
||||
{
|
||||
// reset the path when the pod or namespace changes
|
||||
this.WhenAnyValue(c => c.SelectedContainer)
|
||||
.Throttle(new TimeSpan(10))
|
||||
.Where(x => x != null)
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(_ => SelectedPath = "/");
|
||||
}
|
||||
|
||||
private void RegisterReadFiles(IKubernetesService kubernetesService)
|
||||
{
|
||||
// read the file information when the path changes
|
||||
this
|
||||
.WhenAnyValue(c => c.SelectedContainer, c => c.SelectedPath)
|
||||
.Throttle(new TimeSpan(10))
|
||||
.Where(x => x is { Item1: not null, Item2: not null })
|
||||
.Select(x => GetFileInformation(kubernetesService, x.Item2!, SelectedPod!, SelectedNamespace!, x.Item1!))
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(x => FileInformation = x);
|
||||
}
|
||||
#endregion Property Subscriptions
|
||||
|
||||
#region Configure Commands
|
||||
private void ConfigureGetPodsForNamespaceCommand(IKubernetesService kubernetesService)
|
||||
{
|
||||
GetPodsForNamespace = ReactiveCommand.CreateFromObservable<Namespace, IEnumerable<Pod>>(ns =>
|
||||
Observable.StartAsync(_ => PodsAsync(ns, kubernetesService), RxApp.TaskpoolScheduler));
|
||||
|
||||
GetPodsForNamespace.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(ex => ShowErrorMessage(ex.Message).ConfigureAwait(false).GetAwaiter().GetResult());
|
||||
.Subscribe(ShowErrorMessage);
|
||||
}
|
||||
|
||||
private void ConfigureParentDirectoryCommand()
|
||||
@@ -181,7 +218,7 @@ public class MainWindowViewModel : ViewModelBase
|
||||
}, isNotRoot, RxApp.MainThreadScheduler);
|
||||
|
||||
ParentCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(ex => ShowErrorMessage(ex.Message).ConfigureAwait(false).GetAwaiter().GetResult());
|
||||
.Subscribe(ShowErrorMessage);
|
||||
}
|
||||
|
||||
private void ConfigureDownloadLogCommand(IKubernetesService kubernetesService)
|
||||
@@ -206,7 +243,7 @@ public class MainWindowViewModel : ViewModelBase
|
||||
}, isSelectedPod, RxApp.MainThreadScheduler);
|
||||
|
||||
DownloadLogCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(ex => ShowErrorMessage(ex.Message).ConfigureAwait(false).GetAwaiter().GetResult());
|
||||
.Subscribe(ShowErrorMessage);
|
||||
}
|
||||
|
||||
private void ConfigureDownloadFileCommand(IKubernetesService kubernetesService)
|
||||
@@ -232,7 +269,7 @@ public class MainWindowViewModel : ViewModelBase
|
||||
}, isFile, RxApp.MainThreadScheduler);
|
||||
|
||||
DownloadCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(ex => ShowErrorMessage(ex.Message).ConfigureAwait(false).GetAwaiter().GetResult());
|
||||
.Subscribe(ShowErrorMessage);
|
||||
}
|
||||
|
||||
private void ConfigureOpenDirectoryCommand()
|
||||
@@ -251,9 +288,13 @@ public class MainWindowViewModel : ViewModelBase
|
||||
isDirectory, RxApp.MainThreadScheduler);
|
||||
|
||||
OpenCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(ex => ShowErrorMessage(ex.Message).ConfigureAwait(false).GetAwaiter().GetResult());
|
||||
.Subscribe(ShowErrorMessage);
|
||||
}
|
||||
|
||||
#endregion Configure Commands
|
||||
|
||||
#region Get Data
|
||||
|
||||
private static async Task<IEnumerable<Pod>> PodsAsync(Namespace? ns, IKubernetesService kubernetesService)
|
||||
{
|
||||
if (ns == null)
|
||||
@@ -277,10 +318,8 @@ public class MainWindowViewModel : ViewModelBase
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
RxApp.MainThreadScheduler.Schedule(Action);
|
||||
ShowErrorMessage(e);
|
||||
return new List<Namespace>();
|
||||
|
||||
async void Action() => await ShowErrorMessage(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,6 +347,44 @@ public class MainWindowViewModel : ViewModelBase
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
#endregion Get Data
|
||||
|
||||
#region Reset Data
|
||||
|
||||
private void ResetPath()
|
||||
{
|
||||
FileInformation = new List<FileInformation>();
|
||||
SelectedPath = null;
|
||||
SelectedContainer = null;
|
||||
}
|
||||
|
||||
private void ResetContainers()
|
||||
{
|
||||
ResetPath();
|
||||
Containers = new List<Container>();
|
||||
SelectedPod = null;
|
||||
|
||||
}
|
||||
|
||||
private void ResetPods()
|
||||
{
|
||||
ResetContainers();
|
||||
SelectedNamespace = null;
|
||||
Pods = new List<Pod>();
|
||||
|
||||
}
|
||||
|
||||
private void ResetNamespaces()
|
||||
{
|
||||
ResetPods();
|
||||
Namespaces = new List<Namespace>();
|
||||
SelectedClusterContext = null;
|
||||
}
|
||||
|
||||
#endregion Reset Data
|
||||
|
||||
#region show messages
|
||||
|
||||
private void ShowWorkingMessage(string message)
|
||||
{
|
||||
Message = new Message
|
||||
@@ -318,25 +395,34 @@ public class MainWindowViewModel : ViewModelBase
|
||||
};
|
||||
}
|
||||
|
||||
private async Task ShowErrorMessage(string message)
|
||||
private void ShowErrorMessage(string message)
|
||||
{
|
||||
Message = new Message
|
||||
async void Action()
|
||||
{
|
||||
IsVisible = true,
|
||||
Text = message,
|
||||
IsError = true
|
||||
};
|
||||
Message = new Message { IsVisible = true, Text = message, IsError = true };
|
||||
await Task.Delay(7000);
|
||||
HideWorkingMessage();
|
||||
}
|
||||
|
||||
RxApp.MainThreadScheduler.Schedule(Action);
|
||||
}
|
||||
|
||||
private void ShowErrorMessage(Exception exception)
|
||||
{
|
||||
// ReSharper disable once TemplateIsNotCompileTimeConstantProblem
|
||||
Log.Error(exception, exception.Message);
|
||||
ShowErrorMessage(exception.Message);
|
||||
}
|
||||
|
||||
private void HideWorkingMessage()
|
||||
{
|
||||
Message = new Message
|
||||
RxApp.MainThreadScheduler.Schedule(() => Message = new Message
|
||||
{
|
||||
IsVisible = false,
|
||||
Text = "",
|
||||
IsError = false
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
#endregion show messages
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
</Border>
|
||||
<Grid RowDefinitions="Auto, *">
|
||||
<Border Padding="10 14" Background="#21252b">
|
||||
<Grid ColumnDefinitions="Auto,Auto,Auto,*">
|
||||
<Grid ColumnDefinitions="Auto,Auto,Auto,*,Auto">
|
||||
<Label Grid.Column="0"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0 0 10 0">
|
||||
@@ -49,6 +49,7 @@
|
||||
MinWidth="200"
|
||||
Margin="0 0 10 0">
|
||||
</ComboBox>
|
||||
<TextBlock Grid.Column="4" HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding Version}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
|
||||
10
README.md
10
README.md
@@ -3,4 +3,14 @@
|
||||
A UI tool for downloading files from a Pod.
|
||||
The application is also the first Avalonia UI and C# UI app I have written.
|
||||
|
||||
## Usage
|
||||
|
||||
Just start the executable and select the cluster, namespace and pod you want to download files from.
|
||||
Then select the files you want to download and click the download button.
|
||||
|
||||
The available clusters are read from the `~/.kube/config` file.
|
||||
|
||||
## Limitations
|
||||
It only works on linux containers and the container must support `find` and `tar`.
|
||||
|
||||

|
||||
@@ -31,20 +31,11 @@ class Build : NukeBuild
|
||||
|
||||
|
||||
Target Clean => _ => _
|
||||
.Before(Restore)
|
||||
.Executes(() =>
|
||||
{
|
||||
OutputDirectory.DeleteDirectory();
|
||||
});
|
||||
|
||||
Target Restore => _ => _
|
||||
.Executes(() =>
|
||||
{
|
||||
DotNet($"restore {ProjectFile}");
|
||||
//DotNetTasks.DotNetRestore(new DotNetRestoreSettings());
|
||||
});
|
||||
|
||||
|
||||
Target PublishWin => _ => _
|
||||
.DependsOn(Clean)
|
||||
.Executes(() =>
|
||||
@@ -62,8 +53,7 @@ class Build : NukeBuild
|
||||
.SetCopyright("Copyright (c) 2023")
|
||||
.SetVersion(Version)
|
||||
.SetProcessArgumentConfigurator(_ => _
|
||||
.Add("-p:IncludeNativeLibrariesForSelfExtract=true"))
|
||||
.EnableNoRestore());
|
||||
.Add("-p:IncludeNativeLibrariesForSelfExtract=true")));
|
||||
|
||||
WinOutputDirectory.ZipTo(
|
||||
WinZip,
|
||||
@@ -89,8 +79,7 @@ class Build : NukeBuild
|
||||
.SetCopyright("Copyright (c) 2023")
|
||||
.SetVersion(Version)
|
||||
.SetProcessArgumentConfigurator(_ => _
|
||||
.Add("-p:IncludeNativeLibrariesForSelfExtract=true"))
|
||||
.EnableNoRestore());
|
||||
.Add("-p:IncludeNativeLibrariesForSelfExtract=true")));
|
||||
|
||||
LinuxOutputDirectory.TarGZipTo(
|
||||
LinuxGz,
|
||||
|
||||
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
|
Before Width: | Height: | Size: 65 KiB After Width: | Height: | Size: 150 KiB |
Reference in New Issue
Block a user