Beispiel #1
0
        async Task ReportEdgeDeploymentStatus(EdgeDeploymentDefinition edgeDeploymentDefinition, EdgeDeploymentStatus status)
        {
            if (!status.Equals(this.currentStatus))
            {
                var edgeDeploymentStatus = new EdgeDeploymentDefinition(
                    edgeDeploymentDefinition.ApiVersion,
                    edgeDeploymentDefinition.Kind,
                    edgeDeploymentDefinition.Metadata,
                    edgeDeploymentDefinition.Spec,
                    status);

                var crdObject = JObject.FromObject(edgeDeploymentStatus, JsonSerializer.Create(this.serializerSettings));

                try
                {
                    await this.client.ReplaceNamespacedCustomObjectStatusWithHttpMessagesAsync(
                        crdObject,
                        KubernetesConstants.EdgeDeployment.Group,
                        KubernetesConstants.EdgeDeployment.Version,
                        this.deviceNamespace,
                        KubernetesConstants.EdgeDeployment.Plural,
                        this.resourceName);
                }
                catch (HttpOperationException e)
                {
                    Events.DeploymentStatusFailed(e);
                }
            }
        }
        async Task PushEdgeDeployment(CancellationToken token)
        {
            List <KubernetesModule> modulesList = this.modules
                                                  .Select(
                module =>
            {
                var combinedConfig = this.configProvider.GetCombinedConfig(module, this.runtimeInfo);
                string image       = combinedConfig.Image;

                var authConfig = combinedConfig.ImagePullSecret.Map(secret => new AuthConfig(secret.Name));
                return(new KubernetesModule(module, new KubernetesConfig(image, combinedConfig.CreateOptions, authConfig), this.moduleOwner));
            })
                                                  .ToList();

            var metadata = new V1ObjectMeta
            {
                Name = this.resourceName,
                NamespaceProperty = this.deviceNamespace,
                OwnerReferences   = this.moduleOwner.ToOwnerReferences()
            };

            // need resourceVersion for Replace.
            this.activeDeployment.ForEach(deployment => metadata.ResourceVersion = deployment.Metadata.ResourceVersion);

            var customObjectDefinition = new EdgeDeploymentDefinition(KubernetesConstants.EdgeDeployment.ApiVersion, KubernetesConstants.EdgeDeployment.Kind, metadata, modulesList);
            var crdObject = JObject.FromObject(customObjectDefinition, JsonSerializer.Create(this.serializerSettings));

            await this.activeDeployment.Match(
                async a =>
            {
                Events.ReplaceEdgeDeployment(customObjectDefinition);
                await this.client.ReplaceNamespacedCustomObjectWithHttpMessagesAsync(
                    crdObject,
                    KubernetesConstants.EdgeDeployment.Group,
                    KubernetesConstants.EdgeDeployment.Version,
                    this.deviceNamespace,
                    KubernetesConstants.EdgeDeployment.Plural,
                    this.resourceName,
                    cancellationToken: token);
            },
                async() =>
            {
                try
                {
                    Events.CreateEdgeDeployment(customObjectDefinition);
                    await this.client.CreateNamespacedCustomObjectWithHttpMessagesAsync(
                        crdObject,
                        KubernetesConstants.EdgeDeployment.Group,
                        KubernetesConstants.EdgeDeployment.Version,
                        this.deviceNamespace,
                        KubernetesConstants.EdgeDeployment.Plural,
                        cancellationToken: token);
                }
                catch (HttpOperationException e) when(e.Response.StatusCode == HttpStatusCode.NotFound)
                {
                    Events.ReportCrdInstallationFailed(e);
                    throw;
                }
            });
        }
Beispiel #3
0
        async Task ReportDeploymentFailure(Exception ex, EdgeDeploymentDefinition item)
        {
            var status = EdgeDeploymentStatus.Failure(ex);

            await this.ReportEdgeDeploymentStatus(item, status);

            this.currentStatus = status;
        }
Beispiel #4
0
        internal async Task EdgeDeploymentOnEventHandlerAsync(WatchEventType type, EdgeDeploymentDefinition item)
        {
            using (await this.watchLock.LockAsync())
            {
                try
                {
                    await this.HandleEdgeDeploymentChangedAsync(type, item);
                }
                catch (Exception ex)
                {
                    Events.EdgeDeploymentWatchFailed(ex);
                    await this.ReportDeploymentFailure(ex, item);

                    throw;
                }
            }
        }
        async Task HandleEdgeDeploymentChangedAsync(WatchEventType type, EdgeDeploymentDefinition edgeDeploymentDefinition)
        {
            // only operate on the device that matches this operator.
            if (!this.resourceName.Equals(edgeDeploymentDefinition.Metadata.Name))
            {
                Events.DeploymentNameMismatch(edgeDeploymentDefinition.Metadata.Name, this.resourceName);
                return;
            }

            Events.DeploymentStatus(type, this.resourceName);
            switch (type)
            {
            case WatchEventType.Added:
            case WatchEventType.Modified:
                var desiredModules = ModuleSet.Create(edgeDeploymentDefinition.Spec.ToArray());
                var status         = await this.controller.DeployModulesAsync(desiredModules, this.currentModules);

                await this.ReportEdgeDeploymentStatus(edgeDeploymentDefinition, status);

                this.currentModules = desiredModules;
                this.currentStatus  = status;
                break;

            case WatchEventType.Deleted:
                await this.controller.PurgeModulesAsync();

                this.currentModules = ModuleSet.Empty;
                this.currentStatus  = DefaultStatus;
                break;

            case WatchEventType.Error:
                Events.DeploymentError();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Beispiel #6
0
 public static void ReplaceEdgeDeployment(EdgeDeploymentDefinition deployment) => Log.LogDebug((int)EventIds.ReplaceDeployment, $"Replace edge deployment: {deployment.Metadata.Name}");
Beispiel #7
0
 public static void CreateEdgeDeployment(EdgeDeploymentDefinition deployment) => Log.LogDebug((int)EventIds.CreateDeployment, $"Create edge deployment: {deployment.Metadata.Name}");