Skip to content

Commit deb84e4

Browse files
authored
Updated Terraform, Linted, Standardised
1 parent 3c55a6b commit deb84e4

File tree

26 files changed

+259
-183
lines changed

26 files changed

+259
-183
lines changed

docs/content/advanced/microservices.md

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ You will need to build the {{< short_app_ref >}} container images and stage them
6161
podman push <server_repository>:latest
6262
```
6363

64+
### Namespace
65+
66+
Create a Kubernetes namespace to logically isolate the {{< short_app_ref >}} resources. For demonstration purposes, the `ai-optimizer` namespace will be created and used throughout this documentation.
67+
68+
```yaml
69+
apiVersion: v1
70+
kind: Namespace
71+
metadata:
72+
name: ai-optimizer
73+
```
74+
6475
### Ingress
6576

6677
To access the {{< short_app_ref >}} GUI and API Server, you can either use a port-forward or an Ingress service. For demonstration purposes, the [OCI Native Ingress Controller](https://docs.oracle.com/en-us/iaas/Content/ContEng/Tasks/contengsettingupnativeingresscontroller.htm), which was enabled on the **OKE** cluster as part of the **IaC**, will be used to for public Ingress access.
@@ -81,30 +92,25 @@ These will be output as part of the **IaC** but can be removed from the code if
8192
8293
1. Create a `native_ingress.yaml`:
8394
```yaml
84-
apiVersion: v1
85-
kind: Namespace
86-
metadata:
87-
name: hologram
88-
---
8995
apiVersion: "ingress.oraclecloud.com/v1beta1"
9096
kind: IngressClassParameters
9197
metadata:
9298
name: native-ic-params
9399
namespace: ai-optimizer
94100
spec:
95-
compartmentId: <compartment_ocid>
101+
compartmentId: <lb_compartment_ocid>
96102
subnetId: <lb_subnet_ocid>
97103
loadBalancerName: "ai-optimizer-lb"
98104
reservedPublicAddressId: <lb_reserved_ip_ocid>
99105
isPrivate: false
100-
maxBandwidthMbps: 1250
106+
maxBandwidthMbps: 100
101107
minBandwidthMbps: 10
102108
---
103109
apiVersion: networking.k8s.io/v1
104110
kind: IngressClass
105111
metadata:
106112
name: native-ic
107-
namespace: hologram
113+
namespace: ai-optimizer
108114
annotations:
109115
ingressclass.kubernetes.io/is-default-class: "true"
110116
oci-native-ingress.oraclecloud.com/network-security-group-ids: <lb_nsg_ocid>
@@ -114,7 +120,7 @@ These will be output as part of the **IaC** but can be removed from the code if
114120
controller: oci.oraclecloud.com/native-ingress-controller
115121
parameters:
116122
scope: Namespace
117-
namespace: hologram
123+
namespace: ai-optimizer
118124
apiGroup: ingress.oraclecloud.com
119125
kind: IngressClassParameters
120126
name: native-ic-params
@@ -125,20 +131,13 @@ These will be output as part of the **IaC** but can be removed from the code if
125131
The {{< short_app_ref >}} can be deployed using the [Helm](https://helm.sh/) chart provided with the source:
126132
[{{< short_app_ref >}} Helm Chart](https://github.com/oracle-samples/ai-optimizer/tree/main/helm). A list of all values can be found in [values_summary.md](https://github.com/oracle-samples/ai-optimizer/tree/main/helm/values_summary.md).
127133
128-
If you deployed a GPU node pool as part of the **IaC**, you can deploy Ollama and enable a Large Language and Embedding Model out-of-the-box.
129-
130-
1. Create the `ai-optimizer` namespace:
131-
132-
```bash
133-
kubectl create namespace ai-optimizer
134-
```
134+
If you deployed a GPU node pool as part of the **IaC**, [Ollama](https://ollama.com/) will be deployed automatically and a Large Language and Embedding Model will be available out-of-the-box.
135135
136136
1. Create a secret to hold the API Key:
137137
138138
```bash
139-
kubectl create secret generic api-key \
140-
--from-literal=apiKey=$(openssl rand -hex 32) \
141-
--namespace=ai-optimizer
139+
kubectl -n ai-optimizer create secret generic api-key \
140+
--from-literal=apiKey=$(openssl rand -hex 32)
142141
```
143142
144143
1. Create a secret to hold the Database Authentication:
@@ -149,11 +148,10 @@ If you deployed a GPU node pool as part of the **IaC**, you can deploy Ollama an
149148
- `<adb_service>` - The Service Name (i.e. ADBDB_TP)
150149
151150
```bash
152-
kubectl create secret generic db-authn \
151+
kubectl -n ai-optimizer create secret generic db-authn \
153152
--from-literal=username='ADMIN' \
154153
--from-literal=password='<adb_password>' \
155-
--from-literal=service='<adb_service>' \
156-
--namespace=ai-optimizer
154+
--from-literal=service='<adb_service>'
157155
```
158156
159157
These will be output as part of the **IaC**.
@@ -172,7 +170,7 @@ If you deployed a GPU node pool as part of the **IaC**, you can deploy Ollama an
172170
173171
These will be output as part of the **IaC**.
174172
175-
{{< icon "star" >}} If using the **IaC** for **OCI**, it is not required to specify an ImagePullSecret as the cluster nodes are configured with the [Image Credential Provider for OKE](https://github.com/oracle-devrel/oke-credential-provider-for-ocir).
173+
{{< icon "star" >}} If using the **IaC** for **OCI**, it is not required to specify an ImagePullSecret as the cluster nodes are configured with the [Image Credential Provider for OKE](https://github.com/oracle-devrel/oke-credential-provider-for-ocir). It may take up to 5 minutes for the policy allowing for the image pull to be recognized.
176174
177175
```yaml
178176
global:
@@ -185,6 +183,7 @@ If you deployed a GPU node pool as part of the **IaC**, you can deploy Ollama an
185183
image:
186184
repository: <server_repository>
187185
tag: "latest"
186+
imagePullPolicy: Always
188187
189188
ingress:
190189
enabled: true
@@ -198,20 +197,33 @@ If you deployed a GPU node pool as part of the **IaC**, you can deploy Ollama an
198197
http:
199198
type: "NodePort"
200199
200+
# -- Oracle Cloud Infrastructure Configuration
201+
oci:
202+
tenancy: "<tenancy_ocid>"
203+
region: "<oci_region>"
204+
201205
# -- Oracle Autonomous Database Configuration
202206
adb:
203207
enabled: true
204208
ocid: "<adb_ocid>"
205209
mtls:
206-
enabled: false
210+
enabled: true
207211
authN:
208212
secretName: "db-authn"
213+
usernameKey: "username"
214+
passwordKey: "password"
215+
serviceKey: "service"
216+
217+
models:
218+
ollama:
219+
enabled: false
209220
210221
client:
211222
enabled: true
212223
image:
213224
repository: <client_repository>
214225
tag: "latest"
226+
imagePullPolicy: Always
215227
216228
ingress:
217229
enabled: true
@@ -229,10 +241,10 @@ If you deployed a GPU node pool as part of the **IaC**, you can deploy Ollama an
229241
disableTestbed: "false"
230242
disableApi: "false"
231243
disableTools: "false"
232-
disableDbCfg: "true"
244+
disableDbCfg: "false"
233245
disableModelCfg: "false"
234-
disableOciCfg: "true"
235-
disableSettings: "true"
246+
disableOciCfg: "false"
247+
disableSettings: "false"
236248
237249
ollama:
238250
enabled: true
@@ -250,8 +262,8 @@ If you deployed a GPU node pool as part of the **IaC**, you can deploy Ollama an
250262
251263
```bash
252264
helm upgrade \
253-
--install ai-optimizer . \
254265
--namespace ai-optimizer \
266+
--install ai-optimizer . \
255267
-f values.yaml
256268
```
257269

helm/charts/server/templates/adb.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@ metadata:
3333
labels:
3434
{{- include "app.labels" . | nindent 4 }}
3535
spec:
36+
action: "Sync"
3637
details:
37-
autonomousDatabaseOCID: {{ .Values.adb.ocid }}
38+
id: {{ .Values.adb.ocid }}
3839
adminPassword:
3940
k8sSecret:
4041
name: place-holder
41-
wallet:
42-
name: {{ include "app.fullname" . }}-adb-tns-admin-{{ .Release.Revision }}
43-
password:
44-
k8sSecret:
45-
name: {{ include "app.fullname" . }}-adb-wallet-pass-{{ .Release.Revision }}
42+
wallet:
43+
name: {{ include "app.fullname" . }}-adb-tns-admin-{{ .Release.Revision }}
44+
password:
45+
k8sSecret:
46+
name: {{ include "app.fullname" . }}-adb-wallet-pass-{{ .Release.Revision }}
4647
{{- if .Values.oci.region }}
4748
ociConfig:
4849
configMapName: {{ include "app.fullname" . }}-oci-cred

opentofu/iam.tf

Lines changed: 0 additions & 38 deletions
This file was deleted.

opentofu/locals.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
locals {
77
compartment_ocid = var.compartment_ocid != "" ? var.compartment_ocid : var.tenancy_ocid
88
label_prefix = var.label_prefix != "" ? lower(var.label_prefix) : lower(random_pet.label.id)
9-
identity_tag_key = format("%s.%s", oci_identity_tag_namespace.tag_namespace.name, oci_identity_tag.identity_tag.name)
109
}
1110

1211
// Autonomous Database

opentofu/main.tf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ resource "oci_database_autonomous_database" "default_adb" {
7474
license_model = var.adb_license_model
7575
is_mtls_connection_required = true
7676
whitelisted_ips = local.adb_whitelist_cidrs
77-
defined_tags = { (local.identity_tag_key) = local.label_prefix }
7877
}
7978

8079
// Virtual Machine
@@ -113,7 +112,6 @@ module "kubernetes" {
113112
compartment_id = local.compartment_ocid
114113
vcn_id = module.network.vcn_ocid
115114
region = var.region
116-
dynamic_group = oci_identity_dynamic_group.resource_dynamic_group.name
117115
lb = oci_load_balancer_load_balancer.lb
118116
adb_id = oci_database_autonomous_database.default_adb.id
119117
adb_name = local.adb_name
@@ -132,7 +130,6 @@ module "kubernetes" {
132130
public_subnet_id = module.network.public_subnet_ocid
133131
private_subnet_id = module.network.private_subnet_ocid
134132
lb_nsg_id = oci_core_network_security_group.lb.id
135-
identity_tag_key = local.identity_tag_key
136133
providers = {
137134
oci.home_region = oci.home_region
138135
}

opentofu/modules/kubernetes/iam.tf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
# All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
33
# spell-checker: disable
44

5+
resource "oci_identity_dynamic_group" "workers_dynamic_group" {
6+
compartment_id = var.tenancy_id
7+
name = format("%s-worker-dyngrp", var.label_prefix)
8+
description = format("%s Workers Dynamic Group", var.label_prefix)
9+
matching_rule = format(
10+
"ALL {instance.compartment.id = '%s', tag.Oracle-Tags.CreatedBy.value = '%s'}",
11+
var.compartment_id, oci_containerengine_node_pool.default_node_pool_details.id)
12+
provider = oci.home_region
13+
}
14+
515
resource "oci_identity_policy" "workers_policies" {
616
compartment_id = var.tenancy_id
717
name = format("%s-workers-policy", var.label_prefix)
@@ -27,7 +37,8 @@ resource "oci_identity_policy" "workers_policies" {
2737
format("allow any-user to manage waf-family in compartment id %s where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '%s'}", var.compartment_id, oci_containerengine_cluster.default_cluster.id),
2838
format("allow any-user to read cluster-family in compartment id %s where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '%s'}", var.compartment_id, oci_containerengine_cluster.default_cluster.id),
2939
format("allow any-user to use tag-namespaces in compartment id %s where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '%s'}", var.compartment_id, oci_containerengine_cluster.default_cluster.id),
30-
format("allow dynamic-group %s to manage repos in compartment id %s", var.dynamic_group, var.compartment_id),
40+
format("allow dynamic-group %s to use generative-ai-family in compartment id %s", oci_identity_dynamic_group.workers_dynamic_group.name, var.compartment_id),
41+
format("allow dynamic-group %s to manage repos in compartment id %s", oci_identity_dynamic_group.workers_dynamic_group.name, var.compartment_id),
3142
]
3243
provider = oci.home_region
3344
}

opentofu/modules/kubernetes/main.tf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ resource "oci_containerengine_cluster" "default_cluster" {
8484
}
8585
service_lb_subnet_ids = [var.public_subnet_id]
8686
}
87-
defined_tags = { (var.identity_tag_key) = var.label_prefix }
8887
freeform_tags = {
8988
"clusterName" = local.k8s_cluster_name
9089
}
@@ -146,8 +145,6 @@ resource "oci_containerengine_node_pool" "default_node_pool_details" {
146145
}
147146
size = var.k8s_cpu_node_pool_size
148147
nsg_ids = [oci_core_network_security_group.k8s_workers.id]
149-
// Used for Instance Principles
150-
defined_tags = { (var.identity_tag_key) = var.label_prefix }
151148
}
152149
node_eviction_node_pool_settings {
153150
eviction_grace_duration = "PT5M"
@@ -176,6 +173,7 @@ resource "oci_containerengine_node_pool" "default_node_pool_details" {
176173
}
177174

178175
resource "oci_containerengine_node_pool" "gpu_node_pool_details" {
176+
count = var.k8s_node_pool_gpu_deploy ? 1 : 0
179177
cluster_id = oci_containerengine_cluster.default_cluster.id
180178
compartment_id = var.compartment_id
181179
kubernetes_version = format("v%s", var.k8s_version)
@@ -198,8 +196,6 @@ resource "oci_containerengine_node_pool" "gpu_node_pool_details" {
198196
}
199197
size = var.k8s_gpu_node_pool_size
200198
nsg_ids = [oci_core_network_security_group.k8s_workers.id]
201-
// Used for Instance Principles
202-
defined_tags = { (var.identity_tag_key) = var.label_prefix }
203199
}
204200
node_eviction_node_pool_settings {
205201
eviction_grace_duration = "PT5M"

opentofu/modules/kubernetes/variables.tf

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ variable "label_prefix" {
4747
type = string
4848
}
4949

50-
variable "dynamic_group" {
51-
type = string
52-
}
53-
5450
variable "adb_id" {
5551
type = string
5652
}
@@ -105,7 +101,3 @@ variable "k8s_api_endpoint_allowed_cidrs" {
105101
type = string
106102
default = ""
107103
}
108-
109-
variable "identity_tag_key" {
110-
type = string
111-
}

src/client/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@ RUN microdnf -y update && \
2828
install -d -m 0700 -o $RUNUSER -g $RUNUSER /app/.oci
2929

3030
COPY pyproject.toml /opt/package/pyproject.toml
31-
COPY --chown=$RUNUSER:$RUNUSER . /app
31+
# Use the virtual environment for pip installations (Client Specific)
32+
RUN source /opt/.venv/bin/activate && \
33+
pip install "/opt/package[client]"
3234

3335
##################################################
3436
# Clint Application
3537
##################################################
3638
FROM optimizer_base AS client
3739

38-
# Use the virtual environment for pip installations (Client Specific)
39-
RUN source /opt/.venv/bin/activate && \
40-
pip install "/opt/package[client]"
41-
40+
COPY --chown=$RUNUSER:$RUNUSER . /app
4241
RUN rm -rf /app/server /app/.oci /app/launch_server.py
4342

4443
# Set user and working directory

src/client/content/api_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ async def main() -> None:
110110
if "server_client" not in state:
111111
state.server_client = client.Client(
112112
server=state.server,
113-
settings=state["server_settings"],
113+
settings=state.server_settings,
114114
timeout=10,
115115
)
116116
server_client: client.Client = state.server_client

0 commit comments

Comments
 (0)