Exemplo n.º 1
0
        /// <summary>Removes the first <see cref="V1OwnerReference"/> that matches the given object and returns it, or returns null if no
        /// matching reference could be found.
        /// </summary>
        public static V1OwnerReference RemoveOwnerReference(this IMetadata <V1ObjectMeta> obj,
                                                            IKubernetesObject <V1ObjectMeta> owner)
        {
            int index = FindOwnerReference(obj, owner);
            V1OwnerReference ownerRef = index >= 0 ? obj.Metadata.OwnerReferences[index] : null;

            if (index >= 0)
            {
                obj.Metadata.OwnerReferences.RemoveAt(index);
            }

            return(ownerRef);
        }
Exemplo n.º 2
0
        /// <summary>Adds an owner reference to the object. No attempt is made to ensure the reference is correct or fits with the
        /// other references.
        /// </summary>
        /// <param name="obj">the object meta<see cref="V1ObjectMeta"/></param>
        /// <param name="ownerRef">the owner reference to the object</param>
        public static void AddOwnerReference(this IMetadata <V1ObjectMeta> obj, V1OwnerReference ownerRef)
        {
            if (ownerRef == null)
            {
                throw new ArgumentNullException(nameof(ownerRef));
            }

            if (EnsureMetadata(obj).OwnerReferences == null)
            {
                obj.Metadata.OwnerReferences = new List <V1OwnerReference>();
            }

            obj.Metadata.OwnerReferences.Add(ownerRef);
        }
Exemplo n.º 3
0
        /// <summary>Determines whether an owner reference references the given object.</summary>
        /// <param name="owner">the object reference<see cref="V1ObjectReference"/></param>
        /// <param name="obj">the object meta<see cref="V1ObjectMeta"/></param>
        /// <returns>true if the owner reference references the given object</returns>
        public static bool Matches(this V1OwnerReference owner, IKubernetesObject <V1ObjectMeta> obj)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            return(owner.ApiVersion == obj.ApiVersion && owner.Kind == obj.Kind && owner.Name == obj.Name() &&
                   owner.Uid == obj.Uid());
        }