public async Task UnDo(CityWeatherResource resource)
        {
            _diagnostics.ControllerUndeploying(resource);
            await UndeployService(resource);
            await UndeployDeployment(resource);

            _diagnostics.ControllerUndeployed(resource);
        }
        public async Task Do(CityWeatherResource resource)
        {
            _diagnostics.ControllerDeploying(resource);
            var service = await DeployService(resource);

            var deployment = await DeployDeployment(resource);

            _diagnostics.ControllerDeployed(resource, service, deployment);
        }
        private async Task <V1Service> DeployService(CityWeatherResource resource)
        {
            var labels = new Dictionary <string, string>()
            {
                { "app", _appName },
                { "city", resource.Spec.City }
            };

            var serviceBody = new V1Service(
                metadata: new V1ObjectMeta(
                    name: resource.Metadata.Name,
                    labels: labels),
                spec: new V1ServiceSpec(
                    ports: new List <V1ServicePort>()
            {
                new V1ServicePort(port: 80, targetPort: "http", protocol: "TCP", name: "http")
            },
                    selector: labels
                    )
                );

            return(await _kubernetesClient.CreateNamespacedServiceAsync(serviceBody, resource.Metadata.NamespaceProperty));
        }
        private async Task <V1beta2Deployment> DeployDeployment(CityWeatherResource resource)
        {
            var labels = new Dictionary <string, string>()
            {
                { "app", _appName },
                { "city", resource.Spec.City }
            };

            var deploymentBody = new V1beta2Deployment(
                metadata: new V1ObjectMeta(
                    name: resource.Metadata.Name,
                    labels: labels),
                spec: new V1beta2DeploymentSpec(
                    selector: new V1LabelSelector(matchLabels: labels),
                    replicas: resource.Spec.Replicas,
                    template: new V1PodTemplateSpec(
                        metadata: new V1ObjectMeta(labels: labels),
                        spec: new V1PodSpec(
                            containers: new List <V1Container>()
            {
                new V1Container(
                    name: resource.Metadata.Name,
                    env: new List <V1EnvVar>()
                {
                    new V1EnvVar("Weather__City", resource.Spec.City)
                },
                    imagePullPolicy: "IfNotPresent",
                    image: "xabarilcoding/cityweatherapi:latest",
                    ports: new List <V1ContainerPort>()
                {
                    new V1ContainerPort(containerPort: 80, protocol: "TCP", name: "http")
                })
            }))));

            return(await _kubernetesClient.CreateNamespacedDeployment2Async(deploymentBody, resource.Metadata.NamespaceProperty));
        }
Exemplo n.º 5
0
 public void ControllerUndeployed(CityWeatherResource resource)
 {
     _logger.LogInformation($"{resource.Metadata.Name} service deleted");
     _logger.LogInformation($"{resource.Metadata.Name} deployment deleted");
     _logger.LogInformation($"{resource.Metadata.Name} controller undeployed");
 }
Exemplo n.º 6
0
 public void ControllerUndeploying(CityWeatherResource resource)
 {
     _logger.LogInformation("CityWeatherOperator controller Undoing...");
 }
Exemplo n.º 7
0
 public void ControllerDeployed(CityWeatherResource resource, V1Service service, V1beta2Deployment deployment)
 {
     _logger.LogInformation($"{resource.Metadata.Name} service deployed on IP {service.Spec.ClusterIP}");
     _logger.LogInformation($"{resource.Metadata.Name} deployment deployed with {deployment.Spec.Replicas} replicas");
     _logger.LogInformation($"{resource.Metadata.Name} controller deployed");
 }
Exemplo n.º 8
0
 public void ControllerDeploying(CityWeatherResource resource)
 {
     _logger.LogInformation($"{resource.Metadata.Name} controller deploying...");
 }
 private async Task <V1Status> UndeployDeployment(CityWeatherResource resource)
 {
     return(await _kubernetesClient.DeleteNamespacedDeployment2Async(resource.Metadata.Name, resource.Metadata.NamespaceProperty));
 }