Skip to content

Commit 117aa33

Browse files
author
Sanjay Prabhakar
committed
remove tekton feature flag and introduce flag to create configpvc
1 parent 2bb682b commit 117aa33

1 file changed

Lines changed: 29 additions & 100 deletions

File tree

src/mas/devops/tekton.py

Lines changed: 29 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -27,76 +27,6 @@
2727
logger = logging.getLogger(__name__)
2828

2929

30-
def configureTektonFeatureFlags(dynClient: DynamicClient) -> bool:
31-
"""
32-
Configure Tekton feature flags to disable coschedule (Affinity Assistant).
33-
34-
This prevents the "more than one PersistentVolumeClaim is bound" error when
35-
tasks use multiple PVCs with incompatible access modes.
36-
37-
Parameters:
38-
dynClient (DynamicClient): OpenShift Dynamic Client
39-
40-
Returns:
41-
bool: True if configuration is successful, False otherwise
42-
"""
43-
try:
44-
configMapAPI = dynClient.resources.get(api_version="v1", kind="ConfigMap")
45-
namespace = "openshift-pipelines"
46-
configMapName = "feature-flags"
47-
48-
# Get the existing ConfigMap
49-
try:
50-
featureFlags = configMapAPI.get(name=configMapName, namespace=namespace)
51-
logger.info(f"Found existing Tekton feature-flags ConfigMap in {namespace}")
52-
53-
# Convert to dict to make it mutable
54-
featureFlagsDict = featureFlags.to_dict()
55-
56-
# Update the coschedule setting
57-
if featureFlagsDict.get("data") is None:
58-
featureFlagsDict["data"] = {}
59-
60-
currentCoschedule = featureFlagsDict["data"].get("coschedule", "workspaces")
61-
if currentCoschedule != "disabled":
62-
logger.info(f"Updating Tekton coschedule setting from '{currentCoschedule}' to 'disabled'")
63-
featureFlagsDict["data"]["coschedule"] = "disabled"
64-
configMapAPI.patch(body=featureFlagsDict, namespace=namespace)
65-
logger.info("Successfully updated Tekton feature flags to disable coschedule")
66-
67-
# Restart the Tekton controller to apply changes
68-
logger.info("Restarting tekton-pipelines-controller to apply feature flag changes")
69-
deploymentAPI = dynClient.resources.get(api_version="apps/v1", kind="Deployment")
70-
controller = deploymentAPI.get(name="tekton-pipelines-controller", namespace=namespace)
71-
72-
# Trigger a rollout by updating an annotation
73-
if controller.spec.template.metadata.annotations is None:
74-
controller.spec.template.metadata.annotations = {}
75-
controller.spec.template.metadata.annotations["kubectl.kubernetes.io/restartedAt"] = datetime.now().isoformat()
76-
deploymentAPI.patch(body=controller, namespace=namespace)
77-
78-
# Wait for the controller to be ready
79-
logger.debug("Waiting for tekton-pipelines-controller to be ready after restart")
80-
foundReadyController = waitForDeployment(dynClient, namespace=namespace, deploymentName="tekton-pipelines-controller")
81-
if foundReadyController:
82-
logger.info("Tekton controller restarted successfully")
83-
return True
84-
else:
85-
logger.warning("Tekton controller restart may not have completed successfully")
86-
return False
87-
else:
88-
logger.info("Tekton coschedule is already set to 'disabled', no changes needed")
89-
return True
90-
91-
except NotFoundError:
92-
logger.warning(f"ConfigMap {configMapName} not found in {namespace}, it may not exist yet")
93-
return False
94-
95-
except Exception as e:
96-
logger.error(f"Error configuring Tekton feature flags: {str(e)}")
97-
return False
98-
99-
10030
def installOpenShiftPipelines(dynClient: DynamicClient, customStorageClassName: str = None) -> bool:
10131
"""
10232
Install the OpenShift Pipelines Operator and wait for it to be ready to use.
@@ -167,11 +97,6 @@ def installOpenShiftPipelines(dynClient: DynamicClient, customStorageClassName:
16797
logger.error("OpenShift Pipelines Webhook is NOT installed and ready")
16898
return False
16999

170-
# Configure Tekton feature flags to disable coschedule
171-
# -------------------------------------------------------------------------
172-
logger.debug("Configuring Tekton feature flags")
173-
configureTektonFeatureFlags(dynClient)
174-
175100
# Workaround for bug in OpenShift Pipelines/Tekton
176101
# -------------------------------------------------------------------------
177102
# Wait for the postgredb-tekton-results-postgres-0 PVC to be ready
@@ -337,7 +262,7 @@ def updateTektonDefinitions(namespace: str, yamlFile: str) -> None:
337262
logger.debug(line)
338263

339264

340-
def preparePipelinesNamespace(dynClient: DynamicClient, instanceId: str = None, storageClass: str = None, accessMode: str = None, waitForBind: bool = True, configureRBAC: bool = True, createBackupPVC: bool = False, backupStorageSize: str = "20Gi"):
265+
def preparePipelinesNamespace(dynClient: DynamicClient, instanceId: str = None, storageClass: str = None, accessMode: str = None, waitForBind: bool = True, configureRBAC: bool = True, createConfigPVC: bool = True, createBackupPVC: bool = False, backupStorageSize: str = "20Gi"):
341266
"""
342267
Prepare a namespace for MAS pipelines by creating RBAC and PVC resources.
343268
@@ -351,6 +276,7 @@ def preparePipelinesNamespace(dynClient: DynamicClient, instanceId: str = None,
351276
accessMode (str, optional): Access mode for the PVC. Defaults to None.
352277
waitForBind (bool, optional): Whether to wait for PVC to bind. Defaults to True.
353278
configureRBAC (bool, optional): Whether to configure RBAC. Defaults to True.
279+
createConfigPVC (bool, optional): Whether to create config PVC. Defaults to True.
354280
createBackupPVC (bool, optional): Whether to create backup PVC. Defaults to False.
355281
backupStorageSize (str, optional): Size of the backup PVC storage. Defaults to "20Gi".
356282
@@ -383,33 +309,36 @@ def preparePipelinesNamespace(dynClient: DynamicClient, instanceId: str = None,
383309
if instanceId is not None:
384310
pvcAPI = dynClient.resources.get(api_version="v1", kind="PersistentVolumeClaim")
385311

386-
# Create config PVC
387-
template = env.get_template("pipelines-pvc.yml.j2")
388-
renderedTemplate = template.render(
389-
mas_instance_id=instanceId,
390-
pipeline_storage_class=storageClass,
391-
pipeline_storage_accessmode=accessMode
392-
)
393-
logger.debug(renderedTemplate)
394-
pvc = yaml.safe_load(renderedTemplate)
395-
pvcAPI.apply(body=pvc, namespace=namespace)
396-
397312
# Automatically determine if we should wait for PVC binding based on storage class
398313
volumeBindingMode = getStorageClassVolumeBindingMode(dynClient, storageClass)
399314
waitForBind = (volumeBindingMode == "Immediate")
400-
if waitForBind:
401-
logger.info(f"Storage class {storageClass} uses volumeBindingMode={volumeBindingMode}, waiting for config PVC to bind")
402-
pvcIsBound = False
403-
while not pvcIsBound:
404-
configPVC = pvcAPI.get(name="config-pvc", namespace=namespace)
405-
if configPVC.status.phase == "Bound":
406-
pvcIsBound = True
407-
else:
408-
logger.debug("Waiting 15s before checking status of config PVC again")
409-
logger.debug(configPVC)
410-
sleep(15)
411-
else:
412-
logger.info(f"Storage class {storageClass} uses volumeBindingMode={volumeBindingMode}, skipping config PVC bind wait")
315+
316+
# Create config PVC if requested
317+
if createConfigPVC:
318+
logger.info("Creating config PVC")
319+
template = env.get_template("pipelines-pvc.yml.j2")
320+
renderedTemplate = template.render(
321+
mas_instance_id=instanceId,
322+
pipeline_storage_class=storageClass,
323+
pipeline_storage_accessmode=accessMode
324+
)
325+
logger.debug(renderedTemplate)
326+
pvc = yaml.safe_load(renderedTemplate)
327+
pvcAPI.apply(body=pvc, namespace=namespace)
328+
329+
if waitForBind:
330+
logger.info(f"Storage class {storageClass} uses volumeBindingMode={volumeBindingMode}, waiting for config PVC to bind")
331+
pvcIsBound = False
332+
while not pvcIsBound:
333+
configPVC = pvcAPI.get(name="config-pvc", namespace=namespace)
334+
if configPVC.status.phase == "Bound":
335+
pvcIsBound = True
336+
else:
337+
logger.debug("Waiting 15s before checking status of config PVC again")
338+
logger.debug(configPVC)
339+
sleep(15)
340+
else:
341+
logger.info(f"Storage class {storageClass} uses volumeBindingMode={volumeBindingMode}, skipping config PVC bind wait")
413342

414343
# Create backup PVC if requested
415344
if createBackupPVC:

0 commit comments

Comments
 (0)