From dedddb14854a5d534256cdb9f00889f5527ccfea Mon Sep 17 00:00:00 2001 From: grego952 Date: Fri, 13 Feb 2026 15:01:42 +0100 Subject: [PATCH 01/20] Add api-postgres-go and delete api-mssql-go --- api-mssql-go/README.md | 178 ------------------ api-mssql-go/go.mod | 10 - api-mssql-go/k8s/configmap.yaml | 10 - .../k8s/deployment-servicebinding.yaml | 56 ------ api-postgres-go/README.md | 106 +++++++++++ .../cmd/api/main.go | 2 +- .../docker/Dockerfile | 8 +- api-postgres-go/go.mod | 9 + {api-mssql-go => api-postgres-go}/go.sum | 18 +- .../internal/api/events.go | 5 + .../internal/api/server.go | 37 +++- .../internal/config/config.go | 17 +- .../internal/db/connection.go | 21 ++- .../internal/db/order.go | 25 ++- .../k8s/apirule.yaml | 9 +- .../k8s/authorizationpolicy.yaml | 2 +- api-postgres-go/k8s/configmap.yaml | 10 + .../k8s/deployment-servicebinding.yaml | 82 ++++++++ .../k8s/deployment.yaml | 38 ++-- .../k8s/event.yaml | 4 +- .../k8s/secret.yaml | 8 +- 21 files changed, 311 insertions(+), 344 deletions(-) delete mode 100644 api-mssql-go/README.md delete mode 100644 api-mssql-go/go.mod delete mode 100644 api-mssql-go/k8s/configmap.yaml delete mode 100644 api-mssql-go/k8s/deployment-servicebinding.yaml create mode 100644 api-postgres-go/README.md rename {api-mssql-go => api-postgres-go}/cmd/api/main.go (88%) rename {api-mssql-go => api-postgres-go}/docker/Dockerfile (52%) create mode 100644 api-postgres-go/go.mod rename {api-mssql-go => api-postgres-go}/go.sum (54%) rename {api-mssql-go => api-postgres-go}/internal/api/events.go (84%) rename {api-mssql-go => api-postgres-go}/internal/api/server.go (71%) rename {api-mssql-go => api-postgres-go}/internal/config/config.go (54%) rename {api-mssql-go => api-postgres-go}/internal/db/connection.go (56%) rename {api-mssql-go => api-postgres-go}/internal/db/order.go (72%) rename {api-mssql-go => api-postgres-go}/k8s/apirule.yaml (77%) rename {api-mssql-go => api-postgres-go}/k8s/authorizationpolicy.yaml (91%) create mode 100644 api-postgres-go/k8s/configmap.yaml create mode 100644 api-postgres-go/k8s/deployment-servicebinding.yaml rename {api-mssql-go => api-postgres-go}/k8s/deployment.yaml (58%) rename {api-mssql-go => api-postgres-go}/k8s/event.yaml (56%) rename {api-mssql-go => api-postgres-go}/k8s/secret.yaml (51%) diff --git a/api-mssql-go/README.md b/api-mssql-go/README.md deleted file mode 100644 index c0e51e3f1..000000000 --- a/api-mssql-go/README.md +++ /dev/null @@ -1,178 +0,0 @@ -# Golang MS SQL database API - -## Overview - -This sample provides a Golang API endpoint for communication with the MS SQL databases provided in the `database-mssql` and `database-azure-mssql` directories. You can also enable an Event Trigger for both examples. - -## MS SQL database example - -For the `database-mssql` example, use the `deployment.yaml` file. It provides the Deployment definition as well as an APIRule to expose the Function without authentication. The Deployment also contains a ConfigMap and a Secret with the following parameters for the `database-mssql` example that you can configure to modify the default options: - -| Parameter | Value | -| ------------ | ----------------------------- | -| **database** | `DemoDB` | -| **host** | `mssql.dev.svc.cluster.local` | -| **password** | `Yukon900` | -| **username** | `sa` | -| **port** | `1433` | - -This sample demonstrates how to: - -- Create a development Namespace in the Kyma runtime. -- Deploy the following Kubernetes resources: - - API deployment written in GO - - API Rule - - Service - - Secret - -## Azure MS SQL database example - -For the `database-azure-mssql` example, use the `deployment-servicebinding.yaml` file. It defines the Deployment definition as well as an APIRule to expose the Function without authentication. It also defines a ServiceBinding and ServiceBindingUsage that configure the Function to use the `database-azure-mssql` ServiceInstance. - -This sample demonstrates how to: - -- Create a development Namespace in the Kyma runtime. -- Deploy the following Kubernetes resources: - - API deployment written in GO - - API Rule - - Service - - Event Subscription - - ServiceBinding - - ServiceBindingUsage - -## Prerequisites - -- SAP BTP, Kyma runtime instance -- [Docker](https://www.docker.com/) -- [Go](https://golang.org/doc/install) -- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) configured to use the `KUBECONFIG` file downloaded from the Kyma runtime - -## Steps - -### Run the API locally - -1. Set the environment variables required to connect with the database: - - ```shell script - export MYAPP_username=sa - export MYAPP_password=Yukon900 - export MYAPP_database=DemoDB - export MYAPP_host=localhost - export MYAPP_port=1433 - ``` - -2. Run the application: - - ```shell script - go run ./cmd/api - ``` - -### Build the Docker image - -1. Build and push the image to your Docker repository: - - ```shell script - docker build -t {your-docker-account}/api-mssql-go -f docker/Dockerfile . - docker push {your-docker-account}/api-mssql-go - ``` - -2. To run the image locally, run: - - ```shell script - docker run -p 8000:8000 -d {your-docker-account}/api-mssql-go:latest - ``` - -### Deploy the API - MS SQL database example - -1. Create a new `dev` Namespace: - - ```shell script - kubectl create namespace dev - kubectl label namespaces dev istio-injection=enabled - ``` - -2. Apply the ConfigMap: - - ```shell script - kubectl -n dev apply -f ./k8s/configmap.yaml - ``` - -3. Apply the Secret: - - ```shell script - kubectl -n dev apply -f ./k8s/secret.yaml - ``` - -4. Apply the Deployment: - - ```shell script - kubectl -n dev apply -f ./k8s/deployment.yaml - ``` - -5. Apply the APIRule: - - ```shell script - kubectl -n dev apply -f ./k8s/apirule.yaml - ``` - -6. Verify that the Deployment is up and running: - - ```shell script - kubectl -n dev get deployment api-mssql-go - ``` - -7. Use the APIRule: - - - `https://api-mssql-go.{cluster-domain}/orders` - - `https://api-mssql-go.{cluster-domain}/orders/10000001` - -### Deploy the API - Azure MS SQL database example - -1. Create a new `dev` Namespace: - - ```shell script - kubectl create namespace dev - ``` - -2. Get the name of the ServiceInstance: - - ```shell script - kubectl -n dev get serviceinstances - ``` - - For example: - - | NAME | CLASS | PLAN | STATUS | AGE | - | ------------------------------------- | --------------------------- | ----- | ------ | --- | - | **_azure-sql-12-0-unkempt-entrance_** | ServiceClass/azure-sql-12-0 | basic | Ready | 63m | - -3. Within the `deployment-servicebinding.yaml`, adjust the name of the **instanceRef** property of the corresponding ServiceBinding: - - ```yaml - apiVersion: servicecatalog.k8s.io/v1beta1 - kind: ServiceBinding - metadata: - name: azure-sql - spec: - instanceRef: name:azure-sql-12-0-unkempt-entrance - ``` - -4. Apply the Deployment: - - ```shell script - kubectl -n dev apply -f ./k8s/deployment-servicebinding.yaml - ``` - -### Deploy the Event Subscription - -The Event Subscription works for both samples. It expects that either SAP Commerce Cloud or the Commerce Mock application is connected and configured within the Namespace. You can find a blog post with details on the Commerce Mock setup [here](https://blogs.sap.com/2020/06/17/sap-cloud-platform-extension-factory-kyma-runtime-commerce-mock-events-and-apis/). - -The subscription and code within the Golang application are set up for the `order.created` event. Before you deploy the subscription, verify that the value of `spec.filter.filters.eventType.value` is correct for the name of your application. - -1. Apply the Deployment: - - ```shell script - kubectl -n dev apply -f ./k8s/event.yaml - ``` - -2. Within the mock application, submit the `order.created` event. This populates the database with the submitted order code and the `order received from event` notification. diff --git a/api-mssql-go/go.mod b/api-mssql-go/go.mod deleted file mode 100644 index ce721b7d4..000000000 --- a/api-mssql-go/go.mod +++ /dev/null @@ -1,10 +0,0 @@ -module github.com/SAP-samples/kyma-runtime-extension-samples/api-mssql-go - -go 1.14 - -require ( - github.com/denisenkom/go-mssqldb v0.0.0-20200910202707-1e08a3fab204 - github.com/gorilla/mux v1.8.0 - github.com/vrischmann/envconfig v1.3.0 - golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect -) diff --git a/api-mssql-go/k8s/configmap.yaml b/api-mssql-go/k8s/configmap.yaml deleted file mode 100644 index 70565526f..000000000 --- a/api-mssql-go/k8s/configmap.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: api-mssql-go - labels: - app: api-mssql-go -data: - database: DemoDB - host: mssql.dev.svc.cluster.local - port: "1433" diff --git a/api-mssql-go/k8s/deployment-servicebinding.yaml b/api-mssql-go/k8s/deployment-servicebinding.yaml deleted file mode 100644 index 06f18c7a1..000000000 --- a/api-mssql-go/k8s/deployment-servicebinding.yaml +++ /dev/null @@ -1,56 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: api-mssql-go - labels: - app: api-mssql-go -spec: - replicas: 1 - selector: - matchLabels: - app: api-mssql-go - template: - metadata: - labels: - app: api-mssql-go - spec: - containers: - # replace the repository URL with your own repository - - image: jcawley5/api-mssql-go:latest - imagePullPolicy: Always - name: api-mssql-go - ports: - - name: http - containerPort: 8000 ---- -apiVersion: v1 -kind: Service -metadata: - name: api-mssql-go - labels: - app: api-mssql-go -spec: - ports: - - name: http - port: 80 - targetPort: 8000 - protocol: TCP - selector: - app: api-mssql-go ---- -apiVersion: gateway.kyma-project.io/v2 -kind: APIRule -metadata: - name: api-mssql-go -spec: - gateway: kyma-system/kyma-gateway - hosts: - - api-mssql-go - service: - name: api-mssql-go - port: 80 - rules: - - path: /orders/{**} - noAuth: true - methods: ["GET", "POST", "PUT", "DELETE"] \ No newline at end of file diff --git a/api-postgres-go/README.md b/api-postgres-go/README.md new file mode 100644 index 000000000..702dffed2 --- /dev/null +++ b/api-postgres-go/README.md @@ -0,0 +1,106 @@ +# Golang PostgreSQL database API + +## Overview + +This sample provides a Golang API endpoint for communication with the PostgreSQL database provisioned in the `postgres-provision` tutorial. The service exposes CRUD endpoints for the `Orders` table created in `DemoDB`. An optional Kyma event subscription can insert orders from an `order.created` event. + +Default connection values used throughout the sample: + +| Parameter | Value | +| ------------ | ----------------------------------- | +| **database** | `DemoDB` | +| **host** | `postgres.dev.svc.cluster.local` | +| **password** | `Yukon900` | +| **username** | `postgres` | +| **port** | `5432` (or forwarded port `15432`) | + +## Prerequisites + +- SAP BTP, Kyma runtime instance +- [Docker](https://www.docker.com/) +- [Go](https://golang.org/doc/install) +- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) configured to use the `KUBECONFIG` file downloaded from the Kyma runtime +- PostgreSQL provisioned via `postgres-provision/postgres-provision.md` (Secret `postgres` and Service `postgres` in namespace `dev`) + +## Steps + +### Run the API locally + +1. Set the environment variables required to connect with the database (adjust host/port to match your setup or forwarded port): + + ```shell script + export POSTGRES_USER=postgres + export POSTGRES_PASSWORD=Yukon900 + export POSTGRES_DB=DemoDB + export POSTGRES_HOST=localhost + export POSTGRES_PORT=15432 + export POSTGRES_SSLMODE=disable + ``` + +2. Run the application: + + ```shell script + go run ./cmd/api + ``` + +### Build the Docker image + +1. Build and push the image to your Docker repository: + + ```shell script + docker build -t {your-docker-account}/api-postgres-go -f docker/Dockerfile . + docker push {your-docker-account}/api-postgres-go + ``` + +2. To run the image locally, run: + + ```shell script + docker run -p 8000:8000 -d --name api-postgres-go \ + -e POSTGRES_USER=postgres \ + -e POSTGRES_PASSWORD=Yukon900 \ + -e POSTGRES_DB=DemoDB \ + -e POSTGRES_HOST=host.docker.internal \ + -e POSTGRES_PORT=15432 \ + -e POSTGRES_SSLMODE=disable \ + {your-docker-account}/api-postgres-go:latest + ``` + +### Deploy the API + +1. Create a new `dev` Namespace (skip if already created during provisioning): + + ```shell script + kubectl create namespace dev + kubectl label namespaces dev istio-injection=enabled + ``` + +2. Apply the ConfigMap and Secret (skip the Secret if it already exists from the provisioning tutorial): + + ```shell script + kubectl -n dev apply -f ./k8s/configmap.yaml + kubectl -n dev apply -f ./k8s/secret.yaml + ``` + +3. Apply the Deployment and APIRule: + + ```shell script + kubectl -n dev apply -f ./k8s/deployment.yaml + kubectl -n dev apply -f ./k8s/apirule.yaml + ``` + +4. Verify that the Deployment is up and running: + + ```shell script + kubectl -n dev get deployment api-postgres-go + ``` + +5. Optional: apply the Event Subscription to insert orders from events: + + ```shell script + kubectl -n dev apply -f ./k8s/event.yaml + ``` + +6. Use the APIRule: + + - `https://api-postgres-go.{cluster-domain}/orders` + - `https://api-postgres-go.{cluster-domain}/orders/10000001` diff --git a/api-mssql-go/cmd/api/main.go b/api-postgres-go/cmd/api/main.go similarity index 88% rename from api-mssql-go/cmd/api/main.go rename to api-postgres-go/cmd/api/main.go index 7958e2bb7..9df47fa5e 100644 --- a/api-mssql-go/cmd/api/main.go +++ b/api-postgres-go/cmd/api/main.go @@ -6,7 +6,7 @@ import ( "github.com/gorilla/mux" - "github.com/SAP-samples/kyma-runtime-extension-samples/api-mssql-go/internal/api" + "github.com/SAP-samples/kyma-runtime-extension-samples/api-postgres-go/internal/api" ) func main() { diff --git a/api-mssql-go/docker/Dockerfile b/api-postgres-go/docker/Dockerfile similarity index 52% rename from api-mssql-go/docker/Dockerfile rename to api-postgres-go/docker/Dockerfile index 524b99f9b..ea1fb7dcb 100644 --- a/api-mssql-go/docker/Dockerfile +++ b/api-postgres-go/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.14 as builder +FROM golang:1.21 as builder ENV GO111MODULE=on @@ -12,11 +12,11 @@ COPY cmd ./cmd COPY internal ./internal RUN ls /app/ -RUN CGO_ENABLED=0 GOOS=linux go build -v -a -o api-mssql-go ./cmd/api +RUN CGO_ENABLED=0 GOOS=linux go build -v -trimpath -o api-postgres-go ./cmd/api FROM scratch WORKDIR /app -COPY --from=builder /app/api-mssql-go /app/ +COPY --from=builder /app/api-postgres-go /app/ EXPOSE 8000 -ENTRYPOINT ["/app/api-mssql-go"] \ No newline at end of file +ENTRYPOINT ["/app/api-postgres-go"] \ No newline at end of file diff --git a/api-postgres-go/go.mod b/api-postgres-go/go.mod new file mode 100644 index 000000000..4977bd0fd --- /dev/null +++ b/api-postgres-go/go.mod @@ -0,0 +1,9 @@ +module github.com/SAP-samples/kyma-runtime-extension-samples/api-postgres-go + +go 1.21 + +require ( + github.com/gorilla/mux v1.8.0 + github.com/lib/pq v1.10.9 + github.com/vrischmann/envconfig v1.3.0 +) diff --git a/api-mssql-go/go.sum b/api-postgres-go/go.sum similarity index 54% rename from api-mssql-go/go.sum rename to api-postgres-go/go.sum index 04b111f69..af59615b3 100644 --- a/api-mssql-go/go.sum +++ b/api-postgres-go/go.sum @@ -2,17 +2,13 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/denisenkom/go-mssqldb v0.0.0-20200910202707-1e08a3fab204 h1:tI48fqaIkxxYuIylVv1tdDfBp6836GKSfmmzgSyP1CY= -github.com/denisenkom/go-mssqldb v0.0.0-20200910202707-1e08a3fab204/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= -github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY= -github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= +github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -21,17 +17,7 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/vrischmann/envconfig v1.3.0 h1:4XIvQTXznxmWMnjouj0ST5lFo/WAYf5Exgl3x82crEk= github.com/vrischmann/envconfig v1.3.0/go.mod h1:bbvxFYJdRSpXrhS63mBFtKJzkDiNkyArOLXtY6q0kuI= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c h1:Vj5n4GlwjmQteupaxJ9+0FNOmBrHfq7vN4btdGoDZgI= -golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ= diff --git a/api-mssql-go/internal/api/events.go b/api-postgres-go/internal/api/events.go similarity index 84% rename from api-mssql-go/internal/api/events.go rename to api-postgres-go/internal/api/events.go index d1570371a..8e528673d 100644 --- a/api-mssql-go/internal/api/events.go +++ b/api-postgres-go/internal/api/events.go @@ -20,6 +20,11 @@ func (s *server) ConsumeOrderCode(w http.ResponseWriter, r *http.Request) { return } + if order.OrderCode == "" { + http.Error(w, "orderCode is required", http.StatusBadRequest) + return + } + _, err = s.db.AddOrder(order.OrderCode, "order received from event") if err != nil { diff --git a/api-mssql-go/internal/api/server.go b/api-postgres-go/internal/api/server.go similarity index 71% rename from api-mssql-go/internal/api/server.go rename to api-postgres-go/internal/api/server.go index 2bf9705ff..074ed45df 100644 --- a/api-mssql-go/internal/api/server.go +++ b/api-postgres-go/internal/api/server.go @@ -3,9 +3,10 @@ package api import ( "encoding/json" "net/http" - "strings" - "github.com/SAP-samples/kyma-runtime-extension-samples/api-mssql-go/internal/db" + "github.com/gorilla/mux" + + "github.com/SAP-samples/kyma-runtime-extension-samples/api-postgres-go/internal/db" ) type orderData struct { @@ -24,8 +25,11 @@ func InitAPIServer() *server { } func (s *server) GetOrder(w http.ResponseWriter, r *http.Request) { - - order_id := strings.Split(r.URL.Path, "/")[2] + order_id := mux.Vars(r)["id"] + if order_id == "" { + http.Error(w, "missing order id", http.StatusBadRequest) + return + } orders, err := s.db.GetOrder(order_id) if err != nil { @@ -58,7 +62,14 @@ func (s *server) EditOrder(w http.ResponseWriter, r *http.Request) { var order orderData defer r.Body.Close() - err := json.NewDecoder(r.Body).Decode(&order) + if err := json.NewDecoder(r.Body).Decode(&order); err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + if order.Orderid == "" { + http.Error(w, "order_id is required", http.StatusBadRequest) + return + } rowsEffected, err := s.db.EditOrder(order.Orderid, order.Description) @@ -78,10 +89,12 @@ func (s *server) AddOrder(w http.ResponseWriter, r *http.Request) { var order orderData defer r.Body.Close() - err := json.NewDecoder(r.Body).Decode(&order) - - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + if err := json.NewDecoder(r.Body).Decode(&order); err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + if order.Orderid == "" { + http.Error(w, "order_id is required", http.StatusBadRequest) return } @@ -99,7 +112,11 @@ func (s *server) AddOrder(w http.ResponseWriter, r *http.Request) { } func (s *server) DeleteOrder(w http.ResponseWriter, r *http.Request) { - order_id := strings.Split(r.URL.Path, "/")[2] + order_id := mux.Vars(r)["id"] + if order_id == "" { + http.Error(w, "missing order id", http.StatusBadRequest) + return + } rowsEffected, err := s.db.DeleteOrder(order_id) if err != nil { diff --git a/api-mssql-go/internal/config/config.go b/api-postgres-go/internal/config/config.go similarity index 54% rename from api-mssql-go/internal/config/config.go rename to api-postgres-go/internal/config/config.go index 35ed36fa4..2631c7bd5 100644 --- a/api-mssql-go/internal/config/config.go +++ b/api-postgres-go/internal/config/config.go @@ -9,16 +9,17 @@ import ( var appConfig Config -//Config struct to hold the app config +// Config struct to hold the app config type Config struct { - Server string `envconfig:"MYAPP_host"` - Port string `envconfig:"MYAPP_port,default=1433"` - Username string `envconfig:"MYAPP_username"` - Password string `envconfig:"MYAPP_password"` - Database string `envconfig:"MYAPP_database"` + Host string `envconfig:"POSTGRES_HOST"` + Port string `envconfig:"POSTGRES_PORT,default=5432"` + Username string `envconfig:"POSTGRES_USER"` + Password string `envconfig:"POSTGRES_PASSWORD"` + Database string `envconfig:"POSTGRES_DB"` + SSLMode string `envconfig:"POSTGRES_SSLMODE,default=disable"` } -//InitConfig initializes the AppConfig +// InitConfig initializes the AppConfig func initConfig() { log.Println("initilizing db configuration....") appConfig = Config{} @@ -32,7 +33,7 @@ func initConfig() { } } -//AppConfig returns the current AppConfig +// AppConfig returns the current AppConfig func GetConfig() Config { if appConfig == (Config{}) { initConfig() diff --git a/api-mssql-go/internal/db/connection.go b/api-postgres-go/internal/db/connection.go similarity index 56% rename from api-mssql-go/internal/db/connection.go rename to api-postgres-go/internal/db/connection.go index 85b7173b8..d7f9dcdb1 100644 --- a/api-mssql-go/internal/db/connection.go +++ b/api-postgres-go/internal/db/connection.go @@ -6,8 +6,8 @@ import ( "log" "time" - "github.com/SAP-samples/kyma-runtime-extension-samples/api-mssql-go/internal/config" - _ "github.com/denisenkom/go-mssqldb" + "github.com/SAP-samples/kyma-runtime-extension-samples/api-postgres-go/internal/config" + _ "github.com/lib/pq" ) // var db *sql.DB @@ -16,7 +16,7 @@ type Server struct { db *sql.DB } -//InitDatabase - sets database connection configuration +// InitDatabase - sets database connection configuration func InitDatabase() *Server { var err error @@ -25,7 +25,7 @@ func InitDatabase() *Server { log.Printf("Setting connection to db with configuration: %s \n", connString) server := &Server{} - server.db, err = sql.Open("sqlserver", connString) + server.db, err = sql.Open("postgres", connString) if err != nil { log.Fatal("Error opening connection: ", err.Error()) } @@ -35,18 +35,23 @@ func InitDatabase() *Server { return server } -//gets configuration and returns appropiate connection string +// gets configuration and returns appropiate connection string func getConnString() string { config := config.GetConfig() - connString := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%s;database=%s;", - config.Server, config.Username, config.Password, config.Port, config.Database) + connString := fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=%s", + config.Username, + config.Password, + config.Host, + config.Port, + config.Database, + config.SSLMode) return connString } -//will verify the connection is available or generate a new one +// will verify the connection is available or generate a new one func (s *Server) getConnection() { err := s.db.Ping() diff --git a/api-mssql-go/internal/db/order.go b/api-postgres-go/internal/db/order.go similarity index 72% rename from api-mssql-go/internal/db/order.go rename to api-postgres-go/internal/db/order.go index b22813ac5..0ae1bd590 100644 --- a/api-mssql-go/internal/db/order.go +++ b/api-postgres-go/internal/db/order.go @@ -6,7 +6,7 @@ import ( "time" ) -//Order - +// Order - type Order struct { Orderid string `json:"order_id"` Description string `json:"description"` @@ -18,33 +18,33 @@ type RowsAffected struct { } func (s *Server) GetOrder(order_id string) ([]Order, error) { - tsql := fmt.Sprintf("SELECT * FROM Orders WHERE order_id=@p1;") + tsql := fmt.Sprintf("SELECT order_id, description, created FROM Orders WHERE order_id=$1;") return s.query(tsql, order_id) } func (s *Server) GetOrders() ([]Order, error) { - tsql := fmt.Sprintf("SELECT * FROM Orders;") - return s.query(tsql, nil) + tsql := fmt.Sprintf("SELECT order_id, description, created FROM Orders;") + return s.query(tsql) } func (s *Server) AddOrder(order_id string, description string) ([]Order, error) { - tsql := fmt.Sprintf("INSERT INTO Orders(order_id, description) VALUES(@p1,@p2);") + tsql := fmt.Sprintf("INSERT INTO Orders(order_id, description) VALUES($1,$2);") _, err := s.exec(tsql, order_id, description) if err != nil { return nil, err } - tsql = fmt.Sprintf("SELECT * FROM Orders WHERE order_id=@p1;") - return s.query(tsql, order_id, description) + tsql = fmt.Sprintf("SELECT order_id, description, created FROM Orders WHERE order_id=$1;") + return s.query(tsql, order_id) } func (s *Server) EditOrder(order_id string, description string) (RowsAffected, error) { - tsql := fmt.Sprintf("UPDATE Orders SET description=@p2 WHERE order_id=@p1") + tsql := fmt.Sprintf("UPDATE Orders SET description=$2 WHERE order_id=$1") return s.exec(tsql, order_id, description) } func (s *Server) DeleteOrder(order_id string) (RowsAffected, error) { - tsql := fmt.Sprintf("DELETE FROM Orders WHERE order_id=@p1") + tsql := fmt.Sprintf("DELETE FROM Orders WHERE order_id=$1") return s.exec(tsql, order_id) } @@ -56,7 +56,7 @@ func (s *Server) exec(tsql string, args ...interface{}) (RowsAffected, error) { rowsAffectedResult.RowsAffected = 0 log.Printf("Executing SQL: %s \n", tsql) - log.Printf("With args: %s \n", args...) + log.Printf("With args: %v \n", args) result, err := s.db.Exec(tsql, args...) if err != nil { @@ -78,7 +78,7 @@ func (s *Server) query(tsql string, args ...interface{}) ([]Order, error) { orders := []Order{} log.Printf("Executing SQL: %s \n", tsql) - log.Printf("With args: %s \n", args...) + log.Printf("With args: %v \n", args) rows, err := s.db.Query(tsql, args...) @@ -90,8 +90,7 @@ func (s *Server) query(tsql string, args ...interface{}) ([]Order, error) { defer rows.Close() for rows.Next() { - err := rows.Scan(&order.Orderid, &order.Description, &order.Created) - if err != nil { + if err := rows.Scan(&order.Orderid, &order.Description, &order.Created); err != nil { return nil, err } orders = append(orders, order) diff --git a/api-mssql-go/k8s/apirule.yaml b/api-postgres-go/k8s/apirule.yaml similarity index 77% rename from api-mssql-go/k8s/apirule.yaml rename to api-postgres-go/k8s/apirule.yaml index 4fe985046..7ce7bde01 100644 --- a/api-mssql-go/k8s/apirule.yaml +++ b/api-postgres-go/k8s/apirule.yaml @@ -1,12 +1,12 @@ apiVersion: gateway.kyma-project.io/v2 kind: APIRule metadata: - name: api-mssql-go + name: api-postgres-go spec: hosts: - - api-mssql-go + - api-postgres-go service: - name: api-mssql-go + name: api-postgres-go port: 80 gateway: kyma-system/kyma-gateway corsPolicy: @@ -19,7 +19,8 @@ spec: - DELETE - OPTIONS allowOrigins: - - regex: ".*{YOUR_DOMAIN}" + - regex: ".d3ea4b2.stage.kyma.ondemand.com" + - exact: http://localhost:8080 rules: - path: "/orders" methods: diff --git a/api-mssql-go/k8s/authorizationpolicy.yaml b/api-postgres-go/k8s/authorizationpolicy.yaml similarity index 91% rename from api-mssql-go/k8s/authorizationpolicy.yaml rename to api-postgres-go/k8s/authorizationpolicy.yaml index 73f6750cc..1640daaac 100644 --- a/api-mssql-go/k8s/authorizationpolicy.yaml +++ b/api-postgres-go/k8s/authorizationpolicy.yaml @@ -6,7 +6,7 @@ metadata: spec: selector: matchLabels: - app: api-mssql-go + app: api-postgres-go action: ALLOW rules: - from: diff --git a/api-postgres-go/k8s/configmap.yaml b/api-postgres-go/k8s/configmap.yaml new file mode 100644 index 000000000..06a88b897 --- /dev/null +++ b/api-postgres-go/k8s/configmap.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: api-postgres-go + labels: + app: api-postgres-go +data: + database: DemoDB + host: postgres.dev.svc.cluster.local + port: "5432" diff --git a/api-postgres-go/k8s/deployment-servicebinding.yaml b/api-postgres-go/k8s/deployment-servicebinding.yaml new file mode 100644 index 000000000..1803739e2 --- /dev/null +++ b/api-postgres-go/k8s/deployment-servicebinding.yaml @@ -0,0 +1,82 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: api-postgres-go + labels: + app: api-postgres-go +spec: + replicas: 1 + selector: + matchLabels: + app: api-postgres-go + template: + metadata: + labels: + app: api-postgres-go + spec: + containers: + # replace the repository URL with your own repository + - image: jcawley5/api-postgres-go:latest + imagePullPolicy: Always + name: api-postgres-go + ports: + - name: http + containerPort: 8000 + env: + - name: POSTGRES_DB + valueFrom: + configMapKeyRef: + name: api-postgres-go + key: database + - name: POSTGRES_HOST + valueFrom: + configMapKeyRef: + name: api-postgres-go + key: host + - name: POSTGRES_PORT + valueFrom: + configMapKeyRef: + name: api-postgres-go + key: port + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + key: username + name: postgres + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + key: password + name: postgres +--- +apiVersion: v1 +kind: Service +metadata: + name: api-postgres-go + labels: + app: api-postgres-go +spec: + ports: + - name: http + port: 80 + targetPort: 8000 + protocol: TCP + selector: + app: api-postgres-go +--- +apiVersion: gateway.kyma-project.io/v2 +kind: APIRule +metadata: + name: api-postgres-go +spec: + gateway: kyma-system/kyma-gateway + hosts: + - api-postgres-go + service: + name: api-postgres-go + port: 80 + rules: + - path: /orders/{**} + noAuth: true + methods: ["GET", "POST", "PUT", "DELETE"] \ No newline at end of file diff --git a/api-mssql-go/k8s/deployment.yaml b/api-postgres-go/k8s/deployment.yaml similarity index 58% rename from api-mssql-go/k8s/deployment.yaml rename to api-postgres-go/k8s/deployment.yaml index 83dc63977..eaee642fb 100644 --- a/api-mssql-go/k8s/deployment.yaml +++ b/api-postgres-go/k8s/deployment.yaml @@ -1,59 +1,59 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: api-mssql-go + name: api-postgres-go labels: - app: api-mssql-go + app: api-postgres-go spec: replicas: 1 selector: matchLabels: - app: api-mssql-go + app: api-postgres-go template: metadata: labels: - app: api-mssql-go + app: api-postgres-go spec: containers: - - image: jcawley5/api-mssql-go:latest #change it to your image + - image: 00776600/api-postgres-go:latest #change it to your image imagePullPolicy: Always - name: api-mssql-go + name: api-postgres-go ports: - name: http containerPort: 8000 env: - - name: MYAPP_database + - name: POSTGRES_DB valueFrom: configMapKeyRef: - name: api-mssql-go + name: api-postgres-go key: database - - name: MYAPP_host + - name: POSTGRES_HOST valueFrom: configMapKeyRef: - name: api-mssql-go + name: api-postgres-go key: host - - name: MYAPP_port + - name: POSTGRES_PORT valueFrom: configMapKeyRef: - name: api-mssql-go + name: api-postgres-go key: port - - name: MYAPP_username + - name: POSTGRES_USER valueFrom: secretKeyRef: key: username - name: mssql - - name: MYAPP_password + name: postgres + - name: POSTGRES_PASSWORD valueFrom: secretKeyRef: key: password - name: mssql + name: postgres --- apiVersion: v1 kind: Service metadata: - name: api-mssql-go + name: api-postgres-go labels: - app: api-mssql-go + app: api-postgres-go spec: ports: - name: http @@ -61,4 +61,4 @@ spec: targetPort: 8000 protocol: TCP selector: - app: api-mssql-go + app: api-postgres-go diff --git a/api-mssql-go/k8s/event.yaml b/api-postgres-go/k8s/event.yaml similarity index 56% rename from api-mssql-go/k8s/event.yaml rename to api-postgres-go/k8s/event.yaml index 9b361a70e..584d28a09 100644 --- a/api-mssql-go/k8s/event.yaml +++ b/api-postgres-go/k8s/event.yaml @@ -1,9 +1,9 @@ apiVersion: eventing.kyma-project.io/v1alpha2 kind: Subscription metadata: - name: api-mssql-go-event-sub + name: api-postgres-go-event-sub spec: - sink: 'http://api-mssql-go.dev.svc.cluster.local:80/orderCodeEvent' + sink: 'http://api-postgres-go.dev.svc.cluster.local:80/orderCodeEvent' source: mp-commerce-mock types: - order.created.v1 \ No newline at end of file diff --git a/api-mssql-go/k8s/secret.yaml b/api-postgres-go/k8s/secret.yaml similarity index 51% rename from api-mssql-go/k8s/secret.yaml rename to api-postgres-go/k8s/secret.yaml index 9b357dd7e..155216d20 100644 --- a/api-mssql-go/k8s/secret.yaml +++ b/api-postgres-go/k8s/secret.yaml @@ -1,11 +1,11 @@ apiVersion: v1 kind: Secret metadata: - name: mssql + name: postgres labels: - app: api-mssql-go + app: api-postgres-go type: Opaque data: - #sa:Yukon900 - username: c2E= + #postgres:Yukon900 + username: cG9zdGdyZXM= password: WXVrb245MDA= From 064d0d09301bf4d47f1eedbfb817d50935396a08 Mon Sep 17 00:00:00 2001 From: grego952 Date: Fri, 13 Feb 2026 15:05:31 +0100 Subject: [PATCH 02/20] Small change --- api-postgres-go/k8s/deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-postgres-go/k8s/deployment.yaml b/api-postgres-go/k8s/deployment.yaml index eaee642fb..85841170c 100644 --- a/api-postgres-go/k8s/deployment.yaml +++ b/api-postgres-go/k8s/deployment.yaml @@ -15,7 +15,7 @@ spec: app: api-postgres-go spec: containers: - - image: 00776600/api-postgres-go:latest #change it to your image + - image: /api-postgres-go:latest #change it to your image imagePullPolicy: Always name: api-postgres-go ports: From b022bf63da45a86c04d6fe5b470e2ddc6fe06214 Mon Sep 17 00:00:00 2001 From: grego952 Date: Fri, 20 Feb 2026 14:40:50 +0100 Subject: [PATCH 03/20] Remove hardcoded bit --- api-postgres-go/k8s/apirule.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-postgres-go/k8s/apirule.yaml b/api-postgres-go/k8s/apirule.yaml index 7ce7bde01..356f1db2a 100644 --- a/api-postgres-go/k8s/apirule.yaml +++ b/api-postgres-go/k8s/apirule.yaml @@ -19,7 +19,7 @@ spec: - DELETE - OPTIONS allowOrigins: - - regex: ".d3ea4b2.stage.kyma.ondemand.com" + - regex: ".*{YOUR_DOMAIN}" - exact: http://localhost:8080 rules: - path: "/orders" From c7c8e16c6d0f4f2be41bbb0856d7b2f8d52788bb Mon Sep 17 00:00:00 2001 From: grego952 Date: Fri, 20 Feb 2026 14:45:39 +0100 Subject: [PATCH 04/20] Remove obsolete files --- .../k8s/deployment-servicebinding.yaml | 82 ------------------- api-postgres-go/k8s/secret.yaml | 11 --- 2 files changed, 93 deletions(-) delete mode 100644 api-postgres-go/k8s/deployment-servicebinding.yaml delete mode 100644 api-postgres-go/k8s/secret.yaml diff --git a/api-postgres-go/k8s/deployment-servicebinding.yaml b/api-postgres-go/k8s/deployment-servicebinding.yaml deleted file mode 100644 index 1803739e2..000000000 --- a/api-postgres-go/k8s/deployment-servicebinding.yaml +++ /dev/null @@ -1,82 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: api-postgres-go - labels: - app: api-postgres-go -spec: - replicas: 1 - selector: - matchLabels: - app: api-postgres-go - template: - metadata: - labels: - app: api-postgres-go - spec: - containers: - # replace the repository URL with your own repository - - image: jcawley5/api-postgres-go:latest - imagePullPolicy: Always - name: api-postgres-go - ports: - - name: http - containerPort: 8000 - env: - - name: POSTGRES_DB - valueFrom: - configMapKeyRef: - name: api-postgres-go - key: database - - name: POSTGRES_HOST - valueFrom: - configMapKeyRef: - name: api-postgres-go - key: host - - name: POSTGRES_PORT - valueFrom: - configMapKeyRef: - name: api-postgres-go - key: port - - name: POSTGRES_USER - valueFrom: - secretKeyRef: - key: username - name: postgres - - name: POSTGRES_PASSWORD - valueFrom: - secretKeyRef: - key: password - name: postgres ---- -apiVersion: v1 -kind: Service -metadata: - name: api-postgres-go - labels: - app: api-postgres-go -spec: - ports: - - name: http - port: 80 - targetPort: 8000 - protocol: TCP - selector: - app: api-postgres-go ---- -apiVersion: gateway.kyma-project.io/v2 -kind: APIRule -metadata: - name: api-postgres-go -spec: - gateway: kyma-system/kyma-gateway - hosts: - - api-postgres-go - service: - name: api-postgres-go - port: 80 - rules: - - path: /orders/{**} - noAuth: true - methods: ["GET", "POST", "PUT", "DELETE"] \ No newline at end of file diff --git a/api-postgres-go/k8s/secret.yaml b/api-postgres-go/k8s/secret.yaml deleted file mode 100644 index 155216d20..000000000 --- a/api-postgres-go/k8s/secret.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: postgres - labels: - app: api-postgres-go -type: Opaque -data: - #postgres:Yukon900 - username: cG9zdGdyZXM= - password: WXVrb245MDA= From 025329245e20b134765c552352c81d2790cb5d5b Mon Sep 17 00:00:00 2001 From: grego952 Date: Mon, 2 Mar 2026 15:39:17 +0100 Subject: [PATCH 05/20] Rename the folder and update files --- api-postgres-go/README.md | 106 ------------------ api-postgres-go/k8s/configmap.yaml | 10 -- api-postgres-go/k8s/deployment.yaml | 64 ----------- api-postgresql-go/README.md | 75 +++++++++++++ .../cmd/api/main.go | 2 +- .../docker/Dockerfile | 8 +- {api-postgres-go => api-postgresql-go}/go.mod | 4 +- {api-postgres-go => api-postgresql-go}/go.sum | 3 + .../internal/api/events.go | 5 - .../internal/api/server.go | 37 ++---- .../internal/config/config.go | 11 +- .../internal/db/connection.go | 11 +- .../internal/db/order.go | 13 ++- .../k8s/apirule.yaml | 9 +- .../k8s/authorizationpolicy.yaml | 4 +- api-postgresql-go/k8s/configmap.yaml | 8 ++ api-postgresql-go/k8s/deployment.yaml | 64 +++++++++++ .../k8s/event.yaml | 4 +- 18 files changed, 190 insertions(+), 248 deletions(-) delete mode 100644 api-postgres-go/README.md delete mode 100644 api-postgres-go/k8s/configmap.yaml delete mode 100644 api-postgres-go/k8s/deployment.yaml create mode 100644 api-postgresql-go/README.md rename {api-postgres-go => api-postgresql-go}/cmd/api/main.go (96%) rename {api-postgres-go => api-postgresql-go}/docker/Dockerfile (52%) rename {api-postgres-go => api-postgresql-go}/go.mod (88%) rename {api-postgres-go => api-postgresql-go}/go.sum (88%) rename {api-postgres-go => api-postgresql-go}/internal/api/events.go (84%) rename {api-postgres-go => api-postgresql-go}/internal/api/server.go (73%) rename {api-postgres-go => api-postgresql-go}/internal/config/config.go (67%) rename {api-postgres-go => api-postgresql-go}/internal/db/connection.go (83%) rename {api-postgres-go => api-postgresql-go}/internal/db/order.go (81%) rename {api-postgres-go => api-postgresql-go}/k8s/apirule.yaml (79%) rename {api-postgres-go => api-postgresql-go}/k8s/authorizationpolicy.yaml (83%) create mode 100644 api-postgresql-go/k8s/configmap.yaml create mode 100644 api-postgresql-go/k8s/deployment.yaml rename {api-postgres-go => api-postgresql-go}/k8s/event.yaml (53%) diff --git a/api-postgres-go/README.md b/api-postgres-go/README.md deleted file mode 100644 index 702dffed2..000000000 --- a/api-postgres-go/README.md +++ /dev/null @@ -1,106 +0,0 @@ -# Golang PostgreSQL database API - -## Overview - -This sample provides a Golang API endpoint for communication with the PostgreSQL database provisioned in the `postgres-provision` tutorial. The service exposes CRUD endpoints for the `Orders` table created in `DemoDB`. An optional Kyma event subscription can insert orders from an `order.created` event. - -Default connection values used throughout the sample: - -| Parameter | Value | -| ------------ | ----------------------------------- | -| **database** | `DemoDB` | -| **host** | `postgres.dev.svc.cluster.local` | -| **password** | `Yukon900` | -| **username** | `postgres` | -| **port** | `5432` (or forwarded port `15432`) | - -## Prerequisites - -- SAP BTP, Kyma runtime instance -- [Docker](https://www.docker.com/) -- [Go](https://golang.org/doc/install) -- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) configured to use the `KUBECONFIG` file downloaded from the Kyma runtime -- PostgreSQL provisioned via `postgres-provision/postgres-provision.md` (Secret `postgres` and Service `postgres` in namespace `dev`) - -## Steps - -### Run the API locally - -1. Set the environment variables required to connect with the database (adjust host/port to match your setup or forwarded port): - - ```shell script - export POSTGRES_USER=postgres - export POSTGRES_PASSWORD=Yukon900 - export POSTGRES_DB=DemoDB - export POSTGRES_HOST=localhost - export POSTGRES_PORT=15432 - export POSTGRES_SSLMODE=disable - ``` - -2. Run the application: - - ```shell script - go run ./cmd/api - ``` - -### Build the Docker image - -1. Build and push the image to your Docker repository: - - ```shell script - docker build -t {your-docker-account}/api-postgres-go -f docker/Dockerfile . - docker push {your-docker-account}/api-postgres-go - ``` - -2. To run the image locally, run: - - ```shell script - docker run -p 8000:8000 -d --name api-postgres-go \ - -e POSTGRES_USER=postgres \ - -e POSTGRES_PASSWORD=Yukon900 \ - -e POSTGRES_DB=DemoDB \ - -e POSTGRES_HOST=host.docker.internal \ - -e POSTGRES_PORT=15432 \ - -e POSTGRES_SSLMODE=disable \ - {your-docker-account}/api-postgres-go:latest - ``` - -### Deploy the API - -1. Create a new `dev` Namespace (skip if already created during provisioning): - - ```shell script - kubectl create namespace dev - kubectl label namespaces dev istio-injection=enabled - ``` - -2. Apply the ConfigMap and Secret (skip the Secret if it already exists from the provisioning tutorial): - - ```shell script - kubectl -n dev apply -f ./k8s/configmap.yaml - kubectl -n dev apply -f ./k8s/secret.yaml - ``` - -3. Apply the Deployment and APIRule: - - ```shell script - kubectl -n dev apply -f ./k8s/deployment.yaml - kubectl -n dev apply -f ./k8s/apirule.yaml - ``` - -4. Verify that the Deployment is up and running: - - ```shell script - kubectl -n dev get deployment api-postgres-go - ``` - -5. Optional: apply the Event Subscription to insert orders from events: - - ```shell script - kubectl -n dev apply -f ./k8s/event.yaml - ``` - -6. Use the APIRule: - - - `https://api-postgres-go.{cluster-domain}/orders` - - `https://api-postgres-go.{cluster-domain}/orders/10000001` diff --git a/api-postgres-go/k8s/configmap.yaml b/api-postgres-go/k8s/configmap.yaml deleted file mode 100644 index 06a88b897..000000000 --- a/api-postgres-go/k8s/configmap.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: api-postgres-go - labels: - app: api-postgres-go -data: - database: DemoDB - host: postgres.dev.svc.cluster.local - port: "5432" diff --git a/api-postgres-go/k8s/deployment.yaml b/api-postgres-go/k8s/deployment.yaml deleted file mode 100644 index 85841170c..000000000 --- a/api-postgres-go/k8s/deployment.yaml +++ /dev/null @@ -1,64 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: api-postgres-go - labels: - app: api-postgres-go -spec: - replicas: 1 - selector: - matchLabels: - app: api-postgres-go - template: - metadata: - labels: - app: api-postgres-go - spec: - containers: - - image: /api-postgres-go:latest #change it to your image - imagePullPolicy: Always - name: api-postgres-go - ports: - - name: http - containerPort: 8000 - env: - - name: POSTGRES_DB - valueFrom: - configMapKeyRef: - name: api-postgres-go - key: database - - name: POSTGRES_HOST - valueFrom: - configMapKeyRef: - name: api-postgres-go - key: host - - name: POSTGRES_PORT - valueFrom: - configMapKeyRef: - name: api-postgres-go - key: port - - name: POSTGRES_USER - valueFrom: - secretKeyRef: - key: username - name: postgres - - name: POSTGRES_PASSWORD - valueFrom: - secretKeyRef: - key: password - name: postgres ---- -apiVersion: v1 -kind: Service -metadata: - name: api-postgres-go - labels: - app: api-postgres-go -spec: - ports: - - name: http - port: 80 - targetPort: 8000 - protocol: TCP - selector: - app: api-postgres-go diff --git a/api-postgresql-go/README.md b/api-postgresql-go/README.md new file mode 100644 index 000000000..e74b966e8 --- /dev/null +++ b/api-postgresql-go/README.md @@ -0,0 +1,75 @@ +# Golang PostgreSQL database API + +## Overview + +This sample provides a Golang API endpoint for communication with PostgreSQL databases. The API connects to a BTP-managed PostgreSQL instance using Service Binding credentials available in the Kyma cluster. + +## PostgreSQL database example + +For the PostgreSQL example, use the `deployment.yaml` file. It provides the Deployment definition as well as an APIRule to expose the API without authentication. The Deployment references the PostgreSQL Service Binding Secret for connection credentials. + +This sample demonstrates how to: + +- Create a development Namespace in the Kyma runtime. +- Deploy the following Kubernetes resources: + - API deployment written in GO + - API Rule + - Service + - ConfigMap + +## Prerequisites + +- SAP BTP, Kyma runtime instance +- PostgreSQL Service Instance and Service Binding in Kyma cluster +- [Docker](https://www.docker.com/) +- [Go](https://golang.org/doc/install) +- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) configured to use the `KUBECONFIG` file downloaded from the Kyma runtime + +## Steps + +### Build the Docker image + +1. Build and push the image to your Docker repository: + + ```shell script + docker build -t {your-docker-account}/api-postgresql-go -f docker/Dockerfile . + docker push {your-docker-account}/api-postgresql-go + ``` + +### Deploy the API + +1. Create a new `dev` Namespace: + + ```shell script + kubectl create namespace dev + kubectl label namespaces dev istio-injection=enabled + ``` + +2. Apply the ConfigMap: + + ```shell script + kubectl -n dev apply -f ./k8s/configmap.yaml + ``` + +3. Apply the Deployment: + + ```shell script + kubectl -n dev apply -f ./k8s/deployment.yaml + ``` + +4. Apply the APIRule: + + ```shell script + kubectl -n dev apply -f ./k8s/apirule.yaml + ``` + +5. Verify that the Deployment is up and running: + + ```shell script + kubectl -n dev get deployment api-postgresql-go + ``` + +6. Use the APIRule: + + - `https://api-postgresql-go.{cluster-domain}/orders` + - `https://api-postgresql-go.{cluster-domain}/orders/10000001` diff --git a/api-postgres-go/cmd/api/main.go b/api-postgresql-go/cmd/api/main.go similarity index 96% rename from api-postgres-go/cmd/api/main.go rename to api-postgresql-go/cmd/api/main.go index 9df47fa5e..2a22a6545 100644 --- a/api-postgres-go/cmd/api/main.go +++ b/api-postgresql-go/cmd/api/main.go @@ -6,7 +6,7 @@ import ( "github.com/gorilla/mux" - "github.com/SAP-samples/kyma-runtime-extension-samples/api-postgres-go/internal/api" + "github.com/SAP-samples/kyma-runtime-extension-samples/api-postgresql-go/internal/api" ) func main() { diff --git a/api-postgres-go/docker/Dockerfile b/api-postgresql-go/docker/Dockerfile similarity index 52% rename from api-postgres-go/docker/Dockerfile rename to api-postgresql-go/docker/Dockerfile index ea1fb7dcb..b519fc215 100644 --- a/api-postgres-go/docker/Dockerfile +++ b/api-postgresql-go/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.21 as builder +FROM golang:1.14 as builder ENV GO111MODULE=on @@ -12,11 +12,11 @@ COPY cmd ./cmd COPY internal ./internal RUN ls /app/ -RUN CGO_ENABLED=0 GOOS=linux go build -v -trimpath -o api-postgres-go ./cmd/api +RUN CGO_ENABLED=0 GOOS=linux go build -v -a -o api-postgresql-go ./cmd/api FROM scratch WORKDIR /app -COPY --from=builder /app/api-postgres-go /app/ +COPY --from=builder /app/api-postgresql-go /app/ EXPOSE 8000 -ENTRYPOINT ["/app/api-postgres-go"] \ No newline at end of file +ENTRYPOINT ["/app/api-postgresql-go"] \ No newline at end of file diff --git a/api-postgres-go/go.mod b/api-postgresql-go/go.mod similarity index 88% rename from api-postgres-go/go.mod rename to api-postgresql-go/go.mod index 4977bd0fd..6627c21d5 100644 --- a/api-postgres-go/go.mod +++ b/api-postgresql-go/go.mod @@ -1,6 +1,6 @@ -module github.com/SAP-samples/kyma-runtime-extension-samples/api-postgres-go +module github.com/SAP-samples/kyma-runtime-extension-samples/api-postgresql-go -go 1.21 +go 1.14 require ( github.com/gorilla/mux v1.8.0 diff --git a/api-postgres-go/go.sum b/api-postgresql-go/go.sum similarity index 88% rename from api-postgres-go/go.sum rename to api-postgresql-go/go.sum index af59615b3..57ebc6246 100644 --- a/api-postgres-go/go.sum +++ b/api-postgresql-go/go.sum @@ -6,9 +6,11 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -18,6 +20,7 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/vrischmann/envconfig v1.3.0 h1:4XIvQTXznxmWMnjouj0ST5lFo/WAYf5Exgl3x82crEk= github.com/vrischmann/envconfig v1.3.0/go.mod h1:bbvxFYJdRSpXrhS63mBFtKJzkDiNkyArOLXtY6q0kuI= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ= diff --git a/api-postgres-go/internal/api/events.go b/api-postgresql-go/internal/api/events.go similarity index 84% rename from api-postgres-go/internal/api/events.go rename to api-postgresql-go/internal/api/events.go index 8e528673d..d1570371a 100644 --- a/api-postgres-go/internal/api/events.go +++ b/api-postgresql-go/internal/api/events.go @@ -20,11 +20,6 @@ func (s *server) ConsumeOrderCode(w http.ResponseWriter, r *http.Request) { return } - if order.OrderCode == "" { - http.Error(w, "orderCode is required", http.StatusBadRequest) - return - } - _, err = s.db.AddOrder(order.OrderCode, "order received from event") if err != nil { diff --git a/api-postgres-go/internal/api/server.go b/api-postgresql-go/internal/api/server.go similarity index 73% rename from api-postgres-go/internal/api/server.go rename to api-postgresql-go/internal/api/server.go index 074ed45df..c2af21b29 100644 --- a/api-postgres-go/internal/api/server.go +++ b/api-postgresql-go/internal/api/server.go @@ -3,10 +3,9 @@ package api import ( "encoding/json" "net/http" + "strings" - "github.com/gorilla/mux" - - "github.com/SAP-samples/kyma-runtime-extension-samples/api-postgres-go/internal/db" + "github.com/SAP-samples/kyma-runtime-extension-samples/api-postgresql-go/internal/db" ) type orderData struct { @@ -25,11 +24,8 @@ func InitAPIServer() *server { } func (s *server) GetOrder(w http.ResponseWriter, r *http.Request) { - order_id := mux.Vars(r)["id"] - if order_id == "" { - http.Error(w, "missing order id", http.StatusBadRequest) - return - } + + order_id := strings.Split(r.URL.Path, "/")[2] orders, err := s.db.GetOrder(order_id) if err != nil { @@ -62,14 +58,7 @@ func (s *server) EditOrder(w http.ResponseWriter, r *http.Request) { var order orderData defer r.Body.Close() - if err := json.NewDecoder(r.Body).Decode(&order); err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - if order.Orderid == "" { - http.Error(w, "order_id is required", http.StatusBadRequest) - return - } + err := json.NewDecoder(r.Body).Decode(&order) rowsEffected, err := s.db.EditOrder(order.Orderid, order.Description) @@ -89,12 +78,10 @@ func (s *server) AddOrder(w http.ResponseWriter, r *http.Request) { var order orderData defer r.Body.Close() - if err := json.NewDecoder(r.Body).Decode(&order); err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - if order.Orderid == "" { - http.Error(w, "order_id is required", http.StatusBadRequest) + err := json.NewDecoder(r.Body).Decode(&order) + + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -112,11 +99,7 @@ func (s *server) AddOrder(w http.ResponseWriter, r *http.Request) { } func (s *server) DeleteOrder(w http.ResponseWriter, r *http.Request) { - order_id := mux.Vars(r)["id"] - if order_id == "" { - http.Error(w, "missing order id", http.StatusBadRequest) - return - } + order_id := strings.Split(r.URL.Path, "/")[2] rowsEffected, err := s.db.DeleteOrder(order_id) if err != nil { diff --git a/api-postgres-go/internal/config/config.go b/api-postgresql-go/internal/config/config.go similarity index 67% rename from api-postgres-go/internal/config/config.go rename to api-postgresql-go/internal/config/config.go index 2631c7bd5..eca03524e 100644 --- a/api-postgres-go/internal/config/config.go +++ b/api-postgresql-go/internal/config/config.go @@ -11,12 +11,11 @@ var appConfig Config // Config struct to hold the app config type Config struct { - Host string `envconfig:"POSTGRES_HOST"` - Port string `envconfig:"POSTGRES_PORT,default=5432"` - Username string `envconfig:"POSTGRES_USER"` - Password string `envconfig:"POSTGRES_PASSWORD"` - Database string `envconfig:"POSTGRES_DB"` - SSLMode string `envconfig:"POSTGRES_SSLMODE,default=disable"` + Server string `envconfig:"MYAPP_host"` + Port string `envconfig:"MYAPP_port,default=5432"` + Username string `envconfig:"MYAPP_username"` + Password string `envconfig:"MYAPP_password"` + Database string `envconfig:"MYAPP_database"` } // InitConfig initializes the AppConfig diff --git a/api-postgres-go/internal/db/connection.go b/api-postgresql-go/internal/db/connection.go similarity index 83% rename from api-postgres-go/internal/db/connection.go rename to api-postgresql-go/internal/db/connection.go index d7f9dcdb1..1532e19f1 100644 --- a/api-postgres-go/internal/db/connection.go +++ b/api-postgresql-go/internal/db/connection.go @@ -6,7 +6,7 @@ import ( "log" "time" - "github.com/SAP-samples/kyma-runtime-extension-samples/api-postgres-go/internal/config" + "github.com/SAP-samples/kyma-runtime-extension-samples/api-postgresql-go/internal/config" _ "github.com/lib/pq" ) @@ -40,13 +40,8 @@ func getConnString() string { config := config.GetConfig() - connString := fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=%s", - config.Username, - config.Password, - config.Host, - config.Port, - config.Database, - config.SSLMode) + connString := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=require", + config.Server, config.Port, config.Username, config.Password, config.Database) return connString } diff --git a/api-postgres-go/internal/db/order.go b/api-postgresql-go/internal/db/order.go similarity index 81% rename from api-postgres-go/internal/db/order.go rename to api-postgresql-go/internal/db/order.go index 0ae1bd590..2b6698597 100644 --- a/api-postgres-go/internal/db/order.go +++ b/api-postgresql-go/internal/db/order.go @@ -18,12 +18,12 @@ type RowsAffected struct { } func (s *Server) GetOrder(order_id string) ([]Order, error) { - tsql := fmt.Sprintf("SELECT order_id, description, created FROM Orders WHERE order_id=$1;") + tsql := fmt.Sprintf("SELECT * FROM Orders WHERE order_id=$1;") return s.query(tsql, order_id) } func (s *Server) GetOrders() ([]Order, error) { - tsql := fmt.Sprintf("SELECT order_id, description, created FROM Orders;") + tsql := fmt.Sprintf("SELECT * FROM Orders;") return s.query(tsql) } @@ -34,7 +34,7 @@ func (s *Server) AddOrder(order_id string, description string) ([]Order, error) return nil, err } - tsql = fmt.Sprintf("SELECT order_id, description, created FROM Orders WHERE order_id=$1;") + tsql = fmt.Sprintf("SELECT * FROM Orders WHERE order_id=$1;") return s.query(tsql, order_id) } @@ -56,7 +56,7 @@ func (s *Server) exec(tsql string, args ...interface{}) (RowsAffected, error) { rowsAffectedResult.RowsAffected = 0 log.Printf("Executing SQL: %s \n", tsql) - log.Printf("With args: %v \n", args) + log.Printf("With args: %s \n", args...) result, err := s.db.Exec(tsql, args...) if err != nil { @@ -78,7 +78,7 @@ func (s *Server) query(tsql string, args ...interface{}) ([]Order, error) { orders := []Order{} log.Printf("Executing SQL: %s \n", tsql) - log.Printf("With args: %v \n", args) + log.Printf("With args: %s \n", args...) rows, err := s.db.Query(tsql, args...) @@ -90,7 +90,8 @@ func (s *Server) query(tsql string, args ...interface{}) ([]Order, error) { defer rows.Close() for rows.Next() { - if err := rows.Scan(&order.Orderid, &order.Description, &order.Created); err != nil { + err := rows.Scan(&order.Orderid, &order.Description, &order.Created) + if err != nil { return nil, err } orders = append(orders, order) diff --git a/api-postgres-go/k8s/apirule.yaml b/api-postgresql-go/k8s/apirule.yaml similarity index 79% rename from api-postgres-go/k8s/apirule.yaml rename to api-postgresql-go/k8s/apirule.yaml index 356f1db2a..50c718cdc 100644 --- a/api-postgres-go/k8s/apirule.yaml +++ b/api-postgresql-go/k8s/apirule.yaml @@ -1,12 +1,12 @@ apiVersion: gateway.kyma-project.io/v2 kind: APIRule metadata: - name: api-postgres-go + name: api-postgresql-go spec: hosts: - - api-postgres-go + - api-postgresql-go service: - name: api-postgres-go + name: api-postgresql-go port: 80 gateway: kyma-system/kyma-gateway corsPolicy: @@ -19,8 +19,7 @@ spec: - DELETE - OPTIONS allowOrigins: - - regex: ".*{YOUR_DOMAIN}" - - exact: http://localhost:8080 + - regex: ".*{YOUR_KYMA_DOMAIN}" rules: - path: "/orders" methods: diff --git a/api-postgres-go/k8s/authorizationpolicy.yaml b/api-postgresql-go/k8s/authorizationpolicy.yaml similarity index 83% rename from api-postgres-go/k8s/authorizationpolicy.yaml rename to api-postgresql-go/k8s/authorizationpolicy.yaml index 1640daaac..f7b7eb87a 100644 --- a/api-postgres-go/k8s/authorizationpolicy.yaml +++ b/api-postgresql-go/k8s/authorizationpolicy.yaml @@ -2,11 +2,11 @@ apiVersion: security.istio.io/v1beta1 kind: AuthorizationPolicy metadata: name: allow-internal - namespace: dev + namespace: postgres-dev spec: selector: matchLabels: - app: api-postgres-go + app: api-postgresql-go action: ALLOW rules: - from: diff --git a/api-postgresql-go/k8s/configmap.yaml b/api-postgresql-go/k8s/configmap.yaml new file mode 100644 index 000000000..1ac071b80 --- /dev/null +++ b/api-postgresql-go/k8s/configmap.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: api-postgresql-go + labels: + app: api-postgresql-go +data: + database: orders diff --git a/api-postgresql-go/k8s/deployment.yaml b/api-postgresql-go/k8s/deployment.yaml new file mode 100644 index 000000000..7ab8be060 --- /dev/null +++ b/api-postgresql-go/k8s/deployment.yaml @@ -0,0 +1,64 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: api-postgresql-go + labels: + app: api-postgresql-go +spec: + replicas: 1 + selector: + matchLabels: + app: api-postgresql-go + template: + metadata: + labels: + app: api-postgresql-go + spec: + containers: + - image: johndoe/api-postgresql-go:latest #change it to your image + imagePullPolicy: Always + name: api-postgresql-go + ports: + - name: http + containerPort: 8000 + env: + - name: MYAPP_database + valueFrom: + secretKeyRef: + name: postgres-binding + key: dbname + - name: MYAPP_host + valueFrom: + secretKeyRef: + name: postgres-binding + key: hostname + - name: MYAPP_port + valueFrom: + secretKeyRef: + name: postgres-binding + key: port + - name: MYAPP_username + valueFrom: + secretKeyRef: + key: username + name: postgres-binding + - name: MYAPP_password + valueFrom: + secretKeyRef: + key: password + name: postgres-binding +--- +apiVersion: v1 +kind: Service +metadata: + name: api-postgresql-go + labels: + app: api-postgresql-go +spec: + ports: + - name: http + port: 80 + targetPort: 8000 + protocol: TCP + selector: + app: api-postgresql-go diff --git a/api-postgres-go/k8s/event.yaml b/api-postgresql-go/k8s/event.yaml similarity index 53% rename from api-postgres-go/k8s/event.yaml rename to api-postgresql-go/k8s/event.yaml index 584d28a09..110d14956 100644 --- a/api-postgres-go/k8s/event.yaml +++ b/api-postgresql-go/k8s/event.yaml @@ -1,9 +1,9 @@ apiVersion: eventing.kyma-project.io/v1alpha2 kind: Subscription metadata: - name: api-postgres-go-event-sub + name: api-postgresql-go-event-sub spec: - sink: 'http://api-postgres-go.dev.svc.cluster.local:80/orderCodeEvent' + sink: 'http://api-postgresql-go.postgres-dev.svc.cluster.local:80/orderCodeEvent' source: mp-commerce-mock types: - order.created.v1 \ No newline at end of file From 13b651a6f3ded174eb9d135104f1311d84e67c3a Mon Sep 17 00:00:00 2001 From: grego952 Date: Mon, 2 Mar 2026 15:41:55 +0100 Subject: [PATCH 06/20] Update Dockerfile --- api-postgresql-go/docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-postgresql-go/docker/Dockerfile b/api-postgresql-go/docker/Dockerfile index b519fc215..cfe33b629 100644 --- a/api-postgresql-go/docker/Dockerfile +++ b/api-postgresql-go/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.14 as builder +FROM golang:1.21 as builder ENV GO111MODULE=on From 2875f622ac0b49000a22055ceaf1923de5c73a6d Mon Sep 17 00:00:00 2001 From: grego952 Date: Mon, 2 Mar 2026 15:48:34 +0100 Subject: [PATCH 07/20] Fix links --- README.md | 2 +- helm-charts/api-mssql-go/README.md | 2 +- helm-charts/frontend-ui5-mssql/README.md | 2 +- helm-charts/helm-charts-examples.md | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 14f5503f1..a53074ca5 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ Running various samples requires access to the Kyma environment. There are also | Name | Description | References | | ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | | [MS SQL database](./database-mssql/README.md) | This sample demonstrates how to containerize and deploy an MS SQL database | [Tutorial](https://developers.sap.com/tutorials/cp-kyma-mssql-deployment.html) | -| [Golang MS SQL database API](./api-mssql-go/README.md) | This sample provides a Golang API endpoint for communication with an MS SQL database | [Tutorial](https://developers.sap.com/tutorials/cp-kyma-api-mssql-golang.html) | +| [Golang MS SQL database API](./api-postgresql-go/README.md) | This sample provides a Golang API endpoint for communication with an MS SQL database | [Tutorial](https://developers.sap.com/tutorials/cp-kyma-api-mssql-golang.html) | ## Advanced Scenarios diff --git a/helm-charts/api-mssql-go/README.md b/helm-charts/api-mssql-go/README.md index 0c366cc67..c86936705 100644 --- a/helm-charts/api-mssql-go/README.md +++ b/helm-charts/api-mssql-go/README.md @@ -1,4 +1,4 @@ -This chart installs the example [api-mssql-go](../api-mssql-go/README.md) as well as it's dependency [database-mssql](../database-mssql/README.md) +This chart installs the example [api-postgresql-go](../../api-postgresql-go/README.md) as well as it's dependency [database-mssql](../database-mssql/README.md) ## Installing the Chart diff --git a/helm-charts/frontend-ui5-mssql/README.md b/helm-charts/frontend-ui5-mssql/README.md index b3bd975ba..f53ece800 100644 --- a/helm-charts/frontend-ui5-mssql/README.md +++ b/helm-charts/frontend-ui5-mssql/README.md @@ -1,4 +1,4 @@ -This chart installs the example [frontend-ui5-mssql](../frontend-ui5-mssql/README.md). Installing this chart will also install the charts [api-mssql-go](../api-mssql-go/README.md) and [database-mssql](../database-mssql/README.md) +This chart installs the example [frontend-ui5-mssql](../frontend-ui5-mssql/README.md). Installing this chart will also install the charts [api-mssql-go](../../api-postgresql-go/README.md) and [database-mssql](../database-mssql/README.md) ## Installing the Chart diff --git a/helm-charts/helm-charts-examples.md b/helm-charts/helm-charts-examples.md index 84098496a..82e21f324 100644 --- a/helm-charts/helm-charts-examples.md +++ b/helm-charts/helm-charts-examples.md @@ -16,8 +16,8 @@ For more information see [helm](https://helm.sh/) ## Samples - [UI5 Frontend MSSQL](./frontend-ui5-mssql/README.md) - - will also install dependent charts [Golang MSSQL Database API](./api-mssql-go/README.md) and [MSSQL Database](./database-mssql/README.md) -- [Golang MSSQL Database API](./api-mssql-go/README.md) + - will also install dependent charts [Golang PostgreSQL Database API](./api-postgresql-go/README.md) and [MSSQL Database](./database-mssql/README.md) +- [Golang PostgreSQL Database API](../api-postgresql-go/README.md) - will also install dependent chart [MSSQL Database](./database-mssql/README.md) - [MSSQL Database](./database-mssql/README.md) - [Sample Event Trigger Java](./sample-event-trigger-java/README.md) From 2a7b217a852d1dc6b439739868b076f2a82e1b60 Mon Sep 17 00:00:00 2001 From: grego952 Date: Mon, 2 Mar 2026 15:51:01 +0100 Subject: [PATCH 08/20] Fix link --- helm-charts/helm-charts-examples.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm-charts/helm-charts-examples.md b/helm-charts/helm-charts-examples.md index 82e21f324..2fc27b378 100644 --- a/helm-charts/helm-charts-examples.md +++ b/helm-charts/helm-charts-examples.md @@ -16,7 +16,7 @@ For more information see [helm](https://helm.sh/) ## Samples - [UI5 Frontend MSSQL](./frontend-ui5-mssql/README.md) - - will also install dependent charts [Golang PostgreSQL Database API](./api-postgresql-go/README.md) and [MSSQL Database](./database-mssql/README.md) + - will also install dependent charts [Golang PostgreSQL Database API](../api-postgresql-go/README.md) and [MSSQL Database](./database-mssql/README.md) - [Golang PostgreSQL Database API](../api-postgresql-go/README.md) - will also install dependent chart [MSSQL Database](./database-mssql/README.md) - [MSSQL Database](./database-mssql/README.md) From 24c2a17ffeb84669c31f4848958cf546bb1f4473 Mon Sep 17 00:00:00 2001 From: grego952 Date: Tue, 10 Mar 2026 12:03:55 +0100 Subject: [PATCH 09/20] Add note on where the sample is used --- api-postgresql-go/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api-postgresql-go/README.md b/api-postgresql-go/README.md index e74b966e8..4d262f4e3 100644 --- a/api-postgresql-go/README.md +++ b/api-postgresql-go/README.md @@ -2,6 +2,9 @@ ## Overview +> [!NOTE] +> This sample is used in the Deploy a Go PostgreSQL API Endpoint in SAP BTP, Kyma Runtime tutorial. + This sample provides a Golang API endpoint for communication with PostgreSQL databases. The API connects to a BTP-managed PostgreSQL instance using Service Binding credentials available in the Kyma cluster. ## PostgreSQL database example From 085ef4fd86ce21c9065cdabfc58e20fb841ce352 Mon Sep 17 00:00:00 2001 From: grego952 Date: Wed, 18 Mar 2026 14:20:53 +0100 Subject: [PATCH 10/20] Fix namespace name --- api-postgresql-go/k8s/authorizationpolicy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-postgresql-go/k8s/authorizationpolicy.yaml b/api-postgresql-go/k8s/authorizationpolicy.yaml index f7b7eb87a..bf49e7b64 100644 --- a/api-postgresql-go/k8s/authorizationpolicy.yaml +++ b/api-postgresql-go/k8s/authorizationpolicy.yaml @@ -2,7 +2,7 @@ apiVersion: security.istio.io/v1beta1 kind: AuthorizationPolicy metadata: name: allow-internal - namespace: postgres-dev + namespace: dev spec: selector: matchLabels: From b6a900ac18bc2979786906bb33abd3ac3af59ccf Mon Sep 17 00:00:00 2001 From: Grzegorz Karaluch Date: Tue, 24 Mar 2026 06:49:47 +0100 Subject: [PATCH 11/20] Apply suggestions from mmitoraj review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Małgorzata Świeca --- api-postgresql-go/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/api-postgresql-go/README.md b/api-postgresql-go/README.md index 4d262f4e3..81328e1ed 100644 --- a/api-postgresql-go/README.md +++ b/api-postgresql-go/README.md @@ -1,4 +1,4 @@ -# Golang PostgreSQL database API +# Deploy a Go PostgreSQL API Endpoint in SAP BTP, Kyma Runtime ## Overview @@ -7,13 +7,13 @@ This sample provides a Golang API endpoint for communication with PostgreSQL databases. The API connects to a BTP-managed PostgreSQL instance using Service Binding credentials available in the Kyma cluster. -## PostgreSQL database example +## PostgreSQL Database Example For the PostgreSQL example, use the `deployment.yaml` file. It provides the Deployment definition as well as an APIRule to expose the API without authentication. The Deployment references the PostgreSQL Service Binding Secret for connection credentials. This sample demonstrates how to: -- Create a development Namespace in the Kyma runtime. +- Create a development namespace in the Kyma runtime. - Deploy the following Kubernetes resources: - API deployment written in GO - API Rule @@ -23,14 +23,14 @@ This sample demonstrates how to: ## Prerequisites - SAP BTP, Kyma runtime instance -- PostgreSQL Service Instance and Service Binding in Kyma cluster +- PostgreSQL Service Instance and Service Binding in the Kyma cluster - [Docker](https://www.docker.com/) - [Go](https://golang.org/doc/install) - [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) configured to use the `KUBECONFIG` file downloaded from the Kyma runtime -## Steps +## Procedure -### Build the Docker image +### Build the Docker Image 1. Build and push the image to your Docker repository: @@ -41,7 +41,7 @@ This sample demonstrates how to: ### Deploy the API -1. Create a new `dev` Namespace: +1. Create a new `dev` namespace: ```shell script kubectl create namespace dev From 4e73434eb9be42c802d8ab2c125310f37c855d24 Mon Sep 17 00:00:00 2001 From: Grzegorz Karaluch Date: Tue, 24 Mar 2026 15:11:05 +0100 Subject: [PATCH 12/20] Apply suggestion from @mmitoraj MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Małgorzata Świeca --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a53074ca5..908ef58e6 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ Running various samples requires access to the Kyma environment. There are also | Name | Description | References | | ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | | [MS SQL database](./database-mssql/README.md) | This sample demonstrates how to containerize and deploy an MS SQL database | [Tutorial](https://developers.sap.com/tutorials/cp-kyma-mssql-deployment.html) | -| [Golang MS SQL database API](./api-postgresql-go/README.md) | This sample provides a Golang API endpoint for communication with an MS SQL database | [Tutorial](https://developers.sap.com/tutorials/cp-kyma-api-mssql-golang.html) | +| [Deploy a Go PostgreSQL API Endpoint in SAP BTP, Kyma Runtime](./api-postgresql-go/README.md) | This sample provides a Golang API endpoint for communication with an MS SQL database | [Tutorial](https://developers.sap.com/tutorials/cp-kyma-api-mssql-golang.html) | ## Advanced Scenarios From 54ec327e8431f4ea85a4432303c09905bd0f5bd9 Mon Sep 17 00:00:00 2001 From: Grzegorz Karaluch Date: Tue, 24 Mar 2026 15:11:24 +0100 Subject: [PATCH 13/20] Update helm-charts/helm-charts-examples.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Małgorzata Świeca --- helm-charts/helm-charts-examples.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm-charts/helm-charts-examples.md b/helm-charts/helm-charts-examples.md index 2fc27b378..4f219ac4e 100644 --- a/helm-charts/helm-charts-examples.md +++ b/helm-charts/helm-charts-examples.md @@ -17,7 +17,7 @@ For more information see [helm](https://helm.sh/) - [UI5 Frontend MSSQL](./frontend-ui5-mssql/README.md) - will also install dependent charts [Golang PostgreSQL Database API](../api-postgresql-go/README.md) and [MSSQL Database](./database-mssql/README.md) -- [Golang PostgreSQL Database API](../api-postgresql-go/README.md) +- [Deploy a Go PostgreSQL API Endpoint in SAP BTP, Kyma Runtime](../api-postgresql-go/README.md) - will also install dependent chart [MSSQL Database](./database-mssql/README.md) - [MSSQL Database](./database-mssql/README.md) - [Sample Event Trigger Java](./sample-event-trigger-java/README.md) From 3a313cf64f902e6e65691f422bd18689a9d0fdf1 Mon Sep 17 00:00:00 2001 From: Grzegorz Karaluch Date: Wed, 25 Mar 2026 10:48:02 +0100 Subject: [PATCH 14/20] Update README.md --- helm-charts/api-mssql-go/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helm-charts/api-mssql-go/README.md b/helm-charts/api-mssql-go/README.md index c86936705..4bfcc13e3 100644 --- a/helm-charts/api-mssql-go/README.md +++ b/helm-charts/api-mssql-go/README.md @@ -1,4 +1,4 @@ -This chart installs the example [api-postgresql-go](../../api-postgresql-go/README.md) as well as it's dependency [database-mssql](../database-mssql/README.md) +This chart installs the example [api-postgresql-go](../../api-postgresql-go/README.md) as well as it's dependency [database-postgres](../database-postgres/README.md) ## Installing the Chart @@ -42,4 +42,4 @@ helm install myapp . -n default -f values.yaml You can override values in the cli by specifying the value for example ``` helm install myapp . -n default --set image.repository=mydockeruser/myimage -``` \ No newline at end of file +``` From 4cae025333770820d864cec05ae0f647c205513b Mon Sep 17 00:00:00 2001 From: grego952 Date: Wed, 25 Mar 2026 10:59:39 +0100 Subject: [PATCH 15/20] Renaming --- .../.helmignore | 0 .../Chart.lock | 0 .../Chart.yaml | 0 helm-charts/api-postgresql-go/README.md | 45 ++++++++++++++++++ .../charts/database-mssql-0.1.0.tgz | Bin .../templates/_helpers.tpl | 0 .../templates/apirule.yaml | 0 .../templates/configmap.yaml | 0 .../templates/deployment.yaml | 0 .../templates/service.yaml | 0 .../values.yaml | 0 .../.helmignore | 0 .../Chart.lock | 0 .../Chart.yaml | 0 helm-charts/frontend-ui5-postgresql/README.md | 44 +++++++++++++++++ .../charts/api-mssql-go-0.1.0.tgz | Bin .../templates/_helpers.tpl | 0 .../templates/apirule.yaml | 0 .../templates/configmap.yaml | 0 .../templates/deployment.yaml | 0 .../templates/service.yaml | 0 .../values.yaml | 0 22 files changed, 89 insertions(+) rename helm-charts/{api-mssql-go => api-postgresql-go}/.helmignore (100%) rename helm-charts/{api-mssql-go => api-postgresql-go}/Chart.lock (100%) rename helm-charts/{api-mssql-go => api-postgresql-go}/Chart.yaml (100%) create mode 100644 helm-charts/api-postgresql-go/README.md rename helm-charts/{api-mssql-go => api-postgresql-go}/charts/database-mssql-0.1.0.tgz (100%) rename helm-charts/{api-mssql-go => api-postgresql-go}/templates/_helpers.tpl (100%) rename helm-charts/{api-mssql-go => api-postgresql-go}/templates/apirule.yaml (100%) rename helm-charts/{api-mssql-go => api-postgresql-go}/templates/configmap.yaml (100%) rename helm-charts/{api-mssql-go => api-postgresql-go}/templates/deployment.yaml (100%) rename helm-charts/{api-mssql-go => api-postgresql-go}/templates/service.yaml (100%) rename helm-charts/{api-mssql-go => api-postgresql-go}/values.yaml (100%) rename helm-charts/{frontend-ui5-mssql => frontend-ui5-postgresql}/.helmignore (100%) rename helm-charts/{frontend-ui5-mssql => frontend-ui5-postgresql}/Chart.lock (100%) rename helm-charts/{frontend-ui5-mssql => frontend-ui5-postgresql}/Chart.yaml (100%) create mode 100644 helm-charts/frontend-ui5-postgresql/README.md rename helm-charts/{frontend-ui5-mssql => frontend-ui5-postgresql}/charts/api-mssql-go-0.1.0.tgz (100%) rename helm-charts/{frontend-ui5-mssql => frontend-ui5-postgresql}/templates/_helpers.tpl (100%) rename helm-charts/{frontend-ui5-mssql => frontend-ui5-postgresql}/templates/apirule.yaml (100%) rename helm-charts/{frontend-ui5-mssql => frontend-ui5-postgresql}/templates/configmap.yaml (100%) rename helm-charts/{frontend-ui5-mssql => frontend-ui5-postgresql}/templates/deployment.yaml (100%) rename helm-charts/{frontend-ui5-mssql => frontend-ui5-postgresql}/templates/service.yaml (100%) rename helm-charts/{frontend-ui5-mssql => frontend-ui5-postgresql}/values.yaml (100%) diff --git a/helm-charts/api-mssql-go/.helmignore b/helm-charts/api-postgresql-go/.helmignore similarity index 100% rename from helm-charts/api-mssql-go/.helmignore rename to helm-charts/api-postgresql-go/.helmignore diff --git a/helm-charts/api-mssql-go/Chart.lock b/helm-charts/api-postgresql-go/Chart.lock similarity index 100% rename from helm-charts/api-mssql-go/Chart.lock rename to helm-charts/api-postgresql-go/Chart.lock diff --git a/helm-charts/api-mssql-go/Chart.yaml b/helm-charts/api-postgresql-go/Chart.yaml similarity index 100% rename from helm-charts/api-mssql-go/Chart.yaml rename to helm-charts/api-postgresql-go/Chart.yaml diff --git a/helm-charts/api-postgresql-go/README.md b/helm-charts/api-postgresql-go/README.md new file mode 100644 index 000000000..c86936705 --- /dev/null +++ b/helm-charts/api-postgresql-go/README.md @@ -0,0 +1,45 @@ +This chart installs the example [api-postgresql-go](../../api-postgresql-go/README.md) as well as it's dependency [database-mssql](../database-mssql/README.md) + + +## Installing the Chart +To install the chart with the release name `myapp` in the namespace `default`: +``` +helm install myapp . -n default +``` + +## Uninstalling the Chart +To uninstall/delete the `myapp` deployment in the namespace `default`: +``` +helm delete myapp -n default +``` + +## Update the Dependency +``` +helm dependency update . +``` + +## Parameters +The following tables lists the available parameters of the chart and their default values as found in the `values.yaml` +| Parameter | Description | Default value | +| --------------------------- | -------------------------------- | --------------------------- | +| image.repository | The docker image | | +| image.pullPolicy | The pullPolicy of the image | Always | +| image.tag | The image version tag | latest | +| configmap.database | The name of the database | DemoDB | +| configmap.host | The database service host | mssql.dev.svc.cluster.local | +| configmap.port | The database port | 1433 | +| service.port | The service port | 80 | +| database-mssql.nameOverride | The name overide of the subchart | database-mssql | + +
+ +You can specify your own `values.yaml` + +``` +helm install myapp . -n default -f values.yaml +``` + +You can override values in the cli by specifying the value for example +``` +helm install myapp . -n default --set image.repository=mydockeruser/myimage +``` \ No newline at end of file diff --git a/helm-charts/api-mssql-go/charts/database-mssql-0.1.0.tgz b/helm-charts/api-postgresql-go/charts/database-mssql-0.1.0.tgz similarity index 100% rename from helm-charts/api-mssql-go/charts/database-mssql-0.1.0.tgz rename to helm-charts/api-postgresql-go/charts/database-mssql-0.1.0.tgz diff --git a/helm-charts/api-mssql-go/templates/_helpers.tpl b/helm-charts/api-postgresql-go/templates/_helpers.tpl similarity index 100% rename from helm-charts/api-mssql-go/templates/_helpers.tpl rename to helm-charts/api-postgresql-go/templates/_helpers.tpl diff --git a/helm-charts/api-mssql-go/templates/apirule.yaml b/helm-charts/api-postgresql-go/templates/apirule.yaml similarity index 100% rename from helm-charts/api-mssql-go/templates/apirule.yaml rename to helm-charts/api-postgresql-go/templates/apirule.yaml diff --git a/helm-charts/api-mssql-go/templates/configmap.yaml b/helm-charts/api-postgresql-go/templates/configmap.yaml similarity index 100% rename from helm-charts/api-mssql-go/templates/configmap.yaml rename to helm-charts/api-postgresql-go/templates/configmap.yaml diff --git a/helm-charts/api-mssql-go/templates/deployment.yaml b/helm-charts/api-postgresql-go/templates/deployment.yaml similarity index 100% rename from helm-charts/api-mssql-go/templates/deployment.yaml rename to helm-charts/api-postgresql-go/templates/deployment.yaml diff --git a/helm-charts/api-mssql-go/templates/service.yaml b/helm-charts/api-postgresql-go/templates/service.yaml similarity index 100% rename from helm-charts/api-mssql-go/templates/service.yaml rename to helm-charts/api-postgresql-go/templates/service.yaml diff --git a/helm-charts/api-mssql-go/values.yaml b/helm-charts/api-postgresql-go/values.yaml similarity index 100% rename from helm-charts/api-mssql-go/values.yaml rename to helm-charts/api-postgresql-go/values.yaml diff --git a/helm-charts/frontend-ui5-mssql/.helmignore b/helm-charts/frontend-ui5-postgresql/.helmignore similarity index 100% rename from helm-charts/frontend-ui5-mssql/.helmignore rename to helm-charts/frontend-ui5-postgresql/.helmignore diff --git a/helm-charts/frontend-ui5-mssql/Chart.lock b/helm-charts/frontend-ui5-postgresql/Chart.lock similarity index 100% rename from helm-charts/frontend-ui5-mssql/Chart.lock rename to helm-charts/frontend-ui5-postgresql/Chart.lock diff --git a/helm-charts/frontend-ui5-mssql/Chart.yaml b/helm-charts/frontend-ui5-postgresql/Chart.yaml similarity index 100% rename from helm-charts/frontend-ui5-mssql/Chart.yaml rename to helm-charts/frontend-ui5-postgresql/Chart.yaml diff --git a/helm-charts/frontend-ui5-postgresql/README.md b/helm-charts/frontend-ui5-postgresql/README.md new file mode 100644 index 000000000..f53ece800 --- /dev/null +++ b/helm-charts/frontend-ui5-postgresql/README.md @@ -0,0 +1,44 @@ +This chart installs the example [frontend-ui5-mssql](../frontend-ui5-mssql/README.md). Installing this chart will also install the charts [api-mssql-go](../../api-postgresql-go/README.md) and [database-mssql](../database-mssql/README.md) + + +## Installing the Chart +To install the chart you must set the property `clusterDomain` +To install the chart with the release name `myapp` in the namespace `default`: +``` +helm install myapp . -n default --set clusterDomain="********.kyma.shoot.live.k8s-hana.ondemand.com" +``` + +## Uninstalling the Chart +To uninstall/delete the `myapp` deployment in the namespace `default`: +``` +helm delete myapp -n default +``` + +## Update the Dependency +``` +helm dependency update . +``` + +## Parameters +The following tables lists the available parameters of the chart and their default values as found in the `values.yaml` +| Parameter | Description | Default value | +| ------------------------- | ------------------------------------------------------------------------------- | ------------- | +| image.repository | The docker image | | +| image.pullPolicy | The pullPolicy of the image | Always | +| image.tag | The image version tag | latest | +| clusterDomain.database | The cluster's domain for example ********.kyma.shoot.live.k8s-hana.ondemand.com | | +| service.port | The service port | 80 | +| api-mssql-go.nameOverride | The name overide of the subchart | api-mssql-go | + +
+ +You can specify your own `values.yaml` + +``` +helm install myapp . -n default -f values.yaml +``` + +You can override values in the cli by specifying the value for example +``` +helm install myapp . -n default --set image.repository=mydockeruser/myimage +``` \ No newline at end of file diff --git a/helm-charts/frontend-ui5-mssql/charts/api-mssql-go-0.1.0.tgz b/helm-charts/frontend-ui5-postgresql/charts/api-mssql-go-0.1.0.tgz similarity index 100% rename from helm-charts/frontend-ui5-mssql/charts/api-mssql-go-0.1.0.tgz rename to helm-charts/frontend-ui5-postgresql/charts/api-mssql-go-0.1.0.tgz diff --git a/helm-charts/frontend-ui5-mssql/templates/_helpers.tpl b/helm-charts/frontend-ui5-postgresql/templates/_helpers.tpl similarity index 100% rename from helm-charts/frontend-ui5-mssql/templates/_helpers.tpl rename to helm-charts/frontend-ui5-postgresql/templates/_helpers.tpl diff --git a/helm-charts/frontend-ui5-mssql/templates/apirule.yaml b/helm-charts/frontend-ui5-postgresql/templates/apirule.yaml similarity index 100% rename from helm-charts/frontend-ui5-mssql/templates/apirule.yaml rename to helm-charts/frontend-ui5-postgresql/templates/apirule.yaml diff --git a/helm-charts/frontend-ui5-mssql/templates/configmap.yaml b/helm-charts/frontend-ui5-postgresql/templates/configmap.yaml similarity index 100% rename from helm-charts/frontend-ui5-mssql/templates/configmap.yaml rename to helm-charts/frontend-ui5-postgresql/templates/configmap.yaml diff --git a/helm-charts/frontend-ui5-mssql/templates/deployment.yaml b/helm-charts/frontend-ui5-postgresql/templates/deployment.yaml similarity index 100% rename from helm-charts/frontend-ui5-mssql/templates/deployment.yaml rename to helm-charts/frontend-ui5-postgresql/templates/deployment.yaml diff --git a/helm-charts/frontend-ui5-mssql/templates/service.yaml b/helm-charts/frontend-ui5-postgresql/templates/service.yaml similarity index 100% rename from helm-charts/frontend-ui5-mssql/templates/service.yaml rename to helm-charts/frontend-ui5-postgresql/templates/service.yaml diff --git a/helm-charts/frontend-ui5-mssql/values.yaml b/helm-charts/frontend-ui5-postgresql/values.yaml similarity index 100% rename from helm-charts/frontend-ui5-mssql/values.yaml rename to helm-charts/frontend-ui5-postgresql/values.yaml From a5382119969a776412d3a2957b03fcc84ed50eb1 Mon Sep 17 00:00:00 2001 From: grego952 Date: Wed, 25 Mar 2026 11:01:58 +0100 Subject: [PATCH 16/20] Small fix --- helm-charts/api-postgresql-go/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm-charts/api-postgresql-go/README.md b/helm-charts/api-postgresql-go/README.md index c86936705..3df62e43e 100644 --- a/helm-charts/api-postgresql-go/README.md +++ b/helm-charts/api-postgresql-go/README.md @@ -1,4 +1,4 @@ -This chart installs the example [api-postgresql-go](../../api-postgresql-go/README.md) as well as it's dependency [database-mssql](../database-mssql/README.md) +This chart installs the example [api-postgresql-go](../../api-postgresql-go/README.md) as well as it's dependency [database-postgres](../../database-postgres/README.md) ## Installing the Chart From 9efc6cb90a55c006331b485a6526c2a6d2f86ed1 Mon Sep 17 00:00:00 2001 From: grego952 Date: Wed, 25 Mar 2026 11:02:58 +0100 Subject: [PATCH 17/20] Small fix --- helm-charts/frontend-ui5-postgresql/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm-charts/frontend-ui5-postgresql/README.md b/helm-charts/frontend-ui5-postgresql/README.md index f53ece800..65051514d 100644 --- a/helm-charts/frontend-ui5-postgresql/README.md +++ b/helm-charts/frontend-ui5-postgresql/README.md @@ -1,4 +1,4 @@ -This chart installs the example [frontend-ui5-mssql](../frontend-ui5-mssql/README.md). Installing this chart will also install the charts [api-mssql-go](../../api-postgresql-go/README.md) and [database-mssql](../database-mssql/README.md) +This chart installs the example [frontend-ui5-postgresql](../../frontend-ui5-postgresql/README.md). Installing this chart will also install the charts [api-postgresql-go](../../api-postgresql-go/README.md) and [database-postgres](../../database-postgres/README.md) ## Installing the Chart From f6abdd2e8cb010bced5fa8956ec2a77cbc2a008a Mon Sep 17 00:00:00 2001 From: grego952 Date: Wed, 25 Mar 2026 11:07:32 +0100 Subject: [PATCH 18/20] Fix links --- helm-charts/api-mssql-go/README.md | 45 ------------------- helm-charts/frontend-ui5-mssql/README.md | 44 ------------------ helm-charts/frontend-ui5-postgresql/README.md | 2 +- 3 files changed, 1 insertion(+), 90 deletions(-) delete mode 100644 helm-charts/api-mssql-go/README.md delete mode 100644 helm-charts/frontend-ui5-mssql/README.md diff --git a/helm-charts/api-mssql-go/README.md b/helm-charts/api-mssql-go/README.md deleted file mode 100644 index 4bfcc13e3..000000000 --- a/helm-charts/api-mssql-go/README.md +++ /dev/null @@ -1,45 +0,0 @@ -This chart installs the example [api-postgresql-go](../../api-postgresql-go/README.md) as well as it's dependency [database-postgres](../database-postgres/README.md) - - -## Installing the Chart -To install the chart with the release name `myapp` in the namespace `default`: -``` -helm install myapp . -n default -``` - -## Uninstalling the Chart -To uninstall/delete the `myapp` deployment in the namespace `default`: -``` -helm delete myapp -n default -``` - -## Update the Dependency -``` -helm dependency update . -``` - -## Parameters -The following tables lists the available parameters of the chart and their default values as found in the `values.yaml` -| Parameter | Description | Default value | -| --------------------------- | -------------------------------- | --------------------------- | -| image.repository | The docker image | | -| image.pullPolicy | The pullPolicy of the image | Always | -| image.tag | The image version tag | latest | -| configmap.database | The name of the database | DemoDB | -| configmap.host | The database service host | mssql.dev.svc.cluster.local | -| configmap.port | The database port | 1433 | -| service.port | The service port | 80 | -| database-mssql.nameOverride | The name overide of the subchart | database-mssql | - -
- -You can specify your own `values.yaml` - -``` -helm install myapp . -n default -f values.yaml -``` - -You can override values in the cli by specifying the value for example -``` -helm install myapp . -n default --set image.repository=mydockeruser/myimage -``` diff --git a/helm-charts/frontend-ui5-mssql/README.md b/helm-charts/frontend-ui5-mssql/README.md deleted file mode 100644 index 545d4cc36..000000000 --- a/helm-charts/frontend-ui5-mssql/README.md +++ /dev/null @@ -1,44 +0,0 @@ -This chart installs the example [frontend-ui5-postgresql](../frontend-ui5-postgresql/README.md). Installing this chart will also install the charts [api-postgresql-go](../../api-postgresql-go/README.md) and [database-postgres](../database-postgres/README.md) - - -## Installing the Chart -To install the chart you must set the property `clusterDomain` -To install the chart with the release name `myapp` in the namespace `default`: -``` -helm install myapp . -n default --set clusterDomain="********.kyma.shoot.live.k8s-hana.ondemand.com" -``` - -## Uninstalling the Chart -To uninstall/delete the `myapp` deployment in the namespace `default`: -``` -helm delete myapp -n default -``` - -## Update the Dependency -``` -helm dependency update . -``` - -## Parameters -The following tables lists the available parameters of the chart and their default values as found in the `values.yaml` -| Parameter | Description | Default value | -| ------------------------- | ------------------------------------------------------------------------------- | ------------- | -| image.repository | The docker image | | -| image.pullPolicy | The pullPolicy of the image | Always | -| image.tag | The image version tag | latest | -| clusterDomain.database | The cluster's domain for example ********.kyma.shoot.live.k8s-hana.ondemand.com | | -| service.port | The service port | 80 | -| api-mssql-go.nameOverride | The name overide of the subchart | api-mssql-go | - -
- -You can specify your own `values.yaml` - -``` -helm install myapp . -n default -f values.yaml -``` - -You can override values in the cli by specifying the value for example -``` -helm install myapp . -n default --set image.repository=mydockeruser/myimage -``` \ No newline at end of file diff --git a/helm-charts/frontend-ui5-postgresql/README.md b/helm-charts/frontend-ui5-postgresql/README.md index 65051514d..043443beb 100644 --- a/helm-charts/frontend-ui5-postgresql/README.md +++ b/helm-charts/frontend-ui5-postgresql/README.md @@ -1,4 +1,4 @@ -This chart installs the example [frontend-ui5-postgresql](../../frontend-ui5-postgresql/README.md). Installing this chart will also install the charts [api-postgresql-go](../../api-postgresql-go/README.md) and [database-postgres](../../database-postgres/README.md) +This chart installs the example [frontend-ui5-postgresql](../../frontend-ui5-postgresql). Installing this chart will also install the charts [api-postgresql-go](../../api-postgresql-go/README.md) and [database-postgres](../../database-postgres/README.md) ## Installing the Chart From f23a25852c11ea4bce28f58aa8123ba10acb40fa Mon Sep 17 00:00:00 2001 From: grego952 Date: Wed, 25 Mar 2026 11:10:21 +0100 Subject: [PATCH 19/20] Fix links --- helm-charts/frontend-ui5-postgresql/README.md | 2 +- helm-charts/helm-charts-examples.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/helm-charts/frontend-ui5-postgresql/README.md b/helm-charts/frontend-ui5-postgresql/README.md index 043443beb..d2a89e115 100644 --- a/helm-charts/frontend-ui5-postgresql/README.md +++ b/helm-charts/frontend-ui5-postgresql/README.md @@ -1,4 +1,4 @@ -This chart installs the example [frontend-ui5-postgresql](../../frontend-ui5-postgresql). Installing this chart will also install the charts [api-postgresql-go](../../api-postgresql-go/README.md) and [database-postgres](../../database-postgres/README.md) +This chart installs the example `frontend-ui5-postgresql`. Installing this chart will also install the charts [api-postgresql-go](../../api-postgresql-go/README.md) and [database-postgres](../../database-postgres/README.md) ## Installing the Chart diff --git a/helm-charts/helm-charts-examples.md b/helm-charts/helm-charts-examples.md index 45749b30e..241837392 100644 --- a/helm-charts/helm-charts-examples.md +++ b/helm-charts/helm-charts-examples.md @@ -16,7 +16,7 @@ For more information see [helm](https://helm.sh/) ## Samples - [Deploy a Go PostgreSQL API Endpoint in SAP BTP, Kyma Runtime](../api-postgresql-go/README.md) - - will also install dependent chart [PostgreSQL Database](./database-postgres/README.md) + - will also install dependent chart [PostgreSQL Database](../database-postgres/README.md) - [Use and Seed SAP BTP PostgreSQL in SAP BTP, Kyma Runtime](../database-postgres/README.md) - [Sample Event Trigger Java](./sample-event-trigger-java/README.md) - [Sample Extension Java](./sample-extension-java/README.md) From 967d8212c2d7bd6120dd88a8dc589ba1d9633991 Mon Sep 17 00:00:00 2001 From: grego952 Date: Wed, 25 Mar 2026 11:30:37 +0100 Subject: [PATCH 20/20] Remove postgres from link --- api-postgresql-go/k8s/event.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-postgresql-go/k8s/event.yaml b/api-postgresql-go/k8s/event.yaml index 110d14956..15c9b243c 100644 --- a/api-postgresql-go/k8s/event.yaml +++ b/api-postgresql-go/k8s/event.yaml @@ -3,7 +3,7 @@ kind: Subscription metadata: name: api-postgresql-go-event-sub spec: - sink: 'http://api-postgresql-go.postgres-dev.svc.cluster.local:80/orderCodeEvent' + sink: 'http://api-postgresql-go.dev.svc.cluster.local:80/orderCodeEvent' source: mp-commerce-mock types: - order.created.v1 \ No newline at end of file