Skip to content

Commit

Permalink
add targetConfig for frpc_ingress
Browse files Browse the repository at this point in the history
  • Loading branch information
springhack committed Jan 10, 2023
1 parent c12b189 commit ef23f87
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions charts/frpc-ingress/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
version: 0.4.0
appVersion: 0.4.0
version: 0.4.1
appVersion: 0.4.1
name: frpc-ingress
type: application
description: Frp client ingress define and opertator
Expand Down
3 changes: 3 additions & 0 deletions charts/frpc-ingress/templates/aio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ spec:
required:
- name
- port
- targetConfig
properties:
targetConfig:
type: string
namespace:
type: string
name:
Expand Down
33 changes: 20 additions & 13 deletions frpc_ingress/utils/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const makeSection = (frpcConfig, key) => {
return content;
};

const extractConfigName = (namespace) => {
return namespace || 'default';
const extractConfigName = (name) => {
return name || 'default';
};

watch.getOnce(
Expand All @@ -30,15 +30,18 @@ watch.getOnce(
}
for (const item of items) {
if (item.spec.kind === 'Config') {
allConfigs.set(extractConfigName(item.metadata.namespace), new Map());
allConfigs.set(extractConfigName(item.metadata.name), new Map());
}
}
for (const item of items) {
const frpcConfig = allConfigs.get(extractConfigName(item.metadata.namespace));
const name = item.metadata.name || 'undefined';
const namespace = item.metadata.namespace || 'default';
const frpcSection =
(item.spec.kind === 'Config') ? 'common' : `${name}@${namespace}`;
const frpcConfigName = (item.spec.kind === 'Config') ?
item.metadata.name :
(item.spec.service && item.spec.service.targetConfig || '');
const frpcConfig = allConfigs.get(extractConfigName(frpcConfigName));
if (frpcConfig.has(frpcSection)) {
console.error(`[ERROR] duplicated section ${frpcSection} ...`);
process.exit();
Expand Down Expand Up @@ -69,24 +72,26 @@ watch.getOnce(
`local_port = ${item.spec.service.port}`,
];
if (item.spec.service.remotePort) {
configSection.push(`remote_port = ${item.spec.service.remotePort}`)
configSection.push(
`remote_port = ${item.spec.service.remotePort}`)
}
if (item.spec.service.customDomains) {
configSection.push(`custom_domains = ${item.spec.service.customDomains}`)
configSection.push(
`custom_domains = ${item.spec.service.customDomains}`)
}
if (item.spec.service.subdomain) {
configSection.push(`subdomain = ${item.spec.service.subdomain}`)
}
frpcConfig.set(frpcSection, [
...configSection,
...extraConfig
]);
frpcConfig.set(frpcSection, [...configSection, ...extraConfig]);
break;
}
}
if (!frpcConfig.has('common')) {
console.error(`[ERROR] no common config(${extractConfigName(item.metadata.namespace)}) ...`);
fs.writeFileSync(`/frp/client/${extractConfigName(item.metadata.namespace)}.ini`, '', {encoding: 'utf-8'});
console.error(`[ERROR] no common config(${
extractConfigName(frpcConfigName)}) ...`);
fs.writeFileSync(
`/frp/client/${extractConfigName(frpcConfigName)}.ini`, '',
{encoding: 'utf-8'});
process.exit();
}
let configContent = makeSection(frpcConfig, 'common');
Expand All @@ -95,7 +100,9 @@ watch.getOnce(
configContent += makeSection(frpcConfig, key);
}
}
fs.writeFileSync(`/frp/client/${extractConfigName(item.metadata.namespace)}.ini`, configContent, {encoding: 'utf-8'});
fs.writeFileSync(
`/frp/client/${extractConfigName(frpcConfigName)}.ini`,
configContent, {encoding: 'utf-8'});
}
},
(err) => {
Expand Down

0 comments on commit ef23f87

Please sign in to comment.