Skip to content

Commit

Permalink
Fix internal URL (#3805)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feroze Mohideen authored Oct 12, 2023
1 parent 46d811b commit 68ad236
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ const Overview: React.FC<Props> = ({ buttonStatus }) => {
serviceVersionStatus={serviceVersionStatus}
maxCPU={currentClusterResources.maxCPU}
maxRAM={currentClusterResources.maxRAM}
namespace={deploymentTarget.namespace}
internalNetworkingDetails={{
namespace: deploymentTarget.namespace,
appName: porterApp.name,
}}
/>
<Spacer y={0.75} />
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ const ActivityFeed: React.FC<Props> = ({ appName, deploymentTargetId, currentClu
);
}

if (events != null && events.length === 0) {
// if all the events are hidden and there's only one page, show this no-events-found message
// else, users should be able to go to the next page for events
if (events != null && events.length === 0 && numPages <= 1) {
return (
<Fieldset>
<Text size={16}>No events found for "{appName}"</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ interface ServiceProps {
status?: PorterAppVersionStatus[];
maxCPU: number;
maxRAM: number;
namespace: string;
internalNetworkingDetails: {
namespace: string;
appName: string;
};
}

const ServiceContainer: React.FC<ServiceProps> = ({
Expand All @@ -38,7 +41,7 @@ const ServiceContainer: React.FC<ServiceProps> = ({
status,
maxCPU,
maxRAM,
namespace,
internalNetworkingDetails,
}) => {
const [height, setHeight] = useState<Height>(service.expanded ? "auto" : 0);

Expand All @@ -65,7 +68,13 @@ const ServiceContainer: React.FC<ServiceProps> = ({
const renderTabs = (service: ClientService) => {
return match(service)
.with({ config: { type: "web" } }, (svc) => (
<WebTabs index={index} service={svc} maxCPU={maxCPU} maxRAM={maxRAM} namespace={namespace} />
<WebTabs
index={index}
service={svc}
maxCPU={maxCPU}
maxRAM={maxRAM}
internalNetworkingDetails={internalNetworkingDetails}
/>
))
.with({ config: { type: "worker" } }, (svc) => (
<WorkerTabs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ type ServiceListProps = {
serviceVersionStatus?: Record<string, PorterAppVersionStatus[]>;
maxCPU: number;
maxRAM: number;
namespace?: string;
internalNetworkingDetails?: {
namespace: string;
appName: string;
};
};

const ServiceList: React.FC<ServiceListProps> = ({
Expand All @@ -63,7 +66,10 @@ const ServiceList: React.FC<ServiceListProps> = ({
serviceVersionStatus,
maxCPU,
maxRAM,
namespace = "",
internalNetworkingDetails = {
namespace: "",
appName: "",
},
}) => {
// top level app form
const { control: appControl } = useFormContext<PorterAppFormData>();
Expand Down Expand Up @@ -197,7 +203,7 @@ const ServiceList: React.FC<ServiceListProps> = ({
status={serviceVersionStatus?.[svc.name.value]}
maxCPU={maxCPU}
maxRAM={maxRAM}
namespace={namespace}
internalNetworkingDetails={internalNetworkingDetails}
/>
) : null;
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ type NetworkingProps = {
type: "web";
};
};
namespace: string;
internalNetworkingDetails: {
namespace: string;
appName: string;
};
};

const Networking: React.FC<NetworkingProps> = ({ index, service, namespace }) => {
const Networking: React.FC<NetworkingProps> = ({ index, service, internalNetworkingDetails: {namespace, appName} }) => {
const { register, control, watch } = useFormContext<PorterAppFormData>();

const privateService = watch(`app.services.${index}.config.private.value`);
Expand All @@ -31,16 +34,16 @@ const Networking: React.FC<NetworkingProps> = ({ index, service, namespace }) =>

const internalURL = useMemo(() => {
if (port) {
return `http://${service.name.value}.${namespace}.svc.cluster.local:${port}`;
return `http://${appName}-${service.name.value}.${namespace}.svc.cluster.local:${port}`;
}
return `http://${service.name.value}.${namespace}.svc.cluster.local`;
return `http://${appName}-${service.name.value}.${namespace}.svc.cluster.local`;
}, [service.name.value, namespace, port]);

const getApplicationURLText = () => {
if (service.config.domains.length !== 0) {
return (
<Text>
{`Application URL${service.config.domains.length === 1 ? "" : "s"}: `}
{`External URL${service.config.domains.length === 1 ? "" : "s"}: `}
{service.config.domains.map((d, i) => {
return (
<a href={prefixSubdomain(d.name.value)} target="_blank">
Expand All @@ -55,7 +58,7 @@ const Networking: React.FC<NetworkingProps> = ({ index, service, namespace }) =>

return (
<Text color="helper">
Application URL: Not generated yet. Porter will generate a URL for you
External URL: Not generated yet. Porter will generate a URL for you
on next deploy.
</Text>
);
Expand All @@ -74,21 +77,21 @@ const Networking: React.FC<NetworkingProps> = ({ index, service, namespace }) =>
{...register(`app.services.${index}.port.value`)}
/>
<Spacer y={0.5} />
{namespace &&
{namespace && appName &&
<>
<Spacer y={0.5} />
<Text color="helper">
Internal URL (for networking between services of this application):
</Text>
<Spacer y={0.5} />
<IdContainer>
<Code>{internalURL}</Code>
<CopyContainer>
<CopyToClipboard text={internalURL}>
<CopyIcon src={copy} alt="copy" />
</CopyToClipboard>
</CopyContainer>
</IdContainer>
<Code>{internalURL}</Code>
<CopyContainer>
<CopyToClipboard text={internalURL}>
<CopyIcon src={copy} alt="copy" />
</CopyToClipboard>
</CopyContainer>
</IdContainer>
<Spacer y={0.5} />
</>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ interface Props {
chart?: any;
maxRAM: number;
maxCPU: number;
namespace: string;
internalNetworkingDetails: {
namespace: string;
appName: string;
};
}

const WebTabs: React.FC<Props> = ({ index, service, maxRAM, maxCPU, namespace }) => {
const WebTabs: React.FC<Props> = ({ index, service, maxRAM, maxCPU, internalNetworkingDetails }) => {
const [currentTab, setCurrentTab] = React.useState<
"main" | "resources" | "networking" | "advanced"
>("main");
Expand All @@ -42,7 +45,11 @@ const WebTabs: React.FC<Props> = ({ index, service, maxRAM, maxCPU, namespace })
{match(currentTab)
.with("main", () => <MainTab index={index} service={service} />)
.with("networking", () => (
<Networking index={index} service={service} namespace={namespace} />
<Networking
index={index}
service={service}
internalNetworkingDetails={internalNetworkingDetails}
/>
))
.with("resources", () => (
<Resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ const AppTemplateForm: React.FC<Props> = ({ existingTemplate }) => {
fieldArrayName={"app.services"}
maxCPU={currentClusterResources.maxCPU}
maxRAM={currentClusterResources.maxRAM}
namespace={deploymentTarget.namespace}
internalNetworkingDetails={{
namespace: deploymentTarget.namespace,
appName: porterApp.name,
}}
/>
</>,
<>
Expand Down

0 comments on commit 68ad236

Please sign in to comment.