From ca1b1522cc1616219065c5b119e120f305513b63 Mon Sep 17 00:00:00 2001 From: Phillip Wittrock Date: Fri, 16 Mar 2018 20:20:54 -0700 Subject: [PATCH] Add godocs for inject packages --- .../example_controllermanager_test.go | 24 ++++++++++ pkg/inject/args/args.go | 25 ++++++++-- pkg/inject/args/example_args_test.go | 47 +++++++++++++++++++ pkg/inject/run/example_args_test.go | 29 ++++++++++++ 4 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 pkg/controller/example_controllermanager_test.go create mode 100644 pkg/inject/args/example_args_test.go create mode 100644 pkg/inject/run/example_args_test.go diff --git a/pkg/controller/example_controllermanager_test.go b/pkg/controller/example_controllermanager_test.go new file mode 100644 index 0000000000..7eedd77dff --- /dev/null +++ b/pkg/controller/example_controllermanager_test.go @@ -0,0 +1,24 @@ +/* +Copyright 2017 The Kubernetes 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 controller_test + +import "github.com/kubernetes-sigs/kubebuilder/pkg/controller" + +func ExampleControllerManager() { + // Create a new empty ControllerManager for managing Informers and Controllers + var _ = &controller.ControllerManager{} +} diff --git a/pkg/inject/args/args.go b/pkg/inject/args/args.go index 33a961f654..58db0f5dd7 100644 --- a/pkg/inject/args/args.go +++ b/pkg/inject/args/args.go @@ -77,15 +77,28 @@ func CreateInjectArgs(config *rest.Config) InjectArgs { } } +// Injector is used by code generators to register code generated objects type Injector struct { - CRDs []*apiextensionsv1beta1.CustomResourceDefinition - PolicyRules []rbacv1.PolicyRule - GroupVersions []schema.GroupVersion - Runnables []Runnable - RunFns []RunFn + // CRDs are CRDs that may be created / updated at startup + CRDs []*apiextensionsv1beta1.CustomResourceDefinition + + // PolicyRules are RBAC policy rules that may be installed with the controller + PolicyRules []rbacv1.PolicyRule + + // GroupVersions are the api group versions in the CRDs + GroupVersions []schema.GroupVersion + + // Runnables objects run with RunArguments + Runnables []Runnable + + // RunFns are functions run with RunArguments + RunFns []RunFn + + // ControllerManager is used to register Informers and Controllers ControllerManager *controller.ControllerManager } +// Run will run all of the registered RunFns and Runnables func (i Injector) Run(a run.RunArguments) error { for _, r := range i.Runnables { go r.Run(a) @@ -96,8 +109,10 @@ func (i Injector) Run(a run.RunArguments) error { return nil } +// RunFn can be registered with an Injector and run type RunFn func(arguments run.RunArguments) error +// Runnable can be registered with an Injector and run type Runnable interface { Run(arguments run.RunArguments) error } diff --git a/pkg/inject/args/example_args_test.go b/pkg/inject/args/example_args_test.go new file mode 100644 index 0000000000..fcb7a01ff6 --- /dev/null +++ b/pkg/inject/args/example_args_test.go @@ -0,0 +1,47 @@ +/* +Copyright 2017 The Kubernetes 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 args_test + +import ( + "flag" + "github.com/kubernetes-sigs/kubebuilder/pkg/config" + "github.com/kubernetes-sigs/kubebuilder/pkg/inject/args" +) + +func Example() { + flag.Parse() + config := config.GetConfigOrDie() + + // Create base arguments for initializing controllers + var _ = args.CreateInjectArgs(config) +} + +func ExampleCreateInjectArgs() { + flag.Parse() + config := config.GetConfigOrDie() + + // Create base arguments for initializing controllers + var _ = args.CreateInjectArgs(config) +} + +func ExampleInjectArgs_CreateRecorder() { + flag.Parse() + config := config.GetConfigOrDie() + + iargs := args.CreateInjectArgs(config) + var _ = iargs.CreateRecorder("ControllerName") +} diff --git a/pkg/inject/run/example_args_test.go b/pkg/inject/run/example_args_test.go new file mode 100644 index 0000000000..7b29535a1f --- /dev/null +++ b/pkg/inject/run/example_args_test.go @@ -0,0 +1,29 @@ +/* +Copyright 2017 The Kubernetes 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 run_test + +import "github.com/kubernetes-sigs/kubebuilder/pkg/inject/run" + +func Example() { + // Create arguments for running Controllers + var _ = run.CreateRunArguments() +} + +func ExampleCreateInjectArgs() { + // Create arguments for running Controllers + var _ = run.CreateRunArguments() +}