Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Added export command. Refactor code for parse command. Minor fixes an…
Browse files Browse the repository at this point in the history
…d improvements
  • Loading branch information
rawmind0 authored and Alena Prokharchyk committed Oct 19, 2018
1 parent bb05ebc commit 3b8bd4c
Show file tree
Hide file tree
Showing 230 changed files with 31,128 additions and 301 deletions.
96 changes: 76 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,91 @@ migration-tools
========

This tool is to help migration efforts of apps running on Rancher 1.6 to Rancher 2.0.
This tool will:
- Accept the Rancher 1.6 Docker Compose config files [docker-compose.yml and rancher-compose.yml]
- Output a list of constructs present in the config file that cannot be supported onto Rancher 2.0 without special handling or that cannot be converted to Kubernetes YAML using tools like Kompose.

This should help users to run a quick check to see if their application running on Rancher 1.6 can be migrated to 2.0 and what is lacking to do the migration.

**Usage**:

```migration-tools --docker-file <path to docker-compose.yml> --rancher-file <path to rancher-compose.yml if available>```

**Options**:

- `--docker-file value` An absolute path to an alternate Docker compose file (default: "docker-compose.yml")
- `--rancher-file value` An absolute path to an alternate Rancher compose file (default: "rancher-compose.yml")
- `--help, -h` show help
- `--version, -v` print the version
This tool will:
- Export docker compose config files [docker-compose.yml and rancher-compose.yml] for every stack running on cattle environments on existing Rancher v1.6 system.
- Parse docker compose config files and output a list of constructs present in the config file that cannot be supported onto Rancher 2.0 without special handling or that cannot be converted to Kubernetes YAML using [Kompose tool](https://github.com/kubernetes/kompose) tool.

This should help users to export all docker compose config files, parse them and run a quick check to see if their application running on Rancher 1.6 can be migrated to 2.0 and what is lacking to do the migration.

**Usage**

```
# migration-tools -h
NAME:
Rancher 1.6 to Rancher 2.0 migration-helper - Please check the options using --help flag
USAGE:
migration-tools [global options] command [command options] [arguments...]
VERSION:
git
AUTHOR:
Rancher Labs, Inc.
COMMANDS:
export Export compose files for every stack running on cattle environment on a Rancher v1.6 system
parse Parse docker-compose and rancher-compose files to get k8s manifests
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--debug debug logging
--log value path to log to
--help, -h show help
--version, -v print the version
```

```
# migration-tools export -h
NAME:
migration-tools export - Export compose files for every stack running on cattle environment on a Rancher v1.6 system
USAGE:
migration-tools export [command options] [arguments...]
OPTIONS:
--url value Rancher API endpoint URL [$RANCHER_URL]
--access-key value Rancher API access key. Using admin API key will export stacks on all cattle environments [$RANCHER_ACCESS_KEY]
--secret-key value Rancher API secret key [$RANCHER_SECRET_KEY]
--export-dir value Base directory under which compose files will be exported under sub-directories created for every env/stack (default: "export")
--all, -a Export all stacks. Using this flag stacks with inactive, stopped and removing state, will also be exported
--system, -s Export system and infrastructure stacks
```

```
# migration-tools parse -h
NAME:
migration-tools parse - Parse docker-compose and rancher-compose files to get k8s manifests
USAGE:
migration-tools parse [command options] [arguments...]
OPTIONS:
--docker-file value Docker compose file to parse to get k8s manifest (default: "docker-compose.yml")
--output-file value Output file where to write checks and advices for conversion (default: "output.txt")
--rancher-file value Rancher compose file to parse to get k8s manifest (default: "rancher-compose.yml")
```

**Output**

- output.txt
This tool will generate `output.txt` file to list all constructs for each service in your docker-compose.yml file that will need to be handled specially to sucessfully migrate them to Rancher 2.0.
- Kubernetes YAML specs
This tool also invokes the [Kompose tool](https://github.com/kubernetes/kompose) that generates some Kubernetes YAML specs for the services to get started with migration.
* export
- compose files
This command will connect to Rancher 1.6 system and generate docker-compose and rancher-compose files for every stack running on cattle environment. For every stack, files are exported in `<export-dir>/<env_name>/<stack_name>` folder.
* parse
- output.txt
This command will generate `output.txt` file to list all constructs for each service in your docker-compose.yml file that will need to be handled specially to sucessfully migrate them to Rancher 2.0.
- Kubernetes YAML specs
This command also invokes the [Kompose tool](https://github.com/kubernetes/kompose) that generates some Kubernetes YAML specs for the services to get started with migration.


## Building

`make`
* Linux: Binary generated under `bin/`
`make`

* Linux, darwin and windows: Binaries generated under `build/bin/`
`CROSS=1 make build`.

## Running

Expand Down
146 changes: 146 additions & 0 deletions cmd/doctemplate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package cmd

const (
documentedConstructs = `
Certs:
name: certs
CgroupParent:
name: cgroup_parent
DefaultCert:
name: default_cert
DNS:
name: dns
DNSOpt:
name: dns_opt
DNSSearch:
name: dns_search
DeviceReadBps:
name: device_read_bps
DeviceReadIOps:
name: device_read_iops
Devices:
name: devices
DeviceWriteBps:
name: device_write_bps
DeviceWriteIOps:
name: device_write_iops
DependsOn:
name: depends_on
DrainTimeoutMs:
name: drain_timeout_ms
Expose:
name: expose
doclink: https://rancher.com/blog/2018/2018-08-14-expose-and-monitor-workloads/
helptext: Please add a hostPort or a nodePort to your Kubernetes workload to expose the ports used.
ExternalIps:
name: external_ips
ExternalLinks:
name: external_links
doclink: https://rancher.com/blog/2018/2018-09-04-service_discovery_2dot0/
helptext: Please add the necessary Service Discovery Records for your Rancher 2.0 Kubernetes workload to implement the links.
HealthCheck:
name: health_check
doclink: https://rancher.com/blog/2018/2018-08-22-k8s-monitoring-and-healthchecks/
helptext:
Isolation:
name: isolation
Labels:
name: labels
special: true
doclink:
helptext:
LbConfig:
name: lb_config
doclink: https://rancher.com/blog/2018/2018-09-13-load-balancing-options-2dot0/
helptext: Please refer to load balancer documentation on Rancher 2.0 for alternatives available.
Links:
name: links
doclink: https://rancher.com/blog/2018/2018-09-04-service_discovery_2dot0/
helptext: Please add the necessary Service Discovery Records for your Rancher 2.0 Kubernetes workload to implement the links.
LegacyLoadBalancerConfig:
name: load_balancer_config
NetworkMode:
name: network_mode
Networks:
name: networks
NetworkDriver:
name: network_driver
Ports:
name: ports
doclink: https://rancher.com/blog/2018/2018-08-14-expose-and-monitor-workloads/
helptext: Please add a hostPort or a nodePort to your Kubernetes workload to expose the ports used.
RetainIP:
name: retain_ip
Scale:
name: scale
ScalePolicy:
name: scale_policy
ServiceSchemas:
name: service_schemas
StorageDriver:
name: storage_driver
Secrets:
name: secrets
SecurityOpt:
name: security_opt
StartOnCreate:
name: start_on_create
StopSignal:
name: stop_signal
Sysctls:
name: sysctls
VolumesFrom:
name: volumes_from
Volumes:
name: volumes
VolumeDriver:
name: volume_driver
UpgradeStrategy:
name: upgrade_strategy
Ulimits:
name: ulimits
`

outputTemplate = `{{- if .serviceConstructs}}## This is the service-wise list of constructs that need to be handled specially.
Please refer https://rancher.com/docs/rancher/v2.x/en/v1.6-migration/ to transition these to Rancher 2.0.
{{- range $service, $constructsMap := .serviceConstructs}}
{{$service}}:
{{- range $key, $constructsArray := $constructsMap}}
{{$key}}:
{{- range $i, $construct := $constructsArray -}}
{{- if ne $construct.Name "" -}}
{{- if ne $construct.Name $key}}
>>{{$construct.Name}}
{{- if ne $construct.DocLink ""}}
Refer: {{$construct.DocLink}}
{{- end -}}
{{- if ne $construct.HelpText ""}}
{{$construct.HelpText}}
{{- end -}}
{{- else -}}
{{- if ne $construct.DocLink ""}}
Refer: {{$construct.DocLink}}
{{- end -}}
{{- if ne $construct.HelpText ""}}
{{$construct.HelpText}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end}}
## More Docker/Rancher1.6 constructs that need to be transitioned to Kubernetes/Rancher 2.0 in a special way:
{{- if .usesNetworks}}
networks
{{- end}}
{{- if .usesVolumes}}
volumes
{{- end}}
Rancher Metadata - Incase your applications depend on metadata.
Rancher 1.6 FQDN resolution format
Please contact Rancher Support for more help to migrate these to Rancher 2.0, as there is no direct translation available.
`
)
Loading

0 comments on commit 3b8bd4c

Please sign in to comment.