sigs.k8s.io/cluster-api@v1.7.1/controlplane/kubeadm/internal/controllers/fakes_test.go (about)

     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 controllers
    18  
    19  import (
    20  	"context"
    21  	"time"
    22  
    23  	"github.com/blang/semver/v4"
    24  	"github.com/pkg/errors"
    25  	"sigs.k8s.io/controller-runtime/pkg/client"
    26  
    27  	clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
    28  	bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
    29  	"sigs.k8s.io/cluster-api/controlplane/kubeadm/internal"
    30  	expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
    31  	"sigs.k8s.io/cluster-api/util/collections"
    32  )
    33  
    34  type fakeManagementCluster struct {
    35  	// TODO: once all client interactions are moved to the Management cluster this can go away
    36  	Management   *internal.Management
    37  	Machines     collections.Machines
    38  	MachinePools *expv1.MachinePoolList
    39  	Workload     fakeWorkloadCluster
    40  	Reader       client.Reader
    41  }
    42  
    43  func (f *fakeManagementCluster) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
    44  	return f.Reader.Get(ctx, key, obj, opts...)
    45  }
    46  
    47  func (f *fakeManagementCluster) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error {
    48  	return f.Reader.List(ctx, list, opts...)
    49  }
    50  
    51  func (f *fakeManagementCluster) GetWorkloadCluster(_ context.Context, _ client.ObjectKey) (internal.WorkloadCluster, error) {
    52  	return f.Workload, nil
    53  }
    54  
    55  func (f *fakeManagementCluster) GetMachinesForCluster(c context.Context, cluster *clusterv1.Cluster, filters ...collections.Func) (collections.Machines, error) {
    56  	if f.Management != nil {
    57  		return f.Management.GetMachinesForCluster(c, cluster, filters...)
    58  	}
    59  	return f.Machines, nil
    60  }
    61  
    62  func (f *fakeManagementCluster) GetMachinePoolsForCluster(c context.Context, cluster *clusterv1.Cluster) (*expv1.MachinePoolList, error) {
    63  	if f.Management != nil {
    64  		return f.Management.GetMachinePoolsForCluster(c, cluster)
    65  	}
    66  	return f.MachinePools, nil
    67  }
    68  
    69  type fakeWorkloadCluster struct {
    70  	*internal.Workload
    71  	Status                     internal.ClusterStatus
    72  	EtcdMembersResult          []string
    73  	APIServerCertificateExpiry *time.Time
    74  }
    75  
    76  func (f fakeWorkloadCluster) ForwardEtcdLeadership(_ context.Context, _ *clusterv1.Machine, leaderCandidate *clusterv1.Machine) error {
    77  	if leaderCandidate == nil {
    78  		return errors.New("leaderCandidate is nil")
    79  	}
    80  	return nil
    81  }
    82  
    83  func (f fakeWorkloadCluster) ReconcileEtcdMembers(_ context.Context, _ []string, _ semver.Version) ([]string, error) {
    84  	return nil, nil
    85  }
    86  
    87  func (f fakeWorkloadCluster) ClusterStatus(_ context.Context) (internal.ClusterStatus, error) {
    88  	return f.Status, nil
    89  }
    90  
    91  func (f fakeWorkloadCluster) GetAPIServerCertificateExpiry(_ context.Context, _ *bootstrapv1.KubeadmConfig, _ string) (*time.Time, error) {
    92  	return f.APIServerCertificateExpiry, nil
    93  }
    94  
    95  func (f fakeWorkloadCluster) AllowBootstrapTokensToGetNodes(_ context.Context) error {
    96  	return nil
    97  }
    98  
    99  func (f fakeWorkloadCluster) AllowClusterAdminPermissions(_ context.Context, _ semver.Version) error {
   100  	return nil
   101  }
   102  
   103  func (f fakeWorkloadCluster) ReconcileKubeletRBACRole(_ context.Context, _ semver.Version) error {
   104  	return nil
   105  }
   106  
   107  func (f fakeWorkloadCluster) ReconcileKubeletRBACBinding(_ context.Context, _ semver.Version) error {
   108  	return nil
   109  }
   110  
   111  func (f fakeWorkloadCluster) UpdateKubernetesVersionInKubeadmConfigMap(semver.Version) func(*bootstrapv1.ClusterConfiguration) {
   112  	return nil
   113  }
   114  
   115  func (f fakeWorkloadCluster) UpdateEtcdLocalInKubeadmConfigMap(*bootstrapv1.LocalEtcd) func(*bootstrapv1.ClusterConfiguration) {
   116  	return nil
   117  }
   118  
   119  func (f fakeWorkloadCluster) UpdateKubeletConfigMap(_ context.Context, _ semver.Version) error {
   120  	return nil
   121  }
   122  
   123  func (f fakeWorkloadCluster) RemoveEtcdMemberForMachine(_ context.Context, _ *clusterv1.Machine) error {
   124  	return nil
   125  }
   126  
   127  func (f fakeWorkloadCluster) RemoveMachineFromKubeadmConfigMap(_ context.Context, _ *clusterv1.Machine, _ semver.Version) error {
   128  	return nil
   129  }
   130  
   131  func (f fakeWorkloadCluster) EtcdMembers(_ context.Context) ([]string, error) {
   132  	return f.EtcdMembersResult, nil
   133  }
   134  
   135  func (f fakeWorkloadCluster) UpdateClusterConfiguration(context.Context, semver.Version, ...func(*bootstrapv1.ClusterConfiguration)) error {
   136  	return nil
   137  }
   138  
   139  type fakeMigrator struct {
   140  	migrateCalled    bool
   141  	migrateErr       error
   142  	migratedCorefile string
   143  }
   144  
   145  func (m *fakeMigrator) Migrate(string, string, string, bool) (string, error) {
   146  	m.migrateCalled = true
   147  	if m.migrateErr != nil {
   148  		return "", m.migrateErr
   149  	}
   150  	return m.migratedCorefile, nil
   151  }