From 5eb64eb84baba95c17ee6d6f976238a251a27fc6 Mon Sep 17 00:00:00 2001 From: Carlisia Thompson Date: Tue, 8 Dec 2020 10:42:03 -0800 Subject: [PATCH] Add Tilt configs (#3119) * Adding Tilt configs Signed-off-by: Carlisia * Fix spelling Signed-off-by: Carlisia * Reuse sample BSL yaml file Signed-off-by: Carlisia * Minor fix and more documentation Signed-off-by: Carlisia * Reuse our build.sh script Signed-off-by: Carlisia * Finish tweaking Tilt build Signed-off-by: Carlisia * Improvements Signed-off-by: Carlisia * This will make a better startup config Signed-off-by: Carlisia * Code review + improvements Signed-off-by: Carlisia * Improvements Signed-off-by: Carlisia * Reset go.sum Signed-off-by: Carlisia * Address code reviews Signed-off-by: Carlisia * Improve Tilt code Signed-off-by: Carlisia * Address code reviews Signed-off-by: Carlisia * Fix links Signed-off-by: Carlisia * Add CSI image to example deployment Signed-off-by: Carlisia --- .gitignore | 9 +- Tiltfile | 207 +++++++++++++++++++++ go.sum | 2 +- hack/build.sh | 2 +- site/content/docs/main/tilt.md | 180 ++++++++++++++++++ site/content/docs/v1.5/tilt.md | 181 ++++++++++++++++++ site/data/docs/main-toc.yml | 2 + site/data/docs/v1-5-toc.yml | 2 + tilt-resources/examples/cloud | 3 + tilt-resources/examples/deployment.yaml | 131 +++++++++++++ tilt-resources/examples/restic.yaml | 68 +++++++ tilt-resources/examples/tilt-settings.json | 21 +++ tilt-resources/kustomization.yaml | 13 ++ 13 files changed, 818 insertions(+), 3 deletions(-) create mode 100644 Tiltfile create mode 100644 site/content/docs/main/tilt.md create mode 100644 site/content/docs/v1.5/tilt.md create mode 100644 tilt-resources/examples/cloud create mode 100644 tilt-resources/examples/deployment.yaml create mode 100644 tilt-resources/examples/restic.yaml create mode 100644 tilt-resources/examples/tilt-settings.json create mode 100644 tilt-resources/kustomization.yaml diff --git a/.gitignore b/.gitignore index 983475a64..1107dae8e 100644 --- a/.gitignore +++ b/.gitignore @@ -28,7 +28,6 @@ debug /velero .idea/ -Tiltfile .container-* .vimrc @@ -43,3 +42,11 @@ site/public site/resources .vs + +# these are files for local Tilt development: +_tiltbuild +tilt-resources/tilt-settings.json +tilt-resources/velero_v1_backupstoragelocation.yaml +tilt-resources/deployment.yaml +tilt-resources/restic.yaml +tilt-resources/cloud \ No newline at end of file diff --git a/Tiltfile b/Tiltfile new file mode 100644 index 000000000..7c4ed7a19 --- /dev/null +++ b/Tiltfile @@ -0,0 +1,207 @@ +# -*- mode: Python -*- + +k8s_yaml([ +'config/crd/bases/velero.io_backups.yaml', +'config/crd/bases/velero.io_backupstoragelocations.yaml', +'config/crd/bases/velero.io_deletebackuprequests.yaml', +'config/crd/bases/velero.io_downloadrequests.yaml', +'config/crd/bases/velero.io_podvolumebackups.yaml', +'config/crd/bases/velero.io_podvolumerestores.yaml', +'config/crd/bases/velero.io_resticrepositories.yaml', +'config/crd/bases/velero.io_restores.yaml', +'config/crd/bases/velero.io_schedules.yaml', +'config/crd/bases/velero.io_serverstatusrequests.yaml', +'config/crd/bases/velero.io_volumesnapshotlocations.yaml', +]) + +# default values +settings = { + "default_registry": "", + "enable_restic": False, + "create_backup_locations": False, + "setup-minio": False, +} + +# global settings +settings.update(read_json( + "tilt-resources/tilt-settings.json", + default = {}, +)) + +k8s_yaml(kustomize('tilt-resources')) +k8s_yaml('tilt-resources/deployment.yaml') +if settings.get("enable_restic"): + k8s_yaml('tilt-resources/restic.yaml') +if settings.get("create_backup_locations"): + k8s_yaml('tilt-resources/velero_v1_backupstoragelocation.yaml') +if settings.get("setup-minio"): + k8s_yaml('examples/minio/00-minio-deployment.yaml', allow_duplicates=True) + +# By default, Tilt automatically allows Minikube, Docker for Desktop, Microk8s, Red Hat CodeReady Containers, Kind, K3D, and Krucible. +allow_k8s_contexts(settings.get("allowed_contexts")) +default_registry(settings.get("default_registry")) +local_goos = str(local("go env GOOS", quiet=True, echo_off=True)).strip() +git_sha = str(local("git rev-parse HEAD", quiet=True, echo_off=True)).strip() + + +tilt_helper_dockerfile_header = """ +# Tilt image +FROM golang:1.15.3 as tilt-helper +# Support live reloading with Tilt +RUN wget --output-document /restart.sh --quiet https://raw.githubusercontent.com/windmilleng/rerun-process-wrapper/master/restart.sh && \ + wget --output-document /start.sh --quiet https://raw.githubusercontent.com/windmilleng/rerun-process-wrapper/master/start.sh && \ + chmod +x /start.sh && chmod +x /restart.sh +""" + +additional_docker_helper_commands = """ +RUN wget -qO- https://dl.k8s.io/v1.19.2/kubernetes-client-linux-amd64.tar.gz | tar xvz +RUN wget -qO- https://get.docker.com | sh +""" + +additional_docker_build_commands = """ +COPY --from=tilt-helper /usr/bin/docker /usr/bin/docker +COPY --from=tilt-helper /go/kubernetes/client/bin/kubectl /usr/bin/kubectl +""" + +############################## +# Setup Velero +############################## + +# Set up a local_resource build of the Velero binary. The binary is written to _tiltbuild/velero. +local_resource( + "velero_server_binary", + cmd = 'cd ' + '.' + ';mkdir -p _tiltbuild;PKG=. BIN=velero GOOS=linux GOARCH=amd64 GIT_SHA=' + git_sha + ' VERSION=main GIT_TREE_STATE=dirty OUTPUT_DIR=_tiltbuild ./hack/build.sh', + deps = ["cmd", "internal", "pkg"], + ignore = ["pkg/cmd"], +) + +local_resource( + "velero_local_binary", + cmd = 'cd ' + '.' + ';mkdir -p _tiltbuild/local;PKG=. BIN=velero GOOS=' + local_goos + ' GOARCH=amd64 GIT_SHA=' + git_sha + ' VERSION=main GIT_TREE_STATE=dirty OUTPUT_DIR=_tiltbuild/local ./hack/build.sh', + deps = ["internal", "pkg/cmd"], +) + +tilt_dockerfile_header = """ +FROM gcr.io/distroless/base:debug as tilt +WORKDIR / +COPY --from=tilt-helper /start.sh . +COPY --from=tilt-helper /restart.sh . +COPY velero . +""" + +dockerfile_contents = "\n".join([ + tilt_helper_dockerfile_header, + additional_docker_helper_commands, + tilt_dockerfile_header, + additional_docker_build_commands, +]) + + # Set up an image build for Velero. The live update configuration syncs the output from the local_resource + # build into the container. +docker_build( + ref = "velero/velero", + context = "_tiltbuild/", + dockerfile_contents = dockerfile_contents, + target = "tilt", + entrypoint=["sh", "/start.sh", "/velero"], + live_update=[ + sync("./_tiltbuild/velero", "/velero"), + run("sh /restart.sh"), + ]) + +############################## +# Setup plugins +############################## + +def load_provider_tiltfiles(): + all_providers = settings.get("providers", {}) + enable_providers = settings.get("enable_providers", []) + providers = [] + + ## Load settings only for providers to enable + for name in enable_providers: + repo = all_providers.get(name) + if not repo: + print("Enabled provider '{}' does not exist in list of supported providers".format(name)) + continue + file = repo + "/tilt-provider.json" + if not os.path.exists(file): + print("Provider settings not found for \"{}\". Please ensure this plugin repository has a tilt-provider.json file included.".format(name)) + continue + provider_details = read_json(file, default = {}) + if type(provider_details) == "dict": + provider_details["name"] = name + if "context" in provider_details: + provider_details["context"] = os.path.join(repo, "/", provider_details["context"]) + else: + provider_details["context"] = repo + if "go_main" not in provider_details: + provider_details["go_main"] = "main.go" + providers.append(provider_details) + + return providers + +# Enable each provider +def enable_providers(providers): + if not providers: + print("No providers to enable.") + return + for p in providers: + enable_provider(p) + +# Configures a provider by doing the following: +# +# 1. Enables a local_resource go build of the provider's local binary +# 2. Configures a docker build for the provider, with live updating of the local binary +def enable_provider(provider): + name = provider.get("name") + plugin_name = provider.get("plugin_name") + + # Note: we need a distro other than base:debug to get a shell to do a copy of the plugin binary + tilt_dockerfile_header = """ + FROM ubuntu:focal as tilt + WORKDIR / + COPY --from=tilt-helper /start.sh . + COPY --from=tilt-helper /restart.sh . + COPY """ + plugin_name + """ . + """ + + dockerfile_contents = "\n".join([ + tilt_helper_dockerfile_header, + additional_docker_helper_commands, + tilt_dockerfile_header, + additional_docker_build_commands, + ]) + + context = provider.get("context") + go_main = provider.get("go_main", "main.go") + + live_reload_deps = [] + for d in provider.get("live_reload_deps", []): + live_reload_deps.append(os.path.join(context, "/", d)) + + # Set up a local_resource build of the plugin binary. The main.go path must be provided via go_main option. The binary is written to _tiltbuild/. + local_resource( + name + "_plugin", + cmd = 'cd ' + context + ';mkdir -p _tiltbuild;PKG=' + context + ' BIN=' + go_main + ' GOOS=linux GOARCH=amd64 OUTPUT_DIR=_tiltbuild ./hack/build.sh', + deps = live_reload_deps, + ) + + # Set up an image build for the plugin. The live update configuration syncs the output from the local_resource + # build into the init container, and that restarts the Velero container. + docker_build( + ref = provider.get("image"), + context = os.path.join(context, "/_tiltbuild/"), + dockerfile_contents = dockerfile_contents, + target = "tilt", + entrypoint=["/bin/bash", "-c", "cp /" + plugin_name + " /target/."], + live_update=[ + sync(os.path.join(context, "/_tiltbuild/", plugin_name), os.path.join("/", plugin_name)) + ] + ) + +############################## +# Start +############################# + +enable_providers(load_provider_tiltfiles()) \ No newline at end of file diff --git a/go.sum b/go.sum index 6e788f1fd..45ae9c6b8 100644 --- a/go.sum +++ b/go.sum @@ -1022,4 +1022,4 @@ sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0= -vbom.ml/util v0.0.0-20160121211510-db5cfe13f5cc/go.mod h1:so/NYdZXCz+E3ZpW0uAoCj6uzU2+8OWDFv/HxUSs7kI= +vbom.ml/util v0.0.0-20160121211510-db5cfe13f5cc/go.mod h1:so/NYdZXCz+E3ZpW0uAoCj6uzU2+8OWDFv/HxUSs7kI= \ No newline at end of file diff --git a/hack/build.sh b/hack/build.sh index b04378ad9..c28403fdf 100755 --- a/hack/build.sh +++ b/hack/build.sh @@ -69,4 +69,4 @@ go build \ -o ${OUTPUT} \ -installsuffix "static" \ -ldflags "${LDFLAGS}" \ - ${PKG}/cmd/${BIN} + ${PKG}/cmd/${BIN} \ No newline at end of file diff --git a/site/content/docs/main/tilt.md b/site/content/docs/main/tilt.md new file mode 100644 index 000000000..ce252951b --- /dev/null +++ b/site/content/docs/main/tilt.md @@ -0,0 +1,180 @@ +--- +title: "Rapid iterative Velero development with Tilt " +layout: docs +--- + +## Overview +This document describes how to use [Tilt](https://tilt.dev) with any cluster for a simplified +workflow that offers easy deployments and rapid iterative builds. + +This setup allows for continuing deployment of the Velero server and, if specified, any provider plugin or the restic daemonset. +It does this work by: + +1. Deploying the necessary Kubernetes resources, such as the Velero CRDs and Velero deployment +1. Building a local binary for Velero and (if specified) provider plugins as a `local_resource` +1. Invoking `docker_build` to live update any binary into the container/init container and trigger a re-start + +Tilt will look for configuration files under `velero/tilt-resources`. Most of the +files in this directory are gitignored so you may configure your setup according to your needs. + +## Prerequisites +1. [Docker](https://docs.docker.com/install/) v19.03 or newer +1. A Kubernetes cluster v1.10 or greater (does not have to be Kind) +1. [Tilt](https://docs.tilt.dev/install.html) v0.12.0 or newer +1. Clone the [Velero project](https://github.com/vmware-tanzu/velero) repository + locally +1. Access to an S3 object storage +1. Clone any [provider plugin(s)](https://velero.io/plugins/) you want to make changes to and deploy (optional, must be configured to be deployed by the Velero Tilt's setup, [more info below](#provider-plugins)) + +Note: To properly configure any plugin you use, please follow the plugin's documentation. +## Getting started + +### tl;dr +- Copy all sample files under `velero/tilt-resources/examples` into `velero/tilt-resources`. +- Copy the `config/samples/velero_v1_backupstoragelocation.yaml` file into `velero/tilt-resources`. +- Configure the `velero_v1_backupstoragelocation.yaml` file, and the `cloud` file for the storage credentials/secret. + +- Run `tilt up`. + +### Create a Tilt settings file +Create a configuration file named `tilt-settings.json` and place it in your local copy of `velero/tilt-resources`. Alternatively, +you may copy and paste the sample file found in `velero/tilt-resources/examples`. + +Here is an example: + +```json +{ + "default_registry": "", + "enable_providers": [ + "aws", + "gcp", + "azure", + "csi" + ], + "providers": { + "aws": "../velero-plugin-for-aws", + "gcp": "../velero-plugin-for-gcp", + "azure": "../velero-plugin-for-microsoft-azure", + "csi": "../velero-plugin-for-csi" + }, + "allowed_contexts": [ + "development" + ], + "enable_restic": false, + "create_backup_locations": true, + "setup-minio": true +} +``` + +#### tilt-settings.json fields +**default_registry** (String, default=""): The image registry to use if you need to push images. See the [Tilt +*documentation](https://docs.tilt.dev/api.html#api.default_registry) for more details. + +**provider_repos** (Array[]String, default=[]): A list of paths to all the provider plugins you want to make changes to. Each provider must have a +`tilt-provider.json` file describing how to build the provider. + +**enable_providers** (Array[]String, default=[]): A list of the provider plugins to enable. See [provider plugins](provider-plugins) +for more details. Note: when not making changes to a plugin, it is not necessary to load them into +Tilt: an existing image and version might be specified in the Velero deployment instead, and Tilt will load that. + +**allowed_contexts** (Array, default=[]): A list of kubeconfig contexts Tilt is allowed to use. See the Tilt documentation on +*[allow_k8s_contexts](https://docs.tilt.dev/api.html#api.allow_k8s_contexts) for more details. Note: Kind is automatically allowed. + +**enable_restic** (Bool, default=false): Indicate whether to deploy the restic Daemonset. If set to `true`, Tilt will look for a `velero/tilt-resources/restic.yaml` file +containing the configuration of the Velero restic DaemonSet. + +**create_backup_locations** (Bool, default=false): Indicate whether to create one or more backup storage locations. If set to `true`, Tilt will look for a `velero/tilt-resources/velero_v1_backupstoragelocation.yaml` file +containing at least one configuration for a Velero backup storage location. + +**setup-minio** (Bool, default=false): Configure this to `true` if you want to configure backup storage locations in a Minio instance running inside your cluster. + +### Create Kubernetes resource files to deploy +All needed Kubernetes resource files are provided as ready to use samples in the `velero/tilt-resources/examples` directory. You only have to move them to the `velero/tilt-resources` level. + +Because the Velero Kubernetes deployment as well as the restic DaemonSet contain the configuration +for any plugin to be used, files for these resources are expected to be provided by the user so you may choose +which provider plugin to load as a init container. Currently, the sample files provided are configured with all the +plugins supported by Velero, feel free to remove any of them as needed. + +For Velero to operate fully, it also needs at least one backup +storage location. A sample file is provided that needs to be modified with the specific +configuration for your object storage. See the next sub-section for more details on this. + +### Configure a backup storage location +You will have to configure the `backupstoragelocation.yaml` with the proper values according to your storage provider. Read the [plugin documentation](https://velero.io/plugins/) +to learn what field/value pairs are required for your particular provider's backup storage location configuration. + +Below are some ways to configure a backup storage location for Velero. +#### As a storage with a service provider +Follow the provider documentation to provision the storage. We have a [list of all known object storage providers](supported-providers/) with corresponding plugins for Velero. + +#### Using MinIO as an object storage +Note: to use MinIO as an object storage, you will need to use the [`AWS` plugin](https://github.com/vmware-tanzu/velero-plugin-for-aws), and configure the storage location with the `spec.provider` set to `aws` and the `spec.config.region` set to `minio`. Example: +``` +spec: + config: + region: minio + s3ForcePathStyle: "true" + s3Url: http://minio.velero.svc:9000 + objectStorage: + bucket: velero + provider: aws +``` + +Here are two ways to use MinIO as the storage: + +1) As a MinIO instance running inside your cluster + + In the `tilt-settings.json` file, set `"setup-minio": true`. This will configure a Kubernetes deployment containing a running +instance of Minio inside your cluster. There are [extra steps](contributions/minio/#expose-minio-outside-your-cluster-with-a-service) +necessary to expose Minio outside the cluster. Note: with this setup, when your cluster is terminated so is the storage and any backup/restore in it. + +2) As a standalone MinIO instance running locally in a Docker container + + See [these instructions](https://github.com/vmware-tanzu/velero/wiki/Contributing-FAQ#minio) to run MinIO locally on your computer, as a standalone as opposed to running it on a Pod. + +Please see our [locations documentation](locations/) to learn more how backup locations work. + +### Configure the provider credentials (secret) +Whatever object storage provider you use, configure the credentials for in the `velero/tilt-resources/cloud` file. Read the [plugin documentation](https://velero.io/plugins/) +to learn what field/value pairs are required for your provider's credentials. The Tilt file will invoke Kustomize to create the secret under the hard-coded key `secret.cloud-credentials.data.cloud` in the Velero namespace. + +There is a sample credentials file properly formatted for a MinIO storage credentials in `velero/tilt-resources/examples/cloud`. + +### Run Tilt! +To launch your development environment, run: + +``` bash +tilt up +``` + +This will output the address to a web browser interface where you can monitor Tilt's status and the logs for each Tilt resource. After a brief amount of time, you should have a running development environment, and you should now be able to +create backups/restores and fully operate Velero. + +Note: Running `tilt down` after exiting out of Tilt [will delete all resources](https://docs.tilt.dev/cli/tilt_down.html) specified in the Tiltfile. + +Tip: Create an alias to `velero/_tuiltbuild/local/velero` and you won't have to run `make local` to get a refreshed version of the Velero CLI, just use the alias. + +Please see the documentation for [how Velero works](how-velero-works/). + +## Provider plugins +A provider must supply a `tilt-provider.json` file describing how to build it. Here is an example: + +```json +{ + "plugin_name": "velero-plugin-for-aws", + "context": ".", + "image": "velero/velero-plugin-for-aws", + "live_reload_deps": [ + "velero-plugin-for-aws" + ], + "go_main": "./velero-plugin-for-aws" +} +``` + +## Live updates +Each provider plugin configured to be deployed by Velero's Tilt setup has a `live_reload_deps` list. This defines the files and/or directories that Tilt +should monitor for changes. When a dependency is modified, Tilt rebuilds the provider's binary **on your local +machine**, copies the binary to the init container, and triggers a restart of the Velero container. This is significantly faster +than rebuilding the container image for each change. It also helps keep the size of each development image as small as +possible (the container images do not need the entire go toolchain, source code, module dependencies, etc.). \ No newline at end of file diff --git a/site/content/docs/v1.5/tilt.md b/site/content/docs/v1.5/tilt.md new file mode 100644 index 000000000..b797990cb --- /dev/null +++ b/site/content/docs/v1.5/tilt.md @@ -0,0 +1,181 @@ +--- +title: "Rapid iterative Velero development with Tilt " +layout: docs +--- + +## Overview +This document describes how to use [Tilt](https://tilt.dev) with any cluster for a simplified +workflow that offers easy deployments and rapid iterative builds. + +This setup allows for continuing deployment of the Velero server and, if specified, any provider plugin or the restic daemonset. +It does this work by: + +1. Deploying the necessary Kubernetes resources, such as the Velero CRDs and Velero deployment +1. Building a local binary for Velero and (if specified) provider plugins as a `local_resource` +1. Invoking `docker_build` to live update any binary into the container/init container and trigger a re-start + +Tilt will look for configuration files under `velero/tilt-resources`. Most of the +files in this directory are gitignored so you may configure your setup according to your needs. + +## Prerequisites +1. [Docker](https://docs.docker.com/install/) v19.03 or newer +1. A Kubernetes cluster v1.10 or greater (does not have to be Kind) +1. [Tilt](https://docs.tilt.dev/install.html) v0.12.0 or newer +1. Clone the [Velero project](https://github.com/vmware-tanzu/velero) repository + locally +1. Access to an S3 object storage +1. Clone any [provider plugin(s)](https://velero.io/plugins/) you want to make changes to and deploy (optional, must be configured to be deployed by the Velero Tilt's setup, [more info below](#provider-plugins)) + +Note: To properly configure any plugin you use, please follow the plugin's documentation. + +## Getting started + +### tl;dr +- Copy all sample files under `velero/tilt-resources/examples` into `velero/tilt-resources`. +- Copy the `config/samples/velero_v1_backupstoragelocation.yaml` file into `velero/tilt-resources`. +- Configure the `velero_v1_backupstoragelocation.yaml` file, and the `cloud` file for the storage credentials/secret. + +- Run `tilt up`. + +### Create a Tilt settings file +Create a configuration file named `tilt-settings.json` and place it in your local copy of `velero/tilt-resources`. Alternatively, +you may copy and paste the sample file found in `velero/tilt-resources/examples`. + +Here is an example: + +```json +{ + "default_registry": "", + "enable_providers": [ + "aws", + "gcp", + "azure", + "csi" + ], + "providers": { + "aws": "../velero-plugin-for-aws", + "gcp": "../velero-plugin-for-gcp", + "azure": "../velero-plugin-for-microsoft-azure", + "csi": "../velero-plugin-for-csi" + }, + "allowed_contexts": [ + "development" + ], + "enable_restic": false, + "create_backup_locations": true, + "setup-minio": true +} +``` + +#### tilt-settings.json fields +**default_registry** (String, default=""): The image registry to use if you need to push images. See the [Tilt +*documentation](https://docs.tilt.dev/api.html#api.default_registry) for more details. + +**provider_repos** (Array[]String, default=[]): A list of paths to all the provider plugins you want to make changes to. Each provider must have a +`tilt-provider.json` file describing how to build the provider. + +**enable_providers** (Array[]String, default=[]): A list of the provider plugins to enable. See [provider plugins](#provider-plugins) +for more details. Note: when not making changes to a plugin, it is not necessary to load them into +Tilt: an existing image and version might be specified in the Velero deployment instead, and Tilt will load that. + +**allowed_contexts** (Array, default=[]): A list of kubeconfig contexts Tilt is allowed to use. See the Tilt documentation on +*[allow_k8s_contexts](https://docs.tilt.dev/api.html#api.allow_k8s_contexts) for more details. Note: Kind is automatically allowed. + +**enable_restic** (Bool, default=false): Indicate whether to deploy the restic Daemonset. If set to `true`, Tilt will look for a `velero/tilt-resources/restic.yaml` file +containing the configuration of the Velero restic DaemonSet. + +**create_backup_locations** (Bool, default=false): Indicate whether to create one or more backup storage locations. If set to `true`, Tilt will look for a `velero/tilt-resources/velero_v1_backupstoragelocation.yaml` file +containing at least one configuration for a Velero backup storage location. + +**setup-minio** (Bool, default=false): Configure this to `true` if you want to configure backup storage locations in a Minio instance running inside your cluster. + +### Create Kubernetes resource files to deploy +All needed Kubernetes resource files are provided as ready to use samples in the `velero/tilt-resources/examples` directory. You only have to move them to the `velero/tilt-resources` level. + +Because the Velero Kubernetes deployment as well as the restic DaemonSet contain the configuration +for any plugin to be used, files for these resources are expected to be provided by the user so you may choose +which provider plugin to load as a init container. Currently, the sample files provided are configured with all the +plugins supported by Velero, feel free to remove any of them as needed. + +For Velero to operate fully, it also needs at least one backup +storage location. A sample file is provided that needs to be modified with the specific +configuration for your object storage. See the next sub-section for more details on this. + +### Configure a backup storage location +You will have to configure the `backupstoragelocation.yaml` with the proper values according to your storage provider. Read the [plugin documentation](https://velero.io/plugins/) +to learn what field/value pairs are required for your particular provider's backup storage location configuration. + +Below are some ways to configure a backup storage location for Velero. +#### As a storage with a service provider +Follow the provider documentation to provision the storage. We have a [list of all known object storage providers](supported-providers/) with corresponding plugins for Velero. + +#### Using MinIO as an object storage +Note: to use MinIO as an object storage, you will need to use the [`AWS` plugin](https://github.com/vmware-tanzu/velero-plugin-for-aws), and configure the storage location with the `spec.provider` set to `aws` and the `spec.config.region` set to `minio`. Example: +``` +spec: + config: + region: minio + s3ForcePathStyle: "true" + s3Url: http://minio.velero.svc:9000 + objectStorage: + bucket: velero + provider: aws +``` + +Here are two ways to use MinIO as the storage: + +1) As a MinIO instance running inside your cluster + + In the `tilt-settings.json` file, set `"setup-minio": true`. This will configure a Kubernetes deployment containing a running +instance of Minio inside your cluster. There are [extra steps](contributions/minio/#expose-minio-outside-your-cluster-with-a-service) +necessary to expose Minio outside the cluster. Note: with this setup, when your cluster is terminated so is the storage and any backup/restore in it. + +2) As a standalone MinIO instance running locally in a Docker container + + See [these instructions](https://github.com/vmware-tanzu/velero/wiki/Contributing-FAQ#minio) to run MinIO locally on your computer, as a standalone as opposed to running it on a Pod. + +Please see our [locations documentation](locations/) to learn more how backup locations work. + +### Configure the provider credentials (secret) +Whatever object storage provider you use, configure the credentials for in the `velero/tilt-resources/cloud` file. Read the [plugin documentation](https://velero.io/plugins/) +to learn what field/value pairs are required for your provider's credentials. The Tilt file will invoke Kustomize to create the secret under the hard-coded key `secret.cloud-credentials.data.cloud` in the Velero namespace. + +There is a sample credentials file properly formatted for a MinIO storage credentials in `velero/tilt-resources/examples/cloud`. + +### Run Tilt! +To launch your development environment, run: + +``` bash +tilt up +``` + +This will output the address to a web browser interface where you can monitor Tilt's status and the logs for each Tilt resource. After a brief amount of time, you should have a running development environment, and you should now be able to +create backups/restores and fully operate Velero. + +Note: Running `tilt down` after exiting out of Tilt [will delete all resources](https://docs.tilt.dev/cli/tilt_down.html) specified in the Tiltfile. + +Tip: Create an alias to `velero/_tuiltbuild/local/velero` and you won't have to run `make local` to get a refreshed version of the Velero CLI, just use the alias. + +Please see the documentation for [how Velero works](how-velero-works/). + +## Provider plugins +A provider must supply a `tilt-provider.json` file describing how to build it. Here is an example: + +```json +{ + "plugin_name": "velero-plugin-for-aws", + "context": ".", + "image": "velero/velero-plugin-for-aws", + "live_reload_deps": [ + "velero-plugin-for-aws" + ], + "go_main": "./velero-plugin-for-aws" +} +``` + +## Live updates +Each provider plugin configured to be deployed by Velero's Tilt setup has a `live_reload_deps` list. This defines the files and/or directories that Tilt +should monitor for changes. When a dependency is modified, Tilt rebuilds the provider's binary **on your local +machine**, copies the binary to the init container, and triggers a restart of the Velero container. This is significantly faster +than rebuilding the container image for each change. It also helps keep the size of each development image as small as +possible (the container images do not need the entire go toolchain, source code, module dependencies, etc.). \ No newline at end of file diff --git a/site/data/docs/main-toc.yml b/site/data/docs/main-toc.yml index 8f21ac43a..a6f419d9d 100644 --- a/site/data/docs/main-toc.yml +++ b/site/data/docs/main-toc.yml @@ -71,6 +71,8 @@ toc: url: /start-contributing - page: Development url: /development + - page: Rapid development with Tilt + url: /tilt - page: Build from source url: /build-from-source - page: Run locally diff --git a/site/data/docs/v1-5-toc.yml b/site/data/docs/v1-5-toc.yml index 8f21ac43a..a6f419d9d 100644 --- a/site/data/docs/v1-5-toc.yml +++ b/site/data/docs/v1-5-toc.yml @@ -71,6 +71,8 @@ toc: url: /start-contributing - page: Development url: /development + - page: Rapid development with Tilt + url: /tilt - page: Build from source url: /build-from-source - page: Run locally diff --git a/tilt-resources/examples/cloud b/tilt-resources/examples/cloud new file mode 100644 index 000000000..b26204aea --- /dev/null +++ b/tilt-resources/examples/cloud @@ -0,0 +1,3 @@ +[default] +aws_access_key_id = minio +aws_secret_access_key = minio123 \ No newline at end of file diff --git a/tilt-resources/examples/deployment.yaml b/tilt-resources/examples/deployment.yaml new file mode 100644 index 000000000..b14015484 --- /dev/null +++ b/tilt-resources/examples/deployment.yaml @@ -0,0 +1,131 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + component: velero + name: velero + namespace: velero +spec: + selector: + matchLabels: + deploy: velero + strategy: {} + template: + metadata: + annotations: + prometheus.io/path: /metrics + prometheus.io/port: "8085" + prometheus.io/scrape: "true" + labels: + component: velero + deploy: velero + spec: + containers: + - args: + - server + - --log-level + - debug + command: + - /velero + env: + - name: VELERO_SCRATCH_DIR + value: /scratch + - name: VELERO_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: LD_LIBRARY_PATH + value: /plugins + - name: AWS_SHARED_CREDENTIALS_FILE + value: /credentials/cloud + - name: AZURE_SHARED_CREDENTIALS_FILE + value: /credentials/cloud + - name: GOOGLE_APPLICATION_CREDENTIALS + value: /credentials/cloud + name: velero + image: velero/velero + imagePullPolicy: Always + ports: + - containerPort: 8085 + name: metrics + resources: + limits: + cpu: "1" + memory: 256Mi + requests: + cpu: 500m + memory: 128Mi + volumeMounts: + - mountPath: /scratch + name: scratch + - mountPath: /plugins + name: plugins + - mountPath: /credentials + name: cloud-credentials + initContainers: + - image: velero/velero-plugin-for-aws + imagePullPolicy: Always + name: velero-plugin-for-aws + volumeMounts: + - mountPath: /target + name: plugins + - image: velero/velero-plugin-for-gcp + imagePullPolicy: Always + name: velero-plugin-for-gcp + volumeMounts: + - mountPath: /target + name: plugins + - image: velero/velero-plugin-for-microsoft-azure + imagePullPolicy: Always + name: velero-plugin-for-microsoft-azure + volumeMounts: + - mountPath: /target + name: plugins + - image: velero/velero-plugin-for-csi + imagePullPolicy: Always + name: velero-plugin-for-csi + volumeMounts: + - mountPath: /target + name: plugins + restartPolicy: Always + serviceAccountName: velero + volumes: + - emptyDir: {} + name: scratch + - emptyDir: {} + name: plugins + - name: cloud-credentials + secret: + secretName: cloud-credentials +--- +apiVersion: rbac.authorization.k8s.io/v1beta1 +kind: ClusterRoleBinding +metadata: + labels: + component: velero + name: velero +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: cluster-admin +subjects: + - kind: ServiceAccount + name: velero + namespace: velero +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + labels: + component: velero + name: velero + namespace: velero +--- +apiVersion: v1 +kind: Namespace +metadata: + labels: + component: velero + name: velero +spec: {} \ No newline at end of file diff --git a/tilt-resources/examples/restic.yaml b/tilt-resources/examples/restic.yaml new file mode 100644 index 000000000..ab8ad0d16 --- /dev/null +++ b/tilt-resources/examples/restic.yaml @@ -0,0 +1,68 @@ +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + creationTimestamp: null + labels: + component: velero + name: restic + namespace: velero +spec: + selector: + matchLabels: + name: restic + template: + metadata: + creationTimestamp: null + labels: + component: velero + name: restic + spec: + containers: + - args: + - restic + - server + command: + - /velero + env: + - name: NODE_NAME + valueFrom: + fieldRef: + fieldPath: spec.nodeName + - name: VELERO_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: VELERO_SCRATCH_DIR + value: /scratch + - name: AWS_SHARED_CREDENTIALS_FILE + value: /credentials/cloud + - name: AZURE_SHARED_CREDENTIALS_FILE + value: /credentials/cloud + - name: GOOGLE_APPLICATION_CREDENTIALS + value: /credentials/cloud + image: velero/velero:latest + imagePullPolicy: Always + name: restic + resources: {} + volumeMounts: + - mountPath: /host_pods + mountPropagation: HostToContainer + name: host-pods + - mountPath: /scratch + name: scratch + - mountPath: /credentials + name: cloud-credentials + securityContext: + runAsUser: 0 + serviceAccountName: velero + volumes: + - hostPath: + path: /var/lib/kubelet/pods + name: host-pods + - emptyDir: {} + name: scratch + - name: cloud-credentials + secret: + secretName: cloud-credentials + updateStrategy: {} diff --git a/tilt-resources/examples/tilt-settings.json b/tilt-resources/examples/tilt-settings.json new file mode 100644 index 000000000..84247adfe --- /dev/null +++ b/tilt-resources/examples/tilt-settings.json @@ -0,0 +1,21 @@ +{ + "default_registry": "", + "enable_providers": [ + "aws", + "gcp", + "azure", + "csi" + ], + "providers": { + "aws": "../velero-plugin-for-aws", + "gcp": "../velero-plugin-for-gcp", + "azure": "../velero-plugin-for-microsoft-azure", + "csi": "../velero-plugin-for-csi" + }, + "allowed_contexts": [ + "development" + ], + "enable_restic": false, + "create_backup_locations": true, + "setup-minio": true +} \ No newline at end of file diff --git a/tilt-resources/kustomization.yaml b/tilt-resources/kustomization.yaml new file mode 100644 index 000000000..3bfdef697 --- /dev/null +++ b/tilt-resources/kustomization.yaml @@ -0,0 +1,13 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +generatorOptions: + disableNameSuffixHash: true + labels: + component: velero + +secretGenerator: +- name: cloud-credentials + namespace: velero + files: + - "cloud" \ No newline at end of file