Example #1
0
        private async Task ValidateReplicaAggrement(IEnumerable <KubernetesModule> liveModules, IEnumerable <Module> npModules)
        {
            foreach (var npModule in npModules)
            {
                // Find the corresponding live module
                var liveModule = liveModules.SingleOrDefault(t => t.Deployment.Metadata.Name.Equals(npModule.ModuleName));

                if (liveModule != null) // Found the corresponding module
                {
                    if (liveModule.Deployment.Spec.Replicas.Value != npModule.DesiredReplicas)
                    {
                        // Desired replicas has changed update kubernetes accordingly
                        var response = await _kubectlHelper.ScaleDeployment(liveModule.Deployment.Metadata.Name,
                                                                            new ModuleReplicas(npModule.DesiredReplicas));

                        if (!response.IsSuccessful)
                        {
                            // Log that we tried to scale the module but it did not work
                            await _moduleRepository.AppendLog(npModule.Id,
                                                              npModule.Logs +
                                                              $"\nTried to scale module replicas from {liveModule.Deployment.Spec.Replicas.Value} to {npModule.DesiredReplicas} but received an error: \n ***** \n {response.Message} \n*****\n");
                        }
                    }
                }
            }
        }