Skip to content
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

Upgrade pingsource storage to v1alpha2 #3274

Merged
merged 4 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/200-pingsource-adapter-clusterrole.yaml
6 changes: 3 additions & 3 deletions config/core/resources/pingsource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ spec:
JSONPath: .metadata.creationTimestamp
versions:
- name: v1alpha1
served: true
storage: true
served: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work like this? I thought you needed both v1alpha1 / v1alpha2 to be served since the storage migration reads v1alpha1 then upgrades to v1alpha2, so if you remove the serving, not sure it will work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

served: false means you cannot do kubeclt get pingsources.v1alpha1.sources.knative.dev but kubeclt get pingsources.sources.knative.dev works because of the conversion webhook. Anyway I don't know the details but it works

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, ok, well, wow, I'm really confused then :) I thought it would exactly use the pingsources.v1alpha1.sources.knative.dev (as in versioned read) of v1alpha1, then patch using v1alpha2. I think pingsources.sources.knative.dev will give you the v1alpha2 already converted. But, if you've already verified that the actual conversion happens and the storage version gets bumped, 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The migration tools list all resources and perform an empty patch which triggers a migration on the K8s API server.

I did it twice and it works.

storage: false
- name: v1alpha2
served: true
storage: false
storage: true
21 changes: 21 additions & 0 deletions config/core/roles/pingsource-adapter-clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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-pingsource-adapter
labels:
eventing.knative.dev/release: devel
rules: []
2 changes: 2 additions & 0 deletions config/pre-install/v0.16.0/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ rules:
# Our own resources we care about.
- apiGroups:
- "eventing.knative.dev"
- "sources.knative.dev"
resources:
- "brokers"
- "pingsources"
verbs:
- "get"
- "list"
Expand Down
77 changes: 77 additions & 0 deletions config/pre-install/v0.16.0/pingsource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# 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:
labels:
eventing.knative.dev/release: devel
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
names:
categories:
- all
- knative
- eventing
- sources
kind: PingSource
plural: pingsources
scope: Namespaced
subresources:
status: {}
preserveUnknownFields: false
validation:
openAPIV3Schema:
type: object
# this is a work around so we don't need to flesh out the
# schema for each version at this time
#
# see issue: https://github.com/knative/serving/issues/912
x-kubernetes-preserve-unknown-fields: true
conversion:
strategy: Webhook
webhookClientConfig:
service:
name: eventing-webhook
namespace: knative-eventing
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
versions:
- name: v1alpha1
served: false
storage: false
- name: v1alpha2
served: true
storage: true
1 change: 1 addition & 0 deletions config/pre-install/v0.16.0/storage-version-migration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ spec:
image: ko://knative.dev/eventing/vendor/knative.dev/pkg/apiextensions/storageversion/cmd/migrate
args:
- "brokers.eventing.knative.dev"
- "pingsources.sources.knative.dev"
3 changes: 1 addition & 2 deletions pkg/adapter/mtping/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ import (
"context"
"sync"

"knative.dev/eventing/pkg/adapter/v2"

"github.com/robfig/cron/v3"
"go.uber.org/zap"
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"knative.dev/pkg/logging"
"knative.dev/pkg/source"

"knative.dev/eventing/pkg/adapter/v2"
eventingclient "knative.dev/eventing/pkg/client/injection/client"
pingsourceinformer "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha2/pingsource"
pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/pingsource"
Expand Down
8 changes: 4 additions & 4 deletions pkg/adapter/mtping/pingsource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestAllCases(t *testing.T) {
WithValidPingSourceV1A2Schedule,
WithPingSourceV1A2Deployed,
WithPingSourceV1A2Sink(sinkURI),
WithPingSourceV1A2EventType,
WithPingSourceV1A2CloudEventAttributes,
),
},
WantEvents: []string{
Expand All @@ -114,7 +114,7 @@ func TestAllCases(t *testing.T) {
WithValidPingSourceV1A2Schedule,
WithPingSourceV1A2Deployed,
WithPingSourceV1A2Sink(sinkURI),
WithPingSourceV1A2EventType,
WithPingSourceV1A2CloudEventAttributes,
WithPingSourceV1A2Finalizers(defaultFinalizerName),
),
},
Expand All @@ -136,7 +136,7 @@ func TestAllCases(t *testing.T) {
WithValidPingSourceV1A2Schedule,
WithPingSourceV1A2Deployed,
WithPingSourceV1A2Sink(sinkURI),
WithPingSourceV1A2EventType,
WithPingSourceV1A2CloudEventAttributes,
WithPingSourceV1A2Finalizers(defaultFinalizerName),
WithPingSourceV1A2Deleted,
),
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestAllCases(t *testing.T) {
WithValidPingSourceV1A2Schedule,
WithPingSourceV1A2Deployed,
WithPingSourceV1A2Sink(sinkURI),
WithPingSourceV1A2EventType,
WithPingSourceV1A2CloudEventAttributes,
WithPingSourceV1A2Deleted,
),
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/adapter/ping/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
cloudevents "github.com/cloudevents/sdk-go/v2"
"github.com/robfig/cron/v3"
"go.uber.org/zap"
sourcesv1alpha1 "knative.dev/eventing/pkg/apis/sources/v1alpha1"
"knative.dev/pkg/logging"

"knative.dev/eventing/pkg/adapter/v2"
sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2"
)

type envConfig struct {
Expand Down Expand Up @@ -100,8 +100,8 @@ func (a *pingAdapter) start(stopCh <-chan struct{}) error {
func (a *pingAdapter) cronTick() {
ctx := context.Background()
event := cloudevents.NewEvent(cloudevents.VersionV1)
event.SetType(sourcesv1alpha1.PingSourceEventType)
event.SetSource(sourcesv1alpha1.PingSourceSource(a.Namespace, a.Name))
event.SetType(sourcesv1alpha2.PingSourceEventType)
event.SetSource(sourcesv1alpha2.PingSourceSource(a.Namespace, a.Name))
if err := event.SetData(cloudevents.ApplicationJSON, message(a.Data)); err != nil {
logging.FromContext(ctx).Errorw("ping failed to set event data", zap.Error(err))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/mtbroker/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ func makeReadyPingSource() *sourcesv1alpha2.PingSource {
rtv1alpha1.WithValidPingSourceV1A2Schedule,
rtv1alpha1.WithValidPingSourceV1A2Resources,
rtv1alpha1.WithPingSourceV1A2Deployed,
rtv1alpha1.WithPingSourceV1A2EventType,
rtv1alpha1.WithPingSourceV1A2CloudEventAttributes,
rtv1alpha1.WithPingSourceV1A2Sink(u),
)
}
Expand Down
20 changes: 13 additions & 7 deletions pkg/reconciler/pingsource/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/kelseyhightower/envconfig"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/client-go/tools/cache"
"knative.dev/eventing/pkg/apis/sources/v1alpha1"
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"knative.dev/pkg/logging"
Expand All @@ -31,10 +30,13 @@ import (
"knative.dev/pkg/system"
"knative.dev/pkg/tracker"

pingsourceinformer "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha1/pingsource"
pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha1/pingsource"
"knative.dev/eventing/pkg/apis/sources/v1alpha2"
pingsourceinformer "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha2/pingsource"
pingsourcereconciler "knative.dev/eventing/pkg/client/injection/reconciler/sources/v1alpha2/pingsource"
kubeclient "knative.dev/pkg/client/injection/kube/client"
deploymentinformer "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment"
"knative.dev/pkg/client/injection/kube/informers/core/v1/serviceaccount"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format Go code:

Suggested change
"knative.dev/pkg/client/injection/kube/informers/core/v1/serviceaccount"
"knative.dev/pkg/client/injection/kube/informers/core/v1/serviceaccount"
"knative.dev/pkg/client/injection/kube/informers/rbac/v1/rolebinding"

"knative.dev/pkg/client/injection/kube/informers/rbac/v1/rolebinding"
)

// envConfig will be used to extract the required environment variables using
Expand All @@ -54,11 +56,15 @@ func NewController(

deploymentInformer := deploymentinformer.Get(ctx)
pingSourceInformer := pingsourceinformer.Get(ctx)
serviceAccountInformer := serviceaccount.Get(ctx)
roleBindingInformer := rolebinding.Get(ctx)

r := &Reconciler{
kubeClientSet: kubeclient.Get(ctx),
pingLister: pingSourceInformer.Lister(),
deploymentLister: deploymentInformer.Lister(),
kubeClientSet: kubeclient.Get(ctx),
pingLister: pingSourceInformer.Lister(),
deploymentLister: deploymentInformer.Lister(),
serviceAccountLister: serviceAccountInformer.Lister(),
roleBindingLister: roleBindingInformer.Lister(),

loggingContext: ctx,
}
Expand All @@ -79,7 +85,7 @@ func NewController(

// Watch for deployments owned by the source
deploymentInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: controller.FilterControllerGK(v1alpha1.Kind("PingSource")),
FilterFunc: controller.FilterControllerGK(v1alpha2.Kind("PingSource")),
Handler: controller.HandleAll(impl.EnqueueControllerOf),
})

Expand Down
4 changes: 3 additions & 1 deletion pkg/reconciler/pingsource/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ import (

// Fake injection informers
_ "knative.dev/eventing/pkg/client/injection/informers/eventing/v1beta1/eventtype/fake"
_ "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha1/pingsource/fake"
_ "knative.dev/eventing/pkg/client/injection/informers/sources/v1alpha2/pingsource/fake"
_ "knative.dev/pkg/client/injection/ducks/duck/v1/addressable/fake"
_ "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment/fake"
_ "knative.dev/pkg/client/injection/kube/informers/core/v1/serviceaccount/fake"
_ "knative.dev/pkg/client/injection/kube/informers/rbac/v1/rolebinding/fake"
)

func TestNew(t *testing.T) {
Expand Down
Loading