diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 6de0f5ef2..265445a41 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -19,6 +19,7 @@ set -o nounset set -o pipefail source $(dirname $0)/../vendor/knative.dev/hack/codegen-library.sh +source "${CODEGEN_PKG}/kube_codegen.sh" # If we run with -mod=vendor here, then generate-groups.sh looks for vendor files in the wrong place. export GOFLAGS=-mod= @@ -27,14 +28,16 @@ echo "=== Update Codegen for ${MODULE_NAME}" group "Kubernetes Codegen" -# generate the code with: -# --output-base because this script should also be able to run inside the vendor dir of -# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir -# instead of the $GOPATH directly. For normal projects this can be dropped. -${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \ -"knative.dev/eventing-github/pkg/client" "knative.dev/eventing-github/pkg/apis" \ -"sources:v1alpha1 bindings:v1alpha1" \ ---go-header-file ${REPO_ROOT_DIR}/hack/boilerplate.go.txt +kube::codegen::gen_helpers \ + --boilerplate "${REPO_ROOT_DIR}/hack/boilerplate.go.txt" \ + "${REPO_ROOT_DIR}/pkg/apis" + +kube::codegen::gen_client \ + --boilerplate "${REPO_ROOT_DIR}/hack/boilerplate.go.txt" \ + --output-dir "${REPO_ROOT_DIR}/pkg/client" \ + --output-pkg "knative.dev/eventing-github/pkg/client" \ + --with-watch \ + "${REPO_ROOT_DIR}/pkg/apis" group "Knative Codegen" @@ -44,14 +47,6 @@ ${KNATIVE_CODEGEN_PKG}/hack/generate-knative.sh "injection" \ "sources:v1alpha1 bindings:v1alpha1" \ --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate.go.txt -group "Deepcopy Gen" - -# Depends on generate-groups.sh to install bin/deepcopy-gen -${GOPATH}/bin/deepcopy-gen \ - -O zz_generated.deepcopy \ - --go-header-file ${REPO_ROOT_DIR}/hack/boilerplate.go.txt \ - -i knative.dev/eventing-github/pkg/apis \ - group "Update deps post-codegen" # Make sure our dependencies are up-to-date diff --git a/pkg/apis/bindings/v1alpha1/zz_generated.defaults.go b/pkg/apis/bindings/v1alpha1/zz_generated.defaults.go new file mode 100644 index 000000000..927723623 --- /dev/null +++ b/pkg/apis/bindings/v1alpha1/zz_generated.defaults.go @@ -0,0 +1,33 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +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. +*/ + +// Code generated by defaulter-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// RegisterDefaults adds defaulters functions to the given scheme. +// Public to allow building arbitrary schemes. +// All generated defaulters are covering - they call all nested defaulters. +func RegisterDefaults(scheme *runtime.Scheme) error { + return nil +} diff --git a/pkg/apis/sources/v1alpha1/zz_generated.defaults.go b/pkg/apis/sources/v1alpha1/zz_generated.defaults.go new file mode 100644 index 000000000..927723623 --- /dev/null +++ b/pkg/apis/sources/v1alpha1/zz_generated.defaults.go @@ -0,0 +1,33 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +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. +*/ + +// Code generated by defaulter-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// RegisterDefaults adds defaulters functions to the given scheme. +// Public to allow building arbitrary schemes. +// All generated defaulters are covering - they call all nested defaulters. +func RegisterDefaults(scheme *runtime.Scheme) error { + return nil +} diff --git a/pkg/client/injection/informers/sources/factory/fake/fake.go b/pkg/client/injection/informers/sources/factory/fake/fake.go deleted file mode 100644 index 4b7e7cf26..000000000 --- a/pkg/client/injection/informers/sources/factory/fake/fake.go +++ /dev/null @@ -1,45 +0,0 @@ -/* -Copyright 2019 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 ( - "context" - - externalversions "knative.dev/eventing-github/pkg/client/informers/externalversions" - fake "knative.dev/eventing-github/pkg/client/injection/client/fake" - factory "knative.dev/eventing-github/pkg/client/injection/informers/sources/factory" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" -) - -var Get = factory.Get - -func init() { - injection.Fake.RegisterInformerFactory(withInformerFactory) -} - -func withInformerFactory(ctx context.Context) context.Context { - c := fake.Get(ctx) - opts := make([]externalversions.SharedInformerOption, 0, 1) - if injection.HasNamespaceScope(ctx) { - opts = append(opts, externalversions.WithNamespace(injection.GetNamespaceScope(ctx))) - } - return context.WithValue(ctx, factory.Key{}, - externalversions.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), opts...)) -} diff --git a/pkg/client/injection/informers/sources/factory/sourcesfactory.go b/pkg/client/injection/informers/sources/factory/sourcesfactory.go deleted file mode 100644 index b48846246..000000000 --- a/pkg/client/injection/informers/sources/factory/sourcesfactory.go +++ /dev/null @@ -1,56 +0,0 @@ -/* -Copyright 2019 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 sourcesfactory - -import ( - "context" - - externalversions "knative.dev/eventing-github/pkg/client/informers/externalversions" - client "knative.dev/eventing-github/pkg/client/injection/client" - controller "knative.dev/pkg/controller" - injection "knative.dev/pkg/injection" - logging "knative.dev/pkg/logging" -) - -func init() { - injection.Default.RegisterInformerFactory(withInformerFactory) -} - -// Key is used as the key for associating information with a context.Context. -type Key struct{} - -func withInformerFactory(ctx context.Context) context.Context { - c := client.Get(ctx) - opts := make([]externalversions.SharedInformerOption, 0, 1) - if injection.HasNamespaceScope(ctx) { - opts = append(opts, externalversions.WithNamespace(injection.GetNamespaceScope(ctx))) - } - return context.WithValue(ctx, Key{}, - externalversions.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), opts...)) -} - -// Get extracts the InformerFactory from the context. -func Get(ctx context.Context) externalversions.SharedInformerFactory { - untyped := ctx.Value(Key{}) - if untyped == nil { - logging.FromContext(ctx).Fatalf( - "Unable to fetch %T from context.", (externalversions.SharedInformerFactory)(nil)) - } - return untyped.(externalversions.SharedInformerFactory) -} diff --git a/pkg/client/injection/reconciler/sources/v1alpha1/githubsource/stub/controller.go b/pkg/client/injection/reconciler/sources/v1alpha1/githubsource/stub/controller.go deleted file mode 100644 index aced827e6..000000000 --- a/pkg/client/injection/reconciler/sources/v1alpha1/githubsource/stub/controller.go +++ /dev/null @@ -1,54 +0,0 @@ -/* -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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package githubsource - -import ( - context "context" - - githubsource "knative.dev/eventing-github/pkg/client/injection/informers/sources/v1alpha1/githubsource" - v1alpha1githubsource "knative.dev/eventing-github/pkg/client/injection/reconciler/sources/v1alpha1/githubsource" - configmap "knative.dev/pkg/configmap" - controller "knative.dev/pkg/controller" - logging "knative.dev/pkg/logging" -) - -// TODO: PLEASE COPY AND MODIFY THIS FILE AS A STARTING POINT - -// NewController creates a Reconciler for GitHubSource and returns the result of NewImpl. -func NewController( - ctx context.Context, - cmw configmap.Watcher, -) *controller.Impl { - logger := logging.FromContext(ctx) - - githubsourceInformer := githubsource.Get(ctx) - - // TODO: setup additional informers here. - - r := &Reconciler{} - impl := v1alpha1githubsource.NewImpl(ctx, r) - - logger.Info("Setting up event handlers.") - - githubsourceInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)) - - // TODO: add additional informer event handlers here. - - return impl -} diff --git a/pkg/client/injection/reconciler/sources/v1alpha1/githubsource/stub/reconciler.go b/pkg/client/injection/reconciler/sources/v1alpha1/githubsource/stub/reconciler.go deleted file mode 100644 index d75438328..000000000 --- a/pkg/client/injection/reconciler/sources/v1alpha1/githubsource/stub/reconciler.go +++ /dev/null @@ -1,87 +0,0 @@ -/* -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. -*/ - -// Code generated by injection-gen. DO NOT EDIT. - -package githubsource - -import ( - context "context" - - v1 "k8s.io/api/core/v1" - v1alpha1 "knative.dev/eventing-github/pkg/apis/sources/v1alpha1" - githubsource "knative.dev/eventing-github/pkg/client/injection/reconciler/sources/v1alpha1/githubsource" - reconciler "knative.dev/pkg/reconciler" -) - -// TODO: PLEASE COPY AND MODIFY THIS FILE AS A STARTING POINT - -// newReconciledNormal makes a new reconciler event with event type Normal, and -// reason GitHubSourceReconciled. -func newReconciledNormal(namespace, name string) reconciler.Event { - return reconciler.NewEvent(v1.EventTypeNormal, "GitHubSourceReconciled", "GitHubSource reconciled: \"%s/%s\"", namespace, name) -} - -// Reconciler implements controller.Reconciler for GitHubSource resources. -type Reconciler struct { - // TODO: add additional requirements here. -} - -// Check that our Reconciler implements Interface -var _ githubsource.Interface = (*Reconciler)(nil) - -// Optionally check that our Reconciler implements Finalizer -//var _ githubsource.Finalizer = (*Reconciler)(nil) - -// Optionally check that our Reconciler implements ReadOnlyInterface -// Implement this to observe resources even when we are not the leader. -//var _ githubsource.ReadOnlyInterface = (*Reconciler)(nil) - -// Optionally check that our Reconciler implements ReadOnlyFinalizer -// Implement this to observe tombstoned resources even when we are not -// the leader (best effort). -//var _ githubsource.ReadOnlyFinalizer = (*Reconciler)(nil) - -// ReconcileKind implements Interface.ReconcileKind. -func (r *Reconciler) ReconcileKind(ctx context.Context, o *v1alpha1.GitHubSource) reconciler.Event { - // TODO: use this if the resource implements InitializeConditions. - // o.Status.InitializeConditions() - - // TODO: add custom reconciliation logic here. - - // TODO: use this if the object has .status.ObservedGeneration. - // o.Status.ObservedGeneration = o.Generation - return newReconciledNormal(o.Namespace, o.Name) -} - -// Optionally, use FinalizeKind to add finalizers. FinalizeKind will be called -// when the resource is deleted. -//func (r *Reconciler) FinalizeKind(ctx context.Context, o *v1alpha1.GitHubSource) reconciler.Event { -// // TODO: add custom finalization logic here. -// return nil -//} - -// Optionally, use ObserveKind to observe the resource when we are not the leader. -// func (r *Reconciler) ObserveKind(ctx context.Context, o *v1alpha1.GitHubSource) reconciler.Event { -// // TODO: add custom observation logic here. -// return nil -// } - -// Optionally, use ObserveFinalizeKind to observe resources being finalized when we are no the leader. -//func (r *Reconciler) ObserveFinalizeKind(ctx context.Context, o *v1alpha1.GitHubSource) reconciler.Event { -// // TODO: add custom observation logic here. -// return nil -//}