Knative - Kafka Channel/Broker/Serverless CI/CD架构示意图之GitLab使用Kafka发送事件消息 【十四】
#查看集群默认 Channel
#查看集群默认 Channel
[root@xianchaomaster1 05-gitlabsource-to-knative-service]# kubectl get cm default-ch-webhook -o yaml -n knative-eventing
apiVersion: v1
data:
default-ch-config: |
clusterDefault:
apiVersion: messaging.knative.dev/v1
kind: InMemoryChannel
namespaceDefaults:
some-namespace:
apiVersion: messaging.knative.dev/v1
kind: InMemoryChannel
kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","data":{"default-ch-config":"clusterDefault:\n apiVersion: messaging.knative.dev/v1\n kind: InMemoryChannel\nnamespaceDefaults:\n some-namespace:\n apiVersion: messaging.knative.dev/v1\n kind: InMemoryChannel\n"},"kind":"ConfigMap","metadata":{"annotations":{},"labels":{"app.kubernetes.io/name":"knative-eventing","app.kubernetes.io/version":"1.7.1","eventing.knative.dev/release":"v1.7.1"},"name":"default-ch-webhook","namespace":"knative-eventing"}}
creationTimestamp: "2023-07-09T02:11:15Z"
labels:
app.kubernetes.io/name: knative-eventing
app.kubernetes.io/version: 1.7.1
eventing.knative.dev/release: v1.7.1
name: default-ch-webhook
namespace: knative-eventing
resourceVersion: "37269"
uid: 310b0dbb-32d1-4219-a717-0718ec53acb6
创建Kafka Channel
#messaging.knative.dev:v1beta1
kn channel create kc004 --type messaging.knative.dev:v1beta1:KafkaChannel
[root@xianchaomaster1 KnativeSrc]# kn channel list
NAME TYPE URL AGE READY REASON
imc01 InMemoryChannel http://imc01-kn-channel.default.svc.cluster.local 167m True
kc004 KafkaChannel http://kc004-kn-channel.default.svc.cluster.local 88s True
Configure Channels for Apache Kafka
#https://knative.dev/docs/eventing/configuration/kafka-channel-configuration/#create-a-kafka-channel-configmap
#Channel配置说明:
#1、单独使用的时,默认的Channel类型,受控于knative-eventing名称空间中configmap/default-ch-webhook的定义;该定义并不能直接影响broker默认在底层使用的channel类型;
#创建默认KafkaChannel 默认demo名称空间才使用InMemoryChannel
[root@xianchaomaster1 kafka-broker]# cat default-ch-webhook.yaml
apiVersion: v1
data:
default-ch-config: |
clusterDefault:
apiVersion: messaging.knative.dev/v1beta1
kind: KafkaChannel
spec:
numPartitions: 10
replicationFactor: 3
namespaceDefaults:
demo:
apiVersion: messaging.knative.dev/v1
kind: InMemoryChannel
kind: ConfigMap
metadata:
name: default-ch-webhook
namespace: knative-eventing
[root@xianchaomaster1 kafka-broker]# kubectl apply -f default-ch-webhook.yaml
configmap/default-ch-webhook configured
[root@xianchaomaster1 kafka-broker]# kn channel create channel-02
Channel 'channel-02' created in namespace 'default'.
#查看channel-02 默认已经是 KafkaChannel通道了
[root@xianchaomaster1 kafka-broker]# kn channel list
NAME TYPE URL AGE READY REASON
channel-02 KafkaChannel http://channel-02-kn-channel.default.svc.cluster.local 6s True
imc01 InMemoryChannel http://imc01-kn-channel.default.svc.cluster.local 172m True
kc004 KafkaChannel http://kc004-kn-channel.default.svc.cluster.local 6m58s True
#创建demo名称空间 默认为 InMemoryChannel
[root@xianchaomaster1 kafka-broker]# kubectl create ns demo
namespace/demo created
[root@xianchaomaster1 kafka-broker]# kn channel list -n demo
No channels found.
[root@xianchaomaster1 kafka-broker]# kn channel create channel-03 -n demo
Channel 'channel-03' created in namespace 'demo'.
[root@xianchaomaster1 kafka-broker]# kn channel list -n demo
NAME TYPE URL AGE READY REASON
channel-03 InMemoryChannel http://channel-03-kn-channel.demo.svc.cluster.local 2s True
查看KafkaChannel
[root@xianchaomaster1 kafka-broker]# kubectl get KafkaChannel
NAME READY REASON URL AGE
channel-02 True http://channel-02-kn-channel.default.svc.cluster.local 56m
kc004 True http://kc004-kn-channel.default.svc.cluster.local 63m
[root@xianchaomaster1 kafka-broker]# kubectl get KafkaChannel kc004 -o yaml
apiVersion: messaging.knative.dev/v1beta1
kind: KafkaChannel
metadata:
annotations:
messaging.knative.dev/subscribable: v1
creationTimestamp: "2023-07-09T15:31:34Z"
finalizers:
- kafkachannels.messaging.knative.dev
generation: 1
name: kc004
namespace: default
ownerReferences:
- apiVersion: messaging.knative.dev/v1
blockOwnerDeletion: true
controller: true
kind: Channel
name: kc004
uid: 926380f3-e22c-46f9-a787-d1e8418431f2
resourceVersion: "486618"
uid: 56461639-3bdd-40f6-bd41-3e34a7014000
spec:
numPartitions: 1
replicationFactor: 1
retentionDuration: PT168H
status:
address:
url: http://kc004-kn-channel.default.svc.cluster.local
conditions:
- lastTransitionTime: "2023-07-09T15:31:35Z"
status: "True"
type: Addressable
- lastTransitionTime: "2023-07-09T15:31:34Z"
reason: Config map knative-eventing/kafka-channel-channels-subscriptions updated
status: "True"
type: ConfigMapUpdated
- lastTransitionTime: "2023-07-09T15:31:34Z"
status: "True"
type: ConfigParsed
- lastTransitionTime: "2023-07-09T15:31:34Z"
status: "True"
type: DataPlaneAvailable
- lastTransitionTime: "2023-07-09T16:31:28Z"
status: "True"
type: ProbeSucceeded
- lastTransitionTime: "2023-07-09T16:31:28Z"
status: "True"
type: Ready
- lastTransitionTime: "2023-07-09T15:31:34Z"
reason: Topic knative-messaging-kafka.default.kc004 created
status: "True"
type: TopicReady
observedGeneration: 1
配置默认 Channel -- 修改:config-br-default-channel
#Broker在其底层默认使用的Channel类型,受控于knative-eventing名称空间中configmap/config-br-default-channel的定义;
#默认 是Kafka Channel 、Broker也是Kafka Broker 但是可以自己指定 默认是什么Broker使用什么Channel类型的
[root@xianchaomaster1 kafka-broker]# kubectl get cm -n knative-eventing
NAME DATA AGE
config-br-default-channel 1 14h
config-br-defaults 1 14h
config-features 6 14h
config-imc-event-dispatcher 2 14h
config-kafka-broker-data-plane 5 94m
config-kafka-channel-data-plane 5 96m
config-kafka-descheduler 2 97m
config-kafka-features 3 97m
config-kafka-leader-election 6 97m
config-kafka-scheduler 2 97m
config-kafka-source-defaults 1 97m
config-kreference-mapping 1 14h
config-leader-election 1 14h
config-logging 3 14h
config-observability 1 14h
config-ping-defaults 1 14h
config-sugar 1 14h
config-tracing 1 97m
default-ch-webhook 1 14h
istio-ca-root-cert 1 14h
kafka-broker-brokers-triggers 1 3h30m
kafka-broker-config 3 97m
kafka-channel-channels-subscriptions 1 3h30m
kafka-channel-config 1 97m
kafka-config-logging 1 97m
kafka-sink-sinks 1 3h30m
kube-root-ca.crt 1 14h
#即使default-ch-webhook 中指明了使用Kafka Channel,只是单独使用Channel受影响
#创建底层Broker 不受影响还是使用MT
[root@xianchaomaster1 kafka-broker]# kubectl get cm config-br-default-channel -o yaml -n knative-eventing
apiVersion: v1
data:
channel-template-spec: |
apiVersion: messaging.knative.dev/v1
kind: InMemoryChannel
kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","data":{"channel-template-spec":"apiVersion: messaging.knative.dev/v1\nkind: InMemoryChannel\n"},"kind":"ConfigMap","metadata":{"annotations":{},"labels":{"app.kubernetes.io/name":"knative-eventing","app.kubernetes.io/version":"1.7.1","eventing.knative.dev/release":"v1.7.1"},"name":"config-br-default-channel","namespace":"knative-eventing"}}
creationTimestamp: "2023-07-09T02:11:15Z"
labels:
app.kubernetes.io/name: knative-eventing
app.kubernetes.io/version: 1.7.1
eventing.knative.dev/release: v1.7.1
name: config-br-default-channel
namespace: knative-eventing
resourceVersion: "37267"
uid: fa8b1dcf-863c-4b2c-988b-3e1a20c897f2
#修改默认config-br-default-channel
#指明底层使用 Broker使用KafkaChannel
[root@xianchaomaster1 kafka-broker]# cat config-br-default-channel.yaml
apiVersion: v1
data:
channel-template-spec: |
apiVersion: messaging.knative.dev/v1beta1
kind: KafkaChannel
spec:
numPartitions: 10
replicationFactor: 3
kind: ConfigMap
metadata:
name: config-br-default-channel
namespace: knative-eventing
#应用
[root@xianchaomaster1 kafka-broker]# kubectl apply -f config-br-default-channel.yaml
configmap/config-br-default-channel configured
#默认改为了Broker 使用 KafkaChannel
[root@xianchaomaster1 kafka-broker]# kubectl get cm config-br-default-channel -o yaml -n knative-eventing
apiVersion: v1
data:
channel-template-spec: |
apiVersion: messaging.knative.dev/v1beta1
kind: KafkaChannel
spec:
numPartitions: 10
replicationFactor: 3
kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","data":{"channel-template-spec":"apiVersion: messaging.knative.dev/v1beta1\nkind: KafkaChannel\nspec:\n numPartitions: 10\n replicationFactor: 3\n"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"config-br-default-channel","namespace":"knative-eventing"}}
creationTimestamp: "2023-07-09T02:11:15Z"
name: config-br-default-channel
namespace: knative-eventing
resourceVersion: "495589"
uid: fa8b1dcf-863c-4b2c-988b-3e1a20c897f2
配置默认Broker
#Broker的配置:
1、MT-Channel-based Broker支持使用In Memory Channel和Kafka Channel;Kafka Broker通常只能使用KafkaChannel;
2、使用KafkaChannel时,还需要修改knative-eventing名称空间中configmap/config-br-defaults中的定义:
[root@xianchaomaster1 kafka-broker]# kubectl get cm kafka-broker-config -o yaml -n knative-eventing
apiVersion: v1
data:
bootstrap.servers: my-cluster-kafka-bootstrap.kafka:9092
default.topic.partitions: "10"
default.topic.replication.factor: "3"
kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","data":{"bootstrap.servers":"my-cluster-kafka-bootstrap.kafka:9092","default.topic.partitions":"10","default.topic.replication.factor":"3"},"kind":"ConfigMap","metadata":{"annotations":{},"labels":{"kafka.eventing.knative.dev/release":"fecf5c3b5f9a365030c10cb143d9dc3adb3bdf57"},"name":"kafka-broker-config","namespace":"knative-eventing"}}
creationTimestamp: "2023-07-09T15:01:27Z"
labels:
kafka.eventing.knative.dev/release: fecf5c3b5f9a365030c10cb143d9dc3adb3bdf57
name: kafka-broker-config
namespace: knative-eventing
resourceVersion: "414001"
uid: ba2a5bd9-9501-490f-b6ef-a06b70d00706
#创建会报错
[root@xianchaomaster1 kafka-broker]# kn broker create kbroker01 --class Kafka
Broker 'kbroker01' successfully created in namespace 'default'.
[root@xianchaomaster1 kafka-broker]# kn broker list
NAME URL AGE CONDITIONS READY REASON
kbroker01 7s 1 OK / 7 False unable to build topic config from configmap: error validating topic config from configmap invalid configuration - numPartitions: 0 - replicationFactor: 0 - bootstrapServers: [] - ConfigMap data: map[channel-template-spec:apiVersion: messaging.knative.dev/v1beta1
kind: KafkaChannel
spec:
numPartitions: 10
replicationFactor: 3
] - ConfigMap data: map[channel-template-spec:apiVersion: messaging.knative.dev/v1beta1
kind: KafkaChannel
spec:
numPartitions: 10
replicationFactor: 3
]
#config-br-default-channel 没问题
[root@xianchaomaster1 kafka-broker]# kubectl get cm config-br-default-channel -o yaml -n knative-eventing
apiVersion: v1
data:
channel-template-spec: |
apiVersion: messaging.knative.dev/v1beta1
kind: KafkaChannel
spec:
numPartitions: 10
replicationFactor: 3
kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","data":{"channel-template-spec":"apiVersion: messaging.knative.dev/v1beta1\nkind: KafkaChannel\nspec:\n numPartitions: 10\n replicationFactor: 3\n"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"config-br-default-channel","namespace":"knative-eventing"}}
creationTimestamp: "2023-07-09T02:11:15Z"
name: config-br-default-channel
namespace: knative-eventing
resourceVersion: "495589"
uid: fa8b1dcf-863c-4b2c-988b-3e1a20c897f2
#kafka-broker-config 没问题
[root@xianchaomaster1 kafka-broker]# kubectl get cm kafka-broker-config -o yaml -n knative-eventing
apiVersion: v1
data:
bootstrap.servers: my-cluster-kafka-bootstrap.kafka:9092
default.topic.partitions: "10"
default.topic.replication.factor: "3"
kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","data":{"bootstrap.servers":"my-cluster-kafka-bootstrap.kafka:9092","default.topic.partitions":"10","default.topic.replication.factor":"3"},"kind":"ConfigMap","metadata":{"annotations":{},"labels":{"kafka.eventing.knative.dev/release":"fecf5c3b5f9a365030c10cb143d9dc3adb3bdf57"},"name":"kafka-broker-config","namespace":"knative-eventing"}}
creationTimestamp: "2023-07-09T15:01:27Z"
labels:
kafka.eventing.knative.dev/release: fecf5c3b5f9a365030c10cb143d9dc3adb3bdf57
name: kafka-broker-config
namespace: knative-eventing
resourceVersion: "414001"
uid: ba2a5bd9-9501-490f-b6ef-a06b70d00706
# kafka-channel-config 没问题
[root@xianchaomaster1 kafka-broker]# kubectl get cm kafka-channel-config -o yaml -n knative-eventing
apiVersion: v1
data:
bootstrap.servers: my-cluster-kafka-bootstrap.kafka:9092
kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","data":{"bootstrap.servers":"my-cluster-kafka-bootstrap.kafka:9092"},"kind":"ConfigMap","metadata":{"annotations":{},"labels":{"kafka.eventing.knative.dev/release":"fecf5c3b5f9a365030c10cb143d9dc3adb3bdf57"},"name":"kafka-channel-config","namespace":"knative-eventing"}}
creationTimestamp: "2023-07-09T15:01:27Z"
labels:
kafka.eventing.knative.dev/release: fecf5c3b5f9a365030c10cb143d9dc3adb3bdf57
name: kafka-channel-config
namespace: knative-eventing
resourceVersion: "414002"
uid: 964f6ed2-7205-43d1-9941-83b7c58c0a0b
#config-br-defaults 有问题没有指明所以需要修改 应用下面文件
[root@xianchaomaster1 kafka-broker]# kubectl get cm config-br-defaults -o yaml -n knative-eventing
apiVersion: v1
data:
default-br-config: |
clusterDefault:
brokerClass: MTChannelBasedBroker
apiVersion: v1
kind: ConfigMap
name: config-br-default-channel
namespace: knative-eventing
delivery:
retry: 10
backoffPolicy: exponential
backoffDelay: PT0.2S
kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","data":{"default-br-config":"clusterDefault:\n brokerClass: MTChannelBasedBroker\n apiVersion: v1\n kind: ConfigMap\n name: config-br-default-channel\n namespace: knative-eventing\n delivery:\n retry: 10\n backoffPolicy: exponential\n backoffDelay: PT0.2S\n"},"kind":"ConfigMap","metadata":{"annotations":{},"labels":{"app.kubernetes.io/name":"knative-eventing","app.kubernetes.io/version":"1.7.1","eventing.knative.dev/release":"v1.7.1"},"name":"config-br-defaults","namespace":"knative-eventing"}}
creationTimestamp: "2023-07-09T02:11:15Z"
labels:
app.kubernetes.io/name: knative-eventing
app.kubernetes.io/version: 1.7.1
eventing.knative.dev/release: v1.7.1
name: config-br-defaults
namespace: knative-eventing
resourceVersion: "37268"
uid: f02b3ca3-5cef-4fb6-adfc-409f05878f8d
#修改 应用文件config-br-defaults.yaml 、brokerClass: Kafka
[root@xianchaomaster1 kafka-broker]# cat config-br-defaults.yaml
apiVersion: v1
data:
default-br-config: |
clusterDefault:
brokerClass: Kafka
apiVersion: v1
kind: ConfigMap
name: kafka-broker-config
namespace: knative-eventing
namespacedefaults:
some-namespace:
brokerClass: MTChannelBasedBroker
apiVersion: v1
kind: ConfigMap
name: config-br-default-channel
namespace: knative-eventing
delivery:
retry: 10
backoffPolicy: exponential
backoffDelay: PT0.2S
kind: ConfigMap
metadata:
name: config-br-defaults
namespace: knative-eventing
[root@xianchaomaster1 kafka-broker]# kubectl apply -f config-br-defaults.yaml
configmap/config-br-defaults configured
#再次测试
[root@xianchaomaster1 kafka-broker]# kn broker create kbroker03 --class Kafka
Broker 'kbroker03' successfully created in namespace 'default'.
[root@xianchaomaster1 kafka-broker]# kn broker list
NAME URL AGE CONDITIONS READY REASON
kbroker03 http://kafka-broker-ingress.knative-eventing.svc.cluster.local/default/kbroker03 47s 7 OK / 7 True
Serverless CI/CD架构示意图
创建令牌
# glpat-oL8QxVLFxXbHS9inp-Px
创建资源
# 01-namespace.yaml
[root@xianchaomaster1 gitlab-source]# cat 01-namespace.yaml
kind: Namespace
apiVersion: v1
metadata:
name: event-demo
---
[root@xianchaomaster1 gitlab-source]# kubectl get ns
NAME STATUS AGE
default Active 15d
demo Active 108m
event-demo Active 12h
gitlab Active 14h
istio-system Active 4d13h
kafka Active 4h41m
knative-eventing Active 15h
knative-serving Active 4d13h
knative-sources Active 12h
kube-node-lease Active 15d
kube-public Active 15d
kube-system Active 15d
[root@xianchaomaster1 gitlab-source]# kubectl apply -f 01-namespace.yaml
namespace/event-demo unchanged
#02-kservice-event-display.yaml
[root@xianchaomaster1 gitlab-source]# cat 02-kservice-event-display.yaml
---
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: event-display
namespace: event-demo
spec:
template:
metadata:
annotations:
autoscaling.knative.dev/min-scale: "1"
spec:
containers:
- image: ikubernetes/event_display
ports:
- containerPort: 8080
[root@xianchaomaster1 gitlab-source]# kubectl get pods -n event-demo
NAME READY STATUS RESTARTS AGE
event-display-00001-deployment-57c56789bb-6q2pw 2/2 Running 0 12h
[root@xianchaomaster1 gitlab-source]# kn service delete event-display -n event-demo
Service 'event-display' successfully deleted in namespace 'event-demo'.
[root@xianchaomaster1 gitlab-source]# kubectl apply -f 02-kservice-event-display.yaml
service.serving.knative.dev/event-display created
#03-secret-token.yaml
#此处accessToken 改为上面的 令牌 、secretToken 随机生成一个 openssl 前面文档有
[root@xianchaomaster1 gitlab-source]# cat 03-secret-token.yaml
apiVersion: v1
kind: Secret
metadata:
name: gitlabsecret
namespace: event-demo
type: Opaque
stringData:
accessToken: glpat-oL8QxVLFxXbHS9inp-Px
secretToken: mrwuxlyw0+hZTLTmpEWIpA
[root@xianchaomaster1 gitlab-source]# kubectl apply -f 03-secret-token.yaml
secret/gitlabsecret configured
#04-kafkabroker.yaml
[root@xianchaomaster1 gitlab-source]# cat 04-kafkabroker.yaml
apiVersion: eventing.knative.dev/v1
kind: Broker
metadata:
annotations:
eventing.knative.dev/broker.class: Kafka
name: kbr01
namespace: event-demo
spec:
config:
apiVersion: v1
kind: ConfigMap
name: kafka-broker-config
namespace: knative-eventing
[root@xianchaomaster1 gitlab-source]# kubectl apply -f 04-kafkabroker.yaml
broker.eventing.knative.dev/kbr01 created
[root@xianchaomaster1 gitlab-source]# kn broker list -n event-demo
NAME URL AGE CONDITIONS READY REASON
kbr01 http://kafka-broker-ingress.knative-eventing.svc.cluster.local/event-demo/kbr01 8s 7 OK / 7 True
#05-Trigger-kafkabroker-to-knative-service.yaml
[root@xianchaomaster1 gitlab-source]# cat 05-Trigger-kafkabroker-to-knative-service.yaml
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
name: kafkabroker-to-knative-service
namespace: event-demo
spec:
broker: kbr01
filter: {}
subscriber:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: event-display
namespace: event-demo
[root@xianchaomaster1 gitlab-source]# kubectl apply -f 05-Trigger-kafkabroker-to-knative-service.yaml
trigger.eventing.knative.dev/kafkabroker-to-knative-service created
[root@xianchaomaster1 gitlab-source]# kn trigger list -n event-demo
NAME BROKER SINK AGE CONDITIONS READY REASON
kafkabroker-to-knative-service kbr01 ksvc:event-display 18s 6 OK / 6 True
#06-GitLabSource-to-knative-kafkabroker.yaml
[root@xianchaomaster1 gitlab-source]# cat 06-GitLabSource-to-knative-kafkabroker.yaml
apiVersion: sources.knative.dev/v1alpha1
kind: GitLabSource
metadata:
name: gitlabsource-to-kafkabroker
namespace: event-demo
spec:
eventTypes:
- push_events
- issues_events
- merge_requests_events
- tag_push_events
projectUrl: http://code.gitlab.svc.cluster.local/root/spring-boot-helloworld
#都可以
#projectUrl: http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloworld
sslverify: false
accessToken:
secretKeyRef:
name: gitlabsecret
key: accessToken
secretToken:
secretKeyRef:
name: gitlabsecret
key: secretToken
sink:
ref:
apiVersion: eventing.knative.dev/v1
kind: Broker
name: kbr01
[root@xianchaomaster1 gitlab-source]# kubectl apply -f 06-GitLabSource-to-knative-kafkabroker.yaml
gitlabsource.sources.knative.dev/gitlabsource-to-kafkabroker created
You have new mail in /var/spool/mail/root
[root@xianchaomaster1 gitlab-source]# kubectl get pods -n event-demo
NAME READY STATUS RESTARTS AGE
event-display-00001-deployment-594c69b8b4-bmqc8 2/2 Running 0 6m20s
#06-GitLabSource-to-knative-kafkabroker.yaml会自动在 GitLab上 自动注册一个 Webhooks
修改编辑 Project Hooks
[root@xianchaomaster1 gitlab-source]# kubectl get vs -n event-demo
NAME GATEWAYS HOSTS AGE
event-display-ingress ["knative-serving/knative-ingress-gateway","knative-serving/knative-local-gateway"] ["event-display.event-demo","event-display.event-demo.example.com","event-display.event-demo.svc","event-display.event-demo.svc.cluster.local"] 22m
event-display-mesh ["mesh"] ["event-display.event-demo","event-display.event-demo.svc","event-display.event-demo.svc.cluster.local"] 22m
gitlabsource-demo-j8vmf-ingress ["knative-serving/knative-ingress-gateway","knative-serving/knative-local-gateway"] ["gitlabsource-demo-j8vmf.event-demo","gitlabsource-demo-j8vmf.event-demo.example.com","gitlabsource-demo-j8vmf.event-demo.svc","gitlabsource-demo-j8vmf.event-demo.svc.cluster.local"] 12h
gitlabsource-demo-j8vmf-mesh ["mesh"] ["gitlabsource-demo-j8vmf.event-demo","gitlabsource-demo-j8vmf.event-demo.svc","gitlabsource-demo-j8vmf.event-demo.svc.cluster.local"] 12h
gitlabsource-to-kafkabroker-52z9v-ingress ["knative-serving/knative-ingress-gateway","knative-serving/knative-local-gateway"] ["gitlabsource-to-kafkabroker-52z9v.event-demo","gitlabsource-to-kafkabroker-52z9v.event-demo.example.com","gitlabsource-to-kafkabroker-52z9v.event-demo.svc","gitlabsource-to-kafkabroker-52z9v.event-demo.svc.cluster.local"] 78s
gitlabsource-to-kafkabroker-52z9v-mesh ["mesh"] ["gitlabsource-to-kafkabroker-52z9v.event-demo","gitlabsource-to-kafkabroker-52z9v.event-demo.svc","gitlabsource-to-kafkabroker-52z9v.event-demo.svc.cluster.local"] 78s
#修改域名 改为 内部 svc.cluster.local后缀域名
http://gitlabsource-to-kafkabroker-52z9v.event-demo.example.com
改为
http://gitlabsource-to-kafkabroker-52z9v.event-demo.svc.cluster.local
#修改后 gitlabpod 会重启的
测试event-display是否接收到消息
#接受到了 push、tag、
#但是Merge、issue 报错了没成功
[root@xianchaomaster1 gitlab-source]# kubectl logs -f event-display-00001-deployment-594c69b8b4-bmqc8 -n event-demo
Defaulted container "user-container" out of: user-container, queue-proxy
#Push
☁️ cloudevents.Event
Context Attributes,
specversion: 1.0
type: dev.knative.sources.gitlab.push
source: http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloworld
id: bfec0d1e-702a-4936-861f-8a54d7fd0986
time: 2023-07-09T17:55:03.542825129Z
datacontenttype: application/json
Extensions,
comgitlabevent: Push Hook
Data,
{
"object_kind": "push",
"before": "d52b773acdf8c78c73e150ff2765bceb678e7750",
"after": "fecc8c287a402a63e88ea87db93a3e79c8037b7d",
"ref": "refs/heads/main",
"checkout_sha": "fecc8c287a402a63e88ea87db93a3e79c8037b7d",
"user_id": 1,
"user_name": "Administrator",
"user_username": "root",
"user_email": "",
"user_avatar": "https://www.gravatar.com/avatar/dafa3f209d417114218e7c150f7f4215?s=80\u0026d=identicon",
"project_id": 3,
"Project": {
"id": 3,
"name": "Spring Boot HelloWorld",
"description": "",
"web_url": "http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloWorld",
"avatar_url": "",
"git_ssh_url": "git@gitlab.gitlab.svc.cluster.local:root/spring-boot-helloWorld.git",
"git_http_url": "http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloWorld.git",
"namespace": "Administrator",
"visibility_level": 20,
"path_with_namespace": "root/spring-boot-helloWorld",
"default_branch": "main",
"homepage": "http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloWorld",
"url": "git@gitlab.gitlab.svc.cluster.local:root/spring-boot-helloWorld.git",
"ssh_url": "git@gitlab.gitlab.svc.cluster.local:root/spring-boot-helloWorld.git",
"http_url": "http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloWorld.git"
},
"repository": {
"name": "Spring Boot HelloWorld",
"url": "git@gitlab.gitlab.svc.cluster.local:root/spring-boot-helloWorld.git",
"description": "",
"homepage": "http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloWorld"
},
"commits": [
{
"id": "fecc8c287a402a63e88ea87db93a3e79c8037b7d",
"message": "add rollouts\n",
"timestamp": "2022-12-08T17:24:30+08:00",
"url": "http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloWorld/-/commit/fecc8c287a402a63e88ea87db93a3e79c8037b7d",
"author": {
"name": "iKubernetes",
"email": "mage@magedu.com"
},
"added": [
"deploy/README.md",
"rollouts/README.md",
"rollouts/rollouts-canary-demo.yaml"
],
"modified": [
"pom.xml",
"src/main/java/com/neo/controller/HelloWorldController.java",
"src/test/java/com/neo/controller/HelloTests.java",
"src/test/java/com/neo/controller/HelloWorldControlerTests.java"
],
"removed": []
},
{
"id": "d90952e7509f5965af0800cd0edae7949326b7d1",
"message": "fixed some bugs\n",
"timestamp": "2022-12-04T17:23:01+08:00",
"url": "http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloWorld/-/commit/d90952e7509f5965af0800cd0edae7949326b7d1",
"author": {
"name": "iKubernetes",
"email": "mage@magedu.com"
},
"added": [],
"modified": [
"README.md"
],
"removed": []
},
{
"id": "d52b773acdf8c78c73e150ff2765bceb678e7750",
"message": "udpate to v0.9.6\n",
"timestamp": "2022-12-04T17:19:56+08:00",
"url": "http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloWorld/-/commit/d52b773acdf8c78c73e150ff2765bceb678e7750",
"author": {
"name": "iKubernetes",
"email": "mage@magedu.com"
},
"added": [],
"modified": [
"Jenkinsfile"
],
"removed": []
}
],
"total_commits_count": 3
}
#TAG-push
☁️ cloudevents.Event
Context Attributes,
specversion: 1.0
type: dev.knative.sources.gitlab.tag_push
source: http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloworld
id: d3e3cbaf-c9b3-4fd1-bbae-1fba7a216779
time: 2023-07-09T17:55:26.764736051Z
datacontenttype: application/json
Extensions,
comgitlabevent: Tag Push Hook
Data,
{
"object_kind": "push",
"before": "d52b773acdf8c78c73e150ff2765bceb678e7750",
"after": "fecc8c287a402a63e88ea87db93a3e79c8037b7d",
"ref": "refs/heads/main",
"checkout_sha": "fecc8c287a402a63e88ea87db93a3e79c8037b7d",
"user_id": 1,
"user_name": "Administrator",
"user_username": "root",
"user_avatar": "https://www.gravatar.com/avatar/dafa3f209d417114218e7c150f7f4215?s=80\u0026d=identicon",
"project_id": 3,
"Project": {
"id": 3,
"name": "Spring Boot HelloWorld",
"description": "",
"web_url": "http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloWorld",
"avatar_url": "",
"git_ssh_url": "git@gitlab.gitlab.svc.cluster.local:root/spring-boot-helloWorld.git",
"git_http_url": "http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloWorld.git",
"namespace": "Administrator",
"visibility_level": 20,
"path_with_namespace": "root/spring-boot-helloWorld",
"default_branch": "main",
"homepage": "http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloWorld",
"url": "git@gitlab.gitlab.svc.cluster.local:root/spring-boot-helloWorld.git",
"ssh_url": "git@gitlab.gitlab.svc.cluster.local:root/spring-boot-helloWorld.git",
"http_url": "http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloWorld.git"
},
"repository": {
"name": "Spring Boot HelloWorld",
"url": "git@gitlab.gitlab.svc.cluster.local:root/spring-boot-helloWorld.git",
"description": "",
"homepage": "http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloWorld"
},
"commits": [
{
"id": "fecc8c287a402a63e88ea87db93a3e79c8037b7d",
"message": "add rollouts\n",
"timestamp": "2022-12-08T17:24:30+08:00",
"url": "http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloWorld/-/commit/fecc8c287a402a63e88ea87db93a3e79c8037b7d",
"author": {
"name": "iKubernetes",
"email": "mage@magedu.com"
},
"added": [
"deploy/README.md",
"rollouts/README.md",
"rollouts/rollouts-canary-demo.yaml"
],
"modified": [
"pom.xml",
"src/main/java/com/neo/controller/HelloWorldController.java",
"src/test/java/com/neo/controller/HelloTests.java",
"src/test/java/com/neo/controller/HelloWorldControlerTests.java"
],
"removed": []
},
{
"id": "d90952e7509f5965af0800cd0edae7949326b7d1",
"message": "fixed some bugs\n",
"timestamp": "2022-12-04T17:23:01+08:00",
"url": "http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloWorld/-/commit/d90952e7509f5965af0800cd0edae7949326b7d1",
"author": {
"name": "iKubernetes",
"email": "mage@magedu.com"
},
"added": [],
"modified": [
"README.md"
],
"removed": []
},
{
"id": "d52b773acdf8c78c73e150ff2765bceb678e7750",
"message": "udpate to v0.9.6\n",
"timestamp": "2022-12-04T17:19:56+08:00",
"url": "http://gitlab.gitlab.svc.cluster.local/root/spring-boot-helloWorld/-/commit/d52b773acdf8c78c73e150ff2765bceb678e7750",
"author": {
"name": "iKubernetes",
"email": "mage@magedu.com"
},
"added": [],
"modified": [
"Jenkinsfile"
],
"removed": []
}
],
"total_commits_count": 3
}