-
Notifications
You must be signed in to change notification settings - Fork 630
add post 022 job to remove pingsource finalizer #5008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <<EOF | kind create cluster --name pingsource --config=- | ||
| kind: Cluster | ||
| apiVersion: kind.x-k8s.io/v1alpha4 | ||
| nodes: | ||
| - role: control-plane | ||
| image: kindest/node:v1.16.9@sha256:7175872357bc85847ec4b1aba46ed1d12fa054c83ac7a8a11f5c268957fd5765 | ||
| - role: worker | ||
| image: kindest/node:v1.16.9@sha256:7175872357bc85847ec4b1aba46ed1d12fa054c83ac7a8a11f5c268957fd5765 | ||
| EOF | ||
| ``` | ||
|
|
||
| ## install knative eventing 0.22: | ||
|
|
||
| ``` | ||
| kubectl apply --filename https://github.com/knative/eventing/releases/download/v0.22.0/eventing-crds.yaml | ||
| kubectl apply --filename https://github.com/knative/eventing/releases/download/v0.22.0/eventing-core.yaml | ||
| ``` | ||
|
|
||
| ## monitor | ||
|
|
||
| ``` | ||
| watch kubectl get pingsource,deployments,rolebindings,serviceaccounts,roles | ||
| ``` | ||
|
|
||
| ## app install | ||
|
|
||
| ``` | ||
| cat <<EOF | kubectl apply -f - | ||
| apiVersion: sources.knative.dev/v1beta2 | ||
| kind: PingSource | ||
| metadata: | ||
| name: test-ping-source | ||
| spec: | ||
| schedule: "*/1 * * * *" | ||
| data: '{"message": "OG- 0.21 PingSource"}' | ||
| sink: | ||
| ref: | ||
| # Deliver events to Deployment. | ||
| apiVersion: v1 | ||
| kind: Service | ||
| name: event-display | ||
| EOF | ||
| ``` | ||
|
|
||
| ## Upgrade to Eventing 0.22 | ||
|
|
||
| ``` | ||
| kubectl apply --filename https://github.com/knative/eventing/releases/download/v0.22.0/eventing-core.yaml | ||
| kubectl apply --filename https://github.com/knative/eventing/releases/download/v0.22.0/eventing-post-install-jobs.yaml | ||
| ``` | ||
|
|
||
| # upgrade to Eventing 0.22 (nightly) | ||
|
|
||
| ``` | ||
| kubectl apply --filename https://storage.googleapis.com/knative-nightly/eventing/latest/eventing-core.yaml | ||
| kubectl apply --filename https://storage.googleapis.com/knative-nightly/eventing/latest/eventing-post-install-jobs.yaml | ||
|
|
||
| or | ||
| ko apply -f ./config/post-install/ | ||
| ``` | ||
|
|
||
| # clean up | ||
|
|
||
| ``` | ||
| kind delete cluster --name pingsource | ||
| ``` | ||
|
|
||
| ## Notes: | ||
|
|
||
| PingSource finalizers should be removed | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| 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. | ||
| */ | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "knative.dev/pkg/controller" | ||
| "knative.dev/pkg/injection" | ||
| "knative.dev/pkg/injection/sharedmain" | ||
| "knative.dev/pkg/signals" | ||
| ) | ||
|
|
||
| func injectionEnabled() context.Context { | ||
| ctx := signals.NewContext() | ||
| cfg := sharedmain.ParseAndGetConfigOrDie() | ||
| ctx, informers := injection.Default.SetupInformers(ctx, cfg) | ||
|
|
||
| // Start the injection clients and informers. | ||
| go func(ctx context.Context) { | ||
| if err := controller.StartInformers(ctx.Done(), informers...); err != nil { | ||
| panic(fmt.Sprint("Failed to start informers - ", err)) | ||
| } | ||
| <-ctx.Done() | ||
| }(ctx) | ||
|
|
||
| return ctx | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| 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. | ||
| */ | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "log" | ||
|
|
||
| "k8s.io/apimachinery/pkg/util/sets" | ||
|
|
||
| "github.com/kelseyhightower/envconfig" | ||
|
|
||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
||
| eventingclient "knative.dev/eventing/pkg/client/injection/client" | ||
| kubeclient "knative.dev/pkg/client/injection/kube/client" | ||
|
|
||
| sourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2" | ||
| ) | ||
|
|
||
| type envConfig struct { | ||
| SystemNamespace string `envconfig:"SYSTEM_NAMESPACE" default:"knative-eventing"` | ||
| DryRun bool `envconfig:"DRY_RUN" default:"false"` | ||
| } | ||
|
|
||
| func main() { | ||
| ctx := injectionEnabled() | ||
|
|
||
| var env envConfig | ||
| if err := envconfig.Process("", &env); err != nil { | ||
| log.Fatalf("[ERROR] Failed to process env var: %s", err) | ||
| } | ||
|
|
||
| k8s := kubeclient.Get(ctx) | ||
| client := eventingclient.Get(ctx) | ||
|
|
||
| nss, err := k8s.CoreV1().Namespaces().List(ctx, metav1.ListOptions{}) | ||
|
zhaojizhuang marked this conversation as resolved.
|
||
| if err != nil { | ||
| log.Fatalf("[ERROR] Failed to list namespaces: %s", err) | ||
| } | ||
|
|
||
| var cleanups []sourcesv1beta2.PingSource | ||
|
|
||
| for _, ns := range nss.Items { | ||
| fmt.Printf("# processing namespace %s\n", ns.Name) | ||
|
|
||
| pingsources, err := client.SourcesV1beta2().PingSources(ns.Name).List(ctx, metav1.ListOptions{}) | ||
| if err != nil { | ||
| fmt.Printf("# [error] failed to list pingsources in namespace %q, %s\n", ns.Name, err) | ||
| } | ||
|
|
||
| for _, pingsource := range pingsources.Items { | ||
| if len(pingsource.Finalizers) > 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)) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,3 +44,10 @@ rules: | |
| - "delete" | ||
| - "patch" | ||
| - "watch" | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - "namespaces" | ||
| verbs: | ||
| - "get" | ||
| - "list" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.