/// <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. /// </summary> /// <param name="deployment"> /// The <see cref="DeploymentV1"/> 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 DeploymentV1 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); }
/// <summary> /// Get the composite label selector (if any) associated with the specified Deployment. /// </summary> /// <param name="deployment"> /// A <see cref="DeploymentV1"/> representing the Deployment's current state. /// </param> /// <returns> /// The composite label selector (e.g. "key1=value1,key2=value2"), or <c>null</c> if the Deployment doesn't specify any label selectors. /// </returns> public static string GetLabelSelector(this DeploymentV1 deployment) { if (deployment == null) { throw new ArgumentNullException(nameof(deployment)); } return(deployment.Spec?.Selector?.GetLabelSelector()); }