Skip to content

Commit 6e61acb

Browse files
committed
Added WoT agent with helm chart for testing.
1 parent bac9aa3 commit 6e61acb

File tree

16 files changed

+635
-4
lines changed

16 files changed

+635
-4
lines changed

kotlin-wot-binding-http/src/main/kotlin/http/HttpProtocolServer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ fun Application.setupRouting(servient: Servient) {
223223
}
224224
setupJackson()
225225
routing {
226-
route("/") {
226+
route("/.well-known/wot") {
227227
get {
228-
call.respond(servient.things.values.toList(), typeInfo<List<WoTExposedThing>>())
228+
call.respond(servient.things.values.toList().first(), typeInfo<List<WoTExposedThing>>())
229229
}
230230
}
231231
route("/{id}") {

kotlin-wot-binding-websocket/src/main/kotlin/websocket/WebSocketProtocolServer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ fun Application.setupRoutingWithWebSockets(servient: Servient) {
191191
contentConverter = JacksonWebsocketContentConverter(JsonMapper.instance)
192192
}
193193
routing {
194-
route("/") {
194+
route("/.well-known/wot") {
195195
get {
196-
call.respond(servient.things.values.toList(), typeInfo<List<WoTExposedThing>>())
196+
call.respond(servient.things.values.toList().first(), typeInfo<List<WoTExposedThing>>())
197197
}
198198
}
199199

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage
2+
import org.springframework.boot.gradle.tasks.bundling.BootJar
3+
4+
plugins {
5+
kotlin("plugin.spring") version "1.9.10"
6+
id("org.springframework.boot") version "3.1.5" // Use the latest compatible version
7+
id("io.spring.dependency-management") version "1.1.3"
8+
id("com.citi.helm") version "2.2.0"
9+
id("com.citi.helm-publish") version "2.2.0"
10+
}
11+
12+
dependencies {
13+
api(project(":kotlin-wot-binding-http"))
14+
api(project(":kotlin-wot-binding-websocket"))
15+
api(project(":kotlin-wot-binding-mqtt"))
16+
api(project(":kotlin-wot-spring-boot-starter"))
17+
api(project(":kotlin-wot-lmos-protocol"))
18+
api("ai.ancf.lmos:arc-spring-boot-starter:0.111.0")
19+
20+
implementation("org.springframework.boot:spring-boot-starter-web")
21+
implementation("org.springframework.boot:spring-boot-starter-webflux")
22+
23+
implementation("ai.ancf.lmos:arc-azure-client:0.111.0")
24+
}
25+
26+
tasks.named<Test>("test") {
27+
enabled = false
28+
}
29+
30+
tasks.withType<BootJar> {
31+
mainClass.set("integration.AgentApplicationKt")
32+
}
33+
34+
tasks.named<BootBuildImage>("bootBuildImage") {
35+
if (project.hasProperty("REGISTRY_URL")) {
36+
val registryUrl = getProperty("REGISTRY_URL")
37+
val registryUsername = getProperty("REGISTRY_USERNAME")
38+
val registryPassword = getProperty("REGISTRY_PASSWORD")
39+
val registryNamespace = getProperty("REGISTRY_NAMESPACE")
40+
41+
imageName.set("$registryUrl/$registryNamespace/wot-agent:0.1.0-SNAPSHOT")
42+
publish = true
43+
docker {
44+
publishRegistry {
45+
url.set(registryUrl)
46+
username.set(registryUsername)
47+
password.set(registryPassword)
48+
}
49+
}
50+
} else {
51+
imageName.set("${rootProject.name}:${project.version}")
52+
publish = false
53+
}
54+
}
55+
56+
helm {
57+
charts {
58+
create("main") {
59+
chartName.set("${project.name}-chart")
60+
chartVersion.set("${project.version}")
61+
sourceDir.set(file("src/main/helm"))
62+
}
63+
}
64+
}
65+
66+
tasks.register("helmPush") {
67+
description = "Push Helm chart to OCI registry"
68+
group = "helm"
69+
dependsOn(tasks.named("helmPackageMainChart"))
70+
71+
doLast {
72+
val registryUrl = getProperty("REGISTRY_URL")
73+
val registryUsername = getProperty("REGISTRY_USERNAME")
74+
val registryPassword = getProperty("REGISTRY_PASSWORD")
75+
val registryNamespace = getProperty("REGISTRY_NAMESPACE")
76+
77+
helm.execHelm("registry", "login") {
78+
option("-u", registryUsername)
79+
option("-p", registryPassword)
80+
args(registryUrl)
81+
}
82+
83+
helm.execHelm("push") {
84+
args(tasks.named("helmPackageMainChart").get().outputs.files.singleFile.toString())
85+
args("oci://$registryUrl/$registryNamespace")
86+
}
87+
88+
helm.execHelm("registry", "logout") {
89+
args(registryUrl)
90+
}
91+
}
92+
}
93+
94+
fun getProperty(propertyName: String) = System.getenv(propertyName) ?: project.findProperty(propertyName) as String
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kotlin.code.style=official
2+
3+
chartName=wot-agent
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: v2
2+
name: ${chartName}
3+
description: The WoT Sample Agent
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: ${chartVersion}
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
# It is recommended to use it with quotes.
24+
appVersion: ${projectVersion}
25+
home: https://github.com/eclipse-lmos/lmos-wot-agents
26+
keywords:
27+
- lmos
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "wot-agent.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "wot-agent.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "wot-agent.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "wot-agent.labels" -}}
37+
helm.sh/chart: {{ include "wot-agent.chart" . }}
38+
{{ include "wot-agent.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "wot-agent.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "wot-agent.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "wot-agent.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "wot-agent.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
63+
64+
{{/*
65+
Create Docker secrets for pulling images from a private container registry.
66+
*/}}
67+
{{- define "imagePullSecret" }}
68+
{{- printf "{\"auths\": {\"%s\": {\"auth\": \"%s\"}}}" .Values.imageCredentials.registry (printf "%s:%s" .Values.imageCredentials.username .Values.imageCredentials.password | b64enc) | b64enc }}
69+
{{- end }}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "wot-agent.fullname" . }}
5+
labels:
6+
{{- include "wot-agent.labels" . | nindent 4 }}
7+
wot-agent: "true"
8+
spec:
9+
{{- if not .Values.autoscaling.enabled }}
10+
replicas: {{ .Values.replicaCount }}
11+
{{- end }}
12+
selector:
13+
matchLabels:
14+
{{- include "wot-agent.selectorLabels" . | nindent 6 }}
15+
template:
16+
metadata:
17+
{{- with .Values.podAnnotations }}
18+
annotations:
19+
{{- toYaml . | nindent 8 }}
20+
{{- end }}
21+
labels:
22+
{{- include "wot-agent.labels" . | nindent 8 }}
23+
app: {{ include "wot-agent.fullname" . }} # Adding app label for istio
24+
version: {{ .Chart.AppVersion | quote }} # Adding version label for istio
25+
{{- with .Values.podLabels }}
26+
{{- toYaml . | nindent 8 }}
27+
{{- end }}
28+
spec:
29+
{{- with .Values.imagePullSecrets }}
30+
imagePullSecrets:
31+
{{- toYaml . | nindent 8 }}
32+
{{- end }}
33+
securityContext:
34+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
35+
containers:
36+
- name: {{ .Chart.Name }}
37+
securityContext:
38+
{{- toYaml .Values.securityContext | nindent 12 }}
39+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
40+
imagePullPolicy: Always
41+
envFrom:
42+
- secretRef:
43+
name: openai-secrets
44+
ports:
45+
- name: http
46+
containerPort: {{ .Values.service.port }}
47+
protocol: TCP
48+
livenessProbe:
49+
{{- toYaml .Values.livenessProbe | nindent 12 }}
50+
readinessProbe:
51+
{{- toYaml .Values.readinessProbe | nindent 12 }}
52+
resources:
53+
{{- toYaml .Values.resources | nindent 12 }}
54+
{{- with .Values.volumeMounts }}
55+
volumeMounts:
56+
{{- toYaml . | nindent 12 }}
57+
{{- end }}
58+
{{- with .Values.volumes }}
59+
volumes:
60+
{{- toYaml . | nindent 8 }}
61+
{{- end }}
62+
{{- with .Values.nodeSelector }}
63+
nodeSelector:
64+
{{- toYaml . | nindent 8 }}
65+
{{- end }}
66+
{{- with .Values.affinity }}
67+
affinity:
68+
{{- toYaml . | nindent 8 }}
69+
{{- end }}
70+
{{- with .Values.tolerations }}
71+
tolerations:
72+
{{- toYaml . | nindent 8 }}
73+
{{- end }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ include "wot-agent.fullname" . }}
5+
labels:
6+
{{- include "wot-agent.labels" . | nindent 4 }}
7+
spec:
8+
type: {{ .Values.service.type }}
9+
ports:
10+
- port: {{ .Values.service.port }}
11+
targetPort: {{ .Values.service.port }}
12+
protocol: TCP
13+
name: http
14+
selector:
15+
{{- include "wot-agent.selectorLabels" . | nindent 4 }}

0 commit comments

Comments
 (0)