Skip to content

Commit 99d9e19

Browse files
committed
Add 'namespace' config for NSaaS
This introduces a new namespace configuration designed to deploy OpenShift workloads directly to an existing namespace without requiring infrastructure provisioning or a bastion host. This approach is for users who have direct, but potentially limited, namespace-level access to a shared OpenShift cluster and do not manage the underlying infrastructure. The configuration runs on localhost and connects to the OpenShift API using provided credentials (API token or username/password). Workloads to be deployed are specified in the ocp_workloads_namespaced list variable. A new example role, ocp_workloads_namespaced_example, is included to demonstrate how to build compatible, namespaced workloads. This role shows: - Adding oc login initial authentication. - Managing Kubernetes resources (Deployment, Service) and OpenShift resources (Route) via the kubernetes.core.k8s module and Jinja2 templates. - Including lifecycle tasks for creation, verification, and destruction of the application.
1 parent a4cc46d commit 99d9e19

File tree

21 files changed

+832
-0
lines changed

21 files changed

+832
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
= Namespace Configuration
2+
3+
The `namespace` configuration is designed to deploy OpenShift workloads directly to existing namespaces without requiring infrastructure provisioning or bastion hosts. This is ideal for deploying applications to shared clusters or when you only have namespace-level access.
4+
5+
== Features
6+
7+
* No infrastructure provisioning required
8+
* Direct connection to OpenShift clusters
9+
* Support for both token and user/password authentication
10+
* Simplified deployment for namespace-scoped workloads
11+
* No SSH or bastion host dependencies
12+
13+
== Usage
14+
15+
1. Copy `sample_vars.yml` to create your deployment variables file
16+
2. Configure your OpenShift connection details
17+
3. Define the workloads to deploy in `ocp_workloads_namespaced`
18+
4. Run the deployment
19+
20+
=== Example Deployment
21+
22+
[source,bash]
23+
----
24+
ansible-navigator run ansible/main.yml -e @ansible/configs/namespace/sample_vars.yml -e @/secrets/ns.yaml -e ACTION=create
25+
----
26+
27+
== Required Variables
28+
29+
* `sandbox_openshift_api_url`: OpenShift API endpoint
30+
* `sandbox_openshift_namespace`: Target namespace
31+
* Authentication (choose one):
32+
** `sandbox_openshift_api_token`: API token
33+
** `sandbox_openshift_user` + `sandbox_openshift_password`: Username/password
34+
35+
== Optional Variables
36+
37+
* `sandbox_openshift_cluster`: Cluster name for identification
38+
* `sandbox_openshift_apps_domain`: Apps domain for route creation
39+
* `sandbox_openshift_credentials`: Additional credential objects
40+
41+
== Workloads
42+
43+
Define workloads in the `ocp_workloads_namespaced` list. Each workload should be a role that can deploy to OpenShift using the provided connection variables.
44+
45+
Example:
46+
[source,yaml]
47+
----
48+
ocp_workloads_namespaced:
49+
- ocp_workloads_namespaced_example
50+
- my_custom_workload
51+
----
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
# Namespace Config Default Variables
3+
# This config deploys OpenShift workloads directly to a namespace without
4+
# requiring infrastructure
5+
6+
become_override: false
7+
8+
# Cloud Provider
9+
cloud_provider: none
10+
11+
# OpenShift cluster connection details
12+
sandbox_openshift_cluster: ""
13+
sandbox_openshift_api_url: ""
14+
sandbox_openshift_apps_domain: ""
15+
sandbox_openshift_namespace: ""
16+
sandbox_openshift_api_token: ""
17+
sandbox_openshift_credentials: []
18+
sandbox_openshift_user: ""
19+
sandbox_openshift_password: ""
20+
21+
# List of namespace workloads to deploy
22+
ocp_workloads_namespaced: []
23+
24+
# Environment name to display
25+
short_env_type_name: namespace
26+
27+
# Common AgnosticD variables
28+
env_type: namespace
29+
30+
# User info messages
31+
user_info_messages:
32+
- "This configuration deploys workloads directly to OpenShift namespaces"
33+
- "No infrastructure or bastion host is created"
34+
- "Define 'ocp_workloads_namespaced' to specify workloads to deploy"
35+
36+
target_host: localhost
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
- name: Destroy Namespaced OCP Workloads
3+
hosts: localhost
4+
gather_facts: false
5+
become: false
6+
tags:
7+
- ocp_workloads_namespaced
8+
tasks:
9+
- name: Destroy namespaced workloads
10+
when:
11+
- ocp_workloads_namespaced | default([]) | length > 0
12+
block:
13+
- name: Remove namespaced workload "{{ workload_loop_var }}"
14+
ansible.builtin.include_role:
15+
name: "{{ workload_loop_var }}"
16+
vars:
17+
ACTION: "destroy"
18+
# Pass through OpenShift connection variables
19+
sandbox_openshift_cluster: "{{ sandbox_openshift_cluster | default('') }}"
20+
sandbox_openshift_api_url: "{{ sandbox_openshift_api_url | default('') }}"
21+
sandbox_openshift_apps_domain: "{{ sandbox_openshift_apps_domain | default('') }}"
22+
sandbox_openshift_namespace: "{{ sandbox_openshift_namespace | default('') }}"
23+
sandbox_openshift_api_token: "{{ sandbox_openshift_api_token | default('') }}"
24+
sandbox_openshift_credentials: "{{ sandbox_openshift_credentials | default([]) }}"
25+
sandbox_openshift_user: "{{ sandbox_openshift_user | default('') }}"
26+
sandbox_openshift_password: "{{ sandbox_openshift_password | default('') }}"
27+
loop: "{{ ocp_workloads_namespaced }}"
28+
loop_control:
29+
loop_var: workload_loop_var
30+
31+
- name: Destroy complete
32+
hosts: localhost
33+
gather_facts: false
34+
become: false
35+
tasks:
36+
- debug:
37+
msg: "Namespace workloads destroyed successfully"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
- name: Build inventory
3+
ansible.builtin.import_playbook: post_infra.yml
4+
5+
- name: Destroy workload(s)
6+
hosts: ocp_bastions
7+
become: false
8+
gather_facts: false
9+
tags:
10+
- step005
11+
tasks:
12+
- name: Fail if no action defined
13+
when: ACTION is not defined or ACTION == ''
14+
ansible.builtin.fail:
15+
msg: ACTION must be defined
16+
17+
- name: Set facts for OpenShift cluster(s)
18+
include_tasks: set_cluster_facts.yml
19+
20+
- name: Run Workloads to perform {{ ACTION }}
21+
loop: "{{ cluster_workloads }}"
22+
loop_control:
23+
loop_var: __workload
24+
label: "{{ __workload.name }}"
25+
include_tasks: run_workload_on_clusters.yml
26+
vars:
27+
ACTION: destroy
28+
29+
- name: Cleanup
30+
ansible.builtin.import_playbook: cleanup.yml
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- name: Step 002 Post Infrastructure
3+
hosts: localhost
4+
gather_facts: false
5+
become: false
6+
tasks:
7+
- debug:
8+
msg: "Step 002 Post Infrastructure - No infrastructure setup needed for namespace config"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- name: Step 005 Post Software
3+
hosts: localhost
4+
gather_facts: false
5+
become: false
6+
tasks:
7+
- debug:
8+
msg: "Step 005 Post Software - Namespace workloads deployment completed"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- name: Step 000 Pre Infrastructure
3+
hosts: localhost
4+
gather_facts: false
5+
become: false
6+
tasks:
7+
- debug:
8+
msg: "Step 000 Pre Infrastructure - No infrastructure needed for namespace-only deployment"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- name: Step 003 Pre Software
3+
hosts: localhost
4+
gather_facts: false
5+
become: false
6+
tasks:
7+
- debug:
8+
msg: "Step 003 Pre Software - No infrastructure software needed"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
collections:
3+
- name: kubernetes.core
4+
version: 5.0.0
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
# Sample Variables for Namespace Config
3+
# Copy this file and customize for your deployment
4+
5+
# Basic environment information
6+
cloud_provider: none
7+
env_type: namespace
8+
guid: test-tt
9+
10+
# List of workloads to deploy
11+
ocp_workloads_namespaced:
12+
- ocp_workloads_namespaced_example
13+
14+
# Output directory for deployment artifacts
15+
output_dir: "/tmp/output_dir/{{ guid }}"

0 commit comments

Comments
 (0)