/// <summary> /// Gets the ReplicaSet for the current pod. /// </summary> /// <param name="self">The target pod.</param> /// <param name="scope">List of replicas to search from.</param> /// <returns>Returns the replicaSet of the pod. Returns null when the data doens't exist.</returns> public static K8sReplicaSet GetMyReplicaSet(this K8sPod self, IEnumerable <K8sReplicaSet> scope) { OwnerReference replicaRef = self.Metadata?.OwnerReferences?.FirstOrDefault(owner => owner.GetKind() != null && owner.GetKind() == typeof(K8sReplicaSet)); if (replicaRef != null) { K8sReplicaSet replica = scope?.FirstOrDefault( r => r.Metadata != null && r.Metadata.Uid != null && r.Metadata.Uid.Equals(replicaRef.Uid, StringComparison.OrdinalIgnoreCase)); return(replica); } return(null); }
public static K8sDeployment GetMyDeployment(this K8sReplicaSet self, IEnumerable <K8sDeployment> scope) { IDictionary <string, string> replicaLabels = self.Metadata.Labels; foreach (K8sDeployment deployment in scope) { IDictionary <string, string> matchRule = deployment.Spec.Selector.MatchLabels; if (matchRule.Intersect(replicaLabels).Count() == matchRule.Count) { // All labels are matched return(deployment); } } return(null); }