From 5dae5e52b9631a8e9b95640cd9203c10fc883efa Mon Sep 17 00:00:00 2001 From: "SerDigital64 (Max)" Date: Sat, 2 Nov 2024 10:53:40 +0100 Subject: [PATCH] feat: add argocd cmds (#16) --- CHANGELOG.md | 5 +++ src/argocd/argocd-app-list | 60 +++++++++++++++++++++++++ src/argocd/argocd-app-sync | 63 ++++++++++++++++++++++++++ src/argocd/argocd-cli-context-set | 74 +++++++++++++++++++++++++++++++ src/argocd/argocd-cluster-list | 60 +++++++++++++++++++++++++ src/argocd/argocd-lib | 46 ++++++++++++------- src/argocd/argocd-project-list | 61 +++++++++++++++++++++++++ src/argocd/argocd-repo-list | 60 +++++++++++++++++++++++++ src/argocd/argocd-window-list | 64 ++++++++++++++++++++++++++ src/pgsql/pgsql-index-info | 6 +-- src/pgsql/pgsql-query-info | 8 ++-- 11 files changed, 484 insertions(+), 23 deletions(-) create mode 100755 src/argocd/argocd-app-list create mode 100755 src/argocd/argocd-app-sync create mode 100755 src/argocd/argocd-cli-context-set create mode 100755 src/argocd/argocd-cluster-list create mode 100755 src/argocd/argocd-project-list create mode 100755 src/argocd/argocd-repo-list create mode 100755 src/argocd/argocd-window-list diff --git a/CHANGELOG.md b/CHANGELOG.md index d3abf20..2266648 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.13.0] + +- ArgoCD + - Added app,repo,cli,cluster,project,window commands + ## [0.12.0] ### Added diff --git a/src/argocd/argocd-app-list b/src/argocd/argocd-app-list new file mode 100755 index 0000000..4443df8 --- /dev/null +++ b/src/argocd/argocd-app-list @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# template: 1.0.0 +# template-import: 1.0.0 +####################################### +# ArgoCD / App / List +# +# Version: 1.0.0 +# +####################################### +# Copyright [2024] [serdigital64@gmail.com] +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################### + +# +# Imports +# + +declare S64_CORE_PATH_ROOT="${S64_CORE_PATH_ROOT:-/opt/sysop64}" +# shellcheck source-path=SCRIPTDIR/.. +source "${S64_CORE_PATH_ROOT}/core/core-lib" || { echo "Error: unable to load module library" && exit 1; } +# shellcheck source-path=SCRIPTDIR/.. +source "${S64_CORE_PATH_ROOT}/argocd/argocd-lib" || { echo "Error: unable to load module library" && exit 1; } +# shellcheck disable=SC2015 source-path=SCRIPTDIR/../../lib/bl64 +source "${S64_CORE_PATH_BL64}/bashlib64-core.bash" || + { echo "Error: unable to load bashlib64" && exit 1; } + +# +# Functions +# + +function initialize() { + bl64_dbg_app_show_function + s64_argocd_lib_setup +} + +# +# Main +# + +declare command='argocd-app-list' + +bl64_dbg_set_level "$S64_CORE_SET_DEBUG" && bl64_msg_set_level "$S64_CORE_SET_VERBOSE" || exit $? +initialize || exit $? + +bl64_msg_show_batch_start "$command" +s64_argocd_lib_run_argocd \ + app \ + list +bl64_msg_show_batch_finish $? "$command" diff --git a/src/argocd/argocd-app-sync b/src/argocd/argocd-app-sync new file mode 100755 index 0000000..169627a --- /dev/null +++ b/src/argocd/argocd-app-sync @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +# template: 1.0.0 +# template-import: 1.0.0 +####################################### +# ArgoCD / App / Sync +# +# Version: 1.0.0 +# +####################################### +# Copyright [2024] [serdigital64@gmail.com] +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################### + +# +# Imports +# + +declare S64_CORE_PATH_ROOT="${S64_CORE_PATH_ROOT:-/opt/sysop64}" +# shellcheck source-path=SCRIPTDIR/.. +source "${S64_CORE_PATH_ROOT}/core/core-lib" || { echo "Error: unable to load module library" && exit 1; } +# shellcheck source-path=SCRIPTDIR/.. +source "${S64_CORE_PATH_ROOT}/argocd/argocd-lib" || { echo "Error: unable to load module library" && exit 1; } +# shellcheck disable=SC2015 source-path=SCRIPTDIR/../../lib/bl64 +source "${S64_CORE_PATH_BL64}/bashlib64-core.bash" || + { echo "Error: unable to load bashlib64" && exit 1; } + +# +# Functions +# + +function initialize() { + bl64_dbg_app_show_function + bl64_check_parameter 'app_name' && + s64_argocd_lib_setup +} + +# +# Main +# + +declare command='argocd-app-sync' +declare app_name="${1:-}" + +bl64_dbg_set_level "$S64_CORE_SET_DEBUG" && bl64_msg_set_level "$S64_CORE_SET_VERBOSE" || exit $? +initialize || exit $? + +bl64_msg_show_batch_start "$command" +s64_argocd_lib_run_argocd \ + app \ + sync \ + "$app_name" +bl64_msg_show_batch_finish $? "$command" diff --git a/src/argocd/argocd-cli-context-set b/src/argocd/argocd-cli-context-set new file mode 100755 index 0000000..06a8514 --- /dev/null +++ b/src/argocd/argocd-cli-context-set @@ -0,0 +1,74 @@ +#!/usr/bin/env bash +# template: 1.0.0 +# template-import: 1.0.0 +####################################### +# ArgoCD / CLI / Context set +# +# Version: 1.0.0 +# +####################################### +# Copyright [2024] [serdigital64@gmail.com] +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################### + +# +# Imports +# + +declare S64_CORE_PATH_ROOT="${S64_CORE_PATH_ROOT:-/opt/sysop64}" +# shellcheck source-path=SCRIPTDIR/.. +source "${S64_CORE_PATH_ROOT}/core/core-lib" || { echo "Error: unable to load module library" && exit 1; } +# shellcheck source-path=SCRIPTDIR/.. +source "${S64_CORE_PATH_ROOT}/argocd/argocd-lib" || { echo "Error: unable to load module library" && exit 1; } +# shellcheck disable=SC2015 source-path=SCRIPTDIR/../../lib/bl64 +source "${S64_CORE_PATH_BL64}/bashlib64-core.bash" || + { echo "Error: unable to load bashlib64" && exit 1; } + +# +# Functions +# + +function initialize() { + bl64_dbg_app_show_function + s64_argocd_lib_setup +} + +# +# Main +# + +declare command='argocd-cli-context-set' + +bl64_dbg_set_level "$S64_CORE_SET_DEBUG" && bl64_msg_set_level "$S64_CORE_SET_VERBOSE" || exit $? +initialize || exit $? + +bl64_msg_show_batch_start "$command" +bl64_msg_show_setup \ + 'Configuring KubeCTL context for ArgoCD CLI' \ + 'S64_ARGOCD_SET_CONTEXT_CLUSTER' \ + 'S64_ARGOCD_SET_CONTEXT_NAMESPACE' \ + 'S64_ARGOCD_SET_CONTEXT_NAME' + +bl64_k8s_run_kubectl \ + "$BL64_VAR_DEFAULT" \ + config set-context \ + --cluster="$S64_ARGOCD_SET_CONTEXT_CLUSTER" \ + --namespace="$S64_ARGOCD_SET_CONTEXT_NAMESPACE" \ + "$S64_ARGOCD_SET_CONTEXT_NAME" && + bl64_k8s_run_kubectl \ + "$BL64_VAR_DEFAULT" \ + config use-context \ + "$S64_ARGOCD_SET_CONTEXT_NAME" + +bl64_msg_show_batch_finish $? "$command" diff --git a/src/argocd/argocd-cluster-list b/src/argocd/argocd-cluster-list new file mode 100755 index 0000000..f8bceea --- /dev/null +++ b/src/argocd/argocd-cluster-list @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# template: 1.0.0 +# template-import: 1.0.0 +####################################### +# ArgoCD / Cluster / List +# +# Version: 1.0.0 +# +####################################### +# Copyright [2024] [serdigital64@gmail.com] +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################### + +# +# Imports +# + +declare S64_CORE_PATH_ROOT="${S64_CORE_PATH_ROOT:-/opt/sysop64}" +# shellcheck source-path=SCRIPTDIR/.. +source "${S64_CORE_PATH_ROOT}/core/core-lib" || { echo "Error: unable to load module library" && exit 1; } +# shellcheck source-path=SCRIPTDIR/.. +source "${S64_CORE_PATH_ROOT}/argocd/argocd-lib" || { echo "Error: unable to load module library" && exit 1; } +# shellcheck disable=SC2015 source-path=SCRIPTDIR/../../lib/bl64 +source "${S64_CORE_PATH_BL64}/bashlib64-core.bash" || + { echo "Error: unable to load bashlib64" && exit 1; } + +# +# Functions +# + +function initialize() { + bl64_dbg_app_show_function + s64_argocd_lib_setup +} + +# +# Main +# + +declare command='argocd-cluster-list' + +bl64_dbg_set_level "$S64_CORE_SET_DEBUG" && bl64_msg_set_level "$S64_CORE_SET_VERBOSE" || exit $? +initialize || exit $? + +bl64_msg_show_batch_start "$command" +s64_argocd_lib_run_argocd \ + cluster \ + list +bl64_msg_show_batch_finish $? "$command" diff --git a/src/argocd/argocd-lib b/src/argocd/argocd-lib index 3e0d019..b637fa2 100755 --- a/src/argocd/argocd-lib +++ b/src/argocd/argocd-lib @@ -3,7 +3,7 @@ ####################################### # ArgoCD / Lib # -# Version: 1.0.0 +# Version: 1.1.0 # ####################################### # Copyright [2024] [serdigital64@gmail.com] @@ -21,6 +21,19 @@ # limitations under the License. ####################################### +# +# Imports +# + +# shellcheck disable=SC2015 source-path=SCRIPTDIR/../../lib/bl64 +source "${S64_CORE_PATH_BL64}/bashlib64-module-fmt.bash" && + source "${S64_CORE_PATH_BL64}/bashlib64-module-txt.bash" && + source "${S64_CORE_PATH_BL64}/bashlib64-module-xsv.bash" && + source "${S64_CORE_PATH_BL64}/bashlib64-module-fs.bash" && + source "${S64_CORE_PATH_BL64}/bashlib64-module-k8s.bash" && + source "${S64_CORE_PATH_BL64}/bashlib64-module-bsh.bash" || + { echo "Error: unable to load bashlib64" && exit 1; } + # # Globals # @@ -28,37 +41,38 @@ # shellcheck disable=SC2034 { declare S64_ARGOCD_PATH_CLI="${S64_ARGOCD_PATH_CLI:-}" + # Global Settings + declare S64_ARGOCD_SET_CONNECTION='--core' + declare S64_ARGOCD_SET_CONTEXT_CLUSTER="${S64_ARGOCD_SET_CONTEXT_CLUSTER:-}" + declare S64_ARGOCD_SET_CONTEXT_NAMESPACE="${S64_ARGOCD_SET_CONTEXT_NAMESPACE:-argocd}" + declare S64_ARGOCD_SET_CONTEXT_NAME="${S64_ARGOCD_SET_CONTEXT_NAME:-argocdcli}" } # # Functions # -function s64_X_MODULE_X_lib_setup() { +function s64_argocd_lib_setup() { bl64_dbg_app_show_function + + bl64_k8s_setup && + bl64_check_export 'S64_ARGOCD_SET_CONTEXT_CLUSTER' || + return $? + if [[ -z "$S64_ARGOCD_PATH_CLI" ]]; then - if [[ -x '/home/linuxbrew/.linuxbrew/bin/argocd' ]]; then - S64_ARGOCD_PATH_CLI='/home/linuxbrew/.linuxbrew/bin/argocd' - elif [[ -x '/opt/homebrew/bin/argocd' ]]; then - S64_ARGOCD_PATH_CLI='/opt/homebrew/bin/argocd' - elif [[ -x '/usr/local/bin/argocd' ]]; then - S64_ARGOCD_PATH_CLI='/usr/local/bin/argocd' - elif [[ -x '/usr/bin/argocd' ]]; then - S64_ARGOCD_PATH_CLI='/usr/bin/argocd' - else - bl64_check_alert_resource_not_found 'argocd' - return $? - fi + S64_ARGOCD_PATH_CLI="$(bl64_bsh_command_locate 'argocd')" else - bl64_check_command "$S64_ARGOCD_PATH_CLI" || - return $? + bl64_check_command "$S64_ARGOCD_PATH_CLI" fi } function s64_argocd_lib_run_argocd() { bl64_dbg_app_show_function "$@" bl64_dbg_app_trace_start + # shellcheck disable=SC2086 "$S64_ARGOCD_PATH_CLI" \ + --kube-context="$S64_ARGOCD_SET_CONTEXT_NAME" \ + $S64_ARGOCD_SET_CONNECTION \ "$@" bl64_dbg_app_trace_stop } diff --git a/src/argocd/argocd-project-list b/src/argocd/argocd-project-list new file mode 100755 index 0000000..ff66960 --- /dev/null +++ b/src/argocd/argocd-project-list @@ -0,0 +1,61 @@ + +#!/usr/bin/env bash +# template: 1.0.0 +# template-import: 1.0.0 +####################################### +# ArgoCD / Project / List +# +# Version: 1.0.0 +# +####################################### +# Copyright [2024] [serdigital64@gmail.com] +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################### + +# +# Imports +# + +declare S64_CORE_PATH_ROOT="${S64_CORE_PATH_ROOT:-/opt/sysop64}" +# shellcheck source-path=SCRIPTDIR/.. +source "${S64_CORE_PATH_ROOT}/core/core-lib" || { echo "Error: unable to load module library" && exit 1; } +# shellcheck source-path=SCRIPTDIR/.. +source "${S64_CORE_PATH_ROOT}/argocd/argocd-lib" || { echo "Error: unable to load module library" && exit 1; } +# shellcheck disable=SC2015 source-path=SCRIPTDIR/../../lib/bl64 +source "${S64_CORE_PATH_BL64}/bashlib64-core.bash" || + { echo "Error: unable to load bashlib64" && exit 1; } + +# +# Functions +# + +function initialize() { + bl64_dbg_app_show_function + s64_argocd_lib_setup +} + +# +# Main +# + +declare command='argocd-project-list' + +bl64_dbg_set_level "$S64_CORE_SET_DEBUG" && bl64_msg_set_level "$S64_CORE_SET_VERBOSE" || exit $? +initialize || exit $? + +bl64_msg_show_batch_start "$command" +s64_argocd_lib_run_argocd \ + project \ + list +bl64_msg_show_batch_finish $? "$command" diff --git a/src/argocd/argocd-repo-list b/src/argocd/argocd-repo-list new file mode 100755 index 0000000..08df35a --- /dev/null +++ b/src/argocd/argocd-repo-list @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# template: 1.0.0 +# template-import: 1.0.0 +####################################### +# ArgoCD / Repo / List +# +# Version: 1.0.0 +# +####################################### +# Copyright [2024] [serdigital64@gmail.com] +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################### + +# +# Imports +# + +declare S64_CORE_PATH_ROOT="${S64_CORE_PATH_ROOT:-/opt/sysop64}" +# shellcheck source-path=SCRIPTDIR/.. +source "${S64_CORE_PATH_ROOT}/core/core-lib" || { echo "Error: unable to load module library" && exit 1; } +# shellcheck source-path=SCRIPTDIR/.. +source "${S64_CORE_PATH_ROOT}/argocd/argocd-lib" || { echo "Error: unable to load module library" && exit 1; } +# shellcheck disable=SC2015 source-path=SCRIPTDIR/../../lib/bl64 +source "${S64_CORE_PATH_BL64}/bashlib64-core.bash" || + { echo "Error: unable to load bashlib64" && exit 1; } + +# +# Functions +# + +function initialize() { + bl64_dbg_app_show_function + s64_argocd_lib_setup +} + +# +# Main +# + +declare command='argocd-repo-list' + +bl64_dbg_set_level "$S64_CORE_SET_DEBUG" && bl64_msg_set_level "$S64_CORE_SET_VERBOSE" || exit $? +initialize || exit $? + +bl64_msg_show_batch_start "$command" +s64_argocd_lib_run_argocd \ + repo \ + list +bl64_msg_show_batch_finish $? "$command" diff --git a/src/argocd/argocd-window-list b/src/argocd/argocd-window-list new file mode 100755 index 0000000..eda2fa0 --- /dev/null +++ b/src/argocd/argocd-window-list @@ -0,0 +1,64 @@ +#!/usr/bin/env bash +# template: 1.0.0 +# template-import: 1.0.0 +####################################### +# ArgoCD / Window / List +# +# Version: 1.0.0 +# +####################################### +# Copyright [2024] [serdigital64@gmail.com] +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################### + +# +# Imports +# + +declare S64_CORE_PATH_ROOT="${S64_CORE_PATH_ROOT:-/opt/sysop64}" +# shellcheck source-path=SCRIPTDIR/.. +source "${S64_CORE_PATH_ROOT}/core/core-lib" || { echo "Error: unable to load module library" && exit 1; } +# shellcheck source-path=SCRIPTDIR/.. +source "${S64_CORE_PATH_ROOT}/argocd/argocd-lib" || { echo "Error: unable to load module library" && exit 1; } +# shellcheck disable=SC2015 source-path=SCRIPTDIR/../../lib/bl64 +source "${S64_CORE_PATH_BL64}/bashlib64-core.bash" || + { echo "Error: unable to load bashlib64" && exit 1; } + +# +# Functions +# + +function initialize() { + bl64_dbg_app_show_function + bl64_check_parameter 'project_name' && + s64_argocd_lib_setup +} + +# +# Main +# + +declare command='argocd-window-list' +declare project_name="${1:-}" + +bl64_dbg_set_level "$S64_CORE_SET_DEBUG" && bl64_msg_set_level "$S64_CORE_SET_VERBOSE" || exit $? +initialize || exit $? + +bl64_msg_show_batch_start "$command" +s64_argocd_lib_run_argocd \ + proj \ + windows \ + list \ + "$project_name" +bl64_msg_show_batch_finish $? "$command" diff --git a/src/pgsql/pgsql-index-info b/src/pgsql/pgsql-index-info index d706055..f55ee47 100755 --- a/src/pgsql/pgsql-index-info +++ b/src/pgsql/pgsql-index-info @@ -113,9 +113,9 @@ function help() { -e : Describe index -k : Check index status ' ' - -o Host : Host FQDN. Alternative shell-env: S64_PGSQL_SERVER_HOST - -p Port : DB Port. Alternative shell-ehv: S64_PGSQL_SERVER_PORT - -u User : DB User. Alternative shell-ehv: S64_PGSQL_SERVER_USER + -o Host : Host FQDN. Alternative shell-env: S64_PGSQL_SERVER_HOST + -p Port : DB Port. Alternative shell-ehv: S64_PGSQL_SERVER_PORT + -u User : DB User. Alternative shell-ehv: S64_PGSQL_SERVER_USER -b DB : DB Name. Alternative shell-ehv: S64_PGSQL_DB_NAME -x Index : DB Table. -h : Show help diff --git a/src/pgsql/pgsql-query-info b/src/pgsql/pgsql-query-info index 404f03a..e3e08db 100755 --- a/src/pgsql/pgsql-query-info +++ b/src/pgsql/pgsql-query-info @@ -95,11 +95,11 @@ function help() { '-a [-o Host] [-p Port] [-u User] [-b DB] [-V Verbose] [-D Debug] [-h]' \ 'PGSQL / Query / Info' \ ' - -a : Show active + -a : Show active queries ' ' - -o Host : Host FQDN. Alternative shell-env: S64_PGSQL_SERVER_HOST - -p Port : DB Port. Alternative shell-ehv: S64_PGSQL_SERVER_PORT - -u User : DB User. Alternative shell-ehv: S64_PGSQL_SERVER_USER + -o Host : Host FQDN. Alternative shell-env: S64_PGSQL_SERVER_HOST + -p Port : DB Port. Alternative shell-ehv: S64_PGSQL_SERVER_PORT + -u User : DB User. Alternative shell-ehv: S64_PGSQL_SERVER_USER -b DB : DB Name. Alternative shell-ehv: S64_PGSQL_DB_NAME -h : Show help ' '