diff --git a/README.md b/README.md index ee90f77..3c6a395 100644 --- a/README.md +++ b/README.md @@ -65,10 +65,13 @@ Additional actions: * After the deployment is complete, orca will validate that the environment is in a healthy state. * You can skip the validation using the `--skip-validation` flag. -#### Get the "stable" environment and deploy the same configuration to a new environment, with override(s) +#### Get the "stable" environment and deploy the same configuration to a new environment, with override(s) and environment refresh + +Useful for creating test environments for a single service or for multiple services. +Handy for testing a single feature spanning across one or more services. +This will deploy the "stable" configuration to a destination namespace, except for the specified override(s), which will be deployed with version `CHART_VERSION`. In addition, it will set an annotation stating that `CHART_NAME` is protected and can only be overridden by itself. +If the reference environment has changed between environment deployments, the new environment will be updated with these changes. -Useful for creating test environments for a single service or for multiple services. Handy for testing a single feature spanning across one or more services. -This will deploy the "stable" configuration to a destination namespace, except for the specified override(s), which will be deployed with version `CHART_VERSION`. The following commands will be a part of all CI\CD processes in all services: ``` @@ -76,17 +79,23 @@ orca get env --name $SRC_NS --kube-context $SRC_KUBE_CONTEXT > charts.yaml orca deploy env --name $DST_NS -c charts.yaml \ --kube-context $DST_KUBE_CONTEXT \ --repo myrepo=$REPO_URL \ - --override $CHART_NAME=$CHART_VERSION + --override $CHART_NAME=$CHART_VERSION \ + --protected-chart $CHART_NAME ``` -* If the environment already exists, only the specified override(s) will be deployed. -* After deploying from (for example) 3 different repositories, the new environment will have the "stable" configuration, except for the 3 services which are currently under test, which will be deployed with their respective `CHART_VERSION`s. +* When the first service's process starts, it creates the environment and deploys the configuration from the "stable" environment (exactly the same as the previous example). +* When the Nth service's process starts, the environment already exists, and a previous chart that was deployed is `protected`. The current service will also be marked as `protected`, and will update the environment, without changing the previous protected service(s). +* After deploying from (for example) 3 different repositories, the new environment will have the latest "stable" configuration, except for the 3 services which are currently under test, which will be deployed with their respective `CHART_VERSION`s (protected by `--protected-chart`) +* You can add the `--protected-chart` flag even if this service is completely isolated (for consistency). * Orca also handles a potential race condition between 2 or more services by "locking" the environment during deployment (using a `busy` annotation on the namespace). -#### Get the "stable" environment and deploy the same configuration to the same new environment from multiple CI\CD processes with environment refresh +#### Get the "stable" environment and deploy the same configuration to a new environment, with override(s) and without environment refresh + +Useful for creating test environments for a single service or for multiple services. +Handy for testing a single feature spanning across one or more services, when you want to prevent updates from the reference environment after the initial creation of the new environment. +This will deploy the "stable" configuration to a destination namespace, except for the specified override(s), which will be deployed with version `CHART_VERSION`. +If the reference environment has changed between environment deployments, the new environment will NOT be updated with these changes. -Useful for creating test environments for a single service or for multiple services, when you have a rapidly changing reference environment. -This will deploy the same configuration to a destination namespace, except for the specified override(s), which will be deployed with version CHART_VERSION. If the reference environment has changed between environment deployments, the new environment will be updated with these changes. The following commands will be a part of all CI\CD processes in all services: ``` @@ -95,14 +104,13 @@ orca deploy env --name $DST_NS -c charts.yaml \ --kube-context $DST_KUBE_CONTEXT \ --repo myrepo=$REPO_URL \ --override $CHART_NAME=$CHART_VERSION \ - --protected-chart $CHART_NAME \ - --refresh + -x ``` -When the first service's process starts, it creates the environment and deploys the configuration from the "stable" environment (exactly the same as the previous example). In addition, it will set an annotation stating that `CHART_NAME` is protected and can only be overridden by itself. -When the Nth service's process starts, the environment already exists, and a previous chart that was deployed is `protected`. The current service will also be marked as `protected`, and will update the environment, without changing the previous protected service(s). +* When the first service's process starts, it creates the environment and deploys the configuration from the "stable" environment (exactly the same as the previous example). +* When the Nth service's process starts, the environment already exists, so only the specified override(s) will be deployed. +* Assuming each process deployes a different chart (or charts), there is no need to protect them using the `--protectec-chart`. -* You can add the `--protected-chart` flag even if this service is completely isolated (for consistency). ### Create and update static environments diff --git a/docs/commands/README.md b/docs/commands/README.md index eeef9c9..cca873b 100644 --- a/docs/commands/README.md +++ b/docs/commands/README.md @@ -91,23 +91,23 @@ Aliases: env, environment Flags: - --annotations strings additional environment (namespace) annotations (can specify multiple): annotation=value - -c, --charts-file string path to file with list of Helm charts to install. Overrides $ORCA_CHARTS_FILE - --helm-tls-store string path to TLS certs and keys. Overrides $HELM_TLS_STORE - --inject enable injection during helm upgrade. Overrides $ORCA_INJECT (requires helm inject plugin: https://github.com/maorfr/helm-inject) - --kube-context string name of the kubeconfig context to use. Overrides $ORCA_KUBE_CONTEXT - --labels strings environment (namespace) labels (can specify multiple): label=value - -n, --name string name of environment (namespace) to deploy to. Overrides $ORCA_NAME - --override strings chart to override with different version (can specify multiple): chart=version - -p, --parallel int number of releases to act on in parallel. set this flag to 0 for full parallelism. Overrides $ORCA_PARALLEL (default 1) - --protected-chart strings chart name to protect from being overridden (can specify multiple) - --refresh refresh the environment based on reference environment. Overrides $ORCA_REFRESH - --repo string chart repository (name=url). Overrides $ORCA_REPO - -s, --set strings set additional parameters - --timeout int time in seconds to wait for any individual Kubernetes operation (like Jobs for hooks). Overrides $ORCA_TIMEOUT (default 300) - --tls enable TLS for request. Overrides $ORCA_TLS - --validate perform environment validation after deployment. Overrides $ORCA_VALIDATE - -f, --values strings values file to use (packaged within the chart) + --annotations strings additional environment (namespace) annotations (can specify multiple): annotation=value + -c, --charts-file string path to file with list of Helm charts to install. Overrides $ORCA_CHARTS_FILE + -x, --deploy-only-override-if-env-exists if environment exists - deploy only override(s) (avoid environment update). Overrides $ORCA_DEPLOY_ONLY_OVERRIDE_IF_ENV_EXISTS + --helm-tls-store string path to TLS certs and keys. Overrides $HELM_TLS_STORE + --inject enable injection during helm upgrade. Overrides $ORCA_INJECT (requires helm inject plugin: https://github.com/maorfr/helm-inject) + --kube-context string name of the kubeconfig context to use. Overrides $ORCA_KUBE_CONTEXT + --labels strings environment (namespace) labels (can specify multiple): label=value + -n, --name string name of environment (namespace) to deploy to. Overrides $ORCA_NAME + --override strings chart to override with different version (can specify multiple): chart=version + -p, --parallel int number of releases to act on in parallel. set this flag to 0 for full parallelism. Overrides $ORCA_PARALLEL (default 1) + --protected-chart strings chart name to protect from being overridden (can specify multiple) + --repo string chart repository (name=url). Overrides $ORCA_REPO + -s, --set strings set additional parameters + --timeout int time in seconds to wait for any individual Kubernetes operation (like Jobs for hooks). Overrides $ORCA_TIMEOUT (default 300) + --tls enable TLS for request. Overrides $ORCA_TLS + --validate perform environment validation after deployment. Overrides $ORCA_VALIDATE + -f, --values strings values file to use (packaged within the chart) ``` `helm-tls-store` - path to directory containing `.cert.pem` and `.key.pem` files diff --git a/pkg/orca/env.go b/pkg/orca/env.go index 683423c..e68750e 100644 --- a/pkg/orca/env.go +++ b/pkg/orca/env.go @@ -45,9 +45,9 @@ type envCmd struct { annotations []string labels []string validate bool + deployOnlyOverrideIfEnvExists bool protectedCharts []string refresh bool - deployOnlyOverrideIfEnvExists bool out io.Writer } @@ -126,8 +126,8 @@ func NewDeployEnvCmd(out io.Writer) *cobra.Command { if e.chartsFile == "" { return errors.New("either charts-file or override has to be defined") } - if !e.refresh { - return errors.New("override has to be defined when using not using refresh") + if e.deployOnlyOverrideIfEnvExists { + return errors.New("override has to be defined when using using deploy-only-override-if-env-exists") } } if e.chartsFile != "" && utils.CheckCircularDependencies(utils.InitReleasesFromChartsFile(e.chartsFile, e.name)) { @@ -179,7 +179,7 @@ func NewDeployEnvCmd(out io.Writer) *cobra.Command { log.Print("initializing releases to deploy") var desiredReleases []utils.ReleaseSpec - if nsPreExists && !e.refresh { + if nsPreExists && e.deployOnlyOverrideIfEnvExists { desiredReleases = utils.InitReleases(e.name, e.override) } else { if e.chartsFile != "" { @@ -236,7 +236,7 @@ func NewDeployEnvCmd(out io.Writer) *cobra.Command { log.Fatal(err) } - if e.refresh { + if !e.deployOnlyOverrideIfEnvExists { log.Print("getting currently deployed releases") installedReleases, err := utils.GetInstalledReleases(utils.GetInstalledReleasesOptions{ KubeContext: e.kubeContext, @@ -303,11 +303,11 @@ func NewDeployEnvCmd(out io.Writer) *cobra.Command { f.StringSliceVar(&e.annotations, "annotations", []string{}, "additional environment (namespace) annotations (can specify multiple): annotation=value") f.StringSliceVar(&e.labels, "labels", []string{}, "environment (namespace) labels (can specify multiple): label=value") f.BoolVar(&e.validate, "validate", utils.GetBoolEnvVar("ORCA_VALIDATE", false), "perform environment validation after deployment. Overrides $ORCA_VALIDATE") + f.BoolVarP(&e.deployOnlyOverrideIfEnvExists, "deploy-only-override-if-env-exists", "x", utils.GetBoolEnvVar("ORCA_DEPLOY_ONLY_OVERRIDE_IF_ENV_EXISTS", false), "if environment exists - deploy only override(s) (avoid environment update). Overrides $ORCA_DEPLOY_ONLY_OVERRIDE_IF_ENV_EXISTS") f.StringSliceVar(&e.protectedCharts, "protected-chart", []string{}, "chart name to protect from being overridden (can specify multiple)") - f.BoolVar(&e.refresh, "refresh", utils.GetBoolEnvVar("ORCA_REFRESH", false), "refresh the environment based on reference environment. Overrides $ORCA_REFRESH") - f.BoolVarP(&e.deployOnlyOverrideIfEnvExists, "deploy-only-override-if-env-exists", "x", utils.GetBoolEnvVar("ORCA_DEPLOY_ONLY_OVERRIDE_IF_ENV_EXISTS", false), "if environment exists - deploy only override(s) (avoid environment update). Overrides $ORCA_DEPLOY_ONLY_OVERRIDE_IF_ENV_EXISTS") - f.MarkDeprecated("deploy-only-override-if-env-exists", "this is now the default behavior. use --refresh to deploy all") + f.BoolVar(&e.refresh, "refresh", utils.GetBoolEnvVar("ORCA_REFRESH", false), "refresh the environment based on reference environment. Overrides $ORCA_REFRESH") + f.MarkDeprecated("refresh", "this is now the default behavior. use -x to deploy only overrides") return cmd }