import { Plus, RotateCw } from 'lucide-react'; import { FormikErrors } from 'formik'; import { KubernetesApplicationPublishingTypes } from '@/kubernetes/models/application/models'; import { useCurrentUser } from '@/react/hooks/useUser'; import { useEnvironment } from '@/react/portainer/environments/queries'; import { useEnvironmentId } from '@/react/hooks/useEnvironmentId'; import { Card } from '@@/Card'; import { TextTip } from '@@/Tip/TextTip'; import { Button } from '@@/buttons'; import { FormError } from '@@/form-components/FormError'; import { Link } from '@@/Link'; import { generateUniqueName, newPort, serviceFormDefaultValues } from './utils'; import { ServiceFormValues, ServicePort } from './types'; import { LoadBalancerServiceForm } from './LoadBalancerServiceForm'; interface Props { services: ServiceFormValues[]; onChangeService: (services: ServiceFormValues[]) => void; errors?: FormikErrors; appName: string; selector: Record; } export function LoadBalancerServicesForm({ services, onChangeService, errors, appName, selector, }: Props) { const { isAdmin } = useCurrentUser(); const environmentId = useEnvironmentId(); const { data: loadBalancerEnabled, ...loadBalancerEnabledQuery } = useEnvironment( environmentId, (environment) => environment?.Kubernetes.Configuration.UseLoadBalancer ); const loadBalancerServiceCount = services.filter( (service) => service.Type === KubernetesApplicationPublishingTypes.LOAD_BALANCER ).length; return (
Allow access to traffic external to the cluster via a{' '} LoadBalancer service. If running on a cloud platform, this auto provisions a cloud load balancer. {!loadBalancerEnabled && loadBalancerEnabledQuery.isSuccess && (
{isAdmin ? ( <> Load balancer use is not currently enabled in this cluster. Configure via{' '} Cluster Setup {' '} and then refresh this tab ) : ( 'Load balancer use is not currently enabled in this cluster, contact your administrator.' )}
)} {loadBalancerServiceCount > 0 && (
{services.map((service, index) => service.Type === KubernetesApplicationPublishingTypes.LOAD_BALANCER ? ( { const newServices = [...services]; newServices[index].Ports = servicePorts; onChangeService(newServices); }} services={services} serviceIndex={index} onChangeService={onChangeService} /> ) : null )}
)}
); }