Skip to content

Commit d6b42ec

Browse files
committed
Updated for pipeline-enable
1 parent 31555be commit d6b42ec

1 file changed

Lines changed: 86 additions & 1 deletion

File tree

src/mas/devops/tekton.py

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from jinja2 import Environment, FileSystemLoader
2424

25-
from .ocp import getConsoleURL, waitForCRD, waitForDeployment, crdExists, waitForPVC, getStorageClasses, getStorageClassVolumeBindingMode
25+
from .ocp import getConsoleURL, waitForCRD, waitForDeployment, crdExists, waitForPVC, getStorageClasses, getStorageClassVolumeBindingMode, getClusterVersion
2626

2727
logger = logging.getLogger(__name__)
2828

@@ -158,6 +158,91 @@ def installOpenShiftPipelines(dynClient: DynamicClient, customStorageClassName:
158158
logger.error("OpenShift Pipelines postgres PVC is NOT ready")
159159
return False
160160

161+
def enablePipelinesConsolePlugin(dynClient: DynamicClient) -> bool:
162+
"""
163+
Enable the OpenShift Pipelines console plugin for OCP 4.21+.
164+
165+
In OpenShift 4.21 and later, the Pipelines console plugin must be manually
166+
enabled by patching the Console operator configuration. This function:
167+
1. Detects the OCP version
168+
2. Checks if version >= 4.21
169+
3. Enables the plugin if not already enabled
170+
171+
Parameters:
172+
dynClient (DynamicClient): OpenShift Dynamic Client
173+
174+
Returns:
175+
bool: True if plugin is enabled or already enabled, False on error
176+
"""
177+
try:
178+
# Get cluster version
179+
clusterVersion = getClusterVersion(dynClient)
180+
if not clusterVersion:
181+
logger.warning("Unable to determine cluster version, skipping plugin enablement")
182+
return True # Non-fatal, return True to continue
183+
184+
logger.debug(f"Detected OpenShift version: {clusterVersion}")
185+
186+
# Parse version (e.g., "4.21.0" -> major=4, minor=21)
187+
versionParts = clusterVersion.split('.')
188+
if len(versionParts) < 2:
189+
logger.warning(f"Unable to parse cluster version '{clusterVersion}', skipping plugin enablement")
190+
return True
191+
192+
try:
193+
majorVersion = int(versionParts[0])
194+
minorVersion = int(versionParts[1])
195+
except ValueError:
196+
logger.warning(f"Unable to parse version numbers from '{clusterVersion}', skipping plugin enablement")
197+
return True
198+
199+
# Check if version requires plugin enablement (4.21+)
200+
requiresPlugin = (majorVersion == 4 and minorVersion >= 21) or (majorVersion > 4)
201+
202+
if not requiresPlugin:
203+
logger.info(f"OpenShift version {clusterVersion} does not require manual plugin enablement")
204+
return True
205+
206+
logger.info(f"OpenShift version {clusterVersion} requires Pipelines console plugin to be enabled")
207+
208+
# Get Console operator
209+
consoleAPI = dynClient.resources.get(api_version="operator.openshift.io/v1", kind="Console")
210+
console = consoleAPI.get(name="cluster")
211+
212+
# Check if plugin is already enabled
213+
currentPlugins = console.spec.plugins if hasattr(console.spec, 'plugins') and console.spec.plugins else []
214+
pluginName = "pipelines-console-plugin"
215+
216+
if pluginName in currentPlugins:
217+
logger.info(f"Pipelines console plugin is already enabled")
218+
return True
219+
220+
# Enable the plugin by patching the Console operator
221+
logger.info(f"Enabling Pipelines console plugin...")
222+
223+
# Create patch to add plugin to the list
224+
updatedPlugins = list(currentPlugins) + [pluginName]
225+
patch = {
226+
"spec": {
227+
"plugins": updatedPlugins
228+
}
229+
}
230+
231+
consoleAPI.patch(
232+
name="cluster",
233+
body=patch,
234+
content_type="application/merge-patch+json"
235+
)
236+
237+
logger.info(f"Successfully enabled Pipelines console plugin")
238+
return True
239+
240+
except NotFoundError as e:
241+
logger.warning(f"Console operator not found: {e}")
242+
return True # Non-fatal, plugin can be enabled manually
243+
except Exception as e:
244+
logger.error(f"Error enabling Pipelines console plugin: {e}")
245+
return False
161246

162247
def addMissingStorageClassToTektonPVC(dynClient: DynamicClient, namespace: str, pvcName: str, storageClassName: str = None) -> bool:
163248
"""

0 commit comments

Comments
 (0)