Skip to content

Commit

Permalink
[major] Use new OLM functions in mas-devops (#1573)
Browse files Browse the repository at this point in the history
  • Loading branch information
durera authored Dec 3, 2024
1 parent 3ccdbef commit 9206656
Show file tree
Hide file tree
Showing 50 changed files with 263 additions and 646 deletions.
1 change: 0 additions & 1 deletion build/bin/copy-role-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ copyDoc gencfg_workspace
copyDoc grafana
copyDoc ibm_catalogs
copyDoc ibmcloud_resource_key
copyDoc install_operator
copyDoc kafka
copyDoc key_rotation
copyDoc kmodels
Expand Down
141 changes: 0 additions & 141 deletions ibm/mas_devops/common_tasks/create_subscription.yml

This file was deleted.

67 changes: 67 additions & 0 deletions ibm/mas_devops/plugins/action/apply_subscription.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python3

import logging
import urllib3
from ansible_collections.kubernetes.core.plugins.module_utils.common import get_api_client
from ansible.errors import AnsibleError
from ansible.plugins.action import ActionBase

from mas.devops.olm import applySubscription, OLMException

urllib3.disable_warnings() # Disabling warnings will prevent InsecureRequestWarnings from dynClient
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(name)-20s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S')

class ActionModule(ActionBase):
"""
Usage Example
-------------
tasks:
- name: "Apply Subscription"
ibm.mas_devops.apply_subscription:
namespace: test-namespace
package_name: ibm-sls
package_channel: 3.x
register: subscription
"""
def run(self, tmp=None, task_vars=None):
super(ActionModule, self).run(tmp, task_vars)

# Target subscription
namespace = self._task.args.get('namespace', None)
config = self._task.args.get('config', None)

# From which package?
packageName = self._task.args.get('package_name', None)
packageChannel = self._task.args.get('package_channel', None)

# From which catalog?
catalogSource = self._task.args.get('catalog_source', None)
catalogSourceNamespace = self._task.args.get('catalog_source_namespace', None)

if namespace is None:
raise AnsibleError(f"Error: namespace argument was not provided")
if not isinstance(packageName, str):
raise AnsibleError(f"Error: packageName argument is not a string")

# Initialize DynamicClient and apply the Subscription
dynClient = get_api_client()
try:
subscription = applySubscription(dynClient, namespace, packageName, packageChannel, catalogSource, catalogSourceNamespace, config)
except OLMException as e:
raise AnsibleError(f"Error applying subscription: {e}")

if subscription is None:
return dict(
message=f"Failed to apply subscription for {packageName} in {namespace}",
success=False,
failed=True,
changed=False
)

return dict(
message=f"Successfully applied subscription for {packageName} in {namespace}: {subscription.metadata.name}",
success=True,
failed=False,
changed=False,
**subscription.to_dict()
)
53 changes: 53 additions & 0 deletions ibm/mas_devops/plugins/action/update_ibm_entitlement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python3

import logging
import urllib3
from ansible_collections.kubernetes.core.plugins.module_utils.common import get_api_client
from ansible.errors import AnsibleError
from ansible.plugins.action import ActionBase

from mas.devops.ocp import createNamespace
from mas.devops.mas import updateIBMEntitlementKey

urllib3.disable_warnings() # Disabling warnings will prevent InsecureRequestWarnings from dynClient
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(name)-20s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S')

class ActionModule(ActionBase):
"""
Usage Example
-------------
tasks:
- name: "Update IBM Entitlement Key"
ibm.mas_devops.update_ibm_entitlement:
namespace: "{{ mas_namespace }}"
icr_username: "{{ icr_username }}"
icr_password: "{{ icr_password }}"
artifactory_username: "{{ artifactory_username }}"
artifactory_password: "{{ artifactory_token }}"
register: secret
"""
def run(self, tmp=None, task_vars=None):
super(ActionModule, self).run(tmp, task_vars)

namespace = self._task.args.get('namespace', None)
icrUsername = self._task.args.get('icr_username', None)
icrPassword = self._task.args.get('icr_password', None)
artifactoryUsername = self._task.args.get('artifactory_username', None)
artifactoryPassword = self._task.args.get('artifactory_password', None)
secretName = self._task.args.get('secret_name', None)

if namespace is None:
raise AnsibleError(f"Error: namespace argument was not provided")

# Initialize DynamicClient, ensure the namespace exists, and create/update the entitlement secret
dynClient = get_api_client()
createNamespace(dynClient, namespace)
secret = updateIBMEntitlementKey(dynClient, namespace, icrUsername, icrPassword, artifactoryUsername, artifactoryPassword, secretName)

return dict(
message=f"Successfully updated IBM entitlement in {namespace}: {secret.metadata.name}",
success=True,
failed=False,
changed=False,
**secret.to_dict()
)
2 changes: 1 addition & 1 deletion ibm/mas_devops/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mas-devops >= 1.10.0
mas-devops >= 1.11.1
4 changes: 4 additions & 0 deletions ibm/mas_devops/roles/aibroker/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ mas_entitlement_username: "{{ lookup('env', 'MAS_ENTITLEMENT_USERNAME') | defaul
ibm_entitlement_key: "{{ lookup('env', 'IBM_ENTITLEMENT_KEY') }}"
mas_entitlement_key: "{{ lookup('env', 'MAS_ENTITLEMENT_KEY') | default(ibm_entitlement_key, true) }}"

# Development Registry Entitlement
artifactory_username: "{{ lookup('env', 'ARTIFACTORY_USERNAME') | lower }}"
artifactory_token: "{{ lookup('env', 'ARTIFACTORY_TOKEN') }}"

# MAS Annotation block
# -----------------------------------------------------------------------------
mas_annotations: "{{ lookup('env', 'MAS_ANNOTATIONS') | default(None, true) }}"
19 changes: 13 additions & 6 deletions ibm/mas_devops/roles/aibroker/tasks/aibroker/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,25 @@
kind: Namespace
name: "{{ aibroker_namespace }}"


# Install the operator & create entitlement secret
# -----------------------------------------------------------------------------
- name: "Install IBM Maximo AI Broker Operator"
include_role:
name: ibm.mas_devops.install_operator
vars:
- name: "Create IBM Entitlement Key"
ibm.mas_devops.update_ibm_entitlement:
namespace: "{{ aibroker_namespace }}"
icr_username: "{{ mas_entitlement_username }}"
icr_password: "{{ mas_entitlement_key }}"
artifactory_username: "{{ artifactory_username }}"
artifactory_password: "{{ artifactory_token }}"

- name: "Create ibm-mas-aibroker Subscription"
ibm.mas_devops.apply_subscription:
namespace: "{{ aibroker_namespace }}"
package_name: ibm-mas-aibroker
package_channel: "{{ aibroker_channel }}"
catalog_source: "{{ mas_catalog_source }}"
operator_group: "{{ lookup('template', 'templates/aibroker/operator-group.yml.j2') }}"
subscription: "{{ lookup('template', 'templates/aibroker/subscription.yml.j2') }}"
register: subscription


# Wait until the IBM Maximo AI Broker CRD is available
# -----------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions ibm/mas_devops/roles/arcgis/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ mas_entitlement_username: "{{ lookup('env', 'MAS_ENTITLEMENT_USERNAME') | defaul
ibm_entitlement_key: "{{ lookup('env', 'IBM_ENTITLEMENT_KEY') }}"
mas_entitlement_key: "{{ lookup('env', 'MAS_ENTITLEMENT_KEY') | default(ibm_entitlement_key, true) }}"

# Development Registry Entitlement
artifactory_username: "{{ lookup('env', 'ARTIFACTORY_USERNAME') | lower }}"
artifactory_token: "{{ lookup('env', 'ARTIFACTORY_TOKEN') }}"

# MAS Annotation block
# -----------------------------------------------------------------------------
mas_annotations: "{{ lookup('env', 'MAS_ANNOTATIONS') | default(None, true) }}"
19 changes: 13 additions & 6 deletions ibm/mas_devops/roles/arcgis/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,25 @@
state: present
template: templates/namespace.yml.j2


# 5. Install the operator & create entitlement secret
# -----------------------------------------------------------------------------
- name: "Install IBM Maximo Location Services for Esri Operator"
include_role:
name: ibm.mas_devops.install_operator
vars:
- name: "Create IBM Entitlement Key"
ibm.mas_devops.update_ibm_entitlement:
namespace: "{{ mas_arcgis_namespace }}"
icr_username: "{{ mas_entitlement_username }}"
icr_password: "{{ mas_entitlement_key }}"
artifactory_username: "{{ artifactory_username }}"
artifactory_password: "{{ artifactory_token }}"

- name: "Create ibm-mas-arcgis Subscription"
ibm.mas_devops.apply_subscription:
namespace: "{{ mas_arcgis_namespace }}"
package_name: ibm-mas-arcgis
package_channel: "{{ mas_arcgis_channel }}"
catalog_source: "{{ mas_catalog_source }}"
operator_group: "{{ lookup('template', 'templates/operator-group.yml.j2') }}"
subscription: "{{ lookup('template', 'templates/subscription.yml.j2') }}"
register: subscription


# 6. Wait until the IBM Maximo Location Services CRD is available
# -----------------------------------------------------------------------------
Expand Down
14 changes: 0 additions & 14 deletions ibm/mas_devops/roles/arcgis/templates/operator-group.yml.j2

This file was deleted.

12 changes: 0 additions & 12 deletions ibm/mas_devops/roles/arcgis/templates/subscription.yml.j2

This file was deleted.

Loading

0 comments on commit 9206656

Please sign in to comment.