# 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: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: brokers.eventing.knative.dev
  labels:
    eventing.knative.dev/release: "v0.16.1"
    knative.dev/crd-install: "true"
    duck.knative.dev/addressable: "true"
spec:
  group: eventing.knative.dev
  versions:
  - &version
    name: v1beta1
    served: true
    storage: true
    subresources:
      status: {}
    schema:
      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
    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
  - !!merge <<: *version
    name: v1alpha1
    served: true
    storage: false
  names:
    kind: Broker
    plural: brokers
    singular: broker
    categories:
    - all
    - knative
    - eventing
  scope: Namespaced
  conversion:
    strategy: Webhook
    webhook:
      conversionReviewVersions: ["v1beta1"]
      clientConfig:
        service:
          name: eventing-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: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: knative-eventing-pre-install-job-role
  labels:
    eventing.knative.dev/release: "v0.16.1"
rules:
- # Storage version upgrader needs to be able to patch CRDs.
  apiGroups:
  - "apiextensions.k8s.io"
  resources:
  - "customresourcedefinitions"
  - "customresourcedefinitions/status"
  verbs:
  - "get"
  - "list"
  - "update"
  - "patch"
  - "watch"
- # Our own resources we care about.
  apiGroups:
  - "eventing.knative.dev"
  - "sources.knative.dev"
  resources:
  - "brokers"
  - "pingsources"
  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: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  labels:
    eventing.knative.dev/release: "v0.16.1"
    eventing.knative.dev/source: "true"
    duck.knative.dev/source: "true"
    knative.dev/crd-install: "true"
  annotations:
    # TODO add schemas and descriptions
    registry.knative.dev/eventTypes: |
      [
        { "type": "dev.knative.sources.ping" }
      ]
  name: pingsources.sources.knative.dev
spec:
  group: sources.knative.dev
  versions:
  - &version
    name: v1alpha2
    served: true
    storage: true
    subresources:
      status: {}
    schema:
      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
    additionalPrinterColumns:
    - name: Ready
      type: string
      jsonPath: ".status.conditions[?(@.type=='Ready')].status"
    - name: Reason
      type: string
      jsonPath: ".status.conditions[?(@.type=='Ready')].reason"
    - name: Sink
      type: string
      jsonPath: .status.sinkUri
    - name: Age
      type: date
      jsonPath: .metadata.creationTimestamp
  - !!merge <<: *version
    name: v1alpha1
    served: false
    storage: false
  names:
    categories:
    - all
    - knative
    - eventing
    - sources
    kind: PingSource
    plural: pingsources
  scope: Namespaced
  conversion:
    strategy: Webhook
    webhook:
      conversionReviewVersions: ["v1beta1"]
      clientConfig:
        service:
          name: eventing-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: ServiceAccount
metadata:
  name: knative-eventing-pre-install-job
  namespace: knative-eventing
  labels:
    eventing.knative.dev/release: "v0.16.1"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: knative-eventing-pre-install-job-role-binding
  labels:
    eventing.knative.dev/release: "v0.16.1"
subjects:
- kind: ServiceAccount
  name: knative-eventing-pre-install-job
  namespace: knative-eventing
roleRef:
  kind: ClusterRole
  name: knative-eventing-pre-install-job-role
  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
#
#     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: batch/v1
kind: Job
metadata:
  name: storage-version-migration-eventing
  namespace: knative-eventing
  labels:
    app: "storage-version-migration-eventing"
    eventing.knative.dev/release: "v0.16.1"
spec:
  ttlSecondsAfterFinished: 600
  backoffLimit: 10
  template:
    metadata:
      labels:
        app: "storage-version-migration-eventing"
      annotations:
        sidecar.istio.io/inject: "false"
    spec:
      serviceAccountName: knative-eventing-pre-install-job
      restartPolicy: OnFailure
      containers:
      - name: migrate
        # This is the Go import path for the binary that is containerized
        # and substituted here.
        image: gcr.io/knative-releases/knative.dev/eventing/vendor/knative.dev/pkg/apiextensions/storageversion/cmd/migrate@sha256:7da227ccb60c0a2a19565d88d185ebf2551854c765d539967e84e6166a51d492
        args:
        - "brokers.eventing.knative.dev"
        - "pingsources.sources.knative.dev"

---
