diff --git a/cmd/v0.22/pingsource-cleanup/README.md b/cmd/v0.22/pingsource-cleanup/README.md new file mode 100644 index 00000000000..8b18b28169d --- /dev/null +++ b/cmd/v0.22/pingsource-cleanup/README.md @@ -0,0 +1,82 @@ +# PingSource cleanup post-0.22.0 install + +The following is a log of testing commands to try out this job. + +The job's log is the yaml of all resources that were deleted. The job uses +eventing's service account. + +--- + +## kind start cluster: + +``` +cat < 0 { + finalizers := sets.NewString(pingsource.Finalizers...) + if finalizers.Has("pingsources.sources.knative.dev") { + fmt.Printf("# Found PingSource %s/%s, need to remove finalizer.\n", pingsource.Namespace, pingsource.Name) + cleanups = append(cleanups, pingsource) + } + } + } + } + + if !env.DryRun { + for i := range cleanups { + ref := cleanups[i] + fmt.Printf("# will remove finalizer for %s/%s\n", ref.Namespace, ref.Name) + + finalizers := sets.NewString(ref.Finalizers...) + finalizers.Delete("pingsources.sources.knative.dev") + ref.Finalizers = finalizers.List() + + if _, err := client.SourcesV1beta2().PingSources(ref.Namespace).Update(ctx, &ref, metav1.UpdateOptions{}); err != nil { + fmt.Printf("# [error] failed to update %s/%s %s\n", ref.Namespace, ref.Name, err) + } + } + } + fmt.Printf("# Done, cleaned %d resources.\n", len(cleanups)) +} diff --git a/config/post-install/clusterrole.yaml b/config/post-install/clusterrole.yaml index 6870bf3ffac..37001860507 100644 --- a/config/post-install/clusterrole.yaml +++ b/config/post-install/clusterrole.yaml @@ -44,3 +44,10 @@ rules: - "delete" - "patch" - "watch" + - apiGroups: + - "" + resources: + - "namespaces" + verbs: + - "get" + - "list" diff --git a/config/post-install/pingsource-cleanup.yaml b/config/post-install/pingsource-cleanup.yaml new file mode 100644 index 00000000000..c75ea2a9ebd --- /dev/null +++ b/config/post-install/pingsource-cleanup.yaml @@ -0,0 +1,42 @@ +# Copyright 2021 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: batch/v1 +kind: Job +metadata: + name: v0.22.0-pingsource-cleanup + namespace: knative-eventing + labels: + eventing.knative.dev/release: devel +spec: + ttlSecondsAfterFinished: 600 + template: + metadata: + annotations: + sidecar.istio.io/inject: "false" + spec: + serviceAccountName: knative-eventing-post-install-job + restartPolicy: Never + containers: + - name: pingsource + image: ko://knative.dev/eventing/cmd/v0.22/pingsource-cleanup + env: + - name: SYSTEM_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + +# Note the following ENVVAR settings exist: +# SYSTEM_NAMESPACE - the namespace of the control plane, defaults to knative-eventing +# DRY_RUN - a flag to run the script without deleting or updating, defaults to false.