From a78e74e7820339ea0499781567ddd3564b278193 Mon Sep 17 00:00:00 2001 From: willtome Date: Mon, 28 Aug 2023 15:57:19 -0400 Subject: [PATCH] OpenShift Dev Spaces (#64) --- .devfile.yaml | 12 ++++ .vscode/extensions.json | 7 +++ .vscode/settings.json | 3 + CONTRIBUTING.md | 5 ++ README.md | 3 + ansible.cfg | 10 ++++ collections/requirements.yml | 5 ++ openshift/README.md | 20 +++++++ openshift/devspaces.yml | 112 +++++++++++++++++++++++++++++++++++ openshift/setup.yml | 25 ++++++++ 10 files changed, 202 insertions(+) create mode 100644 .devfile.yaml create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 openshift/README.md create mode 100644 openshift/devspaces.yml create mode 100644 openshift/setup.yml diff --git a/.devfile.yaml b/.devfile.yaml new file mode 100644 index 0000000..db71b4c --- /dev/null +++ b/.devfile.yaml @@ -0,0 +1,12 @@ +schemaVersion: 2.2.0 +metadata: + name: product-demos +components: + - name: product-demos-ee + container: + image: quay.io/mloriedo/ansible-creator-ee:latest # workaround for https://github.com/eclipse/che/issues/21778 + memoryRequest: 256M + memoryLimit: 5Gi + cpuRequest: 250m + cpuLimit: 2000m + args: ['tail', '-f', '/dev/null'] diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..8983e99 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "redhat.vscode-yaml", + "redhat.ansible", + "ms-python.black-formatter" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..bd68aec --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.renderWhitespace": "all" +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3804000..2789479 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -44,3 +44,8 @@ This document aims to outline the requirements for the various forms of contribu - `controller_components` can be any of the roles defined [here](https://github.com/redhat-cop/controller_configuration/tree/devel/roles) - Add variables for each component listed 3) Include a README.md in the subdirectory + +## Testing +To run `ansible-lint` you will need to set an environment variable for the token to connect to Automation Hub. You can get a token from [here](https://console.redhat.com/ansible/automation-hub/token). + +Copy the value of the token and run `export ANSIBLE_GALAXY_SERVER_AH_TOKEN=` diff --git a/README.md b/README.md index dfd19c4..c601e4b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +[![Lab](https://img.shields.io/badge/Try%20Me-EE0000?style=for-the-badge&logo=redhat&logoColor=white)](https://red.ht/aap-product-demos) +[![Dev Spaces](https://img.shields.io/badge/Customize%20Here-0078d7.svg?style=for-the-badge&logo=visual-studio-code&logoColor=white)](https://workspaces.openshift.com/f?url=https://github.com/ansible/product-demos) + # Official Ansible Product Demos This is a centralized location for all Ansible Product Demos going forward. diff --git a/ansible.cfg b/ansible.cfg index 5bd4066..8e1f70d 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -1,3 +1,13 @@ [defaults] collections_paths=./collections roles_path=./roles + +[galaxy] +server_list = ah,galaxy + +[galaxy_server.ah] +url=https://console.redhat.com/api/automation-hub/ +auth_url=https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token + +[galaxy_server.galaxy] +url=https://galaxy.ansible.com/ diff --git a/collections/requirements.yml b/collections/requirements.yml index fe3cf7f..45fc493 100644 --- a/collections/requirements.yml +++ b/collections/requirements.yml @@ -35,3 +35,8 @@ collections: version: 5.0.0 - name: ansible.netcommon version: 5.0.0 + # openshift + - name: redhat.openshift + version: 2.3.0 + - name: kubernetes.core + version: 2.4.0 diff --git a/openshift/README.md b/openshift/README.md new file mode 100644 index 0000000..d5bfd7b --- /dev/null +++ b/openshift/README.md @@ -0,0 +1,20 @@ +# OpenShift Demos + +## Table of Contents +- [OpenShift Demos](#openshift-demos) + - [Table of Contents](#table-of-contents) + - [About These Demos](#about-these-demos) + - [Jobs](#jobs) + - [Pre Setup](#pre-setup) + +## About These Demos +This category of demos shows examples of openshift operations and management with Ansible Automation Platform. The list of demos can be found below. See the [Suggested Usage](#suggested-usage) section of this document for recommendations on how to best use these demos. + +### Jobs +- [**OpenShift / Dev Spaces**](devspaces.yml) - Install and deploy dev spaces on OCP cluster. After this job has run successfully, login to your OCP cluster, click the application icon (to the left of the bell icon in the top right) to access Dev Spaces + +## Pre Setup +This demo requires an OpenShift cluster to deploy to. If you do not have a cluster to use, one can be requested from [demo.redhat.com](https://demo.redhat.com). +- Search for the [Red Hat OpenShift Container Platform 4.12 Workshop](https://demo.redhat.com/catalog?item=babylon-catalog-prod/sandboxes-gpte.ocp412-wksp.prod&utm_source=webapp&utm_medium=share-link) item in the catalog and request with the number of users you would like for Dev Spaces. +- Login using the admin credentials provided. Click the `admin` username at the top right and select `Copy login command`. +- Authenticate and click `Display Token`. This information will be used to populate the OpenShift Credential after you run the setup. diff --git a/openshift/devspaces.yml b/openshift/devspaces.yml new file mode 100644 index 0000000..dc7304d --- /dev/null +++ b/openshift/devspaces.yml @@ -0,0 +1,112 @@ +--- +- name: Deploy Dev Spaces on OCP + hosts: localhost + gather_facts: false + + tasks: + - name: create namespace + redhat.openshift.k8s: + name: eclipse-che + api_version: v1 + kind: Namespace + state: present + + - name: create dev spaces subscription + redhat.openshift.k8s: + state: present + definition: + apiVersion: operators.coreos.com/v1alpha1 + kind: Subscription + metadata: + labels: + operators.coreos.com/devspaces.openshift-operators: '' + name: devspaces + namespace: openshift-operators + spec: + channel: stable + installPlanApproval: Automatic + name: devspaces + source: redhat-operators + sourceNamespace: openshift-marketplace + + - name: wait for dev spaces operator to install + k8s_info: + api_version: apiextensions.k8s.io/v1 + kind: CustomResourceDefinition + name: checlusters.org.eclipse.che + register: crd_che + until: crd_che.resources | list | length == 1 + retries: 10 + delay: 30 + + - name: Wait until devspaces-operator is up + k8s_info: + api_version: v1 + kind: Deployment + name: devspaces-operator + namespace: openshift-operators + register: pod_list + until: pod_list|json_query('resources[*].status.readyReplicas')|unique == [1] + retries: 10 + delay: 30 + + - name: deploy dev spaces + redhat.openshift.k8s: + state: present + definition: + apiVersion: org.eclipse.che/v2 + kind: CheCluster + metadata: + name: devspaces + namespace: eclipse-che + spec: + components: + cheServer: + debug: false + logLevel: INFO + dashboard: {} + database: + credentialsSecretName: postgres-credentials + externalDb: false + postgresDb: dbche + postgresHostName: postgres + postgresPort: '5432' + pvc: + claimSize: 1Gi + devWorkspace: {} + devfileRegistry: {} + imagePuller: + enable: false + spec: {} + metrics: + enable: true + pluginRegistry: + openVSXURL: 'https://open-vsx.org' + containerRegistry: {} + devEnvironments: + startTimeoutSeconds: 300 + secondsOfRunBeforeIdling: -1 + maxNumberOfWorkspacesPerUser: -1 + containerBuildConfiguration: + openShiftSecurityContextConstraint: container-build + disableContainerBuildCapabilities: true + defaultEditor: che-incubator/che-code/insiders + defaultComponents: + - container: + image: >- + registry.redhat.io/devspaces/udi-rhel8@sha256:aa39ede33bcbda6aa2723d271c79ab8d8fd388c7dfcbc3d4ece745b7e9c84193 + sourceMapping: /projects + name: universal-developer-image + defaultNamespace: + autoProvision: true + template: -devspaces + secondsOfInactivityBeforeIdling: 1800 + storage: + pvcStrategy: per-user + gitServices: {} + networking: + auth: + gateway: + configLabels: + app: che + component: che-gateway-config diff --git a/openshift/setup.yml b/openshift/setup.yml new file mode 100644 index 0000000..1403587 --- /dev/null +++ b/openshift/setup.yml @@ -0,0 +1,25 @@ +--- +controller_components: + - credentials + - job_templates + +controller_credentials: + - name: OpenShift Credential + organization: Default + credential_type: OpenShift or Kubernetes API Bearer Token + inputs: + host: CHANGEME + bearer_token: CHANGEME + verify_ssl: false + +controller_templates: + - name: OpenShift / Dev Spaces + job_type: run + inventory: "Demo Inventory" + project: "Ansible official demo project" + playbook: "openshift/devspaces.yml" + notification_templates_started: Telemetry + notification_templates_success: Telemetry + notification_templates_error: Telemetry + credentials: + - "OpenShift Credential"