public ImmutableList <string> Update(WatchEventType eventType, V1Endpoints endpoints) { if (endpoints is null) { throw new ArgumentNullException(nameof(endpoints)); } var serviceName = endpoints.Name(); lock (_sync) { if (eventType == WatchEventType.Added || eventType == WatchEventType.Modified) { _endpointsData[serviceName] = new Endpoints(endpoints); } else if (eventType == WatchEventType.Deleted) { _endpointsData.Remove(serviceName); } if (_serviceToIngressNames.TryGetValue(serviceName, out var ingressNames)) { return(ingressNames); } else { return(ImmutableList <string> .Empty); } } }
/// <summary> /// Called by the informer with real-time resource updates. /// </summary> /// <param name="eventType">Indicates if the resource new, updated, or deleted.</param> /// <param name="resource">The information as provided by the Kubernetes API server.</param> private void Notification(WatchEventType eventType, V1Endpoints resource) { var ingressNames = _cache.Update(eventType, resource); if (ingressNames.Count > 0) { NotificationIngressChanged(); } }
/// <summary> /// Called by the informer with real-time resource updates. /// </summary> /// <param name="eventType">Indicates if the resource new, updated, or deleted.</param> /// <param name="resource">The information as provided by the Kubernets API server.</param> private void Notification(WatchEventType eventType, V1Endpoints resource) { var ingressNames = _cache.Update(eventType, resource); if (ingressNames.Count > 0) { _queue.Add(_ingressChangeQueueItem); } }
/// <summary> /// Called by the informer with real-time resource updates. /// </summary> /// <param name="eventType">Indicates if the resource new, updated, or deleted.</param> /// <param name="resource">The information as provided by the Kubernets API server.</param> private void Notification(WatchEventType eventType, V1Endpoints resource) { var ingressNames = _cache.Update(eventType, resource); foreach (var ingressName in ingressNames) { _queue.Add(new QueueItem(new NamespacedName(resource.Namespace(), ingressName), null)); } }
private Cluster BuildCluster(string clusterId, ServicePortModel sp, V1Endpoints endpoints) { var destinations = new Dictionary <string, Destination>(); var destinationIndex = 0; foreach (var subset in endpoints.Subsets) { foreach (var port in subset.Ports) { if (string.IsNullOrWhiteSpace(sp.PortName)) { // Compare based on port number if (sp.Port == port.Port) { // TODO - Check the scheme! Currently assuming http. Also figure out what to do with unavailable addresses var addresses = subset.Addresses.Select(a => $"http://{a.Ip}:{port.Port}").ToArray(); for (var i = 0; i < addresses.Length; i++) { var dest = new Destination() { Address = addresses[i], }; destinations.Add($"{clusterId}/{destinationIndex}", dest); destinationIndex++; } } } else { if (sp.PortName == port.Name) { // TODO - Check the scheme! Currently assuming http. Also figure out what to do with unavailable addresses var addresses = subset.Addresses.Select(a => $"http://{a.Ip}:{port.Port}").ToArray(); for (var i = 0; i < addresses.Length; i++) { var dest = new Destination() { Address = addresses[i], }; destinations.Add($"{clusterId}/{destinationIndex}", dest); destinationIndex++; } } } } } return(new Cluster { Id = clusterId, Destinations = destinations, }); }
private void HandleDeleteForEndpoint(V1Endpoints endpoint) { lock (_sync) { if (endpoint != null && endpoint.Subsets != null) { _serviceToIp.Remove(endpoint.Metadata.Name); } } }
public Endpoints(V1Endpoints endpoints) { if (endpoints is null) { throw new ArgumentNullException(nameof(endpoints)); } Name = endpoints.Name(); Subsets = endpoints.Subsets; }
public async Task PutEndpointAnnotationsAsync(string ns, string endpoint, IReadOnlyDictionary <string, string> annotationsToUpdate, CancellationToken token) { V1Endpoints ep; try { if (!this.config.IsAllowedNamespace(ns)) { throw new ForbiddenException($"namespace: {ns}"); } ep = await this.client.ReadNamespacedEndpointsAsync(endpoint, ns, cancellationToken : token); } catch (HttpOperationException e) { if (e.Response.StatusCode == System.Net.HttpStatusCode.NotFound) { var newEp = new V1Endpoints() { Metadata = new V1ObjectMeta() { NamespaceProperty = ns, Name = endpoint, }, }; ep = await this.client.CreateNamespacedEndpointsAsync(newEp, ns, cancellationToken : token); } else { this.logger.LogError($"Exception Getting LKG: {e.Response.Content}"); throw; } } try { var newannotations = new Dictionary <string, string>(ep.Annotations() ?? new Dictionary <string, string>()); foreach (var ann in annotationsToUpdate) { newannotations[ann.Key] = ann.Value; } var patch = new JsonPatchDocument <V1Endpoints>(); patch.Replace(e => e.Metadata.Annotations, newannotations); var result = await this.client.PatchNamespacedEndpointsAsync(new V1Patch(patch, V1Patch.PatchType.JsonPatch), endpoint, ns, cancellationToken : token); Console.Error.WriteLine($"{result.Name()} updated"); } catch (HttpOperationException e) { this.logger.LogError($"Exception Putting LKG: {e.Response.Content}"); throw; } }
private void ModifiedEndpoints(V1Endpoints endpoints) { var list = new List <EndpointEntry>(); foreach (var subset in endpoints.Subsets) { var port = subset.Ports.First().Port; foreach (var address in subset.Addresses) { list.Add(new EndpointEntry(address.Ip, port)); } } _endpointEntries = list; }
private void HandleAddForEndpoint(V1Endpoints endpoint) { lock (_sync) { if (endpoint != null && endpoint.Subsets != null) { _serviceToIp[endpoint.Metadata.Name] = endpoint.Subsets.SelectMany((o) => o.Addresses).Select(a => a.Ip).ToList(); foreach (var s in _serviceToIp[endpoint.Metadata.Name]) { _logger.LogInformation($"Current endpoint: {s}"); } } } }
private void onEvent(WatchEventType type, V1Endpoints endpoints) { _logger.LogDebug($"{type} detected {endpoints?.Metadata?.Name}"); switch (type) { case WatchEventType.Added: case WatchEventType.Modified: ModifiedEndpoints(endpoints); break; case WatchEventType.Deleted: case WatchEventType.Error: _endpointEntries = new List <EndpointEntry>(); break; default: throw new InvalidOperationException(); } }
private EndpointSubsetNs GetSubsetsFromEndpoints(V1Endpoints endpoints) { // Start with config or default var es = new EndpointSubsetNs { Namespace = _discoveryOptions.Namespace ?? DefaultNamespace }; if (endpoints?.Subsets == null) { return(es); } es.Namespace = endpoints.Metadata.NamespaceProperty; es.EndpointSubsets = endpoints.Subsets; return(es); }
public FortniteApiClient(string apiKey = null) { var assemblyVersion = GetType().Assembly.GetName().Version; var versionString = assemblyVersion == null ? "unknown" : assemblyVersion.ToString(3); var client = new RestClient("https://fortnite-api.com/") { UserAgent = $"Fortnite-API.NET/{versionString}", Timeout = 10 * 1000 }.UseSerializer <JsonNetSerializer>(); if (!string.IsNullOrWhiteSpace(apiKey)) { client.AddDefaultHeader("x-api-key", apiKey); } V1 = new V1Endpoints(client); V2 = new V2Endpoints(client); }
public FortniteAPIClient(string apiKey) { if (!string.IsNullOrWhiteSpace(apiKey)) { var ver = Assembly.GetExecutingAssembly().GetName().Version; var rest = new RestClient("https://fortniteapi.io") { UserAgent = $"FortniteAPIIO/{ver?.ToString(3)}", Timeout = 10 * 1000 }.UseSerializer <JsonNetSerializer>() .AddDefaultHeader("Authorization", apiKey); V1Endpoints = new V1Endpoints(rest); V2Endpoints = new V2Endpoints(rest); } else { throw new Exception($"{nameof(apiKey)} is required, please supply an API key in the constructor"); } }
public ImmutableList <string> Update(WatchEventType eventType, V1Endpoints endpoints) { throw new NotImplementedException(); }
public ImmutableList <string> Update(WatchEventType eventType, V1Endpoints endpoints) { return(Namespace(endpoints.Namespace()).Update(eventType, endpoints)); }
private async Task <string> DescribeObject(Kubernetes client, V1Namespace ns, V1Endpoints o, StringBuilder buffer) { var fetched = await client.ReadNamespacedEndpointsAsync(o.Metadata.Name, ns.Metadata.Name).ConfigureAwait(false); buffer.AppendLine($"API Veresion: {fetched.ApiVersion}"); buffer.AppendLine($"Kind: {fetched.Kind}"); buffer.AppendLine(DescribeMetadata(fetched.Metadata)); return($"Endpoint - {fetched.Metadata.Name}"); }