-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[major] Use new OLM functions in mas-devops (#1573)
- Loading branch information
Showing
50 changed files
with
263 additions
and
646 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
mas-devops >= 1.10.0 | ||
mas-devops >= 1.11.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
ibm/mas_devops/roles/arcgis/templates/operator-group.yml.j2
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.