From 4bf0bfa8184e8a6c81a67850bb82c272c2af9f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Bebr=C4=ABtis?= Date: Fri, 11 Oct 2024 10:58:49 +0300 Subject: [PATCH] doc updates; release listing --- cmd/ciReleaseDeploy.go | 8 +- cmd/ciReleaseDiff.go | 3 + cmd/ciReleaseList.go | 79 +++++++++++++++++++ docs/silta.md | 2 + docs/silta_ci_release.md | 2 + docs/silta_ci_release_delete.md | 2 +- docs/silta_ci_release_deploy.md | 5 +- docs/silta_ci_release_diff.md | 59 ++++++++++++++ docs/silta_ci_release_list.md | 26 ++++++ docs/silta_ci_release_validate.md | 2 +- docs/silta_config.md | 32 ++++++++ docs/silta_config_get.md | 30 +++++++ docs/silta_config_set.md | 35 ++++++++ docs/silta_scripts.md | 26 ++++++ ...ipts_elasticsearch-initcontainer-remove.md | 31 ++++++++ 15 files changed, 336 insertions(+), 6 deletions(-) create mode 100644 cmd/ciReleaseList.go create mode 100644 docs/silta_ci_release_diff.md create mode 100644 docs/silta_ci_release_list.md create mode 100644 docs/silta_config.md create mode 100644 docs/silta_config_get.md create mode 100644 docs/silta_config_set.md create mode 100644 docs/silta_scripts.md create mode 100644 docs/silta_scripts_elasticsearch-initcontainer-remove.md diff --git a/cmd/ciReleaseDeploy.go b/cmd/ciReleaseDeploy.go index f574173..1c3689f 100644 --- a/cmd/ciReleaseDeploy.go +++ b/cmd/ciReleaseDeploy.go @@ -26,6 +26,9 @@ var ciReleaseDeployCmd = &cobra.Command{ * Chart allows prepending extra configuration (to helm --values line) via "SILTA__CONFIG_VALUES" environment variable. It has to be a base64 encoded string of a silta configuration yaml file. + + * If IMAGE_PULL_SECRET is set (base64 encoded), it will be added to the + release values as imagePullSecret. `, Run: func(cmd *cobra.Command, args []string) { @@ -184,9 +187,6 @@ var ciReleaseDeployCmd = &cobra.Command{ helmFlags = fmt.Sprintf("%s --set imagePullSecret='%s'", helmFlags, imagePullSecret) } - // TODO: fix this - command := "" - if !debug { // Add helm repositories command := fmt.Sprintf("helm repo add '%s' '%s'", "wunderio", chartRepository) @@ -201,6 +201,8 @@ var ciReleaseDeployCmd = &cobra.Command{ exec.Command("bash", "-c", command).Run() } + command := "" + if chartName == "simple" || strings.HasSuffix(chartName, "/simple") { if len(nginxImageUrl) == 0 { diff --git a/cmd/ciReleaseDiff.go b/cmd/ciReleaseDiff.go index 438aa2c..15488a2 100644 --- a/cmd/ciReleaseDiff.go +++ b/cmd/ciReleaseDiff.go @@ -24,6 +24,9 @@ var ciReleaseDiffCmd = &cobra.Command{ * Chart allows prepending extra configuration (to helm --values line) via "SILTA__CONFIG_VALUES" environment variable. It has to be a base64 encoded string of a silta configuration yaml file. + + * If IMAGE_PULL_SECRET is set (base64 encoded), it will be added to the + release values as imagePullSecret. `, Run: func(cmd *cobra.Command, args []string) { diff --git a/cmd/ciReleaseList.go b/cmd/ciReleaseList.go new file mode 100644 index 0000000..a2efa7b --- /dev/null +++ b/cmd/ciReleaseList.go @@ -0,0 +1,79 @@ +package cmd + +import ( + "fmt" + "os" + + helmclient "github.com/mittwald/go-helm-client" + "github.com/spf13/cobra" + "helm.sh/helm/v3/pkg/action" + _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // gcp auth provider + + "text/tabwriter" +) + +var ciReleaseListCmd = &cobra.Command{ + Use: "list", + Short: "List releases", + Run: func(cmd *cobra.Command, args []string) { + + namespace, _ := cmd.Flags().GetString("namespace") + + homeDir, err := os.UserHomeDir() + if err != nil { + fmt.Println("cannot read user home dir") + os.Exit(1) + } + kubeConfigPath := homeDir + "/.kube/config" + + kubeConfig, err := os.ReadFile(kubeConfigPath) + if err != nil { + fmt.Println("cannot read kubeConfig from path") + os.Exit(1) + } + + helmOptions := helmclient.Options{ + Namespace: namespace, + RepositoryCache: "/tmp/.helmcache", + RepositoryConfig: "/tmp/.helmrepo", + Debug: false, + Linting: false, // Change this to false if you don't want linting. + } + + //Helm client init logic + opt := &helmclient.KubeConfClientOptions{ + Options: &helmOptions, + KubeContext: "", + KubeConfig: kubeConfig, + } + + helmClient, err := helmclient.NewClientFromKubeConf(opt) + if err != nil { + fmt.Println("Cannot create client from kubeConfig") + os.Exit(1) + } + + // List Helm releases + releases, err := helmClient.ListReleasesByStateMask(action.ListAll) + if err != nil { + fmt.Printf("Cannot list releases: %s\n", err) + os.Exit(1) + } + + writer := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', tabwriter.AlignRight) + fmt.Fprintln(writer, "NAME\tNAMESPACE\tREVISION\tUPDATED\tSTATUS\tCHART\tAPP VERSION") + + for _, release := range releases { + fmt.Fprintf(writer, "%s\t%s\t%d\t%s\t%s\t%s\t%s\n", release.Name, release.Namespace, release.Version, release.Info.LastDeployed.String(), release.Info.Status.String(), release.Chart.Name(), release.Chart.Metadata.Version) + } + + writer.Flush() + + }, +} + +func init() { + ciReleaseCmd.AddCommand(ciReleaseListCmd) + + ciReleaseListCmd.Flags().StringP("namespace", "n", "", "Project name (namespace, i.e. \"drupal-project\")") +} diff --git a/docs/silta.md b/docs/silta.md index 212c3bd..6ee9ad5 100644 --- a/docs/silta.md +++ b/docs/silta.md @@ -16,7 +16,9 @@ Silta CLI * [silta ci](silta_ci.md) - Silta CI Commands * [silta cloud](silta_cloud.md) - Kubernetes cloud related commands * [silta completion](silta_completion.md) - Generate the autocompletion script for the specified shell +* [silta config](silta_config.md) - Silta configuration commands * [silta doc](silta_doc.md) - Generate menu documentation markdown +* [silta scripts](silta_scripts.md) - Convenience scripts for silta * [silta secrets](silta_secrets.md) - Manage encrypted secret files * [silta tools](silta_tools.md) - CI tooling * [silta version](silta_version.md) - Silta CLI version diff --git a/docs/silta_ci_release.md b/docs/silta_ci_release.md index a806806..72be06c 100644 --- a/docs/silta_ci_release.md +++ b/docs/silta_ci_release.md @@ -25,8 +25,10 @@ silta ci release [flags] * [silta ci release clean-failed](silta_ci_release_clean-failed.md) - Clean failed releases * [silta ci release delete](silta_ci_release_delete.md) - Delete a release * [silta ci release deploy](silta_ci_release_deploy.md) - Deploy release +* [silta ci release diff](silta_ci_release_diff.md) - Diff release resources * [silta ci release environmentname](silta_ci_release_environmentname.md) - Return environment name * [silta ci release info](silta_ci_release_info.md) - Print release information +* [silta ci release list](silta_ci_release_list.md) - List releases * [silta ci release name](silta_ci_release_name.md) - Return release name * [silta ci release validate](silta_ci_release_validate.md) - Validate release * [silta ci release wakeup](silta_ci_release_wakeup.md) - Wake up a downscaled release diff --git a/docs/silta_ci_release_delete.md b/docs/silta_ci_release_delete.md index ad4d8ac..f41fe46 100644 --- a/docs/silta_ci_release_delete.md +++ b/docs/silta_ci_release_delete.md @@ -9,7 +9,7 @@ silta ci release delete [flags] ### Options ``` - --delete-pvcs Delete PVCs (default: false) + --delete-pvcs Delete PVCs (default: true) (default true) -h, --help help for delete --namespace string Project name (namespace, i.e. "drupal-project") --release-name string Release name diff --git a/docs/silta_ci_release_deploy.md b/docs/silta_ci_release_deploy.md index 4d50d3b..b8b1bfe 100644 --- a/docs/silta_ci_release_deploy.md +++ b/docs/silta_ci_release_deploy.md @@ -9,6 +9,9 @@ Release deployment * Chart allows prepending extra configuration (to helm --values line) via "SILTA__CONFIG_VALUES" environment variable. It has to be a base64 encoded string of a silta configuration yaml file. + + * If IMAGE_PULL_SECRET is set (base64 encoded), it will be added to the + release values as imagePullSecret. ``` @@ -20,7 +23,7 @@ silta ci release deploy [flags] ``` --branchname string Repository branchname that will be used for release name and environment name creation --chart-name string Chart name - --chart-repository string Chart repository + --chart-repository string Chart repository (default "https://storage.googleapis.com/charts.wdr.io") --chart-version string Deploy a specific chart version --cluster-domain string Base domain for cluster urls (i.e. dev.example.com) --cluster-type string Cluster type (i.e. gke, aws, aks, other) diff --git a/docs/silta_ci_release_diff.md b/docs/silta_ci_release_diff.md new file mode 100644 index 0000000..00f0349 --- /dev/null +++ b/docs/silta_ci_release_diff.md @@ -0,0 +1,59 @@ +## silta ci release diff + +Diff release resources + +### Synopsis + +Release diff command is used to compare the resources of a release with the current state of the cluster. + + * Chart allows prepending extra configuration (to helm --values line) via + "SILTA__CONFIG_VALUES" environment variable. It has to be a + base64 encoded string of a silta configuration yaml file. + + * If IMAGE_PULL_SECRET is set (base64 encoded), it will be added to the + release values as imagePullSecret. + + +``` +silta ci release diff [flags] +``` + +### Options + +``` + --branchname string Repository branchname that will be used for release name and environment name creation + --chart-name string Chart name + --chart-repository string Chart repository (default "https://storage.googleapis.com/charts.wdr.io") + --chart-version string Diff a specific chart version + --cluster-domain string Base domain for cluster urls (i.e. dev.example.com) + --cluster-type string Cluster type (i.e. gke, aws, aks, other) + --db-root-pass string Database password for root account + --db-user-pass string Database password for user account + --gitauth-password string Gitauth server password + --gitauth-username string Gitauth server username + --helm-flags string Extra flags for helm release + -h, --help help for diff + --namespace string Project name (namespace, i.e. "drupal-project") + --nginx-image-url string PHP image url + --php-image-url string PHP image url + --release-name string Release name + --release-suffix string Release name suffix for environment name creation + --repository-url string Repository url (i.e. git@github.com:wunderio/silta.git) + --shell-image-url string PHP image url + --silta-config string Silta release helm chart values + --silta-environment-name string Environment name override based on branchname and release-suffix. Used in some helm charts. + --vpc-native string VPC-native cluster (GKE specific) + --vpn-ip string VPN IP for basic auth allow list +``` + +### Options inherited from parent commands + +``` + --debug Print variables, do not execute external commands, rather print them + --use-env Use environment variables for value assignment (default true) +``` + +### SEE ALSO + +* [silta ci release](silta_ci_release.md) - CI release related commands + diff --git a/docs/silta_ci_release_list.md b/docs/silta_ci_release_list.md new file mode 100644 index 0000000..bad509f --- /dev/null +++ b/docs/silta_ci_release_list.md @@ -0,0 +1,26 @@ +## silta ci release list + +List releases + +``` +silta ci release list [flags] +``` + +### Options + +``` + -h, --help help for list + -n, --namespace string Project name (namespace, i.e. "drupal-project") +``` + +### Options inherited from parent commands + +``` + --debug Print variables, do not execute external commands, rather print them + --use-env Use environment variables for value assignment (default true) +``` + +### SEE ALSO + +* [silta ci release](silta_ci_release.md) - CI release related commands + diff --git a/docs/silta_ci_release_validate.md b/docs/silta_ci_release_validate.md index aaeb406..eede6c4 100644 --- a/docs/silta_ci_release_validate.md +++ b/docs/silta_ci_release_validate.md @@ -11,7 +11,7 @@ silta ci release validate [flags] ``` --branchname string Repository branchname that will be used for release name and environment name creation --chart-name string Chart name - --chart-repository string Chart repository + --chart-repository string Chart repository (default "https://storage.googleapis.com/charts.wdr.io") --chart-version string Deploy a specific chart version --cluster-type string Cluster type (i.e. gke, aws, aks, other) -h, --help help for validate diff --git a/docs/silta_config.md b/docs/silta_config.md new file mode 100644 index 0000000..8bb6aed --- /dev/null +++ b/docs/silta_config.md @@ -0,0 +1,32 @@ +## silta config + +Silta configuration commands + +### Synopsis + +Silta configuration commands, allows setting and getting configuration values. +Configuration is persistent and is stored in file "/home/jancis/.config/silta/config.yaml". + +``` +silta config [flags] +``` + +### Options + +``` + -h, --help help for config +``` + +### Options inherited from parent commands + +``` + --debug Print variables, do not execute external commands, rather print them + --use-env Use environment variables for value assignment (default true) +``` + +### SEE ALSO + +* [silta](silta.md) - Silta CLI +* [silta config get](silta_config_get.md) - Get configuration +* [silta config set](silta_config_set.md) - Set configuration + diff --git a/docs/silta_config_get.md b/docs/silta_config_get.md new file mode 100644 index 0000000..62deb26 --- /dev/null +++ b/docs/silta_config_get.md @@ -0,0 +1,30 @@ +## silta config get + +Get configuration + +### Synopsis + +This will print configuration information. If no arguments are provided, the entire configuration file will be printed. +If a single argument is provided, the value of the configuration key will be printed. Supports nested keys using dot notation. + +``` +silta config get [flags] +``` + +### Options + +``` + -h, --help help for get +``` + +### Options inherited from parent commands + +``` + --debug Print variables, do not execute external commands, rather print them + --use-env Use environment variables for value assignment (default true) +``` + +### SEE ALSO + +* [silta config](silta_config.md) - Silta configuration commands + diff --git a/docs/silta_config_set.md b/docs/silta_config_set.md new file mode 100644 index 0000000..d7b033c --- /dev/null +++ b/docs/silta_config_set.md @@ -0,0 +1,35 @@ +## silta config set + +Set configuration + +### Synopsis + +This will set configuration information. The first argument is the key and the second argument is the value. +If the key already exists, the value will be overwritten. Supports nested keys using dot notation. +Usage: silta config set +Example: silta config set mykey +Example: silta config set mykey myvalue +Example: silta config set mykey.subkey myvalue + + +``` +silta config set [flags] +``` + +### Options + +``` + -h, --help help for set +``` + +### Options inherited from parent commands + +``` + --debug Print variables, do not execute external commands, rather print them + --use-env Use environment variables for value assignment (default true) +``` + +### SEE ALSO + +* [silta config](silta_config.md) - Silta configuration commands + diff --git a/docs/silta_scripts.md b/docs/silta_scripts.md new file mode 100644 index 0000000..7cb20cb --- /dev/null +++ b/docs/silta_scripts.md @@ -0,0 +1,26 @@ +## silta scripts + +Convenience scripts for silta + +``` +silta scripts [flags] +``` + +### Options + +``` + -h, --help help for scripts +``` + +### Options inherited from parent commands + +``` + --debug Print variables, do not execute external commands, rather print them + --use-env Use environment variables for value assignment (default true) +``` + +### SEE ALSO + +* [silta](silta.md) - Silta CLI +* [silta scripts elasticsearch-initcontainer-remove](silta_scripts_elasticsearch-initcontainer-remove.md) - es-init-remove + diff --git a/docs/silta_scripts_elasticsearch-initcontainer-remove.md b/docs/silta_scripts_elasticsearch-initcontainer-remove.md new file mode 100644 index 0000000..e6291a2 --- /dev/null +++ b/docs/silta_scripts_elasticsearch-initcontainer-remove.md @@ -0,0 +1,31 @@ +## silta scripts elasticsearch-initcontainer-remove + +es-init-remove + +### Synopsis + +Elasticsearch init container removal from all statefulsets in the cluster. + +``` +silta scripts elasticsearch-initcontainer-remove [flags] +``` + +### Options + +``` + --dry-run Dry run (default true) + -h, --help help for elasticsearch-initcontainer-remove + --namespace string Namespace (optional) +``` + +### Options inherited from parent commands + +``` + --debug Print variables, do not execute external commands, rather print them + --use-env Use environment variables for value assignment (default true) +``` + +### SEE ALSO + +* [silta scripts](silta_scripts.md) - Convenience scripts for silta +