sigs.k8s.io/cluster-api@v1.6.3/controllers/alias.go (about)

     1  /*
     2  Copyright 2022 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 controllers
    18  
    19  import (
    20  	"context"
    21  	"time"
    22  
    23  	ctrl "sigs.k8s.io/controller-runtime"
    24  	"sigs.k8s.io/controller-runtime/pkg/client"
    25  	"sigs.k8s.io/controller-runtime/pkg/controller"
    26  
    27  	"sigs.k8s.io/cluster-api/controllers/remote"
    28  	clustercontroller "sigs.k8s.io/cluster-api/internal/controllers/cluster"
    29  	clusterclasscontroller "sigs.k8s.io/cluster-api/internal/controllers/clusterclass"
    30  	machinecontroller "sigs.k8s.io/cluster-api/internal/controllers/machine"
    31  	machinedeploymentcontroller "sigs.k8s.io/cluster-api/internal/controllers/machinedeployment"
    32  	machinehealthcheckcontroller "sigs.k8s.io/cluster-api/internal/controllers/machinehealthcheck"
    33  	machinesetcontroller "sigs.k8s.io/cluster-api/internal/controllers/machineset"
    34  	clustertopologycontroller "sigs.k8s.io/cluster-api/internal/controllers/topology/cluster"
    35  	machinedeploymenttopologycontroller "sigs.k8s.io/cluster-api/internal/controllers/topology/machinedeployment"
    36  	machinesettopologycontroller "sigs.k8s.io/cluster-api/internal/controllers/topology/machineset"
    37  	runtimeclient "sigs.k8s.io/cluster-api/internal/runtime/client"
    38  )
    39  
    40  // Following types provides access to reconcilers implemented in internal/controllers, thus
    41  // allowing users to provide a single binary "batteries included" with Cluster API and providers of choice.
    42  
    43  // ClusterReconciler reconciles a Cluster object.
    44  type ClusterReconciler struct {
    45  	Client                    client.Client
    46  	UnstructuredCachingClient client.Client
    47  	APIReader                 client.Reader
    48  
    49  	// WatchFilterValue is the label value used to filter events prior to reconciliation.
    50  	WatchFilterValue string
    51  }
    52  
    53  func (r *ClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
    54  	return (&clustercontroller.Reconciler{
    55  		Client:                    r.Client,
    56  		UnstructuredCachingClient: r.UnstructuredCachingClient,
    57  		APIReader:                 r.APIReader,
    58  		WatchFilterValue:          r.WatchFilterValue,
    59  	}).SetupWithManager(ctx, mgr, options)
    60  }
    61  
    62  // MachineReconciler reconciles a Machine object.
    63  type MachineReconciler struct {
    64  	Client                    client.Client
    65  	UnstructuredCachingClient client.Client
    66  	APIReader                 client.Reader
    67  	Tracker                   *remote.ClusterCacheTracker
    68  
    69  	// WatchFilterValue is the label value used to filter events prior to reconciliation.
    70  	WatchFilterValue string
    71  
    72  	// NodeDrainClientTimeout timeout of the client used for draining nodes.
    73  	NodeDrainClientTimeout time.Duration
    74  }
    75  
    76  func (r *MachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
    77  	return (&machinecontroller.Reconciler{
    78  		Client:                    r.Client,
    79  		UnstructuredCachingClient: r.UnstructuredCachingClient,
    80  		APIReader:                 r.APIReader,
    81  		Tracker:                   r.Tracker,
    82  		WatchFilterValue:          r.WatchFilterValue,
    83  		NodeDrainClientTimeout:    r.NodeDrainClientTimeout,
    84  	}).SetupWithManager(ctx, mgr, options)
    85  }
    86  
    87  // MachineSetReconciler reconciles a MachineSet object.
    88  type MachineSetReconciler struct {
    89  	Client                    client.Client
    90  	UnstructuredCachingClient client.Client
    91  	APIReader                 client.Reader
    92  	Tracker                   *remote.ClusterCacheTracker
    93  
    94  	// WatchFilterValue is the label value used to filter events prior to reconciliation.
    95  	WatchFilterValue string
    96  }
    97  
    98  func (r *MachineSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
    99  	return (&machinesetcontroller.Reconciler{
   100  		Client:                    r.Client,
   101  		UnstructuredCachingClient: r.UnstructuredCachingClient,
   102  		APIReader:                 r.APIReader,
   103  		Tracker:                   r.Tracker,
   104  		WatchFilterValue:          r.WatchFilterValue,
   105  	}).SetupWithManager(ctx, mgr, options)
   106  }
   107  
   108  // MachineDeploymentReconciler reconciles a MachineDeployment object.
   109  type MachineDeploymentReconciler struct {
   110  	Client                    client.Client
   111  	UnstructuredCachingClient client.Client
   112  	APIReader                 client.Reader
   113  
   114  	// WatchFilterValue is the label value used to filter events prior to reconciliation.
   115  	WatchFilterValue string
   116  }
   117  
   118  func (r *MachineDeploymentReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
   119  	return (&machinedeploymentcontroller.Reconciler{
   120  		Client:                    r.Client,
   121  		UnstructuredCachingClient: r.UnstructuredCachingClient,
   122  		APIReader:                 r.APIReader,
   123  		WatchFilterValue:          r.WatchFilterValue,
   124  	}).SetupWithManager(ctx, mgr, options)
   125  }
   126  
   127  // MachineHealthCheckReconciler reconciles a MachineHealthCheck object.
   128  type MachineHealthCheckReconciler struct {
   129  	Client  client.Client
   130  	Tracker *remote.ClusterCacheTracker
   131  
   132  	// WatchFilterValue is the label value used to filter events prior to reconciliation.
   133  	WatchFilterValue string
   134  }
   135  
   136  func (r *MachineHealthCheckReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
   137  	return (&machinehealthcheckcontroller.Reconciler{
   138  		Client:           r.Client,
   139  		Tracker:          r.Tracker,
   140  		WatchFilterValue: r.WatchFilterValue,
   141  	}).SetupWithManager(ctx, mgr, options)
   142  }
   143  
   144  // ClusterTopologyReconciler reconciles a managed topology for a Cluster object.
   145  type ClusterTopologyReconciler struct {
   146  	Client  client.Client
   147  	Tracker *remote.ClusterCacheTracker
   148  	// APIReader is used to list MachineSets directly via the API server to avoid
   149  	// race conditions caused by an outdated cache.
   150  	APIReader client.Reader
   151  
   152  	RuntimeClient runtimeclient.Client
   153  
   154  	// WatchFilterValue is the label value used to filter events prior to reconciliation.
   155  	WatchFilterValue string
   156  
   157  	// UnstructuredCachingClient provides a client that forces caching of unstructured objects,
   158  	// thus allowing to optimize reads for templates or provider specific objects in a managed topology.
   159  	UnstructuredCachingClient client.Client
   160  }
   161  
   162  func (r *ClusterTopologyReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
   163  	return (&clustertopologycontroller.Reconciler{
   164  		Client:                    r.Client,
   165  		APIReader:                 r.APIReader,
   166  		Tracker:                   r.Tracker,
   167  		RuntimeClient:             r.RuntimeClient,
   168  		UnstructuredCachingClient: r.UnstructuredCachingClient,
   169  		WatchFilterValue:          r.WatchFilterValue,
   170  	}).SetupWithManager(ctx, mgr, options)
   171  }
   172  
   173  // MachineDeploymentTopologyReconciler deletes referenced templates during deletion of topology-owned MachineDeployments.
   174  // The templates are only deleted, if they are not used in other MachineDeployments or MachineSets which are not in deleting state,
   175  // i.e. the templates would otherwise be orphaned after the MachineDeployment deletion completes.
   176  // Note: To achieve this the cluster topology controller sets a finalizer to hook into the MachineDeployment deletions.
   177  type MachineDeploymentTopologyReconciler struct {
   178  	Client client.Client
   179  	// APIReader is used to list MachineSets directly via the API server to avoid
   180  	// race conditions caused by an outdated cache.
   181  	APIReader        client.Reader
   182  	WatchFilterValue string
   183  }
   184  
   185  func (r *MachineDeploymentTopologyReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
   186  	return (&machinedeploymenttopologycontroller.Reconciler{
   187  		Client:           r.Client,
   188  		APIReader:        r.APIReader,
   189  		WatchFilterValue: r.WatchFilterValue,
   190  	}).SetupWithManager(ctx, mgr, options)
   191  }
   192  
   193  // MachineSetTopologyReconciler deletes referenced templates during deletion of topology-owned MachineSets.
   194  // The templates are only deleted, if they are not used in other MachineDeployments or MachineSets which are not in deleting state,
   195  // i.e. the templates would otherwise be orphaned after the MachineSet deletion completes.
   196  // Note: To achieve this the reconciler sets a finalizer to hook into the MachineSet deletions.
   197  type MachineSetTopologyReconciler struct {
   198  	Client client.Client
   199  	// APIReader is used to list MachineSets directly via the API server to avoid
   200  	// race conditions caused by an outdated cache.
   201  	APIReader        client.Reader
   202  	WatchFilterValue string
   203  }
   204  
   205  func (r *MachineSetTopologyReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
   206  	return (&machinesettopologycontroller.Reconciler{
   207  		Client:           r.Client,
   208  		APIReader:        r.APIReader,
   209  		WatchFilterValue: r.WatchFilterValue,
   210  	}).SetupWithManager(ctx, mgr, options)
   211  }
   212  
   213  // ClusterClassReconciler reconciles the ClusterClass object.
   214  type ClusterClassReconciler struct {
   215  	Client    client.Client
   216  	APIReader client.Reader
   217  
   218  	// RuntimeClient is a client for calling runtime extensions.
   219  	RuntimeClient runtimeclient.Client
   220  
   221  	// WatchFilterValue is the label value used to filter events prior to reconciliation.
   222  	WatchFilterValue string
   223  
   224  	// UnstructuredCachingClient provides a client that forces caching of unstructured objects,
   225  	// thus allowing to optimize reads for templates or provider specific objects.
   226  	UnstructuredCachingClient client.Client
   227  }
   228  
   229  func (r *ClusterClassReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
   230  	return (&clusterclasscontroller.Reconciler{
   231  		Client:                    r.Client,
   232  		APIReader:                 r.APIReader,
   233  		RuntimeClient:             r.RuntimeClient,
   234  		UnstructuredCachingClient: r.UnstructuredCachingClient,
   235  		WatchFilterValue:          r.WatchFilterValue,
   236  	}).SetupWithManager(ctx, mgr, options)
   237  }