コード例 #1
0
        async Task WatchPodEventsAsync(WatchEventType type, V1Pod item)
        {
            // if the pod doesn't have the module label set then we are not interested in it
            if (!item.Metadata.Labels.TryGetValue(Constants.K8sEdgeModuleLabel, out string podName))
            {
                return;
            }

            Events.PodStatus(type, podName);
            switch (type)
            {
            case WatchEventType.Added:
            case WatchEventType.Modified:
            case WatchEventType.Error:
                ModuleRuntimeInfo runtimeInfo = item.ConvertToRuntime(podName);
                using (await this.moduleLock.LockAsync())
                {
                    this.moduleRuntimeInfos[podName] = runtimeInfo;
                    this.OnModulesChanged();
                }

                break;

            case WatchEventType.Deleted:
                using (await this.moduleLock.LockAsync())
                {
                    ModuleRuntimeInfo removedRuntimeInfo;
                    if (!this.moduleRuntimeInfos.TryRemove(podName, out removedRuntimeInfo))
                    {
                        Events.PodStatusRemoveError(podName);
                    }

                    this.OnModulesChanged();
                }

                break;
            }
        }
コード例 #2
0
        public void CreateOrUpdateAddPodInfo(V1Pod pod)
        {
            string moduleName = pod.Metadata.Labels[Constants.K8sEdgeModuleLabel];
            var    newPair    = new KeyValuePair <string, ModuleRuntimeInfo>(pod.Metadata.Name, pod.ConvertToRuntime(moduleName));

            this.moduleRuntimeInfo.AddOrUpdate(
                moduleName,
                ImmutableList.Create(newPair),
                (_, existing) =>
            {
                return(existing.FirstOption(pair => pair.Key == pod.Metadata.Name)
                       .Map(pair => existing.Replace(pair, newPair))
                       .GetOrElse(() => existing.Add(newPair)));
            });
        }
コード例 #3
0
        public void CreateOrUpdateAddPodInfo(string podName, V1Pod pod)
        {
            ModuleRuntimeInfo runtimeInfo = pod.ConvertToRuntime(podName);

            this.moduleRuntimeInfo.AddOrUpdate(podName, runtimeInfo, (_, existing) => runtimeInfo);
        }