Skip to content

Commit

Permalink
Merge pull request #180 from Backendless/stage
Browse files Browse the repository at this point in the history
Stage -> master
  • Loading branch information
ksv510 authored Nov 13, 2024
2 parents 98f5854 + 660b4e5 commit ba6d4c3
Show file tree
Hide file tree
Showing 15 changed files with 318 additions and 19 deletions.
11 changes: 11 additions & 0 deletions src/services/bl-containers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { createClusterRoleAndServiceAccount } from './install/create-cluster-rol
import { IngressHazelcastClusterRole } from './k8s/config/roles/ingress-hazelcast-cluster-role'
import { removeClusterRoleAndServiceAccount } from './install/remove-cluster-role-and-service-account'
import { installAutomation } from './install/bl/install-bl-automation'
import { installNodeServer } from './install/bl/install-bl-node-server'

class BlContainers {
bl = {
Expand Down Expand Up @@ -96,6 +97,16 @@ class BlContainers {
restart: () => deploymentRestart('bl-automation'),
skipInstall: true
},
nodeServer: {
name: 'bl-node-server',
imageName: 'bl-node-server',
serviceStatus: () => blDeploymentStatus('bl-node-server'),
installService: installArguments => installNodeServer(installArguments),
deleteService: () => deleteDeploymentAndService('bl-node-server'),
scale: replicas => deploymentScale('bl-node-server', replicas),
restart: () => deploymentRestart('bl-node-server'),
skipInstall: false
},
initConfigValues: {
name: 'bl-init-config-values',
serviceStatus: () => blJobStatus('bl-init-config-values'),
Expand Down
1 change: 1 addition & 0 deletions src/services/install/bl/install-bl-automation.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export async function installAutomation({

logger.info(`turn on automation in consul`)
await consul.put('config/automation/api/enabled', true)
await consul.put('config/console/featureToggle/automations', 1)

return {
createStatefulSetResult,
Expand Down
60 changes: 60 additions & 0 deletions src/services/install/bl/install-bl-node-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { k8sAppsV1Api, k8sCoreV1Api } from '../../k8s/k8s'
import { installStatus } from '../install-status'
import { Logger } from '../../../logger'
import { getMountPathFromDeployment } from '../../get-mount-path'
import { NodeServerConfig } from '../../k8s/config/node-server-config'
import { consul } from '../../consul'
import { k8sConfig } from '../../../config/k8s-config'

const logger = Logger('install-bl-node-server')

export async function installNodeServer({
mountPath,
version
}) {
if (!mountPath) {
logger.info('mountPath is not provided, will get from bl-server')
const repoMountPath = await getMountPathFromDeployment({
workloadName: 'bl-server',
volumeName: 'repo'
})
logger.info(`repo path for bl-server is [${repoMountPath}]`)
mountPath = repoMountPath.replace('/repo', '')
logger.info(`mount path will be [${mountPath}]`)

}

const nodeServerConfig = new NodeServerConfig()
installStatus.info('installing bl-node-server...')
const workload = nodeServerConfig.workload
workload.spec.template.spec.containers[0].image = `backendless/bl-node-server:${version}`
workload.spec.template.spec.volumes.push({
hostPath: {
path: `${mountPath}/repo`,
type: 'DirectoryOrCreate'
},
name: 'repo'
})

workload.spec.template.spec.volumes.push({
hostPath: {
path: `${mountPath}/logs/bl-node-server/`,
type: 'DirectoryOrCreate'
},
name: 'logs'
})

installStatus.info('creating deployment for bl-node-server')
logger.verbose(`creating workload for bl-node-server with config: ${JSON.stringify(workload)}`)
const createStatefulSetResult = await k8sAppsV1Api.createNamespacedDeployment(await k8sConfig.getNamespace(), workload)
installStatus.info('creating service for bl-node-server')
const createServiceResult = await k8sCoreV1Api.createNamespacedService(await k8sConfig.getNamespace(), nodeServerConfig.service)

logger.info(`add config to consul`)
await consul.put('config/nodeServer/internalAddress', 'http://bl-node-server:4000')

return {
createStatefulSetResult,
createServiceResult
}
}
19 changes: 16 additions & 3 deletions src/services/k8s/config/ingress/ingress-api-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export class IngressApiConfig {
'nginx.ingress.kubernetes.io/proxy-body-size': '10000m',
'nginx.ingress.kubernetes.io/proxy-read-timeout': '600',
'nginx.ingress.kubernetes.io/proxy-send-timeout': '600',
'nginx.ingress.kubernetes.io/proxy-connect-timeout': '600'
'nginx.ingress.kubernetes.io/proxy-connect-timeout': '600',
'nginx.ingress.kubernetes.io/use-regex': 'true'
}
},
'spec': {
Expand Down Expand Up @@ -41,14 +42,26 @@ export class IngressApiConfig {
}
}
},
{
'path': '/integration/oauth/callback',
'pathType': 'Prefix',
'backend': {
'service': {
'name': 'bl-node-server',
'port': {
'number': 4000
}
}
}
},
{
'path': '/.*/.*/automation/',
'pathType': 'Prefix',
'backend': {
'service': {
'name': 'bl-server',
'name': 'bl-automation',
'port': {
'number': 9000
'number': 9095
}
}
}
Expand Down
173 changes: 173 additions & 0 deletions src/services/k8s/config/node-server-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
export class NodeServerConfig {
workload = {
'apiVersion': 'apps/v1',
'kind': 'Deployment',
'metadata': {
'annotations': {
'name': 'bl-node-server'
},
'name': 'bl-node-server'
},
'spec': {
'progressDeadlineSeconds': 60,
'replicas': 1,
'selector': {
'matchLabels': {
'app': 'bl-node-server'
}
},
'strategy': {
'rollingUpdate': {
'maxSurge': 1,
'maxUnavailable': 0
},
'type': 'RollingUpdate'
},
'template': {
'metadata': {
'labels': {
'app': 'bl-node-server'
}
},
'spec': {
'containers': [
{
'args': [
'play'
],
'env': [
{
'name': 'BL_CONSUL_PORT',
'valueFrom': {
'configMapKeyRef': {
'key': 'BL_CONSUL_PORT',
'name': 'bl-env',
'optional': false
}
}
},
{
'name': 'BL_HOST_IP',
'valueFrom': {
'fieldRef': {
'fieldPath': 'status.hostIP'
}
}
},
{
'name': 'BL_CONSUL_HOST',
'valueFrom': {
'configMapKeyRef': {
'key': 'BL_CONSUL_HOST',
'name': 'bl-env',
'optional': false
}
}
},
{
'name': 'BL_CONFIG_PROVIDER',
'valueFrom': {
'configMapKeyRef': {
'key': 'BL_CONFIG_PROVIDER',
'name': 'bl-env',
'optional': false
}
}
},
{
'name': 'BL_CONTAINER_IP',
'valueFrom': {
'fieldRef': {
'apiVersion': 'v1',
'fieldPath': 'status.podIP'
}
}
}
],
'image': 'backendless/bl-node-server',
'imagePullPolicy': 'IfNotPresent',
'name': 'bl-node-server',
'startupProbe': {
'failureThreshold': 80,
'periodSeconds': 10,
'httpGet': {
'path': '/health',
'port': 4000,
'scheme': 'HTTP'
}
},
'livenessProbe': {
'failureThreshold': 6,
'httpGet': {
'path': '/health',
'port': 4000,
'scheme': 'HTTP'
},
'initialDelaySeconds': 60,
'periodSeconds': 2,
'successThreshold': 1,
'timeoutSeconds': 10
},
'readinessProbe': {
'failureThreshold': 60,
'httpGet': {
'path': '/health',
'port': 4000,
'scheme': 'HTTP'
},
'initialDelaySeconds': 10,
'periodSeconds': 1,
'successThreshold': 2,
'timeoutSeconds': 1
},
'ports': [
{
'containerPort': 4000,
'name': 'bl-node-server',
'protocol': 'TCP'
}
],
'volumeMounts': [
{
'mountPath': '/opt/backendless/repo',
'name': 'repo'
},
{
'mountPath': '/opt/backendless/logs',
'name': 'logs'
}
]
}
],
'restartPolicy': 'Always',
'volumes': [

]
}
}
}
}
service = {
'apiVersion': 'v1',
'kind': 'Service',
'metadata': {
'name': 'bl-node-server',
'labels': {
'app': 'bl-node-server'
}
},
'spec': {
'type': 'ClusterIP',
'ports': [
{
'port': 4000,
'targetPort': 4000,
'name': 'bl-node-server',
}
],
'selector': {
'app': 'bl-node-server'
}
}
}
}
8 changes: 4 additions & 4 deletions src/services/manage/configuration/domain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { manageService } from '../../manage-service'
import { blContainers } from '../../../bl-containers'
import { getValueByDescription } from '../get-value-by-description'
import { ApiError } from '../../../../error'
import { restartServicesForDomainConfiguration } from './restart-services-for-domain-configuration'
import { publicHostChanged } from './public-host-changed'

const logger = Logger('domain-connection-configuration-service')

Expand Down Expand Up @@ -51,16 +53,14 @@ class DomainConfigurationService {
}

await this._saveToConsul(description, domains[section])
await publicHostChanged({ type: section })
}
}

async saveConfigAndRestart({ config, shouldRestart }){
await this.saveAll(config)
if( shouldRestart === true ) {
await manageService.restartService('bl-server')
await manageService.restartService('bl-web-console')
await manageService.restartService('bl-taskman')
await manageService.restartService('bl-rt-server')
await restartServicesForDomainConfiguration()
}
}

Expand Down
19 changes: 19 additions & 0 deletions src/services/manage/configuration/domain/public-host-changed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { consul } from '../../../consul'
import { Logger } from '../../../../logger'

const logger = Logger('ingress-load-balancer')

export async function publicHostChanged({ type }) {
logger.info(`public host changed for ${type}`)
if (type === 'api') {
const host = await consul.get('config/server/publicHost')
const port = await consul.get('config/server/publicPort')
const protocol = await consul.get('config/server/publicProtocol')

const portSubstitution = port === '80' || port === 443 ? '' : ':' + port

const oauthRedirectURL = `${protocol}://${host}${portSubstitution}/integration/oauth/callback`
logger.info(`changing redirect url for integrations to ${oauthRedirectURL}`)
await consul.put('config/integration/redirectURI', oauthRedirectURL)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { manageService } from '../../manage-service'
import { Logger } from '../../../../logger'

const logger = Logger('restart-services-for-domain-configuration')

export async function restartServicesForDomainConfiguration() {
logger.info('restarting services for-domain configuration')
await manageService.restartService('bl-server')
await manageService.restartService('bl-web-console')
await manageService.restartService('bl-taskman')
await manageService.restartService('bl-rt-server')
await manageService.restartService('bl-node-server')
await manageService.restartService('bl-automation')
}
Loading

0 comments on commit ba6d4c3

Please sign in to comment.