diff --git a/PoC/cloudplayer/deploy.yaml b/PoC/cloudplayer/deploy.yaml new file mode 100644 index 0000000..8ae4be1 --- /dev/null +++ b/PoC/cloudplayer/deploy.yaml @@ -0,0 +1,31 @@ +apiVersion: serving.knative.dev/v1 +kind: Service +metadata: + name: cloudevents-player +spec: + template: + metadata: + annotations: + autoscaling.knative.dev/minScale: "1" + spec: + containers: + - image: quay.io/ruben/cloudevents-player:latest + env: + - name: PLAYER_MODE + value: KNATIVE + - name: PLAYER_BROKER + value: default +--- +apiVersion: eventing.knative.dev/v1 +kind: Trigger +metadata: + name: cloudevents-player + annotations: + knative-eventing-injection: enabled +spec: + broker: events-broker + subscriber: + ref: + apiVersion: serving.knative.dev/v1 + kind: Service + name: cloudevents-player diff --git a/PoC/knative/broker-data-plane.yaml b/PoC/knative/broker-data-plane.yaml new file mode 100644 index 0000000..082ad0e Binary files /dev/null and b/PoC/knative/broker-data-plane.yaml differ diff --git a/PoC/knative/broker.yaml b/PoC/knative/broker.yaml new file mode 100644 index 0000000..2cbd47d --- /dev/null +++ b/PoC/knative/broker.yaml @@ -0,0 +1,5 @@ +apiVersion: eventing.knative.dev/v1 +kind: Broker +metadata: + name: default + namespace: knative-eventing \ No newline at end of file diff --git a/PoC/knative/channel-consolidated.yaml b/PoC/knative/channel-consolidated.yaml new file mode 100644 index 0000000..c61d027 --- /dev/null +++ b/PoC/knative/channel-consolidated.yaml @@ -0,0 +1,985 @@ +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: kafka-addressable-resolver + labels: + contrib.eventing.knative.dev/release: "v0.19.3" + duck.knative.dev/addressable: "true" +# Do not use this role directly. These rules will be added to the "addressable-resolver" role. +rules: + - apiGroups: + - messaging.knative.dev + resources: + - kafkachannels + - kafkachannels/status + verbs: + - get + - list + - watch + +--- +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: kafka-channelable-manipulator + labels: + contrib.eventing.knative.dev/release: "v0.19.3" + duck.knative.dev/channelable: "true" +# Do not use this role directly. These rules will be added to the "channelable-manipulator" role. +rules: + - apiGroups: + - messaging.knative.dev + resources: + - kafkachannels + - kafkachannels/status + verbs: + - create + - get + - list + - watch + - update + - patch + +--- +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: kafka-ch-controller + labels: + contrib.eventing.knative.dev/release: "v0.19.3" +rules: + - apiGroups: + - messaging.knative.dev + resources: + - kafkachannels + - kafkachannels/status + verbs: + - get + - list + - watch + - update + - patch + - apiGroups: + - messaging.knative.dev + resources: + - kafkachannels/finalizers + verbs: + - update + - apiGroups: + - "" # Core API group. + resources: + - services + - configmaps + - secrets + verbs: + - get + - list + - watch + - create + - apiGroups: + - "" # Core API group. + resources: + - services + verbs: &everything + - get + - list + - watch + - create + - patch + - update + - apiGroups: + - "" # Core API Group. + resources: + - configmaps + resourceNames: + - kafka-ch-dispatcher + verbs: + - update + - apiGroups: + - "" # Core API Group. + resources: + - events + verbs: + - create + - patch + - update + - apiGroups: + - "" + resources: + - configmaps + verbs: + - get + - list + - watch + - apiGroups: + - "" # Core API group. + resources: + - endpoints + verbs: + - get + - list + - watch + - apiGroups: + - apps + resources: + - deployments + - deployments/status + verbs: *everything + - apiGroups: + - "" # Core API group. + resources: + - serviceaccounts + verbs: *everything + - apiGroups: + - rbac.authorization.k8s.io + resources: + - rolebindings + verbs: *everything + - apiGroups: + - "coordination.k8s.io" + resources: + - leases + verbs: *everything + +--- +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: v1 +kind: ServiceAccount +metadata: + name: kafka-ch-controller + namespace: knative-eventing + labels: + contrib.eventing.knative.dev/release: "v0.19.3" + +--- +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: kafka-ch-dispatcher + labels: + contrib.eventing.knative.dev/release: "v0.19.3" +rules: + - apiGroups: + - messaging.knative.dev + resources: + - kafkachannels + verbs: + - get + - list + - watch + - patch + - apiGroups: + - messaging.knative.dev + resources: + - kafkachannels/status + verbs: + - get + - update + - patch + - apiGroups: + - "" # Core API group. + resources: + - events + verbs: + - create + - patch + - update + - apiGroups: + - messaging.knative.dev + resources: + - kafkachannels + verbs: + - get + - list + - watch + - patch + - apiGroups: + - "" + resources: + - configmaps + - secrets + verbs: + - get + - list + - watch + - apiGroups: + - "" # Core API Group. + resources: + - events + verbs: + - create + - patch + - apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - get + - list + - watch + - create + - patch + - update + +--- +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: v1 +kind: ServiceAccount +metadata: + name: kafka-ch-dispatcher + namespace: knative-eventing + labels: + contrib.eventing.knative.dev/release: "v0.19.3" + +--- +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: kafka-webhook + labels: + contrib.eventing.knative.dev/release: "v0.19.3" +rules: + # For watching logging configuration and getting certs. + - apiGroups: + - "" + resources: + - "configmaps" + verbs: + - "get" + - "list" + - "watch" + # For manipulating certs into secrets. + - apiGroups: + - "" + resources: + - "secrets" + verbs: + - "get" + - "create" + - "list" + - "watch" + - "update" + # For getting our Deployment so we can decorate with ownerref. + - apiGroups: + - "apps" + resources: + - "deployments" + verbs: + - "get" + - apiGroups: + - "apps" + resources: + - "deployments/finalizers" + verbs: + - update + # For actually registering our webhook. + - apiGroups: + - "admissionregistration.k8s.io" + resources: + - "mutatingwebhookconfigurations" + - "validatingwebhookconfigurations" + verbs: &everything + - "get" + - "list" + - "create" + - "update" + - "delete" + - "patch" + - "watch" + # Our own resources and statuses we care about. + - apiGroups: + - "messaging.knative.dev" + resources: + - "kafkachannels" + - "kafkachannels/status" + verbs: + - "get" + - "list" + - "watch" + # For leader election + - apiGroups: + - "coordination.k8s.io" + resources: + - "leases" + verbs: *everything + # Necessary for conversion webhook. These are copied from the serving + # TODO: Do we really need all these permissions? + - apiGroups: + - "apiextensions.k8s.io" + resources: + - "customresourcedefinitions" + verbs: + - "get" + - "list" + - "create" + - "update" + - "delete" + - "patch" + - "watch" + +--- +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +apiVersion: v1 +kind: ServiceAccount +metadata: + name: kafka-webhook + namespace: knative-eventing + labels: + contrib.eventing.knative.dev/release: "v0.19.3" + +--- +# Copyright 2019 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: kafka-ch-controller + labels: + contrib.eventing.knative.dev/release: "v0.19.3" +subjects: + - kind: ServiceAccount + name: kafka-ch-controller + namespace: knative-eventing +roleRef: + kind: ClusterRole + name: kafka-ch-controller + apiGroup: rbac.authorization.k8s.io +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: kafka-ch-dispatcher + labels: + contrib.eventing.knative.dev/release: "v0.19.3" +subjects: + - kind: ServiceAccount + name: kafka-ch-dispatcher + namespace: knative-eventing +roleRef: + kind: ClusterRole + name: kafka-ch-dispatcher + apiGroup: rbac.authorization.k8s.io +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: kafka-webhook + labels: + contrib.eventing.knative.dev/release: "v0.19.3" +subjects: + - kind: ServiceAccount + name: kafka-webhook + namespace: knative-eventing +roleRef: + kind: ClusterRole + name: kafka-webhook + apiGroup: rbac.authorization.k8s.io + +--- +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: kafkachannels.messaging.knative.dev + labels: + contrib.eventing.knative.dev/release: "v0.19.3" + knative.dev/crd-install: "true" + messaging.knative.dev/subscribable: "true" + duck.knative.dev/addressable: "true" +spec: + group: messaging.knative.dev + preserveUnknownFields: false + validation: + openAPIV3Schema: + type: object + # this is a work around so we don't need to flush out the + # schema for each version at this time + # + # see issue: https://github.com/knative/serving/issues/912 + x-kubernetes-preserve-unknown-fields: true + names: + kind: KafkaChannel + plural: kafkachannels + singular: kafkachannel + categories: + - all + - knative + - messaging + - channel + shortNames: + - kc + scope: Namespaced + subresources: + status: {} + additionalPrinterColumns: + - name: Ready + type: string + JSONPath: ".status.conditions[?(@.type==\"Ready\")].status" + - name: Reason + type: string + JSONPath: ".status.conditions[?(@.type==\"Ready\")].reason" + - name: URL + type: string + JSONPath: .status.address.url + - name: Age + type: date + JSONPath: .metadata.creationTimestamp + versions: + - name: v1alpha1 + served: true + storage: true + - name: v1beta1 + served: true + storage: false + conversion: + strategy: Webhook + conversionReviewVersions: ["v1beta1", "v1alpha1"] + webhookClientConfig: + service: + name: kafka-webhook + namespace: knative-eventing + +--- +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: v1 +kind: ConfigMap +metadata: + name: config-kafka + namespace: knative-eventing +data: + # Broker URL. Replace this with the URLs for your kafka cluster, + # which is in the format of my-cluster-kafka-bootstrap.my-kafka-namespace:9092. + bootstrapServers: my-cluster-kafka-bootstrap.kafka:9092 + #authSecretName: name-of-your-secret-for-kafka-auth + #authSecretNamespace: namespace-of-your-secret-for-kafka-auth + +--- +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: v1 +kind: ConfigMap +metadata: + name: config-leader-election-kafka + namespace: knative-eventing +data: + # An inactive but valid configuration follows; see example. + resourceLock: "leases" + leaseDuration: "15s" + renewDeadline: "10s" + retryPeriod: "2s" + _example: | + ################################ + # # + # EXAMPLE CONFIGURATION # + # # + ################################ + + # This block is not actually functional configuration, + # but serves to illustrate the available configuration + # options and document them in a way that is accessible + # to users that `kubectl edit` this config map. + # + # These sample configuration options may be copied out of + # this example block and unindented to be in the data block + # to actually change the configuration. + + # resourceLock controls which API resource is used as the basis for the + # leader election lock. Valid values are: + # + # - leases -> use the coordination API + # - configmaps -> use configmaps + # - endpoints -> use endpoints + resourceLock: "leases" + + # leaseDuration is how long non-leaders will wait to try to acquire the + # lock; 15 seconds is the value used by core kubernetes controllers. + leaseDuration: "15s" + # renewDeadline is how long a leader will try to renew the lease before + # giving up; 10 seconds is the value used by core kubernetes controllers. + renewDeadline: "10s" + # retryPeriod is how long the leader election client waits between tries of + # actions; 2 seconds is the value used by core kuberntes controllers. + retryPeriod: "2s" + # enabledComponents is a comma-delimited list of component names for which + # leader election is enabled. Valid values are: + # + # - kafkachannel-dispatcher + # - kafkachannel-controller + enabledComponents: "kafkachannel-dispatcher,kafkachannel-controller" + +--- +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: v1 +kind: Service +metadata: + name: kafka-webhook + namespace: knative-eventing + labels: + contrib.eventing.knative.dev/release: "v0.19.3" + role: kafka-webhook +spec: + ports: + - name: https-webhook + port: 443 + targetPort: 8443 + selector: + role: kafka-webhook + +--- +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: kafka-ch-controller + namespace: knative-eventing + labels: + contrib.eventing.knative.dev/release: "v0.19.3" +spec: + replicas: 1 + selector: + matchLabels: &labels + messaging.knative.dev/channel: kafka-channel + messaging.knative.dev/role: controller + template: + metadata: + labels: *labels + spec: + serviceAccountName: kafka-ch-controller + containers: + - name: controller + image: gcr.io/knative-releases/knative.dev/eventing-kafka/cmd/channel/consolidated/controller@sha256:641cd3e6424a0230d83255441d6189ff57d63766b233968cc1b655127365273b + env: + - name: CONFIG_LOGGING_NAME + value: config-logging + - name: METRICS_DOMAIN + value: knative.dev/eventing + - name: SYSTEM_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: CONFIG_LEADERELECTION_NAME + value: config-leader-election-kafka + - name: DISPATCHER_IMAGE + value: gcr.io/knative-releases/knative.dev/eventing-kafka/cmd/channel/consolidated/dispatcher@sha256:6e0790ac1947b695eb96269f09ffbd1cdcc5bb74f57454cdb6884eedc9fbbece + ports: + - containerPort: 9090 + name: metrics + volumeMounts: + - name: config-logging + mountPath: /etc/config-logging + volumes: + - name: config-logging + configMap: + name: config-logging + +--- +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: kafka-ch-dispatcher + namespace: knative-eventing + labels: + contrib.eventing.knative.dev/release: "v0.19.3" +spec: + # this deployment is going to be scaled up by the + # controller when the very first KafkaChannel is created + replicas: 0 + selector: + matchLabels: + messaging.knative.dev/channel: kafka-channel + messaging.knative.dev/role: dispatcher + template: + metadata: + labels: + messaging.knative.dev/channel: kafka-channel + messaging.knative.dev/role: dispatcher + contrib.eventing.knative.dev/release: "v0.19.3" + spec: + containers: + - name: dispatcher + image: gcr.io/knative-releases/knative.dev/eventing-kafka/cmd/channel/consolidated/dispatcher@sha256:6e0790ac1947b695eb96269f09ffbd1cdcc5bb74f57454cdb6884eedc9fbbece + env: + - name: SYSTEM_NAMESPACE + value: '' + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.namespace + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: METRICS_DOMAIN + value: "knative.dev/eventing" + - name: CONFIG_LOGGING_NAME + value: "config-logging" + - name: CONFIG_LEADERELECTION_NAME + value: "config-leader-election-kafka" + - name: CONTAINER_NAME + value: dispatcher + ports: + - containerPort: 9090 + name: metrics + protocol: TCP + volumeMounts: + - name: config-kafka + mountPath: /etc/config-kafka + serviceAccountName: kafka-ch-dispatcher + volumes: + - name: config-kafka + configMap: + name: config-kafka +--- +apiVersion: v1 +kind: Service +metadata: + labels: + messaging.knative.dev/channel: kafka-channel + messaging.knative.dev/role: dispatcher + name: kafka-ch-dispatcher + namespace: knative-eventing +spec: + ports: + - name: http-dispatcher + port: 80 + protocol: TCP + targetPort: 8080 + selector: + messaging.knative.dev/channel: kafka-channel + messaging.knative.dev/role: dispatcher + +--- +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: admissionregistration.k8s.io/v1beta1 +kind: MutatingWebhookConfiguration +metadata: + name: defaulting.webhook.kafka.messaging.knative.dev + labels: + contrib.eventing.knative.dev/release: "v0.19.3" +webhooks: + - admissionReviewVersions: + - v1beta1 + clientConfig: + service: + name: kafka-webhook + namespace: knative-eventing + failurePolicy: Fail + name: defaulting.webhook.kafka.messaging.knative.dev +--- +apiVersion: admissionregistration.k8s.io/v1beta1 +kind: ValidatingWebhookConfiguration +metadata: + name: validation.webhook.kafka.messaging.knative.dev + labels: + contrib.eventing.knative.dev/release: "v0.19.3" +webhooks: + - admissionReviewVersions: + - v1beta1 + clientConfig: + service: + name: kafka-webhook + namespace: knative-eventing + failurePolicy: Fail + name: validation.webhook.kafka.messaging.knative.dev +--- +apiVersion: v1 +kind: Secret +metadata: + name: messaging-webhook-certs + namespace: knative-eventing + labels: + contrib.eventing.knative.dev/release: "v0.19.3" +# The data is populated at install time. + +--- +# Copyright 2020 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: kafka-webhook + namespace: knative-eventing + labels: + contrib.eventing.knative.dev/release: "v0.19.3" +spec: + replicas: 1 + selector: + matchLabels: &labels + app: kafka-webhook + role: kafka-webhook + template: + metadata: + annotations: + sidecar.istio.io/inject: "false" + labels: *labels + spec: + serviceAccountName: kafka-webhook + containers: + - name: kafka-webhook + terminationMessagePolicy: FallbackToLogsOnError + image: gcr.io/knative-releases/knative.dev/eventing-kafka/cmd/webhook@sha256:2ab48e4157481bd00ba564452f39f9e58246cac5481b47d8b12cadd1e1f643f3 + env: + - name: SYSTEM_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: CONFIG_LOGGING_NAME + value: config-logging + - name: METRICS_DOMAIN + value: knative.dev/eventing + - name: WEBHOOK_NAME + value: kafka-webhook + - name: WEBHOOK_PORT + value: "8443" + ports: + - name: https-webhook + containerPort: 8443 + - name: metrics + containerPort: 9090 + - name: profiling + containerPort: 8008 + # TODO set proper resource limits. + + readinessProbe: &probe + periodSeconds: 1 + httpGet: + scheme: HTTPS + port: 8443 + httpHeaders: + - name: k-kubelet-probe + value: "webhook" + livenessProbe: + !!merge <<: *probe + initialDelaySeconds: 20 + # Our webhook should gracefully terminate by lame ducking first, set this to a sufficiently + # high value that we respect whatever value it has configured for the lame duck grace period. + terminationGracePeriodSeconds: 300 + +--- diff --git a/PoC/knative/event-display-service.yaml b/PoC/knative/event-display-service.yaml new file mode 100644 index 0000000..34f4cc8 --- /dev/null +++ b/PoC/knative/event-display-service.yaml @@ -0,0 +1,15 @@ +apiVersion: serving.knative.dev/v1 +kind: Service +metadata: + name: event-display + namespace: default +spec: + template: + metadata: + annotations: + autoscaling.knative.dev/minScale: "2" + spec: + containers: + - # This corresponds to + # https://github.com/knative/eventing/tree/main/cmd/event_display/main.go + image: gcr.io/knative-releases/knative.dev/eventing/cmd/event_display \ No newline at end of file diff --git a/PoC/knative/event-source.yaml b/PoC/knative/event-source.yaml new file mode 100644 index 0000000..298d4fb --- /dev/null +++ b/PoC/knative/event-source.yaml @@ -0,0 +1,15 @@ +apiVersion: sources.knative.dev/v1beta1 +kind: KafkaSource +metadata: + name: kafka-source +spec: + consumerGroup: knative-group + bootstrapServers: + - my-cluster-kafka-bootstrap.kafka:9092 # note the kafka namespace + topics: + - my-topic + sink: + ref: + apiVersion: serving.knative.dev/v1 + kind: Service + name: event-display \ No newline at end of file diff --git a/PoC/knative/kafka-broker-config.yaml b/PoC/knative/kafka-broker-config.yaml new file mode 100644 index 0000000..95da378 --- /dev/null +++ b/PoC/knative/kafka-broker-config.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: kafka-broker-config + namespace: knative-eventing +data: + # Number of topic partitions + default.topic.partitions: "10" + # Replication factor of topic messages. + default.topic.replication.factor: "1" + # A comma separated list of bootstrap servers. (It can be in or out the k8s cluster) + bootstrap.servers: "my-cluster-kafka-bootstrap.kafka:9092" \ No newline at end of file diff --git a/PoC/knative/kafka-broker.yaml b/PoC/knative/kafka-broker.yaml new file mode 100644 index 0000000..77d81dc --- /dev/null +++ b/PoC/knative/kafka-broker.yaml @@ -0,0 +1,15 @@ +apiVersion: eventing.knative.dev/v1 +kind: Broker +metadata: + annotations: + # case-sensitive + eventing.knative.dev/broker.class: Kafka + name: kafka-broker + namespace: knative-eventing +spec: + # Configuration specific to this broker. + config: + apiVersion: v1 + kind: ConfigMap + name: kafka-broker-config + namespace: knative-eventing \ No newline at end of file diff --git a/PoC/knative/kafka-topic.yaml b/PoC/knative/kafka-topic.yaml new file mode 100644 index 0000000..753769e --- /dev/null +++ b/PoC/knative/kafka-topic.yaml @@ -0,0 +1,10 @@ +apiVersion: kafka.strimzi.io/v1beta1 +kind: KafkaTopic +metadata: + name: my-topic + namespace: kafka + labels: + strimzi.io/cluster: my-cluster +spec: + partitions: 10 + replicas: 1 \ No newline at end of file diff --git a/PoC/knative/kafka-trigger.yaml b/PoC/knative/kafka-trigger.yaml new file mode 100644 index 0000000..7406c4d --- /dev/null +++ b/PoC/knative/kafka-trigger.yaml @@ -0,0 +1,15 @@ +apiVersion: eventing.knative.dev/v1 +kind: Trigger +metadata: + name: my-service-trigger + namespace: knative-eventing + annotations: + kafka.eventing.knative.dev/delivery.order: ordered +spec: + broker: kafka-broker + subscriber: + ref: + apiVersion: serving.knative.dev/v1 + kind: Service + name: event-display + namespace: default \ No newline at end of file diff --git a/PoC/knative/logging.json b/PoC/knative/logging.json new file mode 100644 index 0000000..e503c40 Binary files /dev/null and b/PoC/knative/logging.json differ diff --git a/PoC/knative/trigger.yaml b/PoC/knative/trigger.yaml new file mode 100644 index 0000000..286caf0 --- /dev/null +++ b/PoC/knative/trigger.yaml @@ -0,0 +1,12 @@ +apiVersion: eventing.knative.dev/v1 +kind: Trigger +metadata: + name: cdevents-trigger + namespace: knative-eventing +spec: + broker: default + filter: + attributes: + type: org.jenkinsci.queue.entered_waiting + subscriber: + uri: http://ad159ada4a01042bf8ea1f3b773f165b-e5708344b9709abf.elb.us-west-1.amazonaws.com/ diff --git a/PoC/tekton/0000_namespace.yaml b/PoC/tekton/0000_namespace.yaml new file mode 100644 index 0000000..a870952 --- /dev/null +++ b/PoC/tekton/0000_namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: cdevents diff --git a/PoC/tekton/0001_serviceAccount.yaml b/PoC/tekton/0001_serviceAccount.yaml new file mode 100644 index 0000000..01dea3f --- /dev/null +++ b/PoC/tekton/0001_serviceAccount.yaml @@ -0,0 +1,120 @@ +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: triggers-minimal + namespace: cdevents +rules: +- apiGroups: [""] + resources: ["configmaps", "secrets"] + verbs: ["get", "list", "watch"] +- apiGroups: ["triggers.tekton.dev"] + resources: ["eventlisteners", "triggerbindings", "triggertemplates", "triggers"] + verbs: ["get", "list", "watch"] +- apiGroups: ["tekton.dev"] + resources: ["pipelineruns", "pipelineresources", "taskruns"] + verbs: ["create"] +- apiGroups: [""] + resources: ["serviceaccounts"] + verbs: ["impersonate"] +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: cdevent-listener + namespace: cdevents +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: cdevent-listener-triggers-minimal + namespace: cdevents +subjects: +- kind: ServiceAccount + name: cdevent-listener +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: triggers-minimal +--- +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: config-map-admin + namespace: cdevents +rules: +- apiGroups: [""] + resources: ["configmaps"] + verbs: ["*"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: default-config-map-admin + namespace: cdevents +subjects: +- kind: ServiceAccount + name: default +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: config-map-admin +--- +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: cdevent-listener-triggers +rules: +- apiGroups: ["triggers.tekton.dev"] + resources: ["eventlisteners", "triggerbindings", "triggertemplates", "triggers", "clustertriggerbindings", "clusterinterceptors"] + verbs: ["get", "list", "watch"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: cdevent-listener-triggers-cdevents +subjects: +- kind: ServiceAccount + name: cdevent-listener + namespace: cdevents +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: cdevent-listener-triggers +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: runner + namespace: cdevents +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: deployer +rules: + - apiGroups: [""] + resources: [services] + verbs: ["*"] + - apiGroups: [""] + resources: [pods] + verbs: ["get", "list", "watch"] + - apiGroups: [apps] + resources: [deployments] + verbs: ["*"] + - apiGroups: [networking.k8s.io] + resources: [ingresses] + verbs: ["*"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: runner-deployer-production + namespace: cdevents +subjects: + - kind: ServiceAccount + name: runner + namespace: cdevents +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: deployer \ No newline at end of file diff --git a/PoC/tekton/0003_triggers.yaml b/PoC/tekton/0003_triggers.yaml new file mode 100644 index 0000000..72bd0a8 --- /dev/null +++ b/PoC/tekton/0003_triggers.yaml @@ -0,0 +1,53 @@ +apiVersion: triggers.tekton.dev/v1alpha1 +kind: TriggerTemplate +metadata: + name: cdevent-jenkins-tekton-trigger-template + namespace: cdevents +spec: + resourcetemplates: + - apiVersion: tekton.dev/v1beta1 + kind: TaskRun + metadata: + generateName: jenkins-to-tekton-task-run- + spec: + serviceAccountName: runner + taskRef: + name: jenkins-to-tekton-echo-task +--- +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: jenkins-to-tekton-echo-task + namespace: cdevents +spec: + steps: + - image: ubuntu + command: + - echo + args: + - "Hello, Shruti!" +--- +apiVersion: triggers.tekton.dev/v1alpha1 +kind: TriggerBinding +metadata: + name: getting-started-taskrunbinding + namespace: cdevents +spec: + params: + - name: jobname + value: $(header.ce-type) +--- +apiVersion: triggers.tekton.dev/v1alpha1 +kind: EventListener +metadata: + name: cdevent-listener + namespace: cdevents +spec: + serviceAccountName: cdevent-listener + triggers: + - bindings: + - ref: getting-started-taskrunbinding + template: + ref: cdevent-jenkins-tekton-trigger-template + namespaceSelector: + matchNames: ['cdevents'] \ No newline at end of file diff --git a/PoC/tekton/README.md b/PoC/tekton/README.md new file mode 100644 index 0000000..85cdc04 --- /dev/null +++ b/PoC/tekton/README.md @@ -0,0 +1,99 @@ +# Tekton Resources + +This folder contains all the Tekton resources required for the PoC. + +## Prerequisites + +### Install Tekton + +Set up a kind cluster with Tekton using [tekton_in_kind.sh](../tekton_in_kind.sh). +Alternatively: + +1. Install Tekton Pipeline: +```bash +kubectl apply -f https://storage.googleapis.com/tekton-releases/pipeline/previous/v0.25.0/release.yaml +``` + +2. Install Tekton Triggers: +```bash +kubectl apply -f https://storage.googleapis.com/tekton-releases/triggers/previous/v0.14.2/release.yaml +kubectl apply -f https://storage.googleapis.com/tekton-releases/triggers/previous/v0.14.2/interceptors.yaml +``` + +3. Install Tekton Dashboard (optional): +```bash +kubectl apply -f https://github.com/tektoncd/dashboard/releases/download/v0.17.0/tekton-dashboard-release.yaml +``` + +### Configure Tekton Pipeline + +The Tekton pipeline uses some alpha features (Tekton Bundles) which needs to +be enabled in the config. The `feature-flags` config map in the `tekton-pipelines` namespace +should look like: + +```yaml +apiVersion: v1 +data: + enable-api-fields: alpha # <------- + disable-affinity-assistant: "false" + disable-creds-init: "false" + disable-home-env-overwrite: "true" + disable-working-directory-overwrite: "true" + enable-custom-tasks: "false" + enable-tekton-oci-bundles: "false" + require-git-ssh-secret-known-hosts: "false" + running-in-environment-with-injected-sidecars: "true" +kind: ConfigMap +(...) +``` + +### Install Tekton CloudEvents Controller + +Nightly builds are not available yet, so this has to be installed from source. +Requires: + +- go 1.16+ +- `GO111MODULE=on` +- [`ko`](https://github.com/google/ko) + +Clone the [tekton experimental repo](https://github.com/tektoncd/experimental). + +Setup `KO_DOCKER_REPO` to point to your container registry (or `kind.local` when using kind). +Note than when using a private container registry, the tekton cloudevents controller service account +will need to have access via `imagePullSecrets`. + +Move to the cloned folder: +``` +cd cloudevents +ko apply -f config/ +``` + +### Configure Tekton CloudEvents Controller + +The `config-defaults` config map in the `tekton-cloudevents` namespace should look like: + +```yaml +apiVersion: v1 +kind: ConfigMap +data: + default-cloud-events-sink: http:// +(...) +``` + +## Install Tekton Resources + +Install all the yaml files: + +```bash +kubectl create -f poc/tekton +``` + +## Run the build pipeline + +Prerequisites: +- `tkn` (github.com/tektoncd/cli) +- Push access to a container registry. The `dockerconfig` secret in the example below is called `regcred` + +```bash +tkn pipeline start build-artifact -w name=sources,volumeClaimTemplateFile=poc/tekton/workspace-template.yaml -w name=dockerconfig,secret=regcred +``` diff --git a/PoC/tekton/ingress.yaml b/PoC/tekton/ingress.yaml new file mode 100644 index 0000000..ec8b2ac --- /dev/null +++ b/PoC/tekton/ingress.yaml @@ -0,0 +1,16 @@ +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: ingress-resource + namespace: cdevents + annotations: + kubernetes.io/ingress.class: nginx + nginx.ingress.kubernetes.io/ssl-redirect: "false" +spec: + rules: + - http: + paths: + - path: / + backend: + serviceName: el-cdevent-listener + servicePort: 8000 diff --git a/PoC/tekton/rbac.yaml b/PoC/tekton/rbac.yaml new file mode 100644 index 0000000..d1ded59 --- /dev/null +++ b/PoC/tekton/rbac.yaml @@ -0,0 +1,156 @@ +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: triggers-minimal +rules: +- apiGroups: [""] + resources: ["configmaps", "secrets"] + verbs: ["get", "list", "watch"] +- apiGroups: ["triggers.tekton.dev"] + resources: ["eventlisteners", "triggerbindings", "triggertemplates", "triggers"] + verbs: ["get", "list", "watch"] +- apiGroups: ["tekton.dev"] + resources: ["pipelineruns", "pipelineresources", "taskruns"] + verbs: ["create"] +- apiGroups: [""] + resources: ["serviceaccounts"] + verbs: ["impersonate"] +--- +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: triggers-minimal-ci +rules: +# EventListeners need to be able to fetch any clustertriggerbindings +- apiGroups: ["triggers.tekton.dev"] + resources: ["clustertriggerbindings"] + verbs: ["get", "list", "watch"] +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: build-bot +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: tekton-ci-workspace-listener +secrets: +- name: ci-webhook +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: tekton-ci-jobs +secrets: +- name: ci-webhook +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: tekton-ci-workspace-listener-triggers-minimal +subjects: +- kind: ServiceAccount + name: tekton-ci-workspace-listener +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: triggers-minimal +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: tekton-ci-jobs-triggers-minimal +subjects: +- kind: ServiceAccount + name: tekton-ci-jobs +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: triggers-minimal +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: tekton-ci-workspace-listener-triggers-minimal-ci +subjects: +- kind: ServiceAccount + name: tekton-ci-workspace-listener + namespace: default +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: triggers-minimal +--- +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: config-map-admin +rules: +- apiGroups: [""] + resources: ["configmaps"] + verbs: ["*"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: default-config-map-admin +subjects: +- kind: ServiceAccount + name: default +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: config-map-admin +--- +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: tekton-ci-jobs-triggers +rules: +- apiGroups: ["triggers.tekton.dev"] + resources: ["eventlisteners", "triggerbindings", "triggertemplates", "triggers", "clustertriggerbindings"] + verbs: ["get", "list", "watch"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: tekton-ci-jobs-triggers-tekton-ci-workspace-listener +subjects: +- kind: ServiceAccount + name: tekton-ci-workspace-listener + namespace: default +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: tekton-ci-jobs-triggers +--- +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: deployer2default +rules: +- apiGroups: [""] + resources: ["pods", "services"] + verbs: ["*"] +- apiGroups: ["apps"] + resources: ["deployments", "replicasets", "deployments/scale"] + verbs: ["*"] +- apiGroups: [""] + resources: ["configmaps", "secrets"] + verbs: ["get", "list", "watch"] +- apiGroups: ["networking.k8s.io"] + resources: ["ingresses"] + verbs: ["*"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: default-deployer2default +subjects: +- kind: ServiceAccount + name: default +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: deployer2default \ No newline at end of file diff --git a/README.md b/README.md index 23a5a4a..a44b2df 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,19 @@ CloudEvents-Plugin * [Issues](#issues) * [Contributing](#contributing) +Table of Contents +===================================== + + * [Introduction](#introduction) + * [Getting Started](#getting-started) + * [Events Documentation for Jenkins as Source](#events-documentation-for-jenkins-as-source) + * [Queue Events](#queue-events) + * [Build Events](#build-events) + * [Job Events](#job-events) + * [Node Events](#node-events) + * [Issues](#issues) + * [Contributing](#contributing) + Introduction ====================================== @@ -405,16 +418,12 @@ Node Events Issues ========== -TODO Decide where you're going to host your issues, the default is Jenkins JIRA, but you can also enable GitHub issues, -If you use GitHub issues there's no need for this section; else add the following line: - -Report issues and enhancements in the [Jenkins issue tracker](https://issues.jenkins-ci.org/). +If you are facing any issues with the plugin, please feel free to open a new issue inside the [Issues](https://github.com/jenkinsci/cloudevents-plugin/issues) tab under +this repository. We love feedback, and if you would like to share any feedback you have with us, you can submit your feedback using the same procedure. ------------- Contributing ========== -TODO review the default [CONTRIBUTING](https://github.com/jenkinsci/.github/blob/master/CONTRIBUTING.md) file and make sure it is appropriate for your plugin, if not then add your own one adapted from the base file - -Refer to our [contribution guidelines](https://github.com/jenkinsci/.github/blob/master/CONTRIBUTING.md) +If we would like to contribute to this plugin, refer to our [contribution guidelines](https://github.com/jenkinsci/.github/blob/master/CONTRIBUTING.md) diff --git a/pom.xml b/pom.xml index 9031b9f..12f9f04 100644 --- a/pom.xml +++ b/pom.xml @@ -1,18 +1,17 @@ - + 4.0.0 org.jenkins-ci.plugins plugin 4.16 - + io.jenkins.plugins cloudevents - ${revision}${changelist} + 1.0.0 hpi @@ -111,7 +110,7 @@ - + org.mockito mockito-core 3.7.7 @@ -171,6 +170,12 @@ 1.35 test + + org.jetbrains + annotations + RELEASE + compile + @@ -209,8 +214,7 @@ scm:git:git://github.com/${gitHubRepo}.git scm:git:git@github.com:${gitHubRepo}.git https://github.com/${gitHubRepo} - ${scmTag} - + diff --git a/src/main/java/io/jenkins/plugins/cloudevents/Stage.java b/src/main/java/io/jenkins/plugins/cloudevents/Stage.java index 4fe7976..78977e3 100644 --- a/src/main/java/io/jenkins/plugins/cloudevents/Stage.java +++ b/src/main/java/io/jenkins/plugins/cloudevents/Stage.java @@ -74,6 +74,9 @@ public void handleEvent(Object o, String clazz) throws NullPointerException { NodeModel nodeModel = buildNodeModel((Computer) o); sendObject = nodeModel; break; + + default: + break; } if (CloudEventsGlobalConfig.get().getSinkType().equals("http")) { @@ -217,6 +220,9 @@ public QueueModel buildQueueModel(Queue.Item item) { queueModel.setEntryTime(new Date(item.getInQueueSince())); queueModel.setExitTime(new Date()); break; + + default: + break; } @@ -228,8 +234,16 @@ public QueueModel buildQueueModel(Queue.Item item) { public NodeModel buildNodeModel(Computer computer) throws IOException, InterruptedException { NodeModel nodeModel = new NodeModel(); + nodeModel.setNumExecutors(computer.getNumExecutors()); - nodeModel.setNodeName(computer.getNode().getNodeName()); + + Node node = computer.getNode(); + if (node != null) { + String nodeName = node.getNodeName(); + nodeModel.setNodeName(nodeName); + } + + nodeModel.setCachedHostName(computer.getHostName()); nodeModel.setConnectTime(computer.getConnectTime()); @@ -241,6 +255,9 @@ public NodeModel buildNodeModel(Computer computer) throws IOException, Interrupt case OFFLINE: nodeModel.setStatus("offline"); break; + + default: + break; } if (computer.isOffline()) { diff --git a/src/main/java/io/jenkins/plugins/cloudevents/listeners/ItemListener.java b/src/main/java/io/jenkins/plugins/cloudevents/listeners/CE_ItemListener.java similarity index 78% rename from src/main/java/io/jenkins/plugins/cloudevents/listeners/ItemListener.java rename to src/main/java/io/jenkins/plugins/cloudevents/listeners/CE_ItemListener.java index 0322257..d8b2266 100644 --- a/src/main/java/io/jenkins/plugins/cloudevents/listeners/ItemListener.java +++ b/src/main/java/io/jenkins/plugins/cloudevents/listeners/CE_ItemListener.java @@ -5,9 +5,9 @@ import io.jenkins.plugins.cloudevents.Stage; @Extension -public class ItemListener extends hudson.model.listeners.ItemListener { +public class CE_ItemListener extends hudson.model.listeners.ItemListener { - public ItemListener() { + public CE_ItemListener() { } @Override diff --git a/src/main/java/io/jenkins/plugins/cloudevents/listeners/JobListener.java b/src/main/java/io/jenkins/plugins/cloudevents/listeners/CE_JobListener.java similarity index 91% rename from src/main/java/io/jenkins/plugins/cloudevents/listeners/JobListener.java rename to src/main/java/io/jenkins/plugins/cloudevents/listeners/CE_JobListener.java index eab81d3..df5adf7 100644 --- a/src/main/java/io/jenkins/plugins/cloudevents/listeners/JobListener.java +++ b/src/main/java/io/jenkins/plugins/cloudevents/listeners/CE_JobListener.java @@ -14,9 +14,9 @@ * Class which implements RunListener and responds to events relating to run of a job. */ @Extension -public class JobListener extends RunListener { +public class CE_JobListener extends RunListener { - public JobListener() { + public CE_JobListener() { super(Run.class); } diff --git a/src/main/java/io/jenkins/plugins/cloudevents/listeners/NodeListener.java b/src/main/java/io/jenkins/plugins/cloudevents/listeners/CE_NodeListener.java similarity index 89% rename from src/main/java/io/jenkins/plugins/cloudevents/listeners/NodeListener.java rename to src/main/java/io/jenkins/plugins/cloudevents/listeners/CE_NodeListener.java index 3f0f770..af5efd5 100644 --- a/src/main/java/io/jenkins/plugins/cloudevents/listeners/NodeListener.java +++ b/src/main/java/io/jenkins/plugins/cloudevents/listeners/CE_NodeListener.java @@ -11,9 +11,9 @@ import java.io.IOException; @Extension -public class NodeListener extends ComputerListener { +public class CE_NodeListener extends ComputerListener { - public NodeListener() { + public CE_NodeListener() { super(); } diff --git a/src/main/java/io/jenkins/plugins/cloudevents/listeners/QueueListener.java b/src/main/java/io/jenkins/plugins/cloudevents/listeners/CE_QueueListener.java similarity index 84% rename from src/main/java/io/jenkins/plugins/cloudevents/listeners/QueueListener.java rename to src/main/java/io/jenkins/plugins/cloudevents/listeners/CE_QueueListener.java index c6c8652..e42d505 100644 --- a/src/main/java/io/jenkins/plugins/cloudevents/listeners/QueueListener.java +++ b/src/main/java/io/jenkins/plugins/cloudevents/listeners/CE_QueueListener.java @@ -5,7 +5,7 @@ import io.jenkins.plugins.cloudevents.Stage; @Extension -public class QueueListener extends hudson.model.queue.QueueListener { +public class CE_QueueListener extends hudson.model.queue.QueueListener { @Override public void onEnterWaiting(Queue.WaitingItem wi) { Stage.ENTERED_WAITING.handleEvent(wi, "queue"); diff --git a/src/main/java/io/jenkins/plugins/cloudevents/model/JobModel.java b/src/main/java/io/jenkins/plugins/cloudevents/model/JobModel.java index 80be843..03fb46f 100644 --- a/src/main/java/io/jenkins/plugins/cloudevents/model/JobModel.java +++ b/src/main/java/io/jenkins/plugins/cloudevents/model/JobModel.java @@ -37,7 +37,6 @@ public class JobModel implements Model { @JsonIgnore private String stage; - public String getName() { return name; } @@ -87,19 +86,21 @@ public void setUserName(String userName) { } public Date getCreatedDate() { - return createdDate; + Date date = this.createdDate; + return date; } public void setCreatedDate(Date createdDate) { - this.createdDate = createdDate; + this.createdDate = (Date) createdDate.clone(); } public Date getUpdatedDate() { - return updatedDate; + Date date = this.updatedDate; + return date; } public void setUpdatedDate(Date updatedDate) { - this.updatedDate = updatedDate; + this.updatedDate = (Date) updatedDate.clone(); } public String getStatus() { diff --git a/src/main/java/io/jenkins/plugins/cloudevents/model/NodeModel.java b/src/main/java/io/jenkins/plugins/cloudevents/model/NodeModel.java index b08a29f..74a60fd 100644 --- a/src/main/java/io/jenkins/plugins/cloudevents/model/NodeModel.java +++ b/src/main/java/io/jenkins/plugins/cloudevents/model/NodeModel.java @@ -45,7 +45,12 @@ public String getNodeName() { } public void setNodeName(String nodeName) { - this.nodeName = nodeName; + try{ + this.nodeName = nodeName; + } catch (Exception exception) { + exception.printStackTrace(); + } + } public String getCachedHostName() { diff --git a/src/main/java/io/jenkins/plugins/cloudevents/model/QueueModel.java b/src/main/java/io/jenkins/plugins/cloudevents/model/QueueModel.java index 5e090b0..748a4c0 100644 --- a/src/main/java/io/jenkins/plugins/cloudevents/model/QueueModel.java +++ b/src/main/java/io/jenkins/plugins/cloudevents/model/QueueModel.java @@ -52,19 +52,25 @@ public void setCiUrl(String ciUrl) { } public Date getEntryTime() { - return entryTime; + return (Date) entryTime.clone(); } public void setEntryTime(Date entryTime) { - this.entryTime = entryTime; + this.entryTime = (Date) entryTime.clone(); } public Date getExitTime() { - return exitTime; + return (Date) exitTime.clone(); } + public void setExitTime(Date exitTime) { - this.exitTime = exitTime; + try { + this.exitTime = (Date) exitTime.clone(); + } catch (Exception exception) { + exception.printStackTrace(); + } + } public String getStartedBy() { diff --git a/src/main/java/io/jenkins/plugins/cloudevents/sinks/HTTPSink.java b/src/main/java/io/jenkins/plugins/cloudevents/sinks/HTTPSink.java index c198c62..d7bcd48 100644 --- a/src/main/java/io/jenkins/plugins/cloudevents/sinks/HTTPSink.java +++ b/src/main/java/io/jenkins/plugins/cloudevents/sinks/HTTPSink.java @@ -1,6 +1,8 @@ package io.jenkins.plugins.cloudevents.sinks; import io.cloudevents.CloudEvent; +import io.cloudevents.CloudEventData; +import io.cloudevents.SpecVersion; import io.cloudevents.core.message.MessageWriter; import io.cloudevents.core.v1.CloudEventBuilder; import io.jenkins.plugins.cloudevents.CloudEventsSink; @@ -14,6 +16,8 @@ import java.net.URI; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.time.OffsetDateTime; +import java.util.Set; import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; @@ -52,7 +56,67 @@ public CloudEvent buildCloudEvent(Object data) throws NoSuchMethodException, Inv @Override public void sendCloudEvent(String sinkURL, Object data) throws IOException, NullPointerException { - CloudEvent cloudEventToPost = null; + CloudEvent cloudEventToPost = new CloudEvent() { + @Override + public CloudEventData getData() { + return null; + } + + @Override + public SpecVersion getSpecVersion() { + return null; + } + + @Override + public String getId() { + return null; + } + + @Override + public String getType() { + return null; + } + + @Override + public URI getSource() { + return null; + } + + @Override + public String getDataContentType() { + return null; + } + + @Override + public URI getDataSchema() { + return null; + } + + @Override + public String getSubject() { + return null; + } + + @Override + public OffsetDateTime getTime() { + return null; + } + + @Override + public Object getAttribute(String s) throws IllegalArgumentException { + return null; + } + + @Override + public Object getExtension(String s) { + return null; + } + + @Override + public Set getExtensionNames() { + return null; + } + }; try { cloudEventToPost = buildCloudEvent(data); diff --git a/src/test/java/io/jenkins/plugins/cloudevents/StageTest.java b/src/test/java/io/jenkins/plugins/cloudevents/StageTest.java index 86d02ea..0b0d485 100644 --- a/src/test/java/io/jenkins/plugins/cloudevents/StageTest.java +++ b/src/test/java/io/jenkins/plugins/cloudevents/StageTest.java @@ -2,10 +2,10 @@ import hudson.model.*; import hudson.slaves.OfflineCause; -import io.jenkins.plugins.cloudevents.listeners.ItemListener; -import io.jenkins.plugins.cloudevents.listeners.JobListener; -import io.jenkins.plugins.cloudevents.listeners.NodeListener; -import io.jenkins.plugins.cloudevents.listeners.QueueListener; +import io.jenkins.plugins.cloudevents.listeners.CE_ItemListener; +import io.jenkins.plugins.cloudevents.listeners.CE_JobListener; +import io.jenkins.plugins.cloudevents.listeners.CE_NodeListener; +import io.jenkins.plugins.cloudevents.listeners.CE_QueueListener; import io.jenkins.plugins.cloudevents.model.JobModel; import io.jenkins.plugins.cloudevents.model.NodeModel; import io.jenkins.plugins.cloudevents.model.QueueModel; @@ -164,7 +164,7 @@ public void testHandleBuildEvent() { TaskListener taskListener = mock(TaskListener.class); Job job = mock(Job.class); JobModel jobModel = mock(JobModel.class); - JobListener jobListener = mock(JobListener.class); + CE_JobListener jobListener = mock(CE_JobListener.class); Stage started = mock(Stage.STARTED.getClass()); Stage completed = mock(Stage.COMPLETED.getClass()); Stage finalized = mock(Stage.FINALIZED.getClass()); @@ -229,7 +229,7 @@ public void testHandleItemEvent() { Item item = mock(Item.class); - ItemListener itemListener = mock(ItemListener.class); + CE_ItemListener itemListener = mock(CE_ItemListener.class); // On Created Mockito.doAnswer(invocationOnMock -> { @@ -268,7 +268,7 @@ public void testHandleNodeEvent() { Computer computer = mock(Computer.class); TaskListener taskListener = mock(TaskListener.class); OfflineCause offlineCause = mock(OfflineCause.class); - NodeListener nodeListener = mock(NodeListener.class); + CE_NodeListener nodeListener = mock(CE_NodeListener.class); // Computer Online Mockito.doAnswer(invocationOnMock -> { @@ -308,7 +308,7 @@ public void testHandleQueueEvent() { QueueModel queueModel = mock(QueueModel.class); Queue.WaitingItem queueWaitingItem = mock(Queue.WaitingItem.class); Queue.LeftItem queueLeftItem = mock(Queue.LeftItem.class); - QueueListener queueListener = mock(QueueListener.class); + CE_QueueListener queueListener = mock(CE_QueueListener.class); // Queue Entered Waiting Mockito.doAnswer(invocationOnMock -> {