Skip to content

Commit

Permalink
git pull
Browse files Browse the repository at this point in the history
  • Loading branch information
ShravaniAK committed Jul 24, 2024
2 parents 680801c + d8db1f8 commit fa5df54
Show file tree
Hide file tree
Showing 378 changed files with 17,419 additions and 46,629 deletions.
29 changes: 23 additions & 6 deletions .github/workflows/knative-docs-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: ['main']
paths:
- "code-samples/serving/hello-world/helloworld-go/**"
- "code-samples/eventing/bookstore-sample-app/**"
- "docs/serving/autoscaling/autoscale-go/**"
- "hack/docker/**"
- ".github/workflows/knative-docs-image.yaml"
Expand All @@ -19,37 +20,53 @@ jobs:
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build mkdocs image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
push: true
file: ./hack/docker/Dockerfile
tags: ghcr.io/knative/knative-docs:latest

- name: Build helloworld-go image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
context: ./code-samples/serving/hello-world/helloworld-go
tags: ghcr.io/knative/helloworld-go:latest

- name: Build autoscale-go image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
context: ./docs/serving/autoscaling/autoscale-go
tags: ghcr.io/knative/autoscale-go:latest

- name: Build sample-app's frontend image
uses: docker/build-push-action@v4
with:
push: true
platforms: linux/amd64,linux/arm64
context: ./code-samples/eventing/bookstore-sample-app/solution/frontend
tags: ghcr.io/knative/bookstore-frontend:latest

- name: Build sample-app's node-server image
uses: docker/build-push-action@v4
with:
push: true
platforms: linux/amd64,linux/arm64
context: ./code-samples/eventing/bookstore-sample-app/solution/node-server
tags: ghcr.io/knative/node-server:latest
2 changes: 2 additions & 0 deletions .github/workflows/knative-go-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ on:
jobs:
test:
uses: knative/actions/.github/workflows/reusable-go-test.yaml@main
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/mkdocs-strict-verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
GOPATH: ${{ github.workspace }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ hack/__pycache__
!/blog/overrides/partials/source-file.html
!/blog/overrides/partials/content.html
/blog/docs/stylesheets/
/node_modules/
node_modules
venv/

# TODO clean up images copied between blog/ and docs/
Expand All @@ -36,4 +36,3 @@ maven-wrapper.jar

# Ignore Python virtual environments
.venv
/code-samples/eventing/bookstore-sample-app/db/bookstore-eda/node_modules/*
1 change: 1 addition & 0 deletions OWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ approvers:
reviewers:
- docs-writers
- docs-reviewers
- ux-wg-leads
17 changes: 10 additions & 7 deletions OWNERS_ALIASES
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ aliases:
- vyasgun
docs-reviewers:
- nainaz
- pmbanugo
- retocode
- skonto
- snneji
docs-writers:
- csantanapr
- retocode
Expand All @@ -35,7 +33,6 @@ aliases:
- creydr
- lionelvillard
- matzew
- odacremolbap
- pierDipi
func-reviewers:
- jrangelramos
Expand All @@ -52,6 +49,9 @@ aliases:
- lkingland
- salaboy
knative-admin:
- Cali0707
- Leo6Leo
- ReToCode
- aliok
- cardil
- davidhadas
Expand All @@ -63,12 +63,17 @@ aliases:
- knative-prow-robot
- knative-prow-updater-robot
- knative-test-reporter-robot
- krsna-m
- nainaz
- psschwei
- salaboy
- skonto
- upodroid
knative-release-leads: []
knative-release-leads:
- Cali0707
- Leo6Leo
- ReToCode
- dsimansk
- skonto
knative-robots:
- knative-automation
- knative-prow-releaser-robot
Expand Down Expand Up @@ -98,7 +103,6 @@ aliases:
- upodroid
productivity-writers:
- cardil
- krsna-m
- upodroid
security-wg-leads:
- davidhadas
Expand Down Expand Up @@ -132,7 +136,6 @@ aliases:
- davidhadas
- dprotaso
- dsimansk
- krsna-m
- psschwei
ux-wg-leads:
- cali0707
Expand Down
8 changes: 8 additions & 0 deletions blog/config/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ nav:
- releases/announcing-knative-v0-3-release.md
- releases/announcing-knative-v0-2-release.md
- Articles:
- articles/llm-agents-overview.md
- articles/cross-namespace-event-links-feature.md
- articles/aws_to_func_migration.md
- articles/consuming_s3_data_with_knative.md
- articles/How-IBM-watsonx-Assistant-uses-Knative-Eventing-to-train-machine-learning-models.md
- articles/enhancing-the-knative-experience.md
- articles/knative-meets-apache-camel.md
- articles/knative-backstage-plugins.md
- articles/demystifying-activator-on-path.md
- articles/knative-eventing-vision.md
- articles/new_event_discovery_features.md
- articles/getting-started-blog-p3.md
- articles/getting-started-blog-p2.md
- articles/getting-started-blog-p1.md
- articles/getting-started-blog-p0.md
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# How IBM Watsonx Assistant uses Knative Eventing to train machine learning models

![How IBM Watsonx Assistant uses Knative Eventing to train machine learning models](./images/How-IBM-watsonx-Assistant-uses-Knative-Eventing-to-train-machine-learning-models.png)

Read the full case study on the [CNCF website](https://www.cncf.io/case-studies/ibmwatsonxassistant/)!

Thanks to [Firat Bezir](https://www.linkedin.com/in/firatbezir/)
and [Zainab Husain](https://www.linkedin.com/in/zainabhusain1/) for creating the impact visual
summary.
119 changes: 119 additions & 0 deletions blog/docs/articles/aws_to_func_migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Migrating Functions from AWS Lambda to Knative Functions using Golang

**Author: Matthias Weßendorf, Senior Principal Software Engineer @ Red Hat**

_In a [previous post](/blog/articles/consuming_s3_data_with_knative){:target="_blank"} we discussed the consumption of notifications from an AWS S3 bucket inside a Knative Function. This post will describe the migration from a AWS Lambda Function, receiving S3 notifications, to [Knative Functions](docs/functions){:target="_blank"}._

With Serverless Functions one of the common use-cases is to execute custom code based on an event trigger, like a notification from the AWS S3 service. With AWS Lambda you can run those programs on Amazon's cloud offerings, but running the code on your own data-center is much harder.

## A Lambda Function for AWS S3

Taking a look at a Lambda [sample repository](/~https://github.com/aws/aws-lambda-go/blob/main/events/README_S3.md){:target="_blank"} shows a minimal, yet complete function for receiving AWS S3 event notifications. Lets take a look at the code:

```go
// main.go
package main

import (
"fmt"
"context"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-lambda-go/events"
)

func handler(ctx context.Context, s3Event events.S3Event) {
for _, record := range s3Event.Records {
s3 := record.S3
fmt.Printf("[%s - %s] Bucket = %s, Key = %s \n", record.EventSource, record.EventTime, s3.Bucket.Name, s3.Object.Key)
}
}


func main() {
// Make the handler available for Remote Procedure Call by AWS Lambda
lambda.Start(handler)
}
```

You see two functions here: `handler` for the custom application logic and `main` which calls some AWS Lambda APIs which register the custom handler. The signature of `handler` references the standard `Context` and an `S3Event` from the AWS Lambda SDK. In order to be able to run the function one needs two vendor-specific dependencies and a `main` function. These are not directly related to the actual program, but are necessary technical plumbing in order to start the custom `handler` and register it to receive events.


## A Simpler Knative Function for AWS S3

!!! note

To learn more about Knative Functions and how to create, build and deploy a project using the `func` CLI, check out the [documentation](docs/functions){:target="_blank"}.


In the [previous post](/blog/articles/consuming_s3_data_with_knative){:target="_blank"} we discuss how to consume notifications from AWS Lambda in an on-premise cluster using Knative Eventing. Lets take a look at the `main.go` file from the S3 project again:

```go
package function

import (
"context"
"fmt"

"github.com/cloudevents/sdk-go/v2/event"
)

// Handle an event.
func Handle(ctx context.Context, ce event.Event) (*event.Event, error) {
fmt.Println("Received S3 event notification")
fmt.Println("CloudEvent Subject attribute: " + ce.Subject())
fmt.Println("CloudEvent Source attribute: " + ce.Source())

// Some processing of the payload of the CloudEvent...

return nil, nil
}
```

Note that this complete program contains only one function, which is focused on the processing of the incoming events. There is no need for `main`, or to register our event handler with middleware. Therefore, there is also no need for imports. Knative Functions handles creating the process boundary and applying middleware automatically.

Looking closer at the signature of the `Handle` function, we see the standard `Context` API and an `Event` type. This is no vendor specific import. It references the Golang SDK for [CNCF CloudEvents](https://www.cncf.io/projects/cloudevents/){:target="_blank"}, which is a specification for describing event data in a common way.

In this example the `subject` is mapped to the name of the file, or the S3 Object Key, while the `source` attribute is containing the bucket name. In case the entire file is desired for processing, it can be accessed via the `data` attribute.

!!! note

The CNCF CloudEvents specification allows a generic and independent approach for receiving events from 3rd party systems, while providing a common, standardized API.


## Knative CLI for Smooth Development and Deployment

The Knative Function project does not only offer a vendor-neutral approach for creating serverless functions, it also comes with a handy CLI that assists with the creation of the Linux container image and the deployment to a Kubernetes cluster. This is covered in the [previous blog post](/blog/articles/consuming_s3_data_with_knative){:target="_blank"}. It also allows you to test and run the function locally by invoking:

```
$ func run
```

The log for the program reads like:

```
Building function image
🙌 Function built: <your-container-registry>/<account>/<image>:<tag>
Initializing CloudEvent function
listening on http port 8080
Running on host port 8080
```

Now you can simply test the Knative Function on your machine, like:

```
$ curl -v -X POST \
-H "content-type: application/json" \
-H "ce-specversion: 1.0" \
-H "ce-source: /my/file/storage" \
-H "ce-type: test.event.type" \
-H "ce-subject: test-file.txt" \
-H "ce-id: $(uuid)" \
http://127.0.0.1:8080
```


## Conclusion

With Knative Functions it is straightforward to build cloud vendor-neutral functions for consuming event notifications from 3rd party cloud services such as AWS S3. Deploying those functions as Linux containers to your own on-premise Kubernetes cluster is also supported by the Knative CLI, as well as testing the function locally.

To learn more about Knative Functions visit the [documentation](docs/functions){:target="_blank"} on our website or join our CNCF Slack channel [#knative-functions](https://cloud-native.slack.com/archives/C04LKEZUXEE)!
Loading

0 comments on commit fa5df54

Please sign in to comment.