<commit_before>// -----------------------------------------------------------------------
// <copyright file="KubernetesExtensions.cs" company="Asynkron AB">
//      Copyright (C) 2015-2020 Asynkron AB All rights reserved
// </copyright>
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using k8s;
using k8s.Models;
using Microsoft.AspNetCore.JsonPatch;
using static Proto.Cluster.Kubernetes.ProtoLabels;

// ReSharper disable InvertIf

namespace Proto.Cluster.Kubernetes
{
    static class KubernetesExtensions
    {
        private static string cachedNamespace;

        /// <summary>
        ///     Find the container port for a given pod than matches the given port.
        /// </summary>
        /// <param name="pod">Kubernetes Pod object</param>
        /// <param name="port">Port to find in container ports</param>
        /// <returns></returns>
        internal static V1ContainerPort FindPort(this V1Pod pod, int port)
            => pod.Spec.Containers[0].Ports.FirstOrDefault(x => x.ContainerPort == port);

        /// <summary>
        ///     Replace pod labels
        /// </summary>
        /// <param name="kubernetes">Kubernetes client</param>
        /// <param name="podName">Name of the pod</param>
        /// <param name="podNamespace">Namespace of the pod</param>
        /// <param name="labels">Labels collection. All labels will be replaced by the new labels.</param>
        /// <returns></returns>
        internal static Task<V1Pod> ReplacePodLabels(
            this IKubernetes kubernetes,
            string podName,
            string podNamespace,
            IDictionary<string, string> labels
        )
        {
            var patch = new JsonPatchDocument<V1Pod>();
            patch.Replace(x => x.Metadata.Labels, labels);
            return kubernetes.PatchNamespacedPodAsync(new V1Patch(patch), podName, podNamespace);
        }

        /// <summary>
        ///     Get the pod status. The pod must be running in order to be considered as a candidate.<commit_msg>kubernetes patch<commit_after>// -----------------------------------------------------------------------
// <copyright file="KubernetesExtensions.cs" company="Asynkron AB">
//      Copyright (C) 2015-2020 Asynkron AB All rights reserved
// </copyright>
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using k8s;
using k8s.Models;
using Microsoft.AspNetCore.JsonPatch;
using static Proto.Cluster.Kubernetes.ProtoLabels;

// ReSharper disable InvertIf

namespace Proto.Cluster.Kubernetes
{
    static class KubernetesExtensions
    {
        private static string cachedNamespace;

        /// <summary>
        ///     Find the container port for a given pod than matches the given port.
        /// </summary>
        /// <param name="pod">Kubernetes Pod object</param>
        /// <param name="port">Port to find in container ports</param>
        /// <returns></returns>
        internal static V1ContainerPort FindPort(this V1Pod pod, int port)
            => pod.Spec.Containers[0].Ports.FirstOrDefault(x => x.ContainerPort == port);

        /// <summary>
        ///     Replace pod labels
        /// </summary>
        /// <param name="kubernetes">Kubernetes client</param>
        /// <param name="podName">Name of the pod</param>
        /// <param name="podNamespace">Namespace of the pod</param>
        /// <param name="labels">Labels collection. All labels will be replaced by the new labels.</param>
        /// <returns></returns>
        internal static Task<V1Pod> ReplacePodLabels(
            this IKubernetes kubernetes,
            string podName,
            string podNamespace,
            IDictionary<string, string> labels
        )
        {
            var patch = new JsonPatchDocument<V1Pod>();
            patch.Replace(x => x.Metadata.Labels, labels);
            return kubernetes.PatchNamespacedPodAsync(new V1Patch(patch,V1Patch.PatchType.JsonPatch), podName, podNamespace);
        }

        /// <summary>
        ///     Get the pod status. The pod must be running in order to be considered as a candidate.
{'fraction_non_alphanumeric': 0.1734623358673117, 'fraction_numerical': 0.007601935038009675, 'mean_word_length': 1.9457259158751696, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '930874', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1064, 'n_words': 316}