Skip to content

Commit

Permalink
[minor] Automate the HADR setup during provisioning (#1482)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnivedithaa authored Mar 4, 2025
1 parent 21b0712 commit 46e3b51
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files": "^.secrets.baseline$",
"lines": null
},
"generated_at": "2025-02-19T10:22:06Z",
"generated_at": "2025-02-21T13:16:08Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down Expand Up @@ -192,7 +192,7 @@
"hashed_secret": "1459943ba5fd876f7ef6e48f566a40b448a2bf08",
"is_secret": false,
"is_verified": false,
"line_number": 473,
"line_number": 477,
"type": "Secret Keyword",
"verified_result": null
}
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ Documentation
We welcome every Maximo Application Suite users, developers and enthusiasts to contribute to the MAS Command Line Interface while fixing code issues and implementing new automated functionalities.

You can contribute to this collection by raising [a new issue](https://github.com/ibm-mas/cli/issues) with suggestions on how to make our MAS automation engine even better, or if you want to become a new code contributor, please refer to the [Contributing Guidelines](CONTRIBUTING.md) and learn more about how to get started.

8 changes: 8 additions & 0 deletions image/cli/mascli/functions/gitops_db2u_database
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ IBM DB2U:
--is-replica-task ${COLOR_YELLOW}IS_REPLICA_TASK${TEXT_RESET} To check if this is invoked by replica task
--mas-annotations ${COLOR_YELLOW}MAS_ANNOTATIONS${TEXT_RESET} MAS Annotations
--auto-backup ${COLOR_YELLOW}AUTO_BACKUP${TEXT_RESET} Flag whether to install the Auto DB2 backup feature or not
--manually-set-enhanced-hadr ${COLOR_YELLOW}MANUALLY_SET_ENHANCED_HADR${TEXT_RESET} Flag to indicate whether enhanced HADR was configured manually
Secrets Manager:
--secrets-path ${COLOR_YELLOW}SECRETS_PATH${TEXT_RESET} Secrets Manager path
Expand Down Expand Up @@ -293,6 +294,9 @@ function gitops_db2u_database_noninteractive() {
--auto-backup)
export AUTO_BACKUP=$1 && shift
;;
--manually-set-enhanced-hadr)
export MANUALLY_SET_ENHANCED_HADR=$1 && shift
;;


# Automatic GitHub Push
Expand Down Expand Up @@ -506,6 +510,9 @@ DB2_WORKLOAD: '${DB2_WORKLOAD}'"
if [[ -z $AUTO_BACKUP ]]; then
export AUTO_BACKUP=false
fi
if [[ -z $MANUALLY_SET_ENHANCED_HADR ]]; then
export MANUALLY_SET_ENHANCED_HADR=false
fi
export DB2_NAMESPACE="db2u-${MAS_INSTANCE_ID}"
export DB2_DBNAME=${DB2_DBNAME:-"BLUDB"}
export JDBC_ROUTE=${JDBC_ROUTE:-"default"}
Expand Down Expand Up @@ -603,6 +610,7 @@ DB2_WORKLOAD: '${DB2_WORKLOAD}'"
echo_reset_dim "is-replica-task ............................... ${COLOR_MAGENTA}${IS_REPLICA_TASK}"
echo_reset_dim "mas-annotations ............................... ${COLOR_MAGENTA}${MAS_ANNOTATIONS}"
echo_reset_dim "auto-backup ................................... ${COLOR_MAGENTA}${AUTO_BACKUP}"
echo_reset_dim "manually-set-enhanced-hadr .................... ${COLOR_MAGENTA}${MANUALLY_SET_ENHANCED_HADR}"
reset_colors


Expand Down
14 changes: 13 additions & 1 deletion image/cli/mascli/functions/gitops_deprovision_db2u_database
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ GitOps Configuration:
-c, --cluster-id ${COLOR_YELLOW}CLUSTER_ID${TEXT_RESET} Cluster ID
-m, --mas-instance-id ${COLOR_YELLOW}MAS_INSTANCE_ID${TEXT_RESET} IBM Suite Maximo Application Suite Instance ID
--mas-app-id ${COLOR_YELLOW}MAS_APP_ID${TEXT_RESET} IBM Suite Maximo Application Suite App that uses this db2u instance
--is-replica-task ${COLOR_YELLOW}IS_REPLICA_TASK${TEXT_RESET} To deprovision standby database
Secrets Manager:
--secrets-path ${COLOR_YELLOW}SECRETS_PATH${TEXT_RESET} Secrets Manager path
Expand Down Expand Up @@ -88,6 +89,9 @@ function gitops_deprovision_db2u_database_noninteractive() {
--db2-instance-name)
export DB2_INSTANCE_NAME=$1 && shift
;;
--is-replica-task)
export IS_REPLICA_TASK=$1 && shift
;;

# Automatic GitHub Push
-P|--github-push)
Expand Down Expand Up @@ -136,8 +140,15 @@ function gitops_deprovision_db2u_database_noninteractive() {
[[ -z "$GITHUB_REPO" ]] && gitops_deprovision_db2u_database_help "GITHUB_REPO is not set"
[[ -z "$GIT_BRANCH" ]] && gitops_deprovision_db2u_database_help "GIT_BRANCH is not set"
fi
if [[ -z $IS_REPLICA_TASK ]]; then
export IS_REPLICA_TASK='false'
fi
if [[ -z $DB2_INSTANCE_NAME ]]; then
export DB2_INSTANCE_NAME=db2wh-${MAS_INSTANCE_ID}-${MAS_APP_ID}
if [[ $IS_REPLICA_TASK == 'true' ]]; then
export DB2_INSTANCE_NAME=db2wh-${MAS_INSTANCE_ID}-${MAS_APP_ID}-sdb
else
export DB2_INSTANCE_NAME=db2wh-${MAS_INSTANCE_ID}-${MAS_APP_ID}
fi
fi
}

Expand Down Expand Up @@ -207,6 +218,7 @@ function gitops_deprovision_db2u_database() {
echo "${TEXT_DIM}"
echo_h2 "DB2 Cluster Configuration" " "
echo_reset_dim "db2-instance-name ....................... ${COLOR_MAGENTA}${DB2_INSTANCE_NAME}"
echo_reset_dim "is-replica-task ......................... ${COLOR_MAGENTA}${IS_REPLICA_TASK}"
reset_colors

TEMP_DIR=$GITOPS_WORKING_DIR/tmp-deprovision-db2u-database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,43 @@ db2_tls_version: {{DB2_TLS_VERSION}}
db2_table_org: {{DB2_TABLE_ORG}}
db2_node_label: {{DB2_NODE_LABEL}}
db2_dedicated_node: {{DB2_DEDICATED_NODE}}
replica_db: {{REPLICA_DB}}
db2_instance_registry:
{% filter indent(width=2) -%}
{{ DB2_INSTANCE_REGISTRY }}
{%- endfilter %}
{% if REPLICA_DB == 'true' %}
{% filter indent(width=2) -%}
DB2_STANDBY_ISO: 'UR'
DB2_HADR_ROS: 'ON'
DB2_HADR_ROS_AVOID_REPLAY_ONLY_WINDOW: 'ON'
{%- endfilter %}
{% endif %}
db2_database_db_config:
{% filter indent(width=2) -%}
{{ DB2_DATABASE_DB_CONFIG }}
{%- endfilter %}
{% if REPLICA_DB == 'true' %}
{% filter indent(width=2) -%}
HADR_SYNCMODE: 'NEARSYNC'
HADR_REMOTE_INST: 'db2inst1'
LOGINDEXBUILD: 'ON'
{% if MANUALLY_SET_ENHANCED_HADR != 'true' %}
HADR_LOCAL_HOST: 'c-{{DB2_INSTANCE_NAME}}-db2u-0|c-{{DB2_INSTANCE_NAME}}-db2u-0.c-{{DB2_INSTANCE_NAME}}-db2u-internal.{{DB2_NAMESPACE}}.svc.cluster.local'
{% if 'sdb' in DB2_INSTANCE_NAME %}
HADR_LOCAL_SVC: '60007|60007'
HADR_REMOTE_HOST: 'c-{{DB2_INSTANCE_NAME[:-4]}}-db2u-0.c-{{DB2_INSTANCE_NAME[:-4]}}-db2u-internal.{{DB2_NAMESPACE}}.svc.cluster.local'
HADR_REMOTE_SVC: '60006'
HADR_TARGET_LIST: 'c-{{DB2_INSTANCE_NAME[:-4]}}-db2u-0.c-{{DB2_INSTANCE_NAME[:-4]}}-db2u-internal.{{DB2_NAMESPACE}}.svc.cluster.local:60006'
{% else %}
HADR_LOCAL_SVC: '60006|60006'
HADR_REMOTE_HOST: 'c-{{DB2_INSTANCE_NAME}}-sdb-db2u-0.c-{{DB2_INSTANCE_NAME}}-sdb-db2u-internal.{{DB2_NAMESPACE}}.svc.cluster.local'
HADR_REMOTE_SVC: '60007'
HADR_TARGET_LIST: 'c-{{DB2_INSTANCE_NAME}}-sdb-db2u-0.c-{{DB2_INSTANCE_NAME}}-sdb-db2u-internal.{{DB2_NAMESPACE}}.svc.cluster.local:60007'
{% endif %}
{% endif %}
{%- endfilter %}
{% endif %}
{% if DB2_ADDONS_AUDIT_CONFIG %}
db2_addons_audit_config:
{% filter indent(width=2) -%}
Expand Down Expand Up @@ -88,4 +117,4 @@ db2_backup_bucket_access_key: <path:{{ SECRETS_PATH }}:{{ SECRET_KEY_DB2_BACKUP_
db2_backup_bucket_secret_key: <path:{{ SECRETS_PATH }}:{{ SECRET_KEY_DB2_BACKUP_BUCKET_SECRET_KEY }}>
db2_backup_notify_slack_url: {{DB2_BACKUP_NOTIFY_SLACK_URL}}
db2_backup_icd_auth_key: <path:{{ SECRETS_PATH }}:{{ SECRET_KEY_DB2_BACKUP_ICD_AUTH_KEY }}>
{% endif %}
{% endif %}
39 changes: 39 additions & 0 deletions tekton/src/pipelines/gitops/gitops-mas-apps.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ spec:
- name: replica_db
type: string
default: "false"
- name: manually_set_enhanced_hadr
type: string
default: "false"

- name: custom_labels
type: string
Expand Down Expand Up @@ -828,6 +831,10 @@ spec:
value: $(params.db2_timezone)
- name: db2_backup_notify_slack_url
value: $(params.db2_backup_notify_slack_url)
- name: replica_db
value: $(params.replica_db)
- name: manually_set_enhanced_hadr
value: $(params.manually_set_enhanced_hadr)
- name: auto_backup
value: $(params.auto_backup)

Expand Down Expand Up @@ -993,6 +1000,8 @@ spec:
value: "false"
- name: replica_db
value: $(params.replica_db)
- name: manually_set_enhanced_hadr
value: $(params.manually_set_enhanced_hadr)
- name: mas_annotations
value: $(params.mas_annotations)
- name: is_replica_task
Expand Down Expand Up @@ -1868,6 +1877,36 @@ spec:
- input: "$(params.mas_edition)"
operator: in
values: ["essentials-maintenance", "standard", "premium"]

# 6.5 Manage Replica Config
- name: gitops-deprovision-db2u-replica-database-manage
runAfter:
- gitops-deprovision-mas-app-install-manage
params:
{{ lookup('template', pipeline_src_dir ~ '/taskdefs/gitops/common/gitops-params.yml.j2') | indent(8) }}
{{ lookup('template', pipeline_src_dir ~ '/taskdefs/gitops/common/secrets-params.yml.j2') | indent(8) }}
{{ lookup('template', pipeline_src_dir ~ '/taskdefs/gitops/common/git-params.yml.j2') | indent(8) }}

- name: mas_instance_id
value: $(params.mas_instance_id)
- name: mas_app_id
value: manage
- name: is_replica_task
value: 'true'

taskRef:
kind: Task
name: gitops-deprovision-db2u-database
workspaces:
- name: configs
workspace: configs
when:
- input: "$(params.mas_app_channel_manage)"
operator: in
values: [""]
- input: "$(params.mas_edition)"
operator: in
values: ["essentials-maintenance", "standard", "premium"]

# 7. IoT Deprovision
# -------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions tekton/src/tasks/gitops/gitops-db2u-database.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ spec:
- name: mas_annotations
type: string
default: ""
- name: manually_set_enhanced_hadr
type: string
default: ""
stepTemplate:
name: gitops-db2u-database
env:
Expand Down Expand Up @@ -243,6 +246,8 @@ spec:
value: $(params.is_replica_task)
- name: MAS_ANNOTATIONS
value: $(params.mas_annotations)
- name: MANUALLY_SET_ENHANCED_HADR
value: $(params.manually_set_enhanced_hadr)
envFrom:
- configMapRef:
name: environment-properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ spec:
type: string
- name: avp_aws_secret_region
type: string
- name: is_replica_task
type: string
default: ""
stepTemplate:
name: gitops-deprovision-db2u-database
env:
Expand All @@ -52,6 +55,8 @@ spec:
value: $(params.github_repo)
- name: SM_AWS_REGION
value: $(params.avp_aws_secret_region)
- name: IS_REPLICA_TASK
value: $(params.is_replica_task)
envFrom:
- configMapRef:
name: environment-properties
Expand Down

0 comments on commit 46e3b51

Please sign in to comment.