public void LinuxUsesHomeEnvironmentVariable() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Environment.SetEnvironmentVariable("USERPROFILE", UserProfile); var home = Environment.GetEnvironmentVariable("HOME"); var config = K8sConfig.Locate(); Assert.Equal(Path.Combine(home, ".kube", "config"), config); } }
public void WindowsUsesHomeFirst() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Environment.SetEnvironmentVariable("USERPROFILE", UserProfile); Environment.SetEnvironmentVariable("HOMEDRIVE", HomeDrive); Environment.SetEnvironmentVariable("HOMEPATH", HomePath); Environment.SetEnvironmentVariable("HOME", Home); var config = K8sConfig.Locate(); Assert.Equal(Path.Combine(Home, ".kube", "config"), config); } }
protected override async Task ProcessRecordAsync(CancellationToken cancellationToken) { await base.ProcessRecordAsync(cancellationToken); Serializer serializer = new SerializerBuilder().Build(); string yaml = serializer.Serialize(Config); string configPath = K8sConfig.Locate(); if (ShouldProcess(configPath, "update")) { await File.WriteAllTextAsync(configPath, yaml); // Do not pass cancellationToken to not corrupt config file } }
public void WindowsUsesUserProfileAsLastOption() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Environment.SetEnvironmentVariable("HOME", String.Empty); Environment.SetEnvironmentVariable("HOMEDRIVE", String.Empty); Environment.SetEnvironmentVariable("HOMEPATH", String.Empty); Environment.SetEnvironmentVariable("USERPROFILE", UserProfile); var config = K8sConfig.Locate(); Assert.Equal(Path.Combine(UserProfile, ".kube", "config"), config); } }
protected override async Task ProcessRecordAsync(CancellationToken cancellationToken) { await base.ProcessRecordAsync(cancellationToken); string configPath = K8sConfig.Locate(); K8sConfig config = K8sConfig.Load(configPath); config.CurrentContextName = Context; ISerializer serializer = new SerializerBuilder().Build(); string yaml = serializer.Serialize(config); if (ShouldProcess(configPath, "update")) { using (var streamWriter = new StreamWriter(configPath)) { await streamWriter.WriteAsync(yaml); // Do not pass cancellationToken to not corrupt config file } } }