sigs.k8s.io/cluster-api-provider-aws@v1.5.5/pkg/cloud/interfaces.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 cloud 18 19 import ( 20 awsclient "github.com/aws/aws-sdk-go/aws/client" 21 "github.com/go-logr/logr" 22 "sigs.k8s.io/controller-runtime/pkg/client" 23 24 infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1" 25 "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/throttle" 26 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" 27 "sigs.k8s.io/cluster-api/util/conditions" 28 ) 29 30 // Session represents an AWS session. 31 type Session interface { 32 Session() awsclient.ConfigProvider 33 ServiceLimiter(string) *throttle.ServiceLimiter 34 } 35 36 // ScopeUsage is used to indicate which controller is using a scope. 37 type ScopeUsage interface { 38 // ControllerName returns the name of the controller that created the scope 39 ControllerName() string 40 } 41 42 // ClusterObject represents a AWS cluster object. 43 type ClusterObject interface { 44 conditions.Setter 45 } 46 47 // Logger represents the ability to log messages, both errors and not. 48 type Logger interface { 49 // Enabled tests whether this Logger is enabled. For example, commandline 50 // flags might be used to set the logging verbosity and disable some info 51 // logs. 52 Enabled() bool 53 54 // Info logs a non-error message with the given key/value pairs as context. 55 // 56 // The msg argument should be used to add some constant description to 57 // the log line. The key/value pairs can then be used to add additional 58 // variable information. The key/value pairs should alternate string 59 // keys and arbitrary values. 60 Info(msg string, keysAndValues ...interface{}) 61 62 // Error logs an error, with the given message and key/value pairs as context. 63 // It functions similarly to calling Info with the "error" named value, but may 64 // have unique behavior, and should be preferred for logging errors (see the 65 // package documentations for more information). 66 // 67 // The msg field should be used to add context to any underlying error, 68 // while the err field should be used to attach the actual error that 69 // triggered this log line, if present. 70 Error(err error, msg string, keysAndValues ...interface{}) 71 72 // V returns a Logger value for a specific verbosity level, relative to 73 // this Logger. In other words, V values are additive. V higher verbosity 74 // level means a log message is less important. It's illegal to pass a log 75 // level less than zero. 76 V(level int) logr.Logger 77 78 // WithValues adds some key-value pairs of context to a logger. 79 // See Info for documentation on how key/value pairs work. 80 WithValues(keysAndValues ...interface{}) logr.Logger 81 82 // WithName adds a new element to the logger's name. 83 // Successive calls with WithName continue to append 84 // suffixes to the logger's name. It's strongly recommended 85 // that name segments contain only letters, digits, and hyphens 86 // (see the package documentation for more information). 87 WithName(name string) logr.Logger 88 } 89 90 // ClusterScoper is the interface for a cluster scope. 91 type ClusterScoper interface { 92 Logger 93 Session 94 ScopeUsage 95 96 // Name returns the CAPI cluster name. 97 Name() string 98 // Namespace returns the cluster namespace. 99 Namespace() string 100 // AWSClusterName returns the AWS cluster name. 101 InfraClusterName() string 102 // Region returns the cluster region. 103 Region() string 104 // KubernetesClusterName is the name of the Kubernetes cluster. For EKS this 105 // will differ to the CAPI cluster name 106 KubernetesClusterName() string 107 108 // InfraCluster returns the AWS infrastructure cluster object. 109 InfraCluster() ClusterObject 110 111 // Cluster returns the cluster object. 112 ClusterObj() ClusterObject 113 114 // IdentityRef returns the AWS infrastructure cluster identityRef. 115 IdentityRef() *infrav1.AWSIdentityReference 116 117 // ListOptionsLabelSelector returns a ListOptions with a label selector for clusterName. 118 ListOptionsLabelSelector() client.ListOption 119 // APIServerPort returns the port to use when communicating with the API server. 120 APIServerPort() int32 121 // AdditionalTags returns any tags that you would like to attach to AWS resources. The returned value will never be nil. 122 AdditionalTags() infrav1.Tags 123 // SetFailureDomain sets the infrastructure provider failure domain key to the spec given as input. 124 SetFailureDomain(id string, spec clusterv1.FailureDomainSpec) 125 126 // PatchObject persists the cluster configuration and status. 127 PatchObject() error 128 // Close closes the current scope persisting the cluster configuration and status. 129 Close() error 130 }