sigs.k8s.io/cluster-api-provider-aws@v1.5.5/pkg/cloud/services/eks/service.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 eks
    18  
    19  import (
    20  	"github.com/aws/aws-sdk-go/aws/request"
    21  	"github.com/aws/aws-sdk-go/service/autoscaling/autoscalingiface"
    22  	"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
    23  	"github.com/aws/aws-sdk-go/service/eks"
    24  	"github.com/aws/aws-sdk-go/service/eks/eksiface"
    25  	"github.com/aws/aws-sdk-go/service/sts/stsiface"
    26  
    27  	"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/scope"
    28  	"sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/services/eks/iam"
    29  )
    30  
    31  // EKSAPI defines the EKS API interface.
    32  type EKSAPI interface {
    33  	eksiface.EKSAPI
    34  	WaitUntilClusterUpdating(input *eks.DescribeClusterInput, opts ...request.WaiterOption) error
    35  }
    36  
    37  // EKSClient defines a wrapper over EKS API.
    38  type EKSClient struct {
    39  	eksiface.EKSAPI
    40  }
    41  
    42  // Service holds a collection of interfaces.
    43  // The interfaces are broken down like this to group functions together.
    44  // One alternative is to have a large list of functions from the ec2 client.
    45  type Service struct {
    46  	scope     *scope.ManagedControlPlaneScope
    47  	EC2Client ec2iface.EC2API
    48  	EKSClient EKSAPI
    49  	iam.IAMService
    50  	STSClient stsiface.STSAPI
    51  }
    52  
    53  // NewService returns a new service given the api clients.
    54  func NewService(controlPlaneScope *scope.ManagedControlPlaneScope) *Service {
    55  	return &Service{
    56  		scope:     controlPlaneScope,
    57  		EC2Client: scope.NewEC2Client(controlPlaneScope, controlPlaneScope, controlPlaneScope, controlPlaneScope.ControlPlane),
    58  		EKSClient: EKSClient{
    59  			EKSAPI: scope.NewEKSClient(controlPlaneScope, controlPlaneScope, controlPlaneScope, controlPlaneScope.ControlPlane),
    60  		},
    61  		IAMService: iam.IAMService{
    62  			Logger:    controlPlaneScope.Logger,
    63  			IAMClient: scope.NewIAMClient(controlPlaneScope, controlPlaneScope, controlPlaneScope, controlPlaneScope.ControlPlane),
    64  		},
    65  		STSClient: scope.NewSTSClient(controlPlaneScope, controlPlaneScope, controlPlaneScope, controlPlaneScope.ControlPlane),
    66  	}
    67  }
    68  
    69  // NodegroupService holds a collection of interfaces.
    70  // The interfaces are broken down like this to group functions together.
    71  // One alternative is to have a large list of functions from the ec2 client.
    72  type NodegroupService struct {
    73  	scope             *scope.ManagedMachinePoolScope
    74  	AutoscalingClient autoscalingiface.AutoScalingAPI
    75  	EKSClient         eksiface.EKSAPI
    76  	iam.IAMService
    77  	STSClient stsiface.STSAPI
    78  }
    79  
    80  // NewNodegroupService returns a new service given the api clients.
    81  func NewNodegroupService(machinePoolScope *scope.ManagedMachinePoolScope) *NodegroupService {
    82  	return &NodegroupService{
    83  		scope:             machinePoolScope,
    84  		AutoscalingClient: scope.NewASGClient(machinePoolScope, machinePoolScope, machinePoolScope, machinePoolScope.ManagedMachinePool),
    85  		EKSClient:         scope.NewEKSClient(machinePoolScope, machinePoolScope, machinePoolScope, machinePoolScope.ManagedMachinePool),
    86  		IAMService: iam.IAMService{
    87  			Logger:    machinePoolScope.Logger,
    88  			IAMClient: scope.NewIAMClient(machinePoolScope, machinePoolScope, machinePoolScope, machinePoolScope.ManagedMachinePool),
    89  		},
    90  		STSClient: scope.NewSTSClient(machinePoolScope, machinePoolScope, machinePoolScope, machinePoolScope.ManagedMachinePool),
    91  	}
    92  }
    93  
    94  // FargateService holds a collection of interfaces.
    95  // The interfaces are broken down like this to group functions together.
    96  type FargateService struct {
    97  	scope     *scope.FargateProfileScope
    98  	EKSClient eksiface.EKSAPI
    99  	iam.IAMService
   100  	STSClient stsiface.STSAPI
   101  }
   102  
   103  // NewFargateService returns a new service given the api clients.
   104  func NewFargateService(fargatePoolScope *scope.FargateProfileScope) *FargateService {
   105  	return &FargateService{
   106  		scope:     fargatePoolScope,
   107  		EKSClient: scope.NewEKSClient(fargatePoolScope, fargatePoolScope, fargatePoolScope, fargatePoolScope.FargateProfile),
   108  		IAMService: iam.IAMService{
   109  			Logger:    fargatePoolScope.Logger,
   110  			IAMClient: scope.NewIAMClient(fargatePoolScope, fargatePoolScope, fargatePoolScope, fargatePoolScope.FargateProfile),
   111  		},
   112  		STSClient: scope.NewSTSClient(fargatePoolScope, fargatePoolScope, fargatePoolScope, fargatePoolScope.FargateProfile),
   113  	}
   114  }