Skip to content

Commit

Permalink
WIP: upgrade pingsource storage to v1alpha2
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelvillard committed Jun 4, 2020
1 parent 36ed1b3 commit 28af8f9
Show file tree
Hide file tree
Showing 20 changed files with 646 additions and 324 deletions.
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
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
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.eventing.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 @@ -1508,7 +1508,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"
"knative.dev/pkg/client/injection/kube/informers/rbac/v1/rolebinding"
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"
)

// 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

0 comments on commit 28af8f9

Please sign in to comment.