예제 #1
0
        /// <summary>
        /// Use this constructor to configure the deployment differently, using the configuration provided.
        /// </summary>
        /// <param name="cfg">A function, which creates the <see cref="AutoDevOps"/> instance given the settings.</param>
        public DefaultStack(Func <AutoDevOpsSettings, AutoDevOps> cfg)
        {
            var config   = new Config();
            var settings = new AutoDevOpsSettings(config);

            AutoDevOps = cfg(settings);
        }
예제 #2
0
        /// <summary>
        /// The AutoDevOps resource constructor, which takes care of deploying the whole thing
        /// </summary>
        /// <param name="settings">AutoDevOps settings, <see cref="AutoDevOpsSettings"/></param>
        /// <param name="sidecars">Optional: collection of sidecar containers</param>
        /// <param name="configureContainer">Optional: custom application container configuration</param>
        /// <param name="configurePod">Optional: custom pod configuration</param>
        /// <param name="configureDeployment">Optional: custom deployment configuration</param>
        /// <param name="configureService">Optional: custom service configuration</param>
        /// <param name="serviceAnnotations">Optional: service annotations</param>
        /// <param name="ingressAnnotations">Optional: ingress annotations</param>
        /// <param name="namespaceAnnotations">Optional: namespace annotations</param>
        /// <param name="deployExtras">Optional: use this to deploy other resources to the environment namespace,
        /// before the application is deployed.</param>
        /// <param name="provider">Optional: custom Kubernetes resource provider</param>
        public AutoDevOps(
            AutoDevOpsSettings settings,
            IEnumerable <ContainerArgs>?sidecars             = null,
            Action <ContainerArgs>?configureContainer        = null,
            Action <PodSpecArgs>?configurePod                = null,
            Action <DeploymentArgs>?configureDeployment      = null,
            Action <ServiceArgs>?configureService            = null,
            Dictionary <string, string>?serviceAnnotations   = null,
            Dictionary <string, string>?ingressAnnotations   = null,
            Dictionary <string, string>?namespaceAnnotations = null,
            Action <Namespace>?deployExtras = null,
            ProviderResource?provider       = null
            )
        {
            var @namespace    = KubeNamespace.Create(settings.Deploy.Namespace, namespaceAnnotations, provider);
            var namespaceName = @namespace.Metadata.Apply(x => x.Name);

            deployExtras?.Invoke(@namespace);

            var imagePullSecret = settings.GitLab.Visibility != "public" && settings.Registry != null
                ? KubeSecret.CreateRegistrySecret(namespaceName, settings.Registry, provider)
                : null;

            var replicas = settings.Deploy.Percentage > 0 || settings.Deploy.Replicas == 0
                ? GetReplicas(settings.Application.Track, settings.Deploy.Percentage)
                : settings.Deploy.Replicas;

            if (replicas == 0)
            {
                DeploymentResult = new Result {
                    Namespace = @namespace
                };
                return;
            }

            var appSecret = KubeSecret.CreateAppSecret(namespaceName, settings, provider);

            var deployment = KubeDeployment.Create(
                namespaceName,
                settings,
                replicas,
                imagePullSecret,
                appSecret,
                sidecars,
                configureContainer,
                configurePod,
                configureDeployment,
                provider
                );

            var service = settings.Service.Enabled
                ? KubeService.Create(
                namespaceName,
                settings,
                deployment,
                serviceAnnotations,
                configureService,
                provider
                )
                : null;

            var ingress = settings.Ingress.Enabled && !settings.Deploy.Url.IsEmpty()
                ? KubeIngress.Create(namespaceName, settings, settings.Ingress.Class, ingressAnnotations, provider)
                : null;

            if (settings.Prometheus.Metrics && settings.Prometheus.Operator)
            {
                if (service != null)
                {
                    Prometheus.CreateServiceMonitor(settings, service, @namespace, provider);
                }
                else
                {
                    Prometheus.CreatePodMonitor(settings, deployment, @namespace, provider);
                }
            }

            DeploymentResult = new Result {
                Namespace  = @namespace,
                Deployment = deployment,
                Service    = service,
                Ingress    = ingress
            };
        }
예제 #3
0
 /// <summary>
 /// Gets the default labels, which identify the app and the release
 /// </summary>
 /// <param name="settings">Settings for AutoDevOps</param>
 /// <returns>An input map with default annotations</returns>
 public static InputMap <string> BaseLabels(this AutoDevOpsSettings settings)
 => new()