Skip to content

Commit

Permalink
Sample App code finalization (#6011)
Browse files Browse the repository at this point in the history
* fix: update the code according to pierdipi's suggestions

* feat: improve the user experience for the setup script

* feat: improve the user experience for the solution script

* fix: remove unnecessary images

* fix: remove the image registry information in the ML services

* fix: remove the sample webhook URL

* feat: modify the config map to manually disable the scale-to-zero feature

* fix: adding the waiting in the solution setup script

* fix: adding the waiting in the solution setup script for pipe
  • Loading branch information
Leo6Leo authored Jun 27, 2024
1 parent c671f90 commit 1ec7a2b
Show file tree
Hide file tree
Showing 17 changed files with 277 additions and 180 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
specVersion: 0.36.0
name: bad-word-filter
runtime: python
registry: quay.io/rh-ee-leoli
image: quay.io/rh-ee-leoli/bad-word-filter:latest
imageDigest: sha256:b6bec398e44dc20630856f39ef29195db9a3ee5b43cec0372207c89ad633aeb2
created: 2024-03-27T23:12:06.178272+08:00
build:
builder: s2i
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
specVersion: 0.36.0
name: sentiment-analysis-app
runtime: python
registry: quay.io/rh-ee-leoli
image: quay.io/rh-ee-leoli/sentiment-analysis-app:latest
imageDigest: sha256:3565ee0591557eca83f19bafbd5a614c66ff5d863d2521ad7d176c76e8294c93
created: 2024-02-01T00:18:00.06485162-04:00
build:
builder: s2i
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This is a ConfigMap that disables the scale-to-zero feature in Knative Serving.
# The scale-to-zero feature scales down the number of pods to zero when there are no requests.
# You can learn more about the scale-to-zero feature at https://knative.dev/docs/serving/autoscaling/scale-to-zero/#enable-scale-to-zero
apiVersion: v1
kind: ConfigMap
metadata:
name: config-autoscaler
namespace: knative-serving
data:
enable-scale-to-zero: "false"
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,6 @@ kind: Broker
metadata:
name: bookstore-broker


---
# This Trigger subscribes to the Broker and filters events based on the type and badwordfilter attribute.
# Those comments that contain insults are filtered out by the badwordfilter attribute and they will be redirected to the event-display Service.
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
name: temp-trigger
spec:
broker: bookstore-broker
filter:
attributes:
type: new-review-comment # This is the filter that will be applied to the event, only events with the ce-type new-review-comment will be processed
subscriber:
ref:
apiVersion: v1
kind: Service
name: event-display



---
apiVersion: eventing.knative.dev/v1
kind: Trigger
Expand All @@ -40,4 +19,4 @@ spec:
apiVersion: v1
kind: Service
name: node-server-svc
uri: /insert # This is the path where the event will be sent to the subscriber, see /insert in node-server code: index.js
uri: /insert # This is the path where the event will be sent to the subscriber, see /insert in node-server code: index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This Trigger subscribes to the Broker and will forward all the events that it received to event-display.
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
name: log-trigger
spec:
broker: bookstore-broker
subscriber:
ref:
apiVersion: v1
kind: Service
name: event-display
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,4 @@ spec:
ref:
apiVersion: flows.knative.dev/v1
kind: Sequence
name: sequence

---
# This Trigger subscribes to the Broker and filters events based on the type and badwordfilter attribute.
# Those comments that contain insults are filtered out by the badwordfilter attribute and they will be redirected to the event-display Service.
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
name: seq-reply-trigger
spec:
broker: bookstore-broker
filter:
attributes:
type: moderated-comment # This is the filter that will be applied to the event, only events with the ce-type moderated-comment will be processed
badwordfilter: bad # This is the filter that will be applied to the event, only events with the ce-extension badwordfilter: bad will be processed
subscriber:
ref:
apiVersion: v1
kind: Service
name: event-display
name: sequence
104 changes: 0 additions & 104 deletions code-samples/eventing/bookstore-sample-app/solution/setup.sh
Original file line number Diff line number Diff line change
@@ -1,104 +0,0 @@
#!/bin/bash

# Prompt the user to start the installation process
echo "This script will install Knative Serving, Knative Eventing, and install the sample app bookstore on your cluster"
read -p "Press ENTER to continue or Ctrl+C to abort..."

# Install Knative Serving
echo "Installing Knative Serving..."
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.14.0/serving-crds.yaml
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.14.0/serving-core.yaml
kubectl apply -f https://github.com/knative/net-kourier/releases/download/knative-v1.14.0/kourier.yaml

# Configure Kourier as the default ingress
kubectl patch configmap/config-network --namespace knative-serving --type merge --patch '{"data":{"ingress-class":"kourier.ingress.networking.knative.dev"}}'

echo "Knative Serving installed successfully."

# Install Knative Eventing
echo "Installing Knative Eventing..."
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v1.14.0/eventing-crds.yaml
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v1.14.0/eventing-core.yaml
echo "Knative Eventing installed successfully."

# Install Knative imc Broker
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v1.14.0/in-memory-channel.yaml
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v1.14.0/mt-channel-broker.yaml
echo "Knative in-memory Channel and Broker installed successfully."

# Detect whether the user has knative function "func" installed
if ! command -v func &> /dev/null
then
echo "Knative CLI 'func' not found. Please install the Knative CLI by following the instructions at https://knative.dev/docs/admin/install/kn-cli/."
exit
fi

# Detect whether the user has kamel CLI installed
if ! command -v kamel &> /dev/null
then
echo "Kamel CLI not found. Please install the Kamel CLI by following the instructions at https://camel.apache.org/camel-k/latest/installation/installation.html."
exit
fi



# Prompt for the Docker registry details
echo "Please provide the details of your Container registry to install the Camel-K."
read -p "Enter the registry hostname (e.g., docker.io or quay.io): " REGISTRY_HOST
read -p "Enter the registry username: " REGISTRY_USER
read -s -p "Enter the registry password: " REGISTRY_PASSWORD
echo "All the required details have been captured and saved locally."

# Set the registry details as environment variables
export REGISTRY_HOST=$REGISTRY_HOST
export REGISTRY_USER=$REGISTRY_USER
export REGISTRY_PASSWORD=$REGISTRY_PASSWORD

# Set the KO_DOCKER_REPO environment variable
export KO_DOCKER_REPO=$REGISTRY_HOST/$REGISTRY_USER

# Install the camel-K
kamel install --registry $REGISTRY_HOST--organization $REGISTRY_USER --registry-auth-username $REGISTRY_USER --registry-auth-password $REGISTRY_PASSWORD


# Install the Sample Bookstore App
echo "Installing the Sample Bookstore App..., but please follow the instruction below to tell us your registry details"
read -p "Press ENTER to continue..."

# Install the front end first
cd frontend
kubectl apply -f config

# Install the node-server
cd ../node-server
kubectl apply -f config

# Deploy the ML services
cd ../ML-bad-word-filter
func deploy -b=s2i -v

cd ../ML-sentiment-analysis
func deploy -b=s2i -v

# Install the db
cd ..
kubectl apply -f db-service

# Install the sequence
kubectl apply -f sequence/config

# Ask the user to edit the properties file
echo "Please edit slack-sink/application.properties to provide the webhook URL for Slack."
read -p "Press ENTER to continue..."

# Create the secret
kubectl create secret generic slack-credentials --from-file=slack-sink/application.properties

# Install the slack-sink
kubectl apply -f slack-sink/config

# Ask user to open a new terminal to set the minikube tunnel
echo "If you are using minikube: Please open a new terminal and run 'sudo minikube tunnel' to expose the services to the outside world."
read -p "Press ENTER to continue..."
# FIXME: @pierDipi something wrong here. If run minikube tunnel before bookstore is installed, the localhost:80 will not be accessible
# End of script
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
#

slack.channel=#bookstore-owner
slack.webhook.url=https://hooks.slack.com/services/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
slack.webhook.url=<Put your Webhook URL here>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: eventing.knative.dev/v1
kind: Broker
metadata:
name: badword-broker

---
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
name: badword-noti-trigger
spec:
broker: bookstore-broker
filter:
attributes: # Trigger will filter events based on BOTH the type and badwordfilter attribute
type: moderated-comment # This is the filter that will be applied to the event, only events with the ce-type moderated-comment will be processed
badwordfilter: bad # This is the filter that will be applied to the event, only events with the ce-extension badwordfilter: bad will be processed
subscriber:
ref:
apiVersion: eventing.knative.dev/v1
kind: Broker
name: badword-broker
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
ref:
kind: Broker # Specifies the kind of source, in this case, a Knative Eventing Broker.
apiVersion: eventing.knative.dev/v1 # The API version of the Knative Eventing Broker.
name: bookstore-broker # The name of the Broker, "book-review-broker" in this case
name: badword-broker # The name of the Broker, "book-review-broker" in this case
properties:
type: moderated-comment # A filter that specifies the type of events this Pipe will listen for, here it's listening for events of type "bad-comment". You have to have this type specified.
sink: # Defines the destination for events processed by this Pipe.
Expand Down
Loading

0 comments on commit 1ec7a2b

Please sign in to comment.