/// <summary> /// Create a new <see cref="ServiceV1"/>. /// </summary> /// <param name="name"> /// The service name. /// </param> /// <param name="spec"> /// A <see cref="ServiceSpecV1"/> representing the service specification. /// </param> /// <param name="labels"> /// An optional <see cref="Dictionary{TKey, TValue}"/> containing labels to apply to the service. /// </param> /// <param name="annotations"> /// An optional <see cref="Dictionary{TKey, TValue}"/> containing annotations to apply to the service. /// </param> /// <param name="kubeNamespace"> /// An optional target Kubernetes namespace. /// </param> /// <returns> /// The configured <see cref="ServiceV1"/>. /// </returns> public ServiceV1 Service(string name, ServiceSpecV1 spec, Dictionary <string, string> labels = null, Dictionary <string, string> annotations = null, string kubeNamespace = null) { if (String.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Argument cannot be null, empty, or entirely composed of whitespace: 'name'.", nameof(name)); } if (spec == null) { throw new ArgumentNullException(nameof(spec)); } return(new ServiceV1 { ApiVersion = "v1", Kind = "Service", Metadata = new ObjectMetaV1 { Name = name, Namespace = kubeNamespace, Labels = labels, Annotations = annotations }, Spec = spec }); }
/// <summary> /// Build an externally-facing <see cref="ServiceSpecV1"/> for the specified server. /// </summary> /// <param name="server"> /// A <see cref="DatabaseServer"/> representing the target server. /// </param> /// <returns> /// The configured <see cref="ServiceSpecV1"/>. /// </returns> public ServiceSpecV1 ExternalService(DatabaseServer server) { if (server == null) { throw new ArgumentNullException(nameof(server)); } string baseName = Names.BaseName(server); var spec = new ServiceSpecV1 { Type = "NodePort", Ports = new List <ServicePortV1>(), Selector = new Dictionary <string, string> { ["k8s-app"] = baseName } }; switch (server.Kind) { case DatabaseServerKind.SqlServer: { spec.Ports.Add(new ServicePortV1 { Name = "sql-server", Port = 1433, Protocol = "TCP" }); break; } case DatabaseServerKind.RavenDB: { spec.Ports.Add(new ServicePortV1 { Name = "http", Port = 8080, Protocol = "TCP" }); spec.Ports.Add(new ServicePortV1 { Name = "tcp", Port = 38888, Protocol = "TCP" }); break; } default: { throw new NotSupportedException($"Unsupported server type ({server.Kind})."); } } return(spec); }