Skip to content

Commit

Permalink
[patch] Adjustments to Uninstall FVT (#1146)
Browse files Browse the repository at this point in the history
  • Loading branch information
durera authored and andrefgj committed Aug 12, 2024
1 parent 618b559 commit 1e06ad4
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 506 deletions.
23 changes: 15 additions & 8 deletions python/src/mas/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

from argparse import RawTextHelpFormatter
from shutil import which
from os import path
from os import path, environ
from sys import exit

# Use of the openshift client rather than the kubernetes client allows us access to "apply"
from openshift import dynamic
from kubernetes import config
from kubernetes.client import api_client
from kubernetes.client import api_client, Configuration
from openshift.dynamic import DynamicClient
from openshift.dynamic.exceptions import NotFoundError

from prompt_toolkit import prompt, print_formatted_text, HTML
Expand Down Expand Up @@ -177,13 +177,19 @@ def reloadDynamicClient(self):
"""
logger.debug("Reloading Kubernetes Client Configuration")
try:
config.load_kube_config()
self._dynClient = dynamic.DynamicClient(
api_client.ApiClient(configuration=config.load_kube_config())
)
if "KUBERNETES_SERVICE_HOST" in environ:
config.load_incluster_config()
k8s_config = Configuration.get_default_copy()
self._apiClient = api_client.ApiClient(configuration=k8s_config)
self._dynClient = DynamicClient(self._apiClient)
else:
config.load_kube_config()
self._apiClient = api_client.ApiClient()
self._dynClient = DynamicClient(self._apiClient)
return self._dynClient
except Exception as e:
logger.warning(f"Error: Unable to connect to OpenShift Container Platform: {e}")
logger.exception(e, stack_info=True)
return None

def connect(self):
Expand Down Expand Up @@ -212,7 +218,8 @@ def connect(self):
# Prompt for new connection properties
server = prompt(HTML('<Yellow>Server URL:</Yellow> '), placeholder="https://...")
token = prompt(HTML('<Yellow>Login Token:</Yellow> '), is_password=True, placeholder="sha256~...")
connect(server, token)
skipVerify = self.yesOrNo('Disable TLS Verify')
connect(server, token, skipVerify)
self.reloadDynamicClient()
if self._dynClient is None:
print_formatted_text(HTML("<Red>Unable to connect to cluster. See log file for details</Red>"))
Expand Down
4 changes: 1 addition & 3 deletions tekton/generate-tekton-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
- fvt-optimizer
- fvt-predict
- fvt-sls
- fvt-uninstall-after
- fvt-upgrade-post
- fvt-upgrade-pre
- fvt-visualinspection
- fvt-launcher
- fvt-launcher-uninstall
- ivt-manage

# 2. Generate Pipelines
Expand All @@ -69,8 +69,6 @@
- update
- upgrade
- rollback
- uninstall
- fvt-core

# 3. Generate Gitops Pipelines
# -------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions tekton/generate-tekton-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
- fvt-monitor
- fvt-run-suite
- fvt-sls
- fvt-uninstall

- name: Generate Tasks (FVT Launchers)
ansible.builtin.template:
Expand Down
16 changes: 0 additions & 16 deletions tekton/src/pipelines/fvt-core.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
{% if wait_for_install == true %}
name: mas-fvt-core-after-install
{% else %}
name: mas-fvt-core
{% endif %}
spec:
workspaces:
# The generated configuration files
Expand Down Expand Up @@ -51,19 +47,7 @@ spec:
description: IVT Digest - Core
default: ""

{% if wait_for_install == true %}
# 4. Wait params
# -------------------------------------------------------------------------
- name: pipelinerun_name
type: string
- name: ignore_failure
type: string
default: "True"
description: Set to 'True' or 'False' (case-sensitive) to configure whether this pipeline continue if the pipeline we are waiting for has failed.
{% endif %}

tasks:

# Core FVT 1.0 coreidp-auth ~20m - Refresh token and authentication patterns
# We are running this test first since it happens to set the Suite accessTokenTimeout from the default of 30m to 12h
# This prevents subsequent test suites that take >30 mins from hitting unexpected 401s due to tokens generated by
Expand Down
135 changes: 135 additions & 0 deletions tekton/src/pipelines/fvt-launcher-uninstall.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: mas-fvt-launcher-uninstall
spec:
params:
- name: image_pull_policy
type: string
default: IfNotPresent
description: Tekton Pipeline image pull policy (for ibmmas/cli images)

- name: mas_instance_id
type: string
default: ""
description: Instance ID of the MAS installation to remove from the cluster, if not provided the uninstall can still be used to remove shared dependencies from the cluster

- name: sync_with_install
type: string
default: "false"
description: "Set this to 'true' to enable synchronization with a running MAS install pipeline"

# Finalize
# -------------------------------------------------------------------------
- name: finalize
type: string
default: "true"
description: "Set this to 'false' to stop the finalize task from running for this launcher"

# Deprovision Resources
# -------------------------------------------------------------------------
- name: deprovision
type: string
default: "false"
description: "Set this to 'true' to enable deprovision of the target cluster & associated resources following the completion of this pipeline"

tasks:
- name: waitfor-installation
timeout: "0"
taskRef:
kind: Task
name: mas-devops-wait-for-configmap
params:
- name: image_pull_policy
value: $(params.image_pull_policy)
- name: namespace
value: $(context.taskRun.namespace)
- name: configmap_name
value: sync-install
- name: configmap_key
value: INSTALL_STATUS
- name: configmap_target_value
value: Completed,Succeeded
# Escape route
- name: escape_configmap_name
value: sync-install
- name: escape_configmap_key
value: INSTALL_STATUS
# 50 retries at 10 minute intervals = 8 hours
- name: delay
value: "600"
- name: max_retries
value: "50"
- name: ignore_failure
value: "False"
when:
- input: $(params.sync_with_install)
operator: in
values: ["true", "True"]

# This task will launch an uninstall pipeline using the MAS CLI
# IMPORTANT: No additional verification of the success/failure of the uninstall
# should be introduced. If there are validations to run, add them directly to
# the uninstall pipeline so that customers get the same benefit of these checks.
- name: launch-uninstall
timeout: "0"
taskRef:
kind: Task
name: mas-fvt-uninstall
params:
- name: image_pull_policy
value: $(params.image_pull_policy)
- name: mas_instance_id
value: $(params.mas_instance_id)
runAfter:
- waitfor-installation

# The uninstall pipeline, on completion, will create a configmap named "sync-uninstall"
# which can be used to track the completion of the install
- name: waitfor-uninstall
timeout: "0"
taskRef:
kind: Task
name: mas-devops-wait-for-configmap
params:
- name: image_pull_policy
value: $(params.image_pull_policy)
- name: namespace
value: $(context.taskRun.namespace)
- name: configmap_name
value: sync-uninstall
- name: configmap_key
value: UNINSTALL_STATUS
- name: configmap_target_value
value: Completed,Succeeded
# Escape route
- name: escape_configmap_name
value: sync-uninstall
- name: escape_configmap_key
value: UNINSTALL_STATUS
# 50 retries at 5 minute intervals = 4 hours
- name: delay
value: "300"
- name: max_retries
value: "50"
- name: ignore_failure
value: "False"
runAfter:
- launch-uninstall

finally:
- name: launchfvt-finally
timeout: "0"
taskRef:
kind: Task
name: mas-launchfvt-finally
params:
- name: deprovision
value: "$(params.deprovision)"
- name: finalize
value: "$(params.finalize)"
- name: image_pull_policy
value: $(params.image_pull_policy)
- name: pipelinerun_name
value: "$(params.mas_instance_id)-fvt-uninstall-finally"
2 changes: 0 additions & 2 deletions tekton/src/pipelines/fvt-launcher.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,5 @@ spec:
value: "$(params.mas_instance_id)-fvt-finally"

workspaces:
# Shared storage to hold mustgather output for tasks
- name: shared-mustgather
# The generated configuration files
- name: shared-configs
Loading

0 comments on commit 1e06ad4

Please sign in to comment.