-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3466 from terascope/k8s-env-script
Create k8s-env command within ts-scripts to start a kubernetes dev environment
- Loading branch information
Showing
15 changed files
with
448 additions
and
63 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
kind: Cluster | ||
name: k8se2e | ||
apiVersion: kind.x-k8s.io/v1alpha4 | ||
nodes: | ||
- role: control-plane | ||
extraPortMappings: | ||
- containerPort: 30200 # Map internal elasticsearch service to host port | ||
hostPort: 9200 | ||
- containerPort: 30678 # Map internal teraslice service to host port | ||
hostPort: 5678 | ||
- containerPort: 30092 # Map internal kafka service to host port | ||
hostPort: 9092 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
kind: Cluster | ||
name: k8se2e | ||
apiVersion: kind.x-k8s.io/v1alpha4 | ||
nodes: | ||
- role: control-plane | ||
extraPortMappings: | ||
- containerPort: 30200 # Map internal elasticsearch service to host port | ||
hostPort: 49200 | ||
- containerPort: 30678 # Map internal teraslice service to host port | ||
hostPort: 45678 | ||
- containerPort: 30092 # Map internal kafka service to host port | ||
hostPort: 49092 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { CommandModule } from 'yargs'; | ||
import * as config from '../helpers/config'; | ||
import { launchK8sEnv } from '../helpers/k8s-env'; | ||
import { kafkaVersionMapper } from '../helpers/mapper'; | ||
|
||
const cmd: CommandModule = { | ||
command: 'k8s-env', | ||
describe: 'Run a local kubernetes dev environment using kind.', | ||
builder(yargs) { | ||
return yargs | ||
.example('TEST_ELASTICSEARCH=\'true\' ELASTICSEARCH_PORT=\'9200\' $0 k8s-env', 'Start a kind kubernetes cluster running teraslice and elasticsearch.') | ||
.example('TEST_ELASTICSEARCH=\'true\' ELASTICSEARCH_PORT=\'9200\' TEST_KAFKA=\'true\' KAFKA_PORT=\'9092\' $0 k8s-env', 'Start a kind kubernetes cluster running teraslice, elasticsearch, kafka, and zookeeper.') | ||
.example('TEST_ELASTICSEARCH=\'true\' ELASTICSEARCH_PORT=\'9200\' SKIP_DOCKER_BUILD_IN_K8S=\'true\' $0 k8s-env', 'Start a kind kubernetes cluster, but skip building a new teraslice docker image.') | ||
.option('elasticsearch-version', { | ||
description: 'The elasticsearch version to use', | ||
type: 'string', | ||
default: config.ELASTICSEARCH_VERSION, | ||
}) | ||
.option('kafka-version', { | ||
description: 'The kafka version to use', | ||
type: 'string', | ||
default: config.KAFKA_VERSION, | ||
}) | ||
.option('minio-version', { | ||
description: 'The minio version to use', | ||
type: 'string', | ||
default: config.MINIO_VERSION, | ||
}) | ||
.option('rabbitmq-version', { | ||
description: 'The rabbitmq version to use', | ||
type: 'string', | ||
default: config.RABBITMQ_VERSION, | ||
}) | ||
.option('opensearch-version', { | ||
description: 'The opensearch version to use', | ||
type: 'string', | ||
default: config.OPENSEARCH_VERSION, | ||
}) | ||
.option('node-version', { | ||
description: 'Node version, there must be a Docker base image with this version (e.g. 18.16.0)', | ||
type: 'string', | ||
default: config.NODE_VERSION | ||
}) | ||
.option('skip-build', { | ||
description: 'Skip building the teraslice docker iamge', | ||
type: 'boolean', | ||
default: config.SKIP_DOCKER_BUILD_IN_K8S | ||
}); | ||
}, | ||
handler(argv) { | ||
const kafkaCPVersion = kafkaVersionMapper(argv.kafkaVersion as string); | ||
|
||
return launchK8sEnv({ | ||
elasticsearchVersion: argv.elasticsearchVersion as string, | ||
kafkaVersion: argv.kafkaVersion as string, | ||
kafkaImageVersion: kafkaCPVersion, | ||
zookeeperVersion: kafkaCPVersion, | ||
minioVersion: argv.minioVersion as string, | ||
rabbitmqVersion: argv.rabbitmqVersion as string, | ||
opensearchVersion: argv.opensearchVersion as string, | ||
nodeVersion: argv['node-version'] as string, | ||
skipBuild: Boolean(argv['skip-build']) | ||
}); | ||
}, | ||
}; | ||
|
||
export = cmd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// import { debugLogger } from '@terascope/utils'; | ||
import { | ||
createKindCluster, | ||
createNamespace, | ||
deployK8sTeraslice, | ||
dockerTag, | ||
isKindInstalled, | ||
isKubectlInstalled, | ||
loadTerasliceImage | ||
} from '../scripts'; | ||
import { k8sEnvOptions } from './interfaces'; | ||
import signale from '../signale'; | ||
import { getDevDockerImage, getRootInfo } from '../misc'; | ||
import { buildDevDockerImage } from '../publish/utils'; | ||
import { PublishOptions, PublishType } from '../publish/interfaces'; | ||
import * as config from '../config'; | ||
import { ensureServices } from '../test-runner/services'; | ||
|
||
// const logger = debugLogger('ts-scripts:cmd:k8s-env'); | ||
|
||
export async function launchK8sEnv(options: k8sEnvOptions) { | ||
signale.pending('Starting k8s environment with the following options: ', options); | ||
|
||
const kindInstalled = await isKindInstalled(); | ||
if (!kindInstalled) { | ||
signale.error('Please install Kind before launching a k8s dev environment. https://kind.sigs.k8s.io/docs/user/quick-start'); | ||
process.exit(1); | ||
} | ||
|
||
const kubectlInstalled = await isKubectlInstalled(); | ||
if (!kubectlInstalled) { | ||
signale.error('Please install kubectl before launching a k8s dev environment. https://kubernetes.io/docs/tasks/tools/'); | ||
process.exit(1); | ||
} | ||
|
||
signale.pending('Creating kind cluster'); | ||
await createKindCluster('k8s-env'); | ||
signale.success('Kind cluster created'); | ||
await createNamespace('services-ns.yaml'); | ||
|
||
const rootInfo = getRootInfo(); | ||
const e2eImage = `${rootInfo.name}:e2e`; | ||
|
||
let devImage; | ||
if (options.skipBuild) { | ||
devImage = `${getDevDockerImage()}-nodev${options.nodeVersion}`; | ||
} else { | ||
try { | ||
const publishOptions: PublishOptions = { | ||
dryRun: true, | ||
nodeVersion: options.nodeVersion, | ||
type: PublishType.Dev | ||
}; | ||
devImage = await buildDevDockerImage(publishOptions); | ||
} catch (err) { | ||
signale.error('Docker image build failed: ', err); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
try { | ||
await dockerTag(devImage, e2eImage); | ||
} catch (err) { | ||
signale.error(`Failed to tag docker image ${devImage} as ${e2eImage}.`, err); | ||
} | ||
|
||
await loadTerasliceImage(e2eImage); | ||
|
||
await ensureServices('k8s_env', { | ||
...options, | ||
debug: false, | ||
trace: false, | ||
bail: false, | ||
watch: false, | ||
all: false, | ||
keepOpen: false, | ||
reportCoverage: false, | ||
useExistingServices: false, | ||
elasticsearchAPIVersion: config.ELASTICSEARCH_API_VERSION, | ||
ignoreMount: false, | ||
testPlatform: 'kubernetes' | ||
}); | ||
|
||
await deployK8sTeraslice(true); | ||
signale.success('k8s environment ready.\nNext steps:\n\tAdd alias: teraslice-cli aliases add <cluster-alias> http://localhost:5678\n\t\tExample: teraslice-cli aliases add cluster1 http://localhost:5678\n\tLoad assets: teraslice-cli assets deploy <cluster-alias> <user/repo-name>\n\t\tExample: teraslice-cli assets deploy cluster1 terascope/elasticsearch-assets\n\tRegister a job: teraslice-cli tjm register <cluster-alias> <path/to/job/file.json>\n\t\tExample: teraslice-cli tjm reg cluster1 JOB.JSON\n\tStart a job: teraslice-cli tjm start <path/to/job/file.json>\n\t\tExample: teraslice-cli tjm start JOB.JSON\n\tSee the docs for more options: https://terascope.github.io/teraslice/docs/packages/teraslice-cli/overview'); | ||
} |
Oops, something went wrong.