From 7b18c9b13f398726387438b2e0ac7d69daa24d52 Mon Sep 17 00:00:00 2001 From: Pierangelo Di Pilato Date: Wed, 16 Dec 2020 15:42:02 +0100 Subject: [PATCH] ApiServerSource stored version v1 and migration tool Signed-off-by: Pierangelo Di Pilato --- config/core/resources/apiserversource.yaml | 4 +- config/post-install/clusterrole.yaml | 46 +++++++++++++++++++ config/post-install/placeholder.go | 19 ++++++++ config/post-install/serviceaccount.yaml | 38 +++++++++++++++ .../storage-version-migrator.yaml | 40 ++++++++++++++++ hack/generate-yamls.sh | 17 +++---- 6 files changed, 154 insertions(+), 10 deletions(-) create mode 100644 config/post-install/clusterrole.yaml create mode 100644 config/post-install/placeholder.go create mode 100644 config/post-install/serviceaccount.yaml create mode 100644 config/post-install/storage-version-migrator.yaml diff --git a/config/core/resources/apiserversource.yaml b/config/core/resources/apiserversource.yaml index 6d0d68f02e8..44dd0ac09ab 100644 --- a/config/core/resources/apiserversource.yaml +++ b/config/core/resources/apiserversource.yaml @@ -538,7 +538,7 @@ spec: - <<: *version name: v1beta1 served: true - storage: true + storage: false # the schema of v1beta1 is exactly the same as v1alpha2 schema schema: openAPIV3Schema: @@ -546,7 +546,7 @@ spec: - <<: *version name: v1 served: true - storage: false + storage: true # the schema of v1 is exactly the same as v1beta1 schema schema: openAPIV3Schema: diff --git a/config/post-install/clusterrole.yaml b/config/post-install/clusterrole.yaml new file mode 100644 index 00000000000..ee1f1d7e38e --- /dev/null +++ b/config/post-install/clusterrole.yaml @@ -0,0 +1,46 @@ +# 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-post-install-job-role + labels: + eventing.knative.dev/release: devel +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: + - "sources.knative.dev" + resources: + - "apiserversources" + verbs: + - "get" + - "list" + - "create" + - "update" + - "delete" + - "patch" + - "watch" diff --git a/config/post-install/placeholder.go b/config/post-install/placeholder.go new file mode 100644 index 00000000000..6d1d7a97e49 --- /dev/null +++ b/config/post-install/placeholder.go @@ -0,0 +1,19 @@ +/* +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. +*/ + +// Package post_install is a placeholder that allows us to pull in config files +// via go mod vendor. +package post_install diff --git a/config/post-install/serviceaccount.yaml b/config/post-install/serviceaccount.yaml new file mode 100644 index 00000000000..e37249d7076 --- /dev/null +++ b/config/post-install/serviceaccount.yaml @@ -0,0 +1,38 @@ +# 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-post-install-job + namespace: knative-eventing + labels: + eventing.knative.dev/release: devel + +--- + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: knative-eventing-post-install-job-role-binding + labels: + eventing.knative.dev/release: devel +subjects: + - kind: ServiceAccount + name: knative-eventing-post-install-job + namespace: knative-eventing +roleRef: + kind: ClusterRole + name: knative-eventing-post-install-job-role + apiGroup: rbac.authorization.k8s.io diff --git a/config/post-install/storage-version-migrator.yaml b/config/post-install/storage-version-migrator.yaml new file mode 100644 index 00000000000..cd94295d08f --- /dev/null +++ b/config/post-install/storage-version-migrator.yaml @@ -0,0 +1,40 @@ +# 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 + namespace: knative-eventing + labels: + app: "storage-version-migration" + eventing.knative.dev/release: devel +spec: + ttlSecondsAfterFinished: 600 + backoffLimit: 10 + template: + metadata: + labels: + app: "storage-version-migration" + eventing.knative.dev/release: devel + annotations: + sidecar.istio.io/inject: "false" + spec: + serviceAccountName: knative-eventing-post-install-job + restartPolicy: OnFailure + containers: + - name: migrate + image: ko://knative.dev/eventing/vendor/knative.dev/pkg/apiextensions/storageversion/cmd/migrate + args: + - "apiserversources.sources.knative.dev" diff --git a/hack/generate-yamls.sh b/hack/generate-yamls.sh index 654f3bb97da..ef600cfc287 100755 --- a/hack/generate-yamls.sh +++ b/hack/generate-yamls.sh @@ -53,7 +53,6 @@ readonly EVENTING_CRDS_YAML=${YAML_OUTPUT_DIR}/"eventing-crds.yaml" readonly EVENTING_SUGAR_CONTROLLER_YAML=${YAML_OUTPUT_DIR}/"eventing-sugar-controller.yaml" readonly EVENTING_MT_CHANNEL_BROKER_YAML=${YAML_OUTPUT_DIR}/"mt-channel-broker.yaml" readonly EVENTING_IN_MEMORY_CHANNEL_YAML=${YAML_OUTPUT_DIR}/"in-memory-channel.yaml" -readonly EVENTING_POST_INSTALL_YAML=${YAML_OUTPUT_DIR}/"eventing-post-install-jobs.yaml" readonly EVENTING_YAML=${YAML_OUTPUT_DIR}"/eventing.yaml" declare -A RELEASES RELEASES=( @@ -94,14 +93,17 @@ ko resolve ${KO_FLAGS} -f config/brokers/mt-channel-broker/ | "${LABEL_YAML_CMD[ # Create in memory channel yaml ko resolve ${KO_FLAGS} -f config/channels/in-memory-channel/ | "${LABEL_YAML_CMD[@]}" > "${EVENTING_IN_MEMORY_CHANNEL_YAML}" - all_yamls=(${EVENTING_CORE_YAML} ${EVENTING_CRDS_YAML} ${EVENTING_SUGAR_CONTROLLER_YAML} ${EVENTING_MT_CHANNEL_BROKER_YAML} ${EVENTING_IN_MEMORY_CHANNEL_YAML} ${EVENTING_YAML}) - # # Template for POST_INSTALL usage: - # # Create vX.Y.Z post-install job yaml. - # ko resolve ${KO_FLAGS} -f config/post-install/vX.Y.Z/ | "${LABEL_YAML_CMD[@]}" > "${POST_INSTALL_YAML}" - # # If used, add ${EVENTING_POST_INSTALL_YAML} to all_yamls, - # all_yamls+=(${EVENTING_POST_INSTALL_YAML}) +if [ -d "${YAML_REPO_ROOT}/config/post-install" ]; then + + readonly EVENTING_POST_INSTALL_YAML=${YAML_OUTPUT_DIR}/"eventing-post-install.yaml" + + echo "Resolving post install manifests" + + ko resolve ${KO_FLAGS} -f config/post-install/ | "${LABEL_YAML_CMD[@]}" > "${EVENTING_POST_INSTALL_YAML}" + all_yamls+=(${EVENTING_POST_INSTALL_YAML}) +fi # Assemble the release for yaml in "${!RELEASES[@]}"; do @@ -116,7 +118,6 @@ done echo "All manifests generated" - for yaml in "${!all_yamls[@]}"; do echo "${all_yamls[${yaml}]}" >> ${YAML_LIST_FILE} done