Skip to content

Commit

Permalink
BKNDLSS-32460 Change statefulset to deployment (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksv510 authored May 16, 2023
1 parent 1564284 commit 766bb20
Show file tree
Hide file tree
Showing 26 changed files with 183 additions and 75 deletions.
3 changes: 2 additions & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"UpgradeService": "verbose",
"install-bl-rt-server": "verbose",
"install-bl-server": "verbose",
"service-log": "verbose"
"service-log": "verbose",
"k8s-scale": "debug"
}
},
"user": {
Expand Down
84 changes: 63 additions & 21 deletions src/services/bl-containers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { blStatefulsetStatus } from './k8s/bl-statefulset-status'
import { deleteService } from './k8s/k8s-delete-service'
import { blDeploymentStatus, blStatefulsetStatus } from './k8s/bl-status'
import { deleteDeploymentAndService, deleteStatefulsetAndService } from './k8s/k8s-delete-service'
import { blJobStatus } from './k8s/bl-job-status'
import { installConsul } from './install/db/install-consul'
import { installMysql } from './install/db/mysql'
Expand All @@ -14,57 +14,73 @@ import { installBlJsCoderunner } from './install/bl/install-bl-js-coderunner'
import { installBlWebConsole } from './install/bl/install-bl-web-console'
import { installBlRtServer } from './install/bl/install-bl-rt-server'
import { deleteJob } from './k8s/k8s-delete-job'
import { deploymentScale, statefulsetScale } from './k8s/k8s-scale'
import { deploymentRestart, statefulsetRestart } from './k8s/k8s-restart'

class BlContainers {
bl = {
server: {
name: 'bl-server',
imageName: 'bl-server',
serviceStatus: () => blStatefulsetStatus('bl-server'),
serviceStatus: () => blDeploymentStatus('bl-server'),
installService: installArguments => installBlServer(installArguments),
deleteService: () => deleteService('bl-server')
deleteService: () => deleteDeploymentAndService('bl-server'),
scale: replicas => deploymentScale('bl-server', replicas),
restart: () => deploymentRestart('bl-server')
},
rtServer: {
name: 'bl-rt-server',
imageName: 'bl-rt-server',
serviceStatus: () => blStatefulsetStatus('bl-rt-server'),
serviceStatus: () => blDeploymentStatus('bl-rt-server'),
installService: installArguments => installBlRtServer(installArguments),
deleteService: () => deleteService('bl-rt-server')
deleteService: () => deleteDeploymentAndService('bl-rt-server'),
scale: replicas => deploymentScale('bl-rt-server', replicas),
restart: () => deploymentRestart('bl-rt-server')
},
taskman: {
name: 'bl-taskman',
imageName: 'bl-server',
serviceStatus: () => blStatefulsetStatus('bl-taskman'),
serviceStatus: () => blDeploymentStatus('bl-taskman'),
installService: installArguments => installBlTaskman(installArguments),
deleteService: () => deleteService('bl-taskman')
deleteService: () => deleteDeploymentAndService('bl-taskman'),
scale: replicas => deploymentScale('bl-taskman', replicas),
restart: () => deploymentRestart('bl-taskman')
},
hazelcast: {
name: 'bl-hazelcast-3125',
imageName: 'bl-hazelcast',
serviceStatus: () => blStatefulsetStatus('bl-hazelcast-3125'),
serviceStatus: () => blDeploymentStatus('bl-hazelcast-3125'),
installService: installArguments => installBlHazelcast(installArguments),
deleteService: () => deleteService('bl-hazelcast-3125')
deleteService: () => deleteDeploymentAndService('bl-hazelcast-3125'),
scale: replicas => deploymentScale('bl-hazelcast-3125', replicas),
restart: () => deploymentRestart('bl-hazelcast-3125')
},
javaCoderunner: {
name: 'bl-coderunner-java',
imageName: 'bl-coderunner-java',
serviceStatus: () => blStatefulsetStatus('bl-coderunner-java'),
serviceStatus: () => blDeploymentStatus('bl-coderunner-java'),
installService: installArguments => installBlJavaCoderunner(installArguments),
deleteService: () => deleteService('bl-coderunner-java')
deleteService: () => deleteDeploymentAndService('bl-coderunner-java'),
scale: replicas => deploymentScale('bl-coderunner-java', replicas),
restart: () => deploymentRestart('bl-coderunner-java')
},
jsCoderunner: {
name: 'bl-coderunner-js',
imageName: 'bl-coderunner-js',
serviceStatus: () => blStatefulsetStatus('bl-coderunner-js'),
serviceStatus: () => blDeploymentStatus('bl-coderunner-js'),
installService: installArguments => installBlJsCoderunner(installArguments),
deleteService: () => deleteService('bl-coderunner-js')
deleteService: () => deleteDeploymentAndService('bl-coderunner-js'),
scale: replicas => deploymentScale('bl-coderunner-js', replicas),
restart: () => deploymentRestart('bl-coderunner-js')
},
console: {
name: 'bl-web-console',
imageName: 'bl-web-console',
serviceStatus: () => blStatefulsetStatus('bl-web-console'),
serviceStatus: () => blDeploymentStatus('bl-web-console'),
installService: installArguments => installBlWebConsole(installArguments),
deleteService: () => deleteService('bl-web-console')
deleteService: () => deleteDeploymentAndService('bl-web-console'),
scale: replicas => deploymentScale('bl-web-console', replicas),
restart: () => deploymentRestart('bl-web-console')
},
initConfigValues: {
name: 'bl-init-config-values',
Expand All @@ -79,15 +95,19 @@ class BlContainers {
name: 'bl-consul',
serviceStatus: () => blStatefulsetStatus('bl-consul'),
installService: installArguments => installConsul(installArguments),
scale: replicas => statefulsetScale('bl-consul', replicas),
restart: () => statefulsetRestart('bl-consul'),
order: 0,
deleteService: () => deleteService('bl-consul')
deleteService: () => deleteStatefulsetAndService('bl-consul')
},
mysql: {
name: 'bl-mysql',
serviceStatus: () => blStatefulsetStatus('bl-mysql'),
installService: installArguments => installMysql(installArguments),
scale: replicas => statefulsetScale('bl-mysql', replicas),
restart: () => statefulsetRestart('bl-mysql'),
order: 1,
deleteService: () => deleteService('bl-mysql')
deleteService: () => deleteStatefulsetAndService('bl-mysql')
},
redis: {
name: 'bl-redis',
Expand All @@ -98,8 +118,10 @@ class BlContainers {
externalPort: 32379,
name: 'bl-redis'
}),
scale: replicas => statefulsetScale('bl-redis', replicas),
restart: () => statefulsetRestart('bl-redis'),
order: 2,
deleteService: () => deleteService('bl-redis')
deleteService: () => deleteStatefulsetAndService('bl-redis')
},
debugRedis: {
name: 'bl-redis-debug',
Expand All @@ -110,15 +132,19 @@ class BlContainers {
externalPort: 32380,
name: 'bl-redis-debug'
}),
scale: replicas => statefulsetScale('bl-redis-debug', replicas),
restart: () => statefulsetRestart('bl-redis-debug'),
order: 3,
deleteService: () => deleteService('bl-redis-debug')
deleteService: () => deleteStatefulsetAndService('bl-redis-debug')
},
mongo: {
name: 'bl-mongo',
serviceStatus: () => blStatefulsetStatus('bl-mongo'),
installService: installArguments => installMongo(installArguments),
scale: replicas => statefulsetScale('bl-mongo', replicas),
restart: () => statefulsetRestart('bl-mongo'),
order: 4,
deleteService: () => deleteService('bl-mongo')
deleteService: () => deleteStatefulsetAndService('bl-mongo')
},

}
Expand All @@ -128,6 +154,22 @@ class BlContainers {
.sort(([key1, dependency1], [key2, dependency2]) => dependency1.order - dependency2.order)
.map(([key, dependency]) => dependency)
}

findByName(name) {
for (const containerKey in this.bl) {
const container = this.bl[containerKey]
if (container.name === name) {
return container
}
}

for (const containerKey in this.dependencies) {
const container = this.dependencies[containerKey]
if (container.name === name) {
return container
}
}
}
}

export const blContainers = new BlContainers()
4 changes: 2 additions & 2 deletions src/services/install/bl/install-bl-hazelcast.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export async function installBlHazelcast({ version }) {
workload.spec.template.spec.containers[0].image = `backendless/bl-hazelcast:${version}`


installStatus.info('creating statefulset for bl-hazelcast')
const createStatefulSetResult = await k8sAppsV1Api.createNamespacedStatefulSet(await k8sConfig.getNamespace(), workload)
installStatus.info('creating deployment for bl-hazelcast')
const createStatefulSetResult = await k8sAppsV1Api.createNamespacedDeployment(await k8sConfig.getNamespace(), workload)
installStatus.info('creating service for bl-hazelcast')
const createServiceResult = await k8sCoreV1Api.createNamespacedService(await k8sConfig.getNamespace(), blK8sConfig.service)

Expand Down
4 changes: 2 additions & 2 deletions src/services/install/bl/install-bl-java-coderunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export async function installBlJavaCoderunner({ mountPath, version }) {
name: 'logs'
})

installStatus.info('creating statefulset for bl-coderunner-java')
return await k8sAppsV1Api.createNamespacedStatefulSet(await k8sConfig.getNamespace(), workload)
installStatus.info('creating deployment for bl-coderunner-java')
return await k8sAppsV1Api.createNamespacedDeployment(await k8sConfig.getNamespace(), workload)
}
4 changes: 2 additions & 2 deletions src/services/install/bl/install-bl-js-coderunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export async function installBlJsCoderunner({ mountPath, version }) {
name: 'logs'
})

installStatus.info('creating statefulset for bl-coderunner-js')
return await k8sAppsV1Api.createNamespacedStatefulSet(await k8sConfig.getNamespace(), workload)
installStatus.info('creating deployment for bl-coderunner-js')
return await k8sAppsV1Api.createNamespacedDeployment(await k8sConfig.getNamespace(), workload)
}
4 changes: 2 additions & 2 deletions src/services/install/bl/install-bl-rt-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export async function installBlRtServer({ mountPath, version }) {
name: 'logs'
})

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

Expand Down
4 changes: 2 additions & 2 deletions src/services/install/bl/install-bl-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export async function installBlServer({ mountPath, version }) {
name: 'logs'
})

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

Expand Down
4 changes: 2 additions & 2 deletions src/services/install/bl/install-bl-taskman.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export async function installBlTaskman({ mountPath, version }) {
name: 'logs'
})

installStatus.info('creating statefulset for bl-taskman')
const createStatefulSetResult = await k8sAppsV1Api.createNamespacedStatefulSet(await k8sConfig.getNamespace(), workload)
installStatus.info('creating deployment for bl-taskman')
const createStatefulSetResult = await k8sAppsV1Api.createNamespacedDeployment(await k8sConfig.getNamespace(), workload)
installStatus.info('creating service for bl-taskman')
const createServiceResult = await k8sCoreV1Api.createNamespacedService(await k8sConfig.getNamespace(), blK8sConfig.service)

Expand Down
4 changes: 2 additions & 2 deletions src/services/install/bl/install-bl-web-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export async function installBlWebConsole({ mountPath, version }) {
name: 'logs'
})

installStatus.info('creating statefulset for bl-web-console')
const createStatefulSetResult = await k8sAppsV1Api.createNamespacedStatefulSet(await k8sConfig.getNamespace(), workload)
installStatus.info('creating deployment for bl-web-console')
const createStatefulSetResult = await k8sAppsV1Api.createNamespacedDeployment(await k8sConfig.getNamespace(), workload)
installStatus.info('creating service for bl-web-console')
const createServiceResult = await k8sCoreV1Api.createNamespacedService(await k8sConfig.getNamespace(), blK8sConfig.service)

Expand Down
5 changes: 3 additions & 2 deletions src/services/install/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { initConfigMap } from './init-config-map'
import { Logger } from '../../logger'
import { isWin } from '../../utils/os'
import * as fs from 'fs'
import { deleteService } from '../k8s/k8s-delete-service'
import { deleteStatefulsetAndService } from '../k8s/k8s-delete-service'
import { ApiError } from '../../error'
import { mountPathConfig } from '../../config/mount-path-config'
import { registerFirstUser } from './register-first-user'
Expand Down Expand Up @@ -168,7 +168,8 @@ class InstallService {
}

async deleteService(serviceName) {
return deleteService(serviceName)
const container = blContainers.findByName( serviceName )
return container.deleteService()
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import { Logger } from '../../logger'
import { statefulsetStatus } from './k8s-statefulset-status'
import { deploymentStatus, statefulsetStatus } from './k8s-status'
import { getVersionFromStatus } from './bl-get-version'

const Status = require('../service-status.json')
const logger = Logger('bl-statefulset-status')
const logger = Logger('bl-status')

export async function blStatefulsetStatus(containerName) {
return blStatus(containerName, () => statefulsetStatus(containerName, true))
}

export async function blDeploymentStatus(containerName) {
return blStatus(containerName, () => deploymentStatus(containerName, true))
}

async function blStatus(containerName, getK8sStatus) {
const blStatus = { name: containerName }
let status
try {
status = await statefulsetStatus(containerName, true)
status = await getK8sStatus()
} catch (err) {
if (err.statusCode === 404) {
blStatus.status = Status.notInstalled
Expand All @@ -25,7 +33,7 @@ export async function blStatefulsetStatus(containerName) {

logger.verbose(`service status for '${containerName}' is ${JSON.stringify(serviceStatus)}`)

if (serviceStatus.replicas < 1)
if (!serviceStatus.replicas)
blStatus.status = Status.stopped
else if (serviceStatus.readyReplicas !== serviceStatus.replicas || serviceStatus.updatedReplicas !== serviceStatus.readyReplicas)
blStatus.status = Status.changing
Expand Down
2 changes: 1 addition & 1 deletion src/services/k8s/config/console.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"workload": {
"apiVersion": "apps/v1",
"kind": "StatefulSet",
"kind": "Deployment",
"metadata": {
"name": "bl-web-console"
},
Expand Down
2 changes: 1 addition & 1 deletion src/services/k8s/config/hazelcast.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"workload": {
"apiVersion": "apps/v1",
"kind": "StatefulSet",
"kind": "Deployment",
"metadata": {
"name": "bl-hazelcast-3125"
},
Expand Down
2 changes: 1 addition & 1 deletion src/services/k8s/config/java-coderunner.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"workload": {
"apiVersion": "apps/v1",
"kind": "StatefulSet",
"kind": "Deployment",
"metadata": {
"annotations": {
"name": "bl-coderunner-java"
Expand Down
2 changes: 1 addition & 1 deletion src/services/k8s/config/js-coderunner.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"workload": {
"apiVersion": "apps/v1",
"kind": "StatefulSet",
"kind": "Deployment",
"metadata": {
"annotations": {
"name": "bl-coderunner-js"
Expand Down
2 changes: 1 addition & 1 deletion src/services/k8s/config/rt-server.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"workload": {
"apiVersion": "apps/v1",
"kind": "StatefulSet",
"kind": "Deployment",
"metadata": {
"annotations": {
"name": "bl-rt-server"
Expand Down
2 changes: 1 addition & 1 deletion src/services/k8s/config/server.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"workload": {
"apiVersion": "apps/v1",
"kind": "StatefulSet",
"kind": "Deployment",
"metadata": {
"annotations": {
"name": "bl-server"
Expand Down
2 changes: 1 addition & 1 deletion src/services/k8s/config/taskman.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"workload": {
"apiVersion": "apps/v1",
"kind": "StatefulSet",
"kind": "Deployment",
"metadata": {
"annotations": {
"name": "bl-taskman"
Expand Down
Loading

0 comments on commit 766bb20

Please sign in to comment.