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

✨ Deprecate Inject interface #1322

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions pkg/runtime/inject/inject.go
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package inject is used by a Manager to inject types into Sources, EventHandlers, Predicates, and Reconciles.
// Deprecated: Use manager.Options fields directly. This package will be removed in v0.10.
package inject

import (
Expand All @@ -24,8 +26,17 @@ import (

"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/internal/log"
)

// log is specifically to add a warning message for injectors.
var log = logf.RuntimeLog.WithName("injectors-warning")

// logWarningMsg logs a warning message if inject is used
func logWarningMsg() {
log.Info("Injectors are deprecated, and will be removed in v0.10.x")
}

// Cache is used by the ControllerManager to inject Cache into Sources, EventHandlers, Predicates, and
// Reconciles
type Cache interface {
Expand All @@ -36,6 +47,7 @@ type Cache interface {
// false if i does not implement Cache.
func CacheInto(c cache.Cache, i interface{}) (bool, error) {
if s, ok := i.(Cache); ok {
logWarningMsg()
return true, s.InjectCache(c)
}
return false, nil
Expand All @@ -50,6 +62,7 @@ type APIReader interface {
// Returns false if i does not implement APIReader
func APIReaderInto(reader client.Reader, i interface{}) (bool, error) {
if s, ok := i.(APIReader); ok {
logWarningMsg()
return true, s.InjectAPIReader(reader)
}
return false, nil
Expand All @@ -65,6 +78,7 @@ type Config interface {
// false if i does not implement Config.
func ConfigInto(config *rest.Config, i interface{}) (bool, error) {
if s, ok := i.(Config); ok {
logWarningMsg()
return true, s.InjectConfig(config)
}
return false, nil
Expand All @@ -80,6 +94,7 @@ type Client interface {
// false if i does not implement Client.
func ClientInto(client client.Client, i interface{}) (bool, error) {
if s, ok := i.(Client); ok {
logWarningMsg()
return true, s.InjectClient(client)
}
return false, nil
Expand All @@ -95,6 +110,7 @@ type Scheme interface {
// false if i does not implement Scheme.
func SchemeInto(scheme *runtime.Scheme, i interface{}) (bool, error) {
if is, ok := i.(Scheme); ok {
logWarningMsg()
return true, is.InjectScheme(scheme)
}
return false, nil
Expand All @@ -110,6 +126,7 @@ type Stoppable interface {
// Returns false if i does not implement Stoppable.
func StopChannelInto(stop <-chan struct{}, i interface{}) (bool, error) {
if s, ok := i.(Stoppable); ok {
logWarningMsg()
return true, s.InjectStopChannel(stop)
}
return false, nil
Expand All @@ -124,6 +141,7 @@ type Mapper interface {
// Returns false if i does not implement Mapper.
func MapperInto(mapper meta.RESTMapper, i interface{}) (bool, error) {
if m, ok := i.(Mapper); ok {
logWarningMsg()
return true, m.InjectMapper(mapper)
}
return false, nil
Expand All @@ -141,6 +159,7 @@ type Injector interface {
// false if i does not implement Injector.
func InjectorInto(f Func, i interface{}) (bool, error) {
if ii, ok := i.(Injector); ok {
logWarningMsg()
return true, ii.InjectFunc(f)
}
return false, nil
Expand All @@ -156,6 +175,7 @@ type Logger interface {
// returning true if a InjectLogger was called, and false otherwise.
func LoggerInto(l logr.Logger, i interface{}) (bool, error) {
if injectable, wantsLogger := i.(Logger); wantsLogger {
logWarningMsg()
return true, injectable.InjectLogger(l)
}
return false, nil
Expand Down