Skip to content

Commit

Permalink
Merge pull request #23409 from mshima/skip_ci-kubernetes
Browse files Browse the repository at this point in the history
fix kubernetes generation
  • Loading branch information
DanielFran authored Sep 5, 2023
2 parents 6373c9c + d5ce34e commit e77576a
Show file tree
Hide file tree
Showing 26 changed files with 416 additions and 261 deletions.
31 changes: 10 additions & 21 deletions generators/base-workspaces/internal/docker-base.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function checkImages() {
*/
export function generateJwtSecret() {
if (this.jwtSecretKey === undefined) {
this.jwtSecretKey = createBase64Secret(this.options.reproducibleTests);
this.jwtSecretKey = this.jhipsterConfig.jwtSecretKey = createBase64Secret(this.options.reproducibleTests);
}
}

Expand Down Expand Up @@ -136,26 +136,15 @@ export function loadFromYoRc() {
this.useMemcached = false;
this.useRedis = false;

// Current implementation loads appsFolders into defaultAppsFolders
this.defaultAppsFolders = this.appsFolders;
delete this.appsFolders;

if (this.defaultAppsFolders !== undefined) {
this.log.log('\nFound .yo-rc.json config file...');
loadConfigs.call(this);
if (this.microserviceNb > 0 || this.gatewayNb > 0) {
this.deploymentApplicationType = MICROSERVICE;
} else {
this.deploymentApplicationType = MONOLITH;
}

if (this.regenerate) {
this.appsFolders = this.defaultAppsFolders;
loadConfigs.call(this);
if (this.microserviceNb > 0 || this.gatewayNb > 0) {
this.deploymentApplicationType = MICROSERVICE;
} else {
this.deploymentApplicationType = MONOLITH;
}
setClusteredApps.call(this);
if (!this.adminPassword) {
this.adminPassword = 'admin'; // TODO find a better way to do this
this.adminPasswordBase64 = convertSecretToBase64(this.adminPassword);
}
setClusteredApps.call(this);
if (!this.adminPassword) {
this.adminPassword = 'admin'; // TODO find a better way to do this
this.adminPasswordBase64 = convertSecretToBase64(this.adminPassword);
}
}
32 changes: 16 additions & 16 deletions generators/base-workspaces/internal/docker-prompts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ const { PROMETHEUS } = monitoringTypes;
const monitoring = monitoringTypes;

const NO_MONITORING = monitoring.NO;
const { CONSUL, EUREKA } = serviceDiscoveryTypes;
const { CONSUL, EUREKA, NO: NO_SERVICE_DISCOVERY } = serviceDiscoveryTypes;

const NO_SERVICE_DISCOVERY = serviceDiscoveryTypes.NO;
export default {
askForApplicationType,
askForGatewayType,
Expand All @@ -49,7 +48,7 @@ export default {
* Ask For Application Type
*/
async function askForApplicationType() {
if (this.regenerate) return;
if (!this.options.askAnswered && (this.regenerate || this.config.existed)) return;

const prompts = [
{
Expand Down Expand Up @@ -78,7 +77,7 @@ async function askForApplicationType() {
* Ask For Gateway Type
*/
async function askForGatewayType() {
if (this.regenerate) return;
if (!this.options.askAnswered && (this.regenerate || this.config.existed)) return;
if (this.deploymentApplicationType !== MICROSERVICE) return;

const prompts = [
Expand All @@ -104,7 +103,7 @@ async function askForGatewayType() {
* Ask For Path
*/
async function askForPath() {
if (this.regenerate) return;
if (!this.options.askAnswered && (this.regenerate || this.config.existed)) return;

const deploymentApplicationType = this.deploymentApplicationType;
let messageAskForPath;
Expand Down Expand Up @@ -158,7 +157,7 @@ async function askForPath() {
* Ask For Apps
*/
async function askForApps() {
if (this.regenerate) return;
if (!this.options.askAnswered && (this.regenerate || this.config.existed)) return;

const messageAskForApps = 'Which applications do you want to include in your configuration?';

Expand All @@ -168,7 +167,7 @@ async function askForApps() {
name: 'chosenApps',
message: messageAskForApps,
choices: this.appsFolders ?? [],
default: this.defaultAppsFolders,
default: this.jhipsterConfig.appsFolders,
validate: input => (input.length === 0 ? 'Please choose at least one application' : true),
},
];
Expand All @@ -182,7 +181,7 @@ async function askForApps() {
* Ask For Clusters Mode
*/
async function askForClustersMode() {
if (this.regenerate) return;
if (!this.options.askAnswered && (this.regenerate || this.config.existed)) return;

const clusteredDbApps = [];
this.appConfigs.forEach((appConfig, index) => {
Expand Down Expand Up @@ -210,7 +209,7 @@ async function askForClustersMode() {
* Ask For Monitoring
*/
async function askForMonitoring() {
if (this.regenerate) return;
if (!this.options.askAnswered && (this.regenerate || this.config.existed)) return;

const prompts = [
{
Expand Down Expand Up @@ -239,7 +238,7 @@ async function askForMonitoring() {
* Ask For Service Discovery
*/
async function askForServiceDiscovery() {
if (this.regenerate) return;
if (!this.options.askAnswered && (this.regenerate || this.config.existed)) return;

const serviceDiscoveryEnabledApps = [];
this.appConfigs.forEach(appConfig => {
Expand All @@ -252,15 +251,15 @@ async function askForServiceDiscovery() {
});

if (serviceDiscoveryEnabledApps.length === 0) {
this.serviceDiscoveryType = false;
this.serviceDiscoveryType = this.jhipsterConfig.serviceDiscoveryType = NO_SERVICE_DISCOVERY;
return;
}

if (serviceDiscoveryEnabledApps.every(app => app.serviceDiscoveryType === CONSUL)) {
this.serviceDiscoveryType = CONSUL;
this.serviceDiscoveryType = this.jhipsterConfig.serviceDiscoveryType = CONSUL;
this.log.log(chalk.green('Consul detected as the service discovery and configuration provider used by your apps'));
} else if (serviceDiscoveryEnabledApps.every(app => app.serviceDiscoveryType === EUREKA)) {
this.serviceDiscoveryType = EUREKA;
this.serviceDiscoveryType = this.jhipsterConfig.serviceDiscoveryType = EUREKA;
this.log.log(chalk.green('JHipster registry detected as the service discovery and configuration provider used by your apps'));
} else {
this.log.warn(
Expand Down Expand Up @@ -303,7 +302,8 @@ async function askForServiceDiscovery() {
* Ask For Admin Password
*/
async function askForAdminPassword() {
if (this.regenerate || this.serviceDiscoveryType !== EUREKA) return;
if (!this.options.askAnswered && (this.regenerate || this.config.existed)) return;
if (this.serviceDiscoveryType !== EUREKA) return;

const prompts = [
{
Expand All @@ -324,7 +324,7 @@ async function askForAdminPassword() {
* Ask For Docker Repository Name
*/
async function askForDockerRepositoryName() {
if (this.regenerate) return;
if (!this.options.askAnswered && (this.regenerate || this.config.existed)) return;

const prompts = [
{
Expand All @@ -343,7 +343,7 @@ async function askForDockerRepositoryName() {
* Ask For Docker Push Command
*/
async function askForDockerPushCommand() {
if (this.regenerate) return;
if (!this.options.askAnswered && (this.regenerate || this.config.existed)) return;

const prompts = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ exports[`generator - Kubernetes Helm Kafka application should match files snapsh
"generator-jhipster": {
"appsFolders": ["09-kafka"],
"baseName": "workspaces",
"clusteredDbApps": [],
"deploymentApplicationType": "monolith",
"directoryPath": "./",
"dockerPushCommand": "docker push",
"dockerRepositoryName": "jhipster",
"ingressDomain": "",
"istio": false,
"ingressDomain": null,
"ingressType": null,
"jwtSecretKey": "SECRET--50",
"kubernetesNamespace": "default",
"kubernetesServiceType": "LoadBalancer",
"monitoring": "no",
"serviceDiscoveryType": false
"serviceDiscoveryType": "no"
}
}
",
Expand Down Expand Up @@ -395,12 +394,12 @@ exports[`generator - Kubernetes Helm MySQL and PostgreSQL microservices without
"generator-jhipster": {
"appsFolders": ["02-mysql", "03-psql"],
"baseName": "workspaces",
"clusteredDbApps": [],
"deploymentApplicationType": "microservice",
"directoryPath": "./",
"dockerPushCommand": "docker push",
"dockerRepositoryName": "jhipster",
"ingressDomain": "",
"ingressDomain": null,
"ingressType": null,
"istio": false,
"jwtSecretKey": "SECRET--50",
"kubernetesNamespace": "default",
Expand Down Expand Up @@ -1282,7 +1281,6 @@ exports[`generator - Kubernetes Helm gateway and ingress should match files snap
"generator-jhipster": {
"appsFolders": ["01-gateway"],
"baseName": "workspaces",
"clusteredDbApps": [],
"deploymentApplicationType": "microservice",
"directoryPath": "./",
"dockerPushCommand": "docker push",
Expand Down Expand Up @@ -1931,12 +1929,12 @@ exports[`generator - Kubernetes Helm gateway and mysql microservice should match
"generator-jhipster": {
"appsFolders": ["01-gateway", "02-mysql"],
"baseName": "workspaces",
"clusteredDbApps": [],
"deploymentApplicationType": "microservice",
"directoryPath": "./",
"dockerPushCommand": "docker push",
"dockerRepositoryName": "jhipster",
"ingressDomain": "",
"ingressDomain": null,
"ingressType": null,
"istio": false,
"jwtSecretKey": "SECRET--50",
"kubernetesNamespace": "default",
Expand Down Expand Up @@ -2743,16 +2741,16 @@ exports[`generator - Kubernetes Helm gateway with istio should match files snaps
"generator-jhipster": {
"appsFolders": ["01-gateway"],
"baseName": "workspaces",
"clusteredDbApps": [],
"deploymentApplicationType": "microservice",
"directoryPath": "./",
"dockerPushCommand": "docker push",
"dockerRepositoryName": "jhipster",
"ingressDomain": "example.com",
"ingressType": null,
"istio": true,
"jwtSecretKey": "SECRET--50",
"kubernetesNamespace": "default",
"kubernetesServiceType": "LoadBalancer",
"kubernetesServiceType": null,
"monitoring": "no",
"serviceDiscoveryType": "consul"
}
Expand Down Expand Up @@ -3629,7 +3627,8 @@ exports[`generator - Kubernetes Helm gateway, mysql, psql, mongodb, mariadb micr
"directoryPath": "./",
"dockerPushCommand": "docker push",
"dockerRepositoryName": "jhipster",
"ingressDomain": "",
"ingressDomain": null,
"ingressType": null,
"istio": false,
"jwtSecretKey": "SECRET--50",
"kubernetesNamespace": "default",
Expand Down Expand Up @@ -5068,18 +5067,17 @@ exports[`generator - Kubernetes Helm monolith application should match files sna
"generator-jhipster": {
"appsFolders": ["08-monolith"],
"baseName": "workspaces",
"clusteredDbApps": [],
"deploymentApplicationType": "monolith",
"directoryPath": "./",
"dockerPushCommand": "docker push",
"dockerRepositoryName": "jhipster",
"ingressDomain": "",
"istio": false,
"ingressDomain": null,
"ingressType": null,
"jwtSecretKey": "SECRET--50",
"kubernetesNamespace": "default",
"kubernetesServiceType": "LoadBalancer",
"monitoring": "no",
"serviceDiscoveryType": false
"serviceDiscoveryType": "no"
}
}
",
Expand Down Expand Up @@ -5441,12 +5439,12 @@ exports[`generator - Kubernetes Helm mysql microservice with custom namespace an
"generator-jhipster": {
"appsFolders": ["02-mysql"],
"baseName": "workspaces",
"clusteredDbApps": [],
"deploymentApplicationType": "microservice",
"directoryPath": "./",
"dockerPushCommand": "docker push",
"dockerRepositoryName": "jhipster",
"ingressDomain": "",
"ingressDomain": null,
"ingressType": null,
"istio": false,
"jwtSecretKey": "SECRET--50",
"kubernetesNamespace": "mynamespace",
Expand Down Expand Up @@ -8421,12 +8419,12 @@ exports[`generator - Kubernetes Helm mysql microservice with custom namespace sh
"generator-jhipster": {
"appsFolders": ["02-mysql"],
"baseName": "workspaces",
"clusteredDbApps": [],
"deploymentApplicationType": "microservice",
"directoryPath": "./",
"dockerPushCommand": "docker push",
"dockerRepositoryName": "jhipster",
"ingressDomain": "",
"ingressDomain": null,
"ingressType": null,
"istio": false,
"jwtSecretKey": "SECRET--50",
"kubernetesNamespace": "mynamespace",
Expand Down Expand Up @@ -9054,12 +9052,12 @@ exports[`generator - Kubernetes Helm only gateway should match files snapshot 1`
"generator-jhipster": {
"appsFolders": ["01-gateway"],
"baseName": "workspaces",
"clusteredDbApps": [],
"deploymentApplicationType": "microservice",
"directoryPath": "./",
"dockerPushCommand": "docker push",
"dockerRepositoryName": "jhipsterrepository",
"ingressDomain": "",
"ingressDomain": null,
"ingressType": null,
"istio": false,
"jwtSecretKey": "SECRET--50",
"kubernetesNamespace": "jhipsternamespace",
Expand Down
Loading

0 comments on commit e77576a

Please sign in to comment.