/// <summary> /// Determine whether a Deployment owns a ReplicaSet. /// </summary> /// <param name="replicaSet"> /// The ReplicaSet to examine. /// </param> /// <param name="deployment"> /// The Deployment to examine. /// </param> /// <returns> /// <c>true</c>, if the ReplicaSet has an owner-reference to the Deployment; otherwise, <c>false</c>. /// </returns> public static bool IsOwnedBy(this ReplicaSetV1 replicaSet, DeploymentV1 deployment) { if (replicaSet == null) { throw new ArgumentNullException(nameof(replicaSet)); } if (deployment == null) { throw new ArgumentNullException(nameof(deployment)); } if (replicaSet.Metadata == null) { throw new ArgumentException("Cannot evaluate ownership of the supplied ReplicaSet because its Metadata is null.", nameof(replicaSet)); } if (deployment.Metadata == null) { throw new ArgumentException("Cannot evaluate ownership of the supplied ReplicaSet because the supplied Deployment's Metadata is null.", nameof(replicaSet)); } bool isOwnedBy = replicaSet.Metadata.OwnerReferences.Any(ownerReference => ownerReference.Kind == deployment.Kind && ownerReference.ApiVersion == deployment.ApiVersion && ownerReference.Name == deployment.Metadata.Name ); return(isOwnedBy); }
/// <summary> /// Determine the revision (represented by the "deployment.kubernetes.io/revision" annotation) of the Deployment represented by the ReplicaSet. /// </summary> /// <param name="deployment"> /// The <see cref="ReplicaSetV1"/> model. /// </param> /// <returns> /// The revision, if present; <c>null</c>, if the annotation is absent or not a number. /// </returns> public static int?GetRevision(this ReplicaSetV1 deployment) { if (deployment == null) { throw new ArgumentNullException(nameof(deployment)); } if (deployment.Metadata == null) { return(null); } string rawRevision; if (!deployment.Metadata.Annotations.TryGetValue(K8sAnnotations.Deployment.Revision, out rawRevision)) { return(null); } int revision; if (!Int32.TryParse(rawRevision, out revision)) { return(null); } return(revision); }