Skip to content

Commit 37bf8ab

Browse files
[patch] Red Hat Pipelines Console Plugin Auto-Enablement Implementation (#264)
Co-authored-by: Parveen Kumar <Parveenkumar@ibm.com>
1 parent 213894b commit 37bf8ab

1 file changed

Lines changed: 88 additions & 1 deletion

File tree

src/mas/devops/tekton.py

Lines changed: 88 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

@@ -159,6 +159,93 @@ def installOpenShiftPipelines(dynClient: DynamicClient, customStorageClassName:
159159
return False
160160

161161

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

0 commit comments

Comments
 (0)