Class KubeHelper
cluster related utilties.
Namespace: Neon.Kube
Assembly: Neon.Kube.dll
Syntax
public static class KubeHelper
Fields
CurlOptions
CURL command common options.
Declaration
public const string CurlOptions = "-4fsSL --retry 10 --retry-delay 30 --max-redirs 10"
Field Value
| Type | Description |
|---|---|
| string |
VmImageFolderName
The name of the user's cluster virtual machine image cache folder.
Declaration
public const string VmImageFolderName = "images"
Field Value
| Type | Description |
|---|---|
| string |
Properties
CacheFolder
Returns the path the folder containing cached files for various environments.
Declaration
public static string CacheFolder { get; }
Property Value
| Type | Description |
|---|---|
| string | The folder path. |
ClientConfig
Accesses the NEONDESKTOP client configuration.
Declaration
public static KubeClientConfig ClientConfig { get; set; }
Property Value
| Type | Description |
|---|---|
| KubeClientConfig |
ClientId
Returns a unique ID for the client installation. This used for identifying the client for logs and traces so we can correlate problems specific users are seeing.
note
This is persisted to: ~/.neonkube/desktop/client-id
Declaration
public static Guid ClientId { get; }
Property Value
| Type | Description |
|---|---|
| Guid |
CurrentCluster
Returns the current KubeConfigCluster specified by the CurrentContext
from the KubeContext or null when no context is selected or the named cluster does not exist.
Declaration
public static KubeConfigCluster CurrentCluster { get; }
Property Value
| Type | Description |
|---|---|
| KubeConfigCluster |
CurrentContext
Returns the current KubeConfigContext from the KubeContext or
null when no context is selected.
Declaration
public static KubeConfigContext CurrentContext { get; }
Property Value
| Type | Description |
|---|---|
| KubeConfigContext |
CurrentContextName
Returns the current context's CurrentContextName or null
if there's no current context.
Declaration
public static KubeContextName CurrentContextName { get; }
Property Value
| Type | Description |
|---|---|
| KubeContextName |
CurrentUser
Returns the current KubeConfigUser specified by the CurrentContext
from the KubeContext or null when no context is selected or the named user does not exist.
Declaration
public static KubeConfigUser CurrentUser { get; }
Property Value
| Type | Description |
|---|---|
| KubeConfigUser |
DesktopCommonFolder
Returns the path to the global NEONDESKTOP program data folder. This is used for information to be shared across all users as well as between the user programs and the neon-desktop-service.
note
All users will have read/write access to files in this folder.
Declaration
public static string DesktopCommonFolder { get; }
Property Value
| Type | Description |
|---|---|
| string |
DesktopFolder
Returns the path to the NEONDESKTOP state folder.
Declaration
public static string DesktopFolder { get; }
Property Value
| Type | Description |
|---|---|
| string |
DesktopHypervFolder
Returns path to the NEONDESKTOP Hyper-V state folder.
Declaration
public static string DesktopHypervFolder { get; }
Property Value
| Type | Description |
|---|---|
| string |
DesktopLogFolder
Returns path to the NEONDESKTOP log folder.
Declaration
public static string DesktopLogFolder { get; }
Property Value
| Type | Description |
|---|---|
| string |
DevelopmentFolder
Returns the path the folder used by NEONKUBE development tools, creating the folder if it doesn't already exist.
Declaration
public static string DevelopmentFolder { get; }
Property Value
| Type | Description |
|---|---|
| string | The folder path. |
HostPlatform
Returns the KubeClientPlatform for the current workstation.
Declaration
public static KubeClientPlatform HostPlatform { get; }
Property Value
| Type | Description |
|---|---|
| KubeClientPlatform |
InstallFolder
Returns the path to the neon installation folder. This is where the either neon-cli or neon-desktop are installed. This is used to determine where tools like pwsh and ssh-keygen are located.
Declaration
public static string InstallFolder { get; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
One of neon-cli or neon-desktop are allowed to be installed on a user's workstation and the NEON_INSTALL_FOLDER environment variable will be set during installation to point to the program installation folder.
This folder will be structured like for a neon-cli onlyinstallation:
C:\Program Files\NEONFORGE\neon-cli\
. # neon-cli binaries
neon-desktop-service # neon-desktop-service binaries
ssh\ # SSH related tools
and this for neon-desktop (which includes neon-cli):
C:\Program Files\NEONFORGE\neon-desktop\
. # neon-desktop and neon-cli binaries
neon-desktop-service # neon-desktop-service binaries
ssh\ # SSH related tools
IsRelease
Returns true if the current assembly was built from the production PROD
source code branch.
Declaration
public static bool IsRelease { get; }
Property Value
| Type | Description |
|---|---|
| bool |
KubeConfig
Returns the user's current KubeConfig.
Declaration
public static KubeConfig KubeConfig { get; }
Property Value
| Type | Description |
|---|---|
| KubeConfig |
KubeConfigPath
Returns the path to the Kubernetes configuration file.
Declaration
public static string KubeConfigPath { get; }
Property Value
| Type | Description |
|---|---|
| string |
LogDetailsFolder
Returns the default directory path where neon-cli cluster details will be written.
Declaration
public static string LogDetailsFolder { get; }
Property Value
| Type | Description |
|---|---|
| string | The folder path. |
LogFolder
Returns the default directory path where neon-cli logs will be written.
Declaration
public static string LogFolder { get; }
Property Value
| Type | Description |
|---|---|
| string | The folder path. |
NeonCliPath
Locates the most recent neon-cli executable. Note that this returns the path to our version of kubectl rather than the neon-cli executable that implements our customized subcommands.
Declaration
public static string NeonCliPath { get; }
Property Value
| Type | Description |
|---|---|
| string | The path to the executable. |
Remarks
This method is intended to work well on normal user machines where the neonKUBE/neonCLOUD sources and build environments are not configured as well as for maintainers that need to execute most recent executable to test/debug recent changes.
If either of neon-cli or neon-desktop is installed on the workstation (determined by the presence of the NEON_INSTALL_FOLDER environment variable), we'll return the path to the executable from the installation folder. When those are not installed, we'll return $(NC_ROOT)/Build/neon-cli/neon.exe.
A FileNotFoundException will be thrown we couldn't locate the executable.
Exceptions
| Type | Condition |
|---|---|
| FileNotFoundException | Thrown when no executable was found. |
NeonKubeUserFolder
Returns the path the folder holding the user specific cluster logins and other files.
Declaration
public static string NeonKubeUserFolder { get; }
Property Value
| Type | Description |
|---|---|
| string | The folder path. |
NodeContainerImagesFolder
Returns the path the folder used by NEONKUBE development tools to cache the packed container image files used to prepare NEONKUBE node images, creating the folder if it doesn't already exist.
note
The path returned will always be within the user's original HOME folder. This does not honor custom HOME folders set via SetUserHomeFolder(string). We do this because we use this folder to cache these images so we don't need to rebuild them multiple times for a release.
Declaration
public static string NodeContainerImagesFolder { get; }
Property Value
| Type | Description |
|---|---|
| string | The folder path. |
OpenSshConfig
Returns the OpenSSH configuration file used for cluster nodes.
Declaration
public static string OpenSshConfig { get; }
Property Value
| Type | Description |
|---|---|
| string |
PasswordsFolder
Returns path to the folder holding the encryption passwords.
Declaration
public static string PasswordsFolder { get; }
Property Value
| Type | Description |
|---|---|
| string | The folder path. |
Resources
Returns the IStaticDirectory for the assembly's resources.
Declaration
public static IStaticDirectory Resources { get; }
Property Value
| Type | Description |
|---|---|
| IStaticDirectory |
RunFolder
Returns the directory path where the [neon run CMD ...] will copy secrets and run the command.
Declaration
public static string RunFolder { get; }
Property Value
| Type | Description |
|---|---|
| string | The folder path. |
SetupFolder
Returns the path the folder containing the temporary setup state files, creating the folder if it doesn't already exist.
Declaration
public static string SetupFolder { get; }
Property Value
| Type | Description |
|---|---|
| string | The folder path. |
Remarks
This folder holds KubeSetupState for clusters in the process of being prepared and setup. Files will be named like CLUSTER-NAME.json
StandardNeonKubeFolder
Returns the path to the current user's .neonkube folder.
Declaration
public static string StandardNeonKubeFolder { get; }
Property Value
| Type | Description |
|---|---|
| string |
TelemetryTags
Returns the tags to be included in all logs and root activity traces.
Declaration
public static IEnumerable<KeyValuePair<string, object>> TelemetryTags { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<KeyValuePair<string, object>> |
TempFolder
Returns the path the user specific NEONKUBE temporary folder, creating the folder if it doesn't already exist.
Declaration
public static string TempFolder { get; }
Property Value
| Type | Description |
|---|---|
| string | The folder path. |
Remarks
This folder will exist on developer/operator workstations that have used the neon-cli to deploy and manage clusters.
ToolsFolder
Returns the path the folder used for holding Kubernetes related tools when running neon-cli as a developer, creating the folder if it doesn't already exist.
Declaration
public static string ToolsFolder { get; }
Property Value
| Type | Description |
|---|---|
| string | The folder path. |
UserSshFolder
Returns the path to the .ssh folder within user's home folder.
Declaration
public static string UserSshFolder { get; }
Property Value
| Type | Description |
|---|---|
| string |
VmImageFolder
Returns the path to the current user's cluster virtual machine image cache folder, creating the directory if it doesn't already exist.
Declaration
public static string VmImageFolder { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The path to the cluster setup folder. |
Remarks
In very special situations, you may use this to set a custom cache folder.
WinDesktopServiceSocketPath
k
Returns the path to the Windows Desktop Service Unix domain socket.
note
The Neon Windows Desktop Service runs in the background for all users so the socket will be located within the Windows program data folder.
Declaration
public static string WinDesktopServiceSocketPath { get; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
CheckName(string)
Determines whether a name is a valid Kubernetes name.
- contain no more than 253 characters
- contain only lowercase alphanumeric characters, '-' or '.'
- start with an alphanumeric character
- end with an alphanumeric character
Declaration
public static void CheckName(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name to check. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown for null or empty names. |
| FormatException | Thrown for invalid names. |
CreateIsoFile(string, string, string)
Packages files within a folder into an ISO file.
note
This requires Powershell to be installed and this will favor using the version of Powershell installed along with the neon-cli, if present.
Declaration
public static void CreateIsoFile(string sourceFolder, string isoPath, string label = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | sourceFolder | Path to the input folder. |
| string | isoPath | Path to the output ISO file. |
| string | label | Optionally specifies a volume label. |
Exceptions
| Type | Condition |
|---|---|
| ExecuteException | Thrown if the operation failed. |
CreateKubeObject<T>(string)
Constructs an initialized Kubernetes object of a specific type.
Declaration
public static T CreateKubeObject<T>(string name) where T : IKubernetesObject, IMetadata<V1ObjectMeta>, new()
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Specifies the object name. |
Returns
| Type | Description |
|---|---|
| T | The new |
Type Parameters
| Name | Description |
|---|---|
| T | The Kubernetes object type. |
Remarks
Unfortunately, the default constructors for objects like V1ConfigMap do not initialize the ApiVersion and Kind and properties even though these values will be the same for all instances of each object type. (I assume that Microsoft doesn't do this as an optimization that avoids initializing these properties and then doing that again when deserializing responses from the API server.
This method constructs the request object and then configures its ApiVersion
and Kind properties by reflecting T and using
the constant KubeGroup, KubeApiVersion and KubeKind values. This is very convenient
but will be somwehat slower than setting these values explicitly but is probably worth the cost in most
situations because Kubernetes objects are typically read much more often than being created.
note
This method requires that T define string KubeGroup KubeApiVersion
and KubeKind constants that return the correct values for the type.
Exceptions
| Type | Condition |
|---|---|
| NotSupportedException | Thrown when |
CreateKubernetesClient(string, string)
Creates a IKubernetes client from a kubeconfig file.
Declaration
public static IKubernetes CreateKubernetesClient(string kubeConfigPath = null, string currentContext = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | kubeConfigPath | Optionally specifies the path to the kubecontext file. |
| string | currentContext | Optionally specifies the name of the context to use. |
Returns
| Type | Description |
|---|---|
| IKubernetes | The IKubernetes. |
Remarks
This method just returns a client for the current context in the standard location when
kubeConfigPath isn't passed, otherwise it will load the kubeconfig
from that path and return a client for the current context or the specific context identified
by currentContext.
CreateNeonInitIso(ClusterDefinition, NodeDefinition, int, string)
Creates an ISO file containing the neon-init.sh script that will be used for confguring the node on first boot. This includes disabling the APT package update services, optionally setting a secure password for the sysadmin account, and configuring the network interface with a static IP address.
This override has obtains network settings from a ClusterDefinition and NodeDefinition.
Declaration
public static TempFile CreateNeonInitIso(ClusterDefinition clusterDefinition, NodeDefinition nodeDefinition, int nodeMtu = 0, string newPassword = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ClusterDefinition | clusterDefinition | The cluster definition. |
| NodeDefinition | nodeDefinition | The node definition. |
| int | nodeMtu | Optionally specifies the MTU to be configured for the node's network interface. Pass 0 to configure DefaultMTU or a value between 512-9000. |
| string | newPassword | Optionally specifies the new SSH password to be configured on the node. |
Returns
| Type | Description |
|---|---|
| TempFile | A TempFile that references the generated ISO file. |
Remarks
The hosting manager will call this for each node being prepared and then insert the ISO into the node VM's DVD/CD drive before booting the node for the first time. The neon-init service configured on the corresponding node templates will look for this DVD and script and execute it early during the node boot process.
The ISO file reference is returned as a TempFile. The caller should call Dispose() when it's done with the file to ensure that it is deleted.
CreateNeonInitIso(string, string, string, IEnumerable<string>, int, string)
Creates an ISO file containing the neon-init.sh script that will be used for confguring the node on first boot. This includes disabling the APT package update services, optionally setting a secure password for the sysadmin account, and configuring the network interface with a static IP address.
This override has explict parameters for configuring the network.
Declaration
public static TempFile CreateNeonInitIso(string address, string subnet, string gateway, IEnumerable<string> nameServers, int nodeMtu = 0, string newPassword = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | address | The IP address to be assigned the the VM. |
| string | subnet | The network subnet to be configured. |
| string | gateway | The network gateway to be configured. |
| IEnumerable<string> | nameServers | The nameserver addresses to be configured. |
| int | nodeMtu | Optionally specifies the MTU to be configured for the node's network interface. Pass 0 to configure DefaultMTU or a value between 512-9000. |
| string | newPassword | Optionally specifies the new SSH password to be configured on the node. |
Returns
| Type | Description |
|---|---|
| TempFile | A TempFile that references the generated ISO file. |
Remarks
The hosting manager will call this for each node being prepared and then insert the ISO into the node VM's DVD/CD drive before booting the node for the first time. The neon-init service configured on the corresponding node templates will look for this DVD and script and execute it early during the node boot process.
The ISO file reference is returned as a TempFile. The caller should call Dispose() when it's done with the file to ensure that it is deleted.
CreateSelfSigned(string, int, int, Wildcard, string, string, string)
Generates a self-signed certificate for arbitrary hostnames, possibly including hostnames with wildcards.
Declaration
public static X509Certificate2 CreateSelfSigned(string hostname, int bitCount = 2048, int validDays = 365000, Wildcard wildcard = Wildcard.None, string issuedBy = null, string issuedTo = null, string friendlyName = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | hostname | The certificate host names. noteYou can use include a "*" to specify a wildcard certificate like: *.test.com. |
| int | bitCount | The certificate key size in bits: one of 1024, 2048, or 4096 (defaults to 2048). |
| int | validDays | The number of days the certificate will be valid. This defaults to 365,000 days or about 1,000 years. |
| Wildcard | wildcard | Optionally generate a wildcard certificate for the subdomains of
|
| string | issuedBy | Optionally specifies the issuer. |
| string | issuedTo | Optionally specifies who/what the certificate is issued for. |
| string | friendlyName | Optionally specifies the certificate's friendly name. |
Returns
| Type | Description |
|---|---|
| X509Certificate2 | The new X509Certificate2. |
DownloadNodeImageAsync(string, string, DownloadProgressDelegate, bool, CancellationToken)
Downloads a multi-part node image to a local folder.
Declaration
public static Task<string> DownloadNodeImageAsync(string imageUri, string imagePath, DownloadProgressDelegate progressAction = null, bool strictCheck = true, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | imageUri | The node image multi-part download information URI. |
| string | imagePath | The local path where the image will be written. |
| DownloadProgressDelegate | progressAction | Optional progress action that will be called with operation percent complete. |
| bool | strictCheck | Optionally used to disable a slow but more comprehensive check of any existing file. When this is disabled and the download file already exists along with its MD5 hash file, the method will assume that the existing file matches when the file size is the same as specified in the manifest and manifest overall MD5 matches the local MD5 file.
Otherwise when
This defaults to |
| CancellationToken | cancellationToken | Optional cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<string> | The path to the downloaded file. |
Remarks
This checks to see if the target file already exists and will download only what's required to update the file to match the source. This means that partially completed downloads can restart essentially where they left off.
Exceptions
| Type | Condition |
|---|---|
| SocketException | Thrown for network errors. |
| HttpException | Thrown for HTTP network errors. |
| OperationCanceledException | Thrown when the operation was cancelled. |
EditNeonKubeVersion(SemanticVersion)
Edits the $/NEONKUBE/Lib/Neon.Kube/KubeVersions.cs source file by setting the NeonKube constant to the version passed.
Declaration
public static bool EditNeonKubeVersion(SemanticVersion version)
Parameters
| Type | Name | Description |
|---|---|---|
| SemanticVersion | version | The new version number. |
Returns
| Type | Description |
|---|---|
| bool |
|
EnsureIngressNodes(ClusterDefinition)
Ensures that at least one cluster node is enabled for cluster ingress network traffic.
note
It is possible for the user to have set Ingress
to false for all nodes. We're going to pick a reasonable set of
nodes in this case. I there are 3 or more workers, then only the workers
will receive traffic, otherwise all nodes will receive traffic.
Declaration
public static void EnsureIngressNodes(ClusterDefinition clusterDefinition)
Parameters
| Type | Name | Description |
|---|---|---|
| ClusterDefinition | clusterDefinition | The cluster definition. |
GenerateClusterId()
Generates a unique cluster ID.
Declaration
public static string GenerateClusterId()
Returns
| Type | Description |
|---|---|
| string | The generated cluster ID. |
GenerateSshKey(string, string)
Creates a SSH key for a NEONKUBE cluster.
Declaration
public static KubeSshKey GenerateSshKey(string clusterName, string userName = "root")
Parameters
| Type | Name | Description |
|---|---|---|
| string | clusterName | The cluster name. |
| string | userName | Optionally specifies the user name (defaults to root). |
Returns
| Type | Description |
|---|---|
| KubeSshKey | A KubeSshKey holding the public and private parts of the key. |
GetBuiltinDesktopSshKey()
Returns the fixed SSH key shared by all NEONDESKTOP clusters.
note
This isn't really a security issue because NEONDESKTOP clusters are not reachable from outside the machine they're deployed on and also because the NEONDESKTOP cluster is not intended to host production workloads.
Declaration
public static KubeSshKey GetBuiltinDesktopSshKey()
Returns
| Type | Description |
|---|---|
| KubeSshKey | The KubeSshKey. |
GetCachedComponentPath(KubeClientPlatform, string, string)
Returns the path to the cached file for a specific named component with optional version.
Declaration
public static string GetCachedComponentPath(KubeClientPlatform platform, string component, string version)
Parameters
| Type | Name | Description |
|---|---|---|
| KubeClientPlatform | platform | Identifies the platform. |
| string | component | The component name. |
| string | version | The component version (or |
Returns
| Type | Description |
|---|---|
| string | The component file path. |
GetClusterHealthAsync(KubeConfigContext, CancellationToken)
Determines the health of a cluster by querying the API server.
Declaration
public static Task<ClusterHealth> GetClusterHealthAsync(KubeConfigContext context, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| KubeConfigContext | context | The cluster context. |
| CancellationToken | cancellationToken | Optionally specifies the cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<ClusterHealth> | A ClusterHealth instance. |
GetClusterLdapUserAsync(IKubernetes, string)
Returns the credentials for a specific cluster user from the Glauth LDAP secret.
Declaration
public static Task<GlauthUser> GetClusterLdapUserAsync(IKubernetes k8s, string username)
Parameters
| Type | Name | Description |
|---|---|---|
| IKubernetes | k8s | The Kubernetes client. |
| string | username | The desired username. |
Returns
| Type | Description |
|---|---|
| Task<GlauthUser> | The GlauthUser requested user credentials. |
Exceptions
| Type | Condition |
|---|---|
| KeyNotFoundException | Thrown when the user doesn't exist. |
GetCurrentNamespaceAsync()
Gets the current namespace from within a pod.
Declaration
public static Task<string> GetCurrentNamespaceAsync()
Returns
| Type | Description |
|---|---|
| Task<string> | The current namespacee. |
GetEmulatedPodName(string)
Generates a unique(ish) pod name for application instances that are actually running outside of the cluster, typically for testing purposes. This is based on the deployment name passed and a small UUID.
Declaration
public static string GetEmulatedPodName(string deployment)
Parameters
| Type | Name | Description |
|---|---|---|
| string | deployment |
Returns
| Type | Description |
|---|---|
| string | The emulated pod name. |
GetHelmPath(string, bool)
Returns the path to the a tool binary to be used by neon-cli.
Declaration
public static string GetHelmPath(string installFolder, bool userToolsFolder = false)
Parameters
| Type | Name | Description |
|---|---|---|
| string | installFolder | Path to the tool installation folder. |
| bool | userToolsFolder | Optionally specifies that instead of downloading missing tool binaries to |
Returns
| Type | Description |
|---|---|
| string | The fully qualified tool path. |
Remarks
If the installFolder folder and the binary exist then we'll simply
return the tool path when userToolsFolder=true and verify
that tool version is correct when userToolsFolder=false.
If the installFolder or binary does not exist, then the user is probably
a developer running an uninstalled version of the tool, perhaps in the debugger. In this case,
we're going to download the binaries to installFolder by default or to
ToolsFolder when userToolsFolder=true.
Exceptions
| Type | Condition |
|---|---|
| FileNotFoundException | Thrown when the tool cannot be located. |
GetKubernetesClient(KubeConfig)
Creates a IKubernetes client for the current cluster specified by a KubeConfig.
Declaration
public static IKubernetes GetKubernetesClient(KubeConfig config)
Parameters
| Type | Name | Description |
|---|---|---|
| KubeConfig | config | The source kubeconfig. |
Returns
| Type | Description |
|---|---|
| IKubernetes | The IKubernetes. |
GetNeonKubeVersion()
Returns the NeonKube constant value extracted from the $/NEONKUBE/Lib/Neon.Kube/KubeVersions.cs source file. Note that the NK_ROOT environment variable must reference the root of the NEONKUBE git repository.
Declaration
public static SemanticVersion GetNeonKubeVersion()
Returns
| Type | Description |
|---|---|
| SemanticVersion | The NeonKube version. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown if the NK_ROOT environment variable does not exist or the git repo is invalid, the source file doesn't exist or the NeonKube constant could not be located. |
GetOpenSshPrepareSubConfig(bool)
Returns the contexts of the OpenSSH sub-config file to deployed during as node images are created or when the cluster nodes are provisioned to /etc/ssh/sshd_config.d/20-neonkube.conf to customize OpenSSH.
Declaration
public static string GetOpenSshPrepareSubConfig(bool allowPasswordAuth)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | allowPasswordAuth | Enable password authentication. |
Returns
| Type | Description |
|---|---|
| string |
GetPlatformCacheFolder(KubeClientPlatform)
Returns the path to the folder containing cached files for the specified platform.
Declaration
public static string GetPlatformCacheFolder(KubeClientPlatform platform)
Parameters
| Type | Name | Description |
|---|---|---|
| KubeClientPlatform | platform | Identifies the platform. |
Returns
| Type | Description |
|---|---|
| string | The folder path. |
GetToolPath(string, string, Func<string, bool>, Func<string>, bool)
Returns the path to the a tool binary to be used by neon-cli.
Declaration
public static string GetToolPath(string installFolder, string toolName, Func<string, bool> toolChecker, Func<string> toolUriRetriever, bool userToolsFolder = false)
Parameters
| Type | Name | Description |
|---|---|---|
| string | installFolder | Path to the tool installation folder. |
| string | toolName | The requested tool name, currently helm is supported. |
| Func<string, bool> | toolChecker | Callback taking the the tool path as a parameter and returning |
| Func<string> | toolUriRetriever | Callback that returns the URI to be used to download the tool. |
| bool | userToolsFolder | Optionally specifies that instead of downloading missing tool binaries to |
Returns
| Type | Description |
|---|---|
| string | The fully qualified tool path. |
Remarks
If the installFolder folder and the binary exist then we'll simply
return the tool path when userToolsFolder=true and verify
that tool version is correct when userToolsFolder=false.
If the installFolder or binary does not exist, then the user is probably
a developer running an uninstalled version of the tool, perhaps in the debugger. In this case,
we're going to download the binaries to installFolder by default or to
ToolsFolder when userToolsFolder=true.
Exceptions
| Type | Condition |
|---|---|
| FileNotFoundException | Thrown when the tool cannot be located. |
InitializeJson()
Used to initialize KubernetesJson.
Declaration
public static void InitializeJson()
InstallKubeCtl()
Ensures that kubectl tool whose version is at least as great as the Kubernetes cluster version is installed to the NEONKUBE programs folder by copying the tool from the cache if necessary.
note
This will probably require elevated privileges.
note
This assumes that kubectl has already been downloaded and cached and also that more recent kubectl releases are backwards compatible with older deployed versions of Kubernetes.
Declaration
public static void InstallKubeCtl()
InstallWorkstationHelm()
Ensures that helm client installed on the workstation version is at least as great as the requested cluster version is installed to the NEONKUBE programs folder by copying the tool from the cache if necessary.
note
This will probably require elevated privileges.
note
This assumes that Helm has already been downloaded and cached and also that more recent Helm releases are backwards compatible with older deployed versions of Tiller.
Declaration
public static void InstallWorkstationHelm()
IsCloudEnvironment(HostingEnvironment)
Determines whether a cluster hosting environment deploys to the cloud.
Declaration
public static bool IsCloudEnvironment(HostingEnvironment hostingEnvironment)
Parameters
| Type | Name | Description |
|---|---|---|
| HostingEnvironment | hostingEnvironment | Specifies the hosting environment. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsNeonKubeCustomResource(V1CustomResourceDefinition)
Determines whether a custom resource definition is a NEONKUBE custom resource.
Declaration
public static bool IsNeonKubeCustomResource(V1CustomResourceDefinition crd)
Parameters
| Type | Name | Description |
|---|---|---|
| V1CustomResourceDefinition | crd | The custom resource definition. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsOnPremiseEnvironment(HostingEnvironment)
Determines whether a cluster hosting environment deploys on-premise.
Declaration
public static bool IsOnPremiseEnvironment(HostingEnvironment hostingEnvironment)
Parameters
| Type | Name | Description |
|---|---|---|
| HostingEnvironment | hostingEnvironment | The hosting environment. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsOnPremiseHypervisorEnvironment(HostingEnvironment)
Determines whether a cluster hosting environment deploys to on-premise hypervisors.
Declaration
public static bool IsOnPremiseHypervisorEnvironment(HostingEnvironment hostingEnvironment)
Parameters
| Type | Name | Description |
|---|---|---|
| HostingEnvironment | hostingEnvironment | The hosting environment. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsPaidHostingEnvironment(HostingEnvironment)
Determines whether NEONFORGE collects revenue from a cluster hosting environment.
Declaration
public static bool IsPaidHostingEnvironment(HostingEnvironment hostingEnvironment)
Parameters
| Type | Name | Description |
|---|---|---|
| HostingEnvironment | hostingEnvironment | Specifies the hosting environment. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsPremiumEnvironment(HostingEnvironment)
Determines whether a cluster hosting environment is available only for NEONFORGE premium (closed-source) related projects.
Declaration
public static bool IsPremiumEnvironment(HostingEnvironment hostingEnvironment)
Parameters
| Type | Name | Description |
|---|---|---|
| HostingEnvironment | hostingEnvironment | The hosting environment. |
Returns
| Type | Description |
|---|---|
| bool |
|
Kubectl(params object[])
Executes a kubectl command on the local workstation.
Declaration
public static ExecuteResponse Kubectl(params object[] args)
Parameters
| Type | Name | Description |
|---|---|---|
| object[] | args | The command arguments. |
Returns
| Type | Description |
|---|---|
| ExecuteResponse | The ExecuteResponse. |
LoadClientConfig()
Loads or reloads the ClientConfig.
Declaration
public static KubeClientConfig LoadClientConfig()
Returns
| Type | Description |
|---|---|
| KubeClientConfig | The client configuration. |
LoadConfig()
Loads or reloads the Kubernetes configuration.
Declaration
public static KubeConfig LoadConfig()
Returns
| Type | Description |
|---|---|
| KubeConfig | The KubeConfig. |
LoginOidcAsync(string, string, string[])
Performs Open IC Connect Login
Declaration
public static Task<LoginResult> LoginOidcAsync(string authority, string clientId, string[] scopes = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | authority | Specifies the authority. |
| string | clientId | Specifies the client ID. |
| string[] | scopes | Optionally specifies any scopes. |
Returns
| Type | Description |
|---|---|
| Task<LoginResult> | A IdentityModel.OidcClient.LoginResult. |
LookupPassword(string)
Looks up a password given its name.
Declaration
public static string LookupPassword(string passwordName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | passwordName | The password name. |
Returns
| Type | Description |
|---|---|
| string | The password value. |
Exceptions
| Type | Condition |
|---|---|
| KeyNotFoundException | Thrown if the password doesn't exist. |
NeonCliExecuteAsync(object[])
Executes a neon/kubectl command using the installed executable or the executable from the NEONCLOUD build folder.
Declaration
public static Task<int> NeonCliExecuteAsync(object[] args)
Parameters
| Type | Name | Description |
|---|---|---|
| object[] | args | The command line arguments. |
Returns
| Type | Description |
|---|---|
| Task<int> | The command exit code. |
Remarks
note
For maintainers, this method will build the neon/kubectl tool if it does not already exist.
NeonCliExecuteCapture(params object[])
Executes a neon/kubectl command using the installed executable or the executable from the NEONCLOUD build folder, capturing the output streams.
Declaration
public static ExecuteResponse NeonCliExecuteCapture(params object[] args)
Parameters
| Type | Name | Description |
|---|---|---|
| object[] | args | The command line arguments. |
Returns
| Type | Description |
|---|---|
| ExecuteResponse | The command exit code. |
Remarks
note
For maintainers, this method will build the neon/kubectl tool if it does not already exist.
NeonCliExecuteCaptureAsync(params object[])
Executes a neon/kubectl command using the installed executable or the executable from the NEONCLOUD build folder, capturing the output streams.
Declaration
public static Task<ExecuteResponse> NeonCliExecuteCaptureAsync(params object[] args)
Parameters
| Type | Name | Description |
|---|---|---|
| object[] | args | The command line arguments. |
Returns
| Type | Description |
|---|---|
| Task<ExecuteResponse> | The command exit code. |
Remarks
note
For maintainers, this method will build the neon/kubectl tool if it does not already exist.
PortForward(string, int, int, string, Process)
Executes a kubectl port-forward command on the local workstation.
Declaration
public static void PortForward(string serviceName, int remotePort, int localPort, string @namespace, Process process)
Parameters
| Type | Name | Description |
|---|---|---|
| string | serviceName | The service to forward. |
| int | remotePort | The service port. |
| int | localPort | The local port to forward to. |
| string | namespace | The Kubernetes namespace where the service is running. |
| Process | process | The Process to use. |
SaveClientState()
Persists the ClientConfig to disk.
Declaration
public static void SaveClientState()
SetConfig(KubeConfig)
Rewrites the local kubeconfig file.
Declaration
public static void SetConfig(KubeConfig config)
Parameters
| Type | Name | Description |
|---|---|---|
| KubeConfig | config | The new configuration. |
SetCurrentContext(KubeContextName)
Sets the current Kubernetes config context.
Declaration
public static void SetCurrentContext(KubeContextName contextName)
Parameters
| Type | Name | Description |
|---|---|---|
| KubeContextName | contextName | The context name or |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown if the context specified doesn't exist. |
SetCurrentContext(string)
Sets the current Kubernetes config context by string name.
Declaration
public static void SetCurrentContext(string contextName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | contextName | The context name or |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown if the context specified doesn't exist. |
ValidateKubernetesLabel(string, string, string)
Verifies that the label name and valud conforms to the Kubernetes label constraints: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set
Declaration
public static void ValidateKubernetesLabel(string labelType, string key, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | labelType | Identifies the type of label being checked. Any exceptions thrown wil; have their message text prefixed by this. |
| string | key | Specifies the label key. |
| string | value | Specifies the label value. |
Exceptions
| Type | Condition |
|---|---|
| ClusterDefinitionException | Thrown when the label name or value invalid. |