public static IngressRoute Clone()

in src/routingmanager/Extensions.cs [270:352]


        public static IngressRoute Clone(this IngressRoute ingressRoute)
        {
            var clonedIngressRoute = new IngressRoute
            {
                ApiVersion = ingressRoute.ApiVersion,
                Kind = ingressRoute.Kind,
                Metadata = new V1ObjectMeta
                {
                    Annotations = new Dictionary<string, string>(),
                    DeletionGracePeriodSeconds = ingressRoute.Metadata.DeletionGracePeriodSeconds,
                    Finalizers = ingressRoute.Metadata.Finalizers,
                    Labels = new Dictionary<string, string>(),
                    Name = ingressRoute.Metadata.Name,
                    NamespaceProperty = ingressRoute.Metadata.NamespaceProperty,
                },
                Spec = new Spec
                {
                    Virtualhost = new Virtualhost
                    {
                        Tls = new Tls()
                    },
                    Routes = new List<Route>(),
                    Strategy = ingressRoute.Spec.Strategy,
                    HealthCheckOptional = ingressRoute.Spec.HealthCheckOptional
                }
            };

            if (ingressRoute.Spec.Virtualhost?.Fqdn != null)
            {
                clonedIngressRoute.Spec.Virtualhost.Fqdn = ingressRoute.Spec.Virtualhost.Fqdn;
            }

            if (ingressRoute.Spec.Virtualhost?.Tls != null)
            {
                clonedIngressRoute.Spec.Virtualhost.Tls.MinimumProtocolVersion = ingressRoute.Spec.Virtualhost.Tls.MinimumProtocolVersion;
                clonedIngressRoute.Spec.Virtualhost.Tls.SecretName = ingressRoute.Spec.Virtualhost.Tls.SecretName;
            }

            if (ingressRoute.Metadata.Annotations != null)
            {
                ingressRoute.Metadata.Annotations.ExecuteForEach(kv => clonedIngressRoute.Metadata.Annotations.Add(kv.Key, kv.Value));
            }
            // Add the clonedFrom annotation
            clonedIngressRoute.Metadata.Annotations.Add(Constants.ClonedFromAnnotation, ingressRoute.Metadata.Name);

            if (ingressRoute.Metadata.Labels != null)
            {
                ingressRoute.Metadata.Labels.ExecuteForEach(kv => clonedIngressRoute.Metadata.Labels.Add(kv.Key, kv.Value));
            }

            if (ingressRoute.Spec.Routes != null)
            {
                foreach (var route in ingressRoute.Spec.Routes)
                {
                    var clonedRoute = new Route
                    {
                        Services = new List<Service>(),
                        Delegate = route.Delegate,
                        Match = route.Match,
                        PermitInsecure = route.PermitInsecure
                    };

                    if (route.Services != null)
                    {
                        foreach (var service in route.Services)
                        {
                            clonedRoute.Services.Add(new Service
                            {
                                Name = service.Name,
                                Port = service.Port,
                                Strategy = service.Strategy,
                                Weight = service.Weight,
                                HealthCheckOptional = service.HealthCheckOptional
                            });
                        }
                    }

                    clonedIngressRoute.Spec.Routes.Add(clonedRoute);
                }
            }

            return clonedIngressRoute;
        }