예제 #1
0
        /// <summary>
        /// Serializes this instance of <see cref="MulticlusterConfigMetadata" /> into a <see cref="Carbon.Json.JsonNode" />.
        /// </summary>
        /// <param name="container">The <see cref="Carbon.Json.JsonObject"/> container to serialize this object into. If the caller
        /// passes in <c>null</c>, a new instance will be created and returned to the caller.</param>
        /// <param name="serializationMode">Allows the caller to choose the depth of the serialization. See <see cref="Microsoft.Rest.ClientRuntime.SerializationMode"/>.</param>
        /// <returns>
        /// a serialized instance of <see cref="MulticlusterConfigMetadata" /> as a <see cref="Carbon.Json.JsonNode" />.
        /// </returns>
        public Carbon.Json.JsonNode ToJson(Carbon.Json.JsonObject container, Microsoft.Rest.ClientRuntime.SerializationMode serializationMode)
        {
            container = container ?? new Carbon.Json.JsonObject();

            bool returnNow = false;

            BeforeToJson(ref container, ref returnNow);
            if (returnNow)
            {
                return(container);
            }
            AddIf(null != Name ? (Carbon.Json.JsonNode) new Carbon.Json.JsonString(Name) : null, "name", container.Add);
            if (null != Categories)
            {
                foreach (var __x in Categories)
                {
                    AddIf(null != __x.Value ? (Carbon.Json.JsonNode) new Carbon.Json.JsonString(__x.Value) : null, (__w) => container.Add(__x.Key, __w));
                }
            }
            AddIf(null != CreationTime ? (Carbon.Json.JsonNode) new Carbon.Json.JsonString(CreationTime?.ToString(@"yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK", System.Globalization.CultureInfo.InvariantCulture)) : null, "creation_time", container.Add);
            AddIf(null != Kind ? (Carbon.Json.JsonNode) new Carbon.Json.JsonString(Kind) : null, "kind", container.Add);
            AddIf(null != LastUpdateTime ? (Carbon.Json.JsonNode) new Carbon.Json.JsonString(LastUpdateTime?.ToString(@"yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK", System.Globalization.CultureInfo.InvariantCulture)) : null, "last_update_time", container.Add);
            AddIf(null != OwnerReference ? (Carbon.Json.JsonNode)OwnerReference.ToJson(null) : null, "owner_reference", container.Add);
            AddIf(null != ProjectReference ? (Carbon.Json.JsonNode)ProjectReference.ToJson(null) : null, "project_reference", container.Add);
            AddIf(null != SpecHash ? (Carbon.Json.JsonNode) new Carbon.Json.JsonString(SpecHash) : null, "spec_hash", container.Add);
            AddIf(null != SpecVersion ? (Carbon.Json.JsonNode) new Carbon.Json.JsonNumber((int)SpecVersion) : null, "spec_version", container.Add);
            AddIf(null != Uuid ? (Carbon.Json.JsonNode) new Carbon.Json.JsonString(Uuid) : null, "uuid", container.Add);
            AfterToJson(ref container);
            return(container);
        }
        public static Type GetKind(this OwnerReference self)
        {
            switch (self.Kind)
            {
            case "ReplicaSet":
                return(typeof(K8sReplicaSet));

            default:
                return(null);
            }
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        /// <summary>
        /// Serializes this instance of <see cref="UserMetadata" /> into a <see cref="Carbon.Json.JsonNode" />.
        /// </summary>
        /// <param name="container">The <see cref="Carbon.Json.JsonObject"/> container to serialize this object into. If the caller
        /// passes in <c>null</c>, a new instance will be created and returned to the caller.</param>
        /// <param name="serializationMode">Allows the caller to choose the depth of the serialization. See <see cref="Microsoft.Rest.ClientRuntime.SerializationMode"/>.</param>
        /// <returns>
        /// a serialized instance of <see cref="UserMetadata" /> as a <see cref="Carbon.Json.JsonNode" />.
        /// </returns>
        public Carbon.Json.JsonNode ToJson(Carbon.Json.JsonObject container, Microsoft.Rest.ClientRuntime.SerializationMode serializationMode)
        {
            container = container ?? new Carbon.Json.JsonObject();

            bool returnNow = false;

            BeforeToJson(ref container, ref returnNow);
            if (returnNow)
            {
                return(container);
            }
            if (serializationMode.HasFlag(Microsoft.Rest.ClientRuntime.SerializationMode.IncludeReadOnly))
            {
                AddIf(null != Name ? (Carbon.Json.JsonNode) new Carbon.Json.JsonString(Name) : null, "name", container.Add);
            }
            /* serializeToContainerMember (wildcard) doesn't support 'application/json' C:\Users\hugo1\Documents\autorest\autorest.incubator\dist\csharp\schema\wildcard.js*/
            if (serializationMode.HasFlag(Microsoft.Rest.ClientRuntime.SerializationMode.IncludeReadOnly))
            {
                AddIf(null != CreationTime ? (Carbon.Json.JsonNode) new Carbon.Json.JsonString(CreationTime?.ToString(@"yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK", System.Globalization.CultureInfo.InvariantCulture)) : null, "creation_time", container.Add);
            }
            if (serializationMode.HasFlag(Microsoft.Rest.ClientRuntime.SerializationMode.IncludeReadOnly))
            {
                AddIf(null != Kind ? (Carbon.Json.JsonNode) new Carbon.Json.JsonString(Kind) : null, "kind", container.Add);
            }
            if (serializationMode.HasFlag(Microsoft.Rest.ClientRuntime.SerializationMode.IncludeReadOnly))
            {
                AddIf(null != LastUpdateTime ? (Carbon.Json.JsonNode) new Carbon.Json.JsonString(LastUpdateTime?.ToString(@"yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK", System.Globalization.CultureInfo.InvariantCulture)) : null, "last_update_time", container.Add);
            }
            AddIf(null != OwnerReference ? (Carbon.Json.JsonNode)OwnerReference.ToJson(null) : null, "owner_reference", container.Add);
            AddIf(null != ProjectReference ? (Carbon.Json.JsonNode)ProjectReference.ToJson(null) : null, "project_reference", container.Add);
            AddIf(null != SpecHash ? (Carbon.Json.JsonNode) new Carbon.Json.JsonString(SpecHash) : null, "spec_hash", container.Add);
            AddIf(null != SpecVersion ? (Carbon.Json.JsonNode) new Carbon.Json.JsonNumber((int)SpecVersion) : null, "spec_version", container.Add);
            AddIf(null != Uuid ? (Carbon.Json.JsonNode) new Carbon.Json.JsonString(Uuid) : null, "uuid", container.Add);
            AfterToJson(ref container);
            return(container);
        }
예제 #5
0
        private async Task ResolveOwnerReferenceAsync(HttpClient httpClient, PodInfo podInfo, OwnerReference ownerReference)
        {
            JsonReader    reader;
            IMetaV1Object?obj = default;

            switch (ownerReference.Kind)
            {
            case "StatefulSet" when ownerReference.ApiVersion == "apps/v1":
                reader = await GetJsonAsync(httpClient, $"/apis/apps/v1/namespaces/{podInfo.Namespace}/statefulsets/{ownerReference.Name}");

                var statefulSet = new StatefulSet(ref reader);
                obj = statefulSet;
                podInfo.StatefulSet = new StatefulSetInfo(statefulSet);
                break;

            case "DaemonSet" when ownerReference.ApiVersion == "apps/v1":
                reader = await GetJsonAsync(httpClient, $"/apis/apps/v1/namespaces/{podInfo.Namespace}/daemonsets/{ownerReference.Name}");

                var daemonSet = new DaemonSet(ref reader);
                obj = daemonSet;
                podInfo.DaemonSet = new DaemonSetInfo(daemonSet);
                break;

            case "ReplicaSet" when ownerReference.ApiVersion == "apps/v1":
                reader = await GetJsonAsync(httpClient, $"/apis/apps/v1/namespaces/{podInfo.Namespace}/replicasets/{ownerReference.Name}");

                var replicaSet = new ReplicaSet(ref reader);
                obj = replicaSet;
                podInfo.ReplicaSet = new ReplicaSetInfo(replicaSet);
                break;

            case "Deployment" when ownerReference.ApiVersion == "apps/v1":
                reader = await GetJsonAsync(httpClient, $"/apis/apps/v1/namespaces/{podInfo.Namespace}/deployments/{ownerReference.Name}");

                var deployment = new Deployment(ref reader);
                obj = deployment;
                podInfo.Deployment = new DeploymentInfo(deployment);
                break;

            case "Job" when ownerReference.ApiVersion == "batch/v1":
                reader = await GetJsonAsync(httpClient, $"/apis/batch/v1/namespaces/{podInfo.Namespace}/jobs/{ownerReference.Name}");

                var job = new Job(ref reader);
                obj         = job;
                podInfo.Job = new JobInfo(job);
                break;

            case "CronJob" when ownerReference.ApiVersion == "batch/v1beta1":
                reader = await GetJsonAsync(httpClient, $"/apis/{ownerReference.ApiVersion}/namespaces/{podInfo.Namespace}/cronjobs/{ownerReference.Name}");

                var cronJob = new CronJob(ref reader);
                obj             = cronJob;
                podInfo.CronJob = new CronJobInfo(cronJob);
                break;
            }

            if (obj != null)
            {
                await ResolveOwnerReferencesAsync(httpClient, podInfo, obj.Metadata.OwnerReferences);
            }
        }