namespace KubernetesWorkflow
{
public interface IKnownLocations
{
///
/// Returns a known location given an index.
/// Each index guarantees a different location.
///
ILocation Get(int index);
int NumberOfLocations { get; }
///
/// Returns the location object for a specific kubernetes node. Throws if it doesn't exist.
///
ILocation Get(string kubeNodeName);
}
public class KnownLocations : IKnownLocations
{
private readonly Location[] locations;
public KnownLocations(Location[] locations)
{
this.locations = locations;
if (locations.Any(l => l.NodeLabel == null)) throw new Exception("Must not contain unspecified location");
}
public static ILocation UnspecifiedLocation { get; } = new Location();
public int NumberOfLocations => locations.Length;
public ILocation Get(int index)
{
return locations[index];
}
public ILocation Get(string kubeNodeName)
{
return locations.Single(l => l.NodeLabel != null && l.NodeLabel.Value == kubeNodeName);
}
}
}