Skip to content

Commit

Permalink
[PCP-8898] Initial support for TP automation (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
syan-tibco authored Dec 31, 2024
1 parent ed668e2 commit a23978c
Show file tree
Hide file tree
Showing 23 changed files with 1,907 additions and 62 deletions.
2 changes: 1 addition & 1 deletion charts/generic-runner/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

apiVersion: v2
name: generic-runner
version: "1.0.5"
version: "1.0.6"
appVersion: "1.0.0"
description: generic-runner
type: application
Expand Down
3 changes: 3 additions & 0 deletions charts/generic-runner/scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ declare -xr RECIPE_FILE=recipe.yaml
# save input to recipe.yaml
function save_input() {
echo "${INPUT}" | common::yq4-get . > "${RECIPE_FILE}"
if [[ ${PIPELINE_RECIPE_PRINT} == "false" ]]; then
return 0
fi
common::info "input recipe:"
common::info "$(cat ${RECIPE_FILE})"
}
Expand Down
2 changes: 1 addition & 1 deletion charts/helm-install/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

apiVersion: v2
name: helm-install
version: "1.0.9"
version: "1.0.10"
appVersion: "1.0.0"
description: helm-install
type: application
Expand Down
3 changes: 3 additions & 0 deletions charts/helm-install/scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ declare -xr RECIPE_FILE=recipe.yaml
# save input to recipe.yaml
function save_input() {
echo "${INPUT}" | common::yq4-get . > "${RECIPE_FILE}"
if [[ ${PIPELINE_RECIPE_PRINT} == "false" ]]; then
return 0
fi
common::info "input recipe:"
common::info "$(cat ${RECIPE_FILE})"
}
Expand Down
2 changes: 1 addition & 1 deletion charts/provisioner-config-local/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ apiVersion: v2
name: provisioner-config-local
description: Platform Provisioner local config
type: application
version: "1.0.95"
version: "1.0.99"
appVersion: "2.0.0"
home: https://github.com/TIBCOSoftware/tp-helm-charts
maintainers:
Expand Down
2 changes: 1 addition & 1 deletion charts/provisioner-config-local/config/menuContent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ menuConfig:
icon: 'pi pi-th-large'
items:
- label: "Deploy DP and config o11y"
url: "/pipelines/generic-runner?title=tp-automation-o11y"
url: "/pipelines/generic-runner-tester?title=tp-automation-o11y"
config: pp-maintain-tp-automation-o11y.yaml
- label: "Pipelines"
url: "/pipelines"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# in the license file that is distributed with this file.
#

pipelineName: "TP Automation o11y"
pipelineName: "TP Automation"
description: |
This pipeline will run an automation for o11y services.
This pipeline will run an automation to create a new DP, register a DP and configure o11y service for a given DP.
The input of this recipe is user name an password.
Expand All @@ -22,19 +22,46 @@ description: |
* Config o11y service for a given DP
options:
- name: "DP user name"
- name: "GitHub token"
type: password
guiType: input
reference: "meta.guiEnv.GUI_GITHUB_TOKEN"
description: |
The GitHub token for DP to access private helm chart repo. If you deploy unreleased CP/DP; this GitHub token is a must.
- name: "DP host prefix"
type: string
guiType: input
reference: "meta.guiEnv.GUI_DP_USER_NAME"
reference: "meta.guiEnv.GUI_DP_HOST_PREFIX"
required: true
description: |
The user name of DP
- name: "DP password"
The host prefix of DP
- name: "DP user email"
type: string
guiType: input
reference: "meta.guiEnv.GUI_DP_USER_EMAIL"
required: true
description: |
The user email of DP
- name: "DP user password"
type: password
guiType: input
reference: "meta.guiEnv.GUI_DP_PASSWORD"
reference: "meta.guiEnv.GUI_DP_USER_PASSWORD"
required: true
description: |
The password of DP
The password of DP user
- name: "TP port forward"
groupIndex: 5
type: boolean
guiType: checkbox
reference: "meta.guiEnv.GUI_TP_PORT_FORWARD"
description: |
This will run kubedtl port-forward command to forward the port of ingress controller. If you change the ingress controller name; you need to update the script.
- name: "TP overwrite DNS"
groupIndex: 5
type: boolean
guiType: checkbox
reference: "meta.guiEnv.GUI_TP_OVERWRITE_DNS"
description: |
If you see DNS issue; set this to ture. Or if you want to run the tester outside of current kubernetes cluster. For VDI use 10.178.2.10 as DNS server.
recipe: |
{{ tpl (.Files.Get "recipes/tp-automation-o11y.yaml") . | indent 2 }}
{{ tpl (.Files.Get "recipes/tp-automation-o11y.yaml") . | indent 2 }}
90 changes: 58 additions & 32 deletions charts/provisioner-config-local/recipes/tp-automation-o11y.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,69 @@ kind: generic-runner
meta:
guiEnv:
note: "tp-automation-o11y"
GUI_TP_CLUSTER_NAME: ''
GUI_PIPELINE_LOG_DEBUG: false
GUI_DP_USER_NAME: ""
GUI_DP_PASSWORD: ""
GUI_TP_CLUSTER_NAME: ''
GUI_GITHUB_TOKEN: ""
GUI_DP_HOST_PREFIX: "cp-sub1"
GUI_DP_USER_EMAIL: "[email protected]"
GUI_DP_USER_PASSWORD: "Tibco@123"
GUI_TP_PORT_FORWARD: true
GUI_TP_OVERWRITE_DNS: false
globalEnvVariable:
REPLACE_RECIPE: true
GITHUB_TOKEN: ${GUI_GITHUB_TOKEN:-""}
PIPELINE_LOG_DEBUG: ${GUI_PIPELINE_LOG_DEBUG}
PIPELINE_CHECK_DOCKER_STATUS: false
TP_CLUSTER_NAME: ${GUI_TP_CLUSTER_NAME}
DP_USER_NAME: ${GUI_DP_USER_NAME:-""}
DP_PASSWORD: ${GUI_DP_PASSWORD:-""}
TP_CLUSTER_NAME: ${GUI_TP_CLUSTER_NAME:-"on-prem"}
DP_HOST_PREFIX: ${GUI_DP_HOST_PREFIX:-"cp-sub1"}
DP_USER_EMAIL: ${GUI_DP_USER_EMAIL:-"[email protected]"}
DP_USER_PASSWORD: ${GUI_DP_USER_PASSWORD:-"Tibco@123"}
CP_ADMIN_EMAIL: ${GUI_CP_ADMIN_EMAIL:-"[email protected]"}
CP_ADMIN_PASSWORD: ${GUI_CP_ADMIN_PASSWORD:-"Tibco@123"}
PYTHON_FILE_INPUT_NAME: py-scripts.yaml
PYTHON_FILE_ENTRY_POINT: run.py
TP_PORT_FORWARD: ${GUI_TP_PORT_FORWARD:-true}
TP_OVERWRITE_DNS: ${GUI_TP_OVERWRITE_DNS:-false}
tasks:
- condition: true
clusters:
- name: ${TP_CLUSTER_NAME}
script:
ignoreErrors: false
fileName: script.sh
content: |
input_yaml="${PYTHON_FILE_INPUT_NAME}"
yq eval 'to_entries | .[] | .key + " " + (.value)' "$input_yaml" | while read -r file_name decoded_content; do
if [[ -n $file_name ]]; then
echo "$decoded_content" | base64 -d > "$file_name"
echo "Created file: $file_name"
fi
done
python ${PYTHON_FILE_ENTRY_POINT}
payload:
base64Encoded: false
fileName: ${PYTHON_FILE_INPUT_NAME}
content: |
{{- $root := . }}
{{- range $path, $bytes := .Files.Glob "scripts/o11y/*" }}
{{ base $path }}: |
{{ $root.Files.Get $path | b64enc | indent 2 -}}
{{- end }}
- condition: ${TP_OVERWRITE_DNS} # this is used for overwrite DNS
clusters:
- name: ${TP_CLUSTER_NAME}
script:
ignoreErrors: false
fileName: script.sh
content: |
echo "nameserver 10.178.2.10" > /etc/resolv.conf
- condition: ${TP_PORT_FORWARD} # this is used for run pipeline locally
clusters:
- name: ${TP_CLUSTER_NAME}
script:
ignoreErrors: false
fileName: script.sh
content: |
nohup kubectl port-forward -n ingress-system --address 0.0.0.0 service/ingress-nginx-controller 80:http 443:https &
- condition: true
clusters:
- name: ${TP_CLUSTER_NAME}
script:
ignoreErrors: false
fileName: script.sh
content: |
input_yaml="${PYTHON_FILE_INPUT_NAME}"
yq eval 'to_entries | .[] | .key + " " + (.value)' "$input_yaml" | while read -r file_name decoded_content; do
if [[ -n $file_name ]]; then
echo "$decoded_content" | base64 -d > "$file_name"
echo "Created file: $file_name"
fi
done
pip install -r requirements.txt
python ${PYTHON_FILE_ENTRY_POINT}
payload:
base64Encoded: false
fileName: ${PYTHON_FILE_INPUT_NAME}
content: |
{{- $root := . }}
{{- range $path, $bytes := .Files.Glob "scripts/o11y/*" }}
{{ base $path }}: |
{{ $root.Files.Get $path | b64enc | indent 2 -}}
{{- end }}
57 changes: 57 additions & 0 deletions charts/provisioner-config-local/scripts/o11y/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Test Python script in Docker container

```shell
# Optional, GITHUB_TOKEN is required for private repo
export GITHUB_TOKEN=""

# Optional, if you want to use different host prefix, email and password, you can set them here
export HOST_PREFIX="cp-sub1"
export USER_EMAIL="[email protected]"
export USER_PASSWORD="Tibco@123"

# Optional, if you want to use different admin email and password, you can set them here
export ADMIN_EMAIL="[email protected]"
export ADMIN_PASSWORD="Tibco@123"

cd charts
helm template provisioner-config-local provisioner-config-local | yq eval .data | yq eval '.["pp-maintain-tp-automation-o11y.yaml"]' | yq eval .recipe > recipe.yaml
export PIPELINE_INPUT_RECIPE="$(pwd)/recipe.yaml"
export PIPELINE_DOCKER_IMAGE="ghcr.io/tibcosoftware/platform-provisioner/platform-provisioner:v1.0.0-tester"
export PIPELINE_ON_PREM_KUBECONFIG_FILE_NAME=config
../dev/platform-provisioner.sh
```

## Test Python script in Mac

```shell

# Install pyenv and python 3.12.8 if you don't have it(Only need to run once)
brew update && brew install pyenv
pyenv install 3.12.8
pyenv global 3.12.8
python --version

cd charts/provisioner-config-local/scripts/o11y
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

# Install playwright (Only need to run once)
playwright install

# Optional, GITHUB_TOKEN is required for private repo
export GITHUB_TOKEN=""

# Optional, if you want to use different host prefix, email and password, you can set them here
export HOST_PREFIX="cp-sub1"
export USER_EMAIL="[email protected]"
export USER_PASSWORD="Tibco@123"

# Optional, if you want to use different admin email and password, you can set them here
export ADMIN_EMAIL="[email protected]"
export ADMIN_PASSWORD="Tibco@123"

# Optional, if you want to see the browser UI during the test
export HEADLESS="false"
python run.py
```
38 changes: 38 additions & 0 deletions charts/provisioner-config-local/scripts/o11y/color_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from colorama import Fore, Style, init

# Initialize colorama for cross-platform support
init(autoreset=True)

class ColorLogger:
@staticmethod
def info(message):
print(f"{Fore.LIGHTBLUE_EX}[INFO] {message}")

@staticmethod
def success(message):
print(f"{Fore.GREEN}[INFO] {message}")

@staticmethod
def warning(message):
print(f"{Fore.YELLOW}[WARNING] {message}")

@staticmethod
def error(message):
print(f"{Fore.RED}[ERROR] {message}")

@staticmethod
def debug(message):
print(f"{Fore.CYAN}[DEBUG] {message}")

@staticmethod
def critical(message):
print(f"{Fore.MAGENTA}[CRITICAL] {message}")

@staticmethod
def custom(message, color):
"""
Print a custom-colored message.
:param message: The message to print.
:param color: The color from `colorama.Fore` (e.g., Fore.BLUE).
"""
print(f"{color}{message}{Style.RESET_ALL}")
Loading

0 comments on commit a23978c

Please sign in to comment.