mirror of https://github.com/knative/pkg.git
Generate kresource duck type codegen (#2754)
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
This commit is contained in:
parent
4dbc3122f3
commit
74c4be5e93
|
|
@ -23,6 +23,7 @@ import (
|
|||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
|
||||
"knative.dev/pkg/apis/duck/ducktypes"
|
||||
|
||||
"knative.dev/pkg/apis"
|
||||
|
|
@ -41,6 +42,7 @@ type KRShaped interface {
|
|||
// Asserts KResource conformance with KRShaped
|
||||
var _ KRShaped = (*KResource)(nil)
|
||||
|
||||
// +genduck
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
|
||||
// KResource is a skeleton type wrapping Conditions in the manner we expect
|
||||
|
|
@ -54,6 +56,11 @@ type KResource struct {
|
|||
Status Status `json:"status"`
|
||||
}
|
||||
|
||||
// GetFullType implements duck.Implementable
|
||||
func (*KResource) GetFullType() ducktypes.Populatable {
|
||||
return &KResource{}
|
||||
}
|
||||
|
||||
// Populate implements duck.Populatable
|
||||
func (t *KResource) Populate() {
|
||||
t.Status.ObservedGeneration = 42
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
Copyright 2022 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.
|
||||
*/
|
||||
|
||||
// Code generated by injection-gen. DO NOT EDIT.
|
||||
|
||||
package fake
|
||||
|
||||
import (
|
||||
kresource "knative.dev/pkg/client/injection/ducks/duck/v1/kresource"
|
||||
injection "knative.dev/pkg/injection"
|
||||
)
|
||||
|
||||
var Get = kresource.Get
|
||||
|
||||
func init() {
|
||||
injection.Fake.RegisterDuck(kresource.WithDuck)
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
Copyright 2022 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.
|
||||
*/
|
||||
|
||||
// Code generated by injection-gen. DO NOT EDIT.
|
||||
|
||||
package kresource
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
duck "knative.dev/pkg/apis/duck"
|
||||
v1 "knative.dev/pkg/apis/duck/v1"
|
||||
controller "knative.dev/pkg/controller"
|
||||
injection "knative.dev/pkg/injection"
|
||||
dynamicclient "knative.dev/pkg/injection/clients/dynamicclient"
|
||||
logging "knative.dev/pkg/logging"
|
||||
)
|
||||
|
||||
func init() {
|
||||
injection.Default.RegisterDuck(WithDuck)
|
||||
}
|
||||
|
||||
// Key is used for associating the Informer inside the context.Context.
|
||||
type Key struct{}
|
||||
|
||||
func WithDuck(ctx context.Context) context.Context {
|
||||
dc := dynamicclient.Get(ctx)
|
||||
dif := &duck.CachedInformerFactory{
|
||||
Delegate: &duck.TypedInformerFactory{
|
||||
Client: dc,
|
||||
Type: (&v1.KResource{}).GetFullType(),
|
||||
ResyncPeriod: controller.GetResyncPeriod(ctx),
|
||||
StopChannel: ctx.Done(),
|
||||
},
|
||||
}
|
||||
return context.WithValue(ctx, Key{}, dif)
|
||||
}
|
||||
|
||||
// Get extracts the typed informer from the context.
|
||||
func Get(ctx context.Context) duck.InformerFactory {
|
||||
untyped := ctx.Value(Key{})
|
||||
if untyped == nil {
|
||||
logging.FromContext(ctx).Panic(
|
||||
"Unable to fetch knative.dev/pkg/apis/duck.InformerFactory from context.")
|
||||
}
|
||||
return untyped.(duck.InformerFactory)
|
||||
}
|
||||
Loading…
Reference in New Issue