Class KubeContextName
Handles the parsing of a Kubernetes context name which by convention encodes the user, cluster, and optional namespace as a string.
Namespace: Neon.Kube.Config
Assembly: Neon.Kube.dll
Syntax
public class KubeContextName
Remarks
NEONKUBE encodes context names like:
USER "@" CLUSTER [ "/" NAMESPACE ]
k where USER is the username, CLUSTER identifies the cluster and NAMESPACE optionally identifies the Kubernetes namespace (which defaults to default when not specified).
Constructors
KubeContextName(string, string, string)
Parameterized constructor.
Declaration
public KubeContextName(string username, string cluster, string kubeNamespace = "default")
Parameters
| Type | Name | Description |
|---|---|---|
| string | username | The username. This may be |
| string | cluster | The cluster name. |
| string | kubeNamespace | Optionally specifies the namespace (defaults to "default"). |
Remarks
note
The username, cluster, and namespace will be converted to lowercase.
Properties
Cluster
Returns the cluster name.
Declaration
public string Cluster { get; }
Property Value
| Type | Description |
|---|---|
| string |
IsNeonKube
Indicates whether this is a NEONKUBE context name or a standard one. NEONKUBE contexts include a user name before the "@" symbol.
Declaration
public bool IsNeonKube { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Namespace
Returns the namespace or default.
Declaration
public string Namespace { get; }
Property Value
| Type | Description |
|---|---|
| string |
User
Returns the username if present, otherwise null.
note
We currently assume that only contexts with a User are NEONKUBE clusters.
Declaration
public string User { get; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
Equals(object)
Determines whether the specified object is equal to the current object.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with the current object. |
Returns
| Type | Description |
|---|---|
| bool | true if the specified object is equal to the current object; otherwise, false. |
Overrides
GetHashCode()
Serves as the default hash function.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hash code for the current object. |
Overrides
Parse(string)
Parses a Kubernetes context name.
Declaration
public static KubeContextName Parse(string input)
Parameters
| Type | Name | Description |
|---|---|---|
| string | input | The input text. |
Returns
| Type | Description |
|---|---|
| KubeContextName | The parsed name. |
Remarks
NEONKUBE supports a context name format that includes a user name like:
We assume that contexts including an "@" are associated with a
NEONKUBE cluster and use this to link to additional login information.
We can also parse context names without an "@". The parsed
User property will be set to null in this case.
Exceptions
| Type | Condition |
|---|---|
| FormatException | Thrown if the name is not valid. |
ToString()
Returns a string that represents the current object.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string that represents the current object. |
Overrides
Operators
operator ==(KubeContextName, KubeContextName)
Compares KubeContextName for equality.
Declaration
public static bool operator ==(KubeContextName name1, KubeContextName name2)
Parameters
| Type | Name | Description |
|---|---|---|
| KubeContextName | name1 | Name 1 |
| KubeContextName | name2 | Name 2 |
Returns
| Type | Description |
|---|---|
| bool |
|
explicit operator string(KubeContextName)
Explicitly casts a KubeContextName into a string.
Declaration
public static explicit operator string(KubeContextName name)
Parameters
| Type | Name | Description |
|---|---|---|
| KubeContextName | name | The context name or |
Returns
| Type | Description |
|---|---|
| string | The converted string. |
explicit operator KubeContextName(string)
Explicitly casts a string into a KubeContextName.
Declaration
public static explicit operator KubeContextName(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The context name or |
Returns
| Type | Description |
|---|---|
| KubeContextName | The converted context name. |
operator !=(KubeContextName, KubeContextName)
Compares KubeContextName for inequality.
Declaration
public static bool operator !=(KubeContextName name1, KubeContextName name2)
Parameters
| Type | Name | Description |
|---|---|---|
| KubeContextName | name1 | Name 1 |
| KubeContextName | name2 | Name 2 |
Returns
| Type | Description |
|---|---|
| bool |
|