...

Source file src/sigs.k8s.io/controller-runtime/pkg/cluster/internal.go

Documentation: sigs.k8s.io/controller-runtime/pkg/cluster

     1  /*
     2  Copyright 2020 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package cluster
    18  
    19  import (
    20  	"context"
    21  	"net/http"
    22  
    23  	"github.com/go-logr/logr"
    24  	"k8s.io/apimachinery/pkg/api/meta"
    25  	"k8s.io/apimachinery/pkg/runtime"
    26  	"k8s.io/client-go/rest"
    27  	"k8s.io/client-go/tools/record"
    28  
    29  	"sigs.k8s.io/controller-runtime/pkg/cache"
    30  	"sigs.k8s.io/controller-runtime/pkg/client"
    31  	intrec "sigs.k8s.io/controller-runtime/pkg/internal/recorder"
    32  )
    33  
    34  type cluster struct {
    35  	// config is the rest.config used to talk to the apiserver.  Required.
    36  	config *rest.Config
    37  
    38  	httpClient *http.Client
    39  	scheme     *runtime.Scheme
    40  	cache      cache.Cache
    41  	client     client.Client
    42  
    43  	// apiReader is the reader that will make requests to the api server and not the cache.
    44  	apiReader client.Reader
    45  
    46  	// fieldIndexes knows how to add field indexes over the Cache used by this controller,
    47  	// which can later be consumed via field selectors from the injected client.
    48  	fieldIndexes client.FieldIndexer
    49  
    50  	// recorderProvider is used to generate event recorders that will be injected into Controllers
    51  	// (and EventHandlers, Sources and Predicates).
    52  	recorderProvider *intrec.Provider
    53  
    54  	// mapper is used to map resources to kind, and map kind and version.
    55  	mapper meta.RESTMapper
    56  
    57  	// Logger is the logger that should be used by this manager.
    58  	// If none is set, it defaults to log.Log global logger.
    59  	logger logr.Logger
    60  }
    61  
    62  func (c *cluster) GetConfig() *rest.Config {
    63  	return c.config
    64  }
    65  
    66  func (c *cluster) GetHTTPClient() *http.Client {
    67  	return c.httpClient
    68  }
    69  
    70  func (c *cluster) GetClient() client.Client {
    71  	return c.client
    72  }
    73  
    74  func (c *cluster) GetScheme() *runtime.Scheme {
    75  	return c.scheme
    76  }
    77  
    78  func (c *cluster) GetFieldIndexer() client.FieldIndexer {
    79  	return c.fieldIndexes
    80  }
    81  
    82  func (c *cluster) GetCache() cache.Cache {
    83  	return c.cache
    84  }
    85  
    86  func (c *cluster) GetEventRecorderFor(name string) record.EventRecorder {
    87  	return c.recorderProvider.GetEventRecorderFor(name)
    88  }
    89  
    90  func (c *cluster) GetRESTMapper() meta.RESTMapper {
    91  	return c.mapper
    92  }
    93  
    94  func (c *cluster) GetAPIReader() client.Reader {
    95  	return c.apiReader
    96  }
    97  
    98  func (c *cluster) GetLogger() logr.Logger {
    99  	return c.logger
   100  }
   101  
   102  func (c *cluster) Start(ctx context.Context) error {
   103  	defer c.recorderProvider.Stop(ctx)
   104  	return c.cache.Start(ctx)
   105  }
   106  

View as plain text