@@ -34,26 +34,26 @@ import (
34
34
// awsInstanceRegMatch represents Regex Match for AWS instance.
35
35
var awsInstanceRegMatch = regexp .MustCompile ("^i-[^/]*$" )
36
36
37
- // awsInstanceID represents the ID of the instance in the AWS API, e.g. i-12345678
37
+ // InstanceID represents the ID of the instance in the AWS API, e.g. i-12345678
38
38
// The "traditional" format is "i-12345678"
39
39
// A new longer format is also being introduced: "i-12345678abcdef01"
40
40
// We should not assume anything about the length or format, though it seems
41
41
// reasonable to assume that instances will continue to start with "i-".
42
- type awsInstanceID string
42
+ type InstanceID string
43
43
44
- func (i awsInstanceID ) awsString () * string {
44
+ func (i InstanceID ) awsString () * string {
45
45
return aws .String (string (i ))
46
46
}
47
47
48
- // kubernetesInstanceID represents the id for an instance in the kubernetes API;
48
+ // KubernetesInstanceID represents the id for an instance in the kubernetes API;
49
49
// the following form
50
50
// * aws:///<zone>/<awsInstanceId>
51
51
// * aws:////<awsInstanceId>
52
52
// * <awsInstanceId>
53
- type kubernetesInstanceID string
53
+ type KubernetesInstanceID string
54
54
55
- // mapToAWSInstanceID extracts the awsInstanceID from the kubernetesInstanceID
56
- func (name kubernetesInstanceID ) mapToAWSInstanceID () (awsInstanceID , error ) {
55
+ // MapToAWSInstanceID extracts the InstanceID from the KubernetesInstanceID
56
+ func (name KubernetesInstanceID ) MapToAWSInstanceID () (InstanceID , error ) {
57
57
s := string (name )
58
58
59
59
if ! strings .HasPrefix (s , "aws://" ) {
@@ -85,17 +85,17 @@ func (name kubernetesInstanceID) mapToAWSInstanceID() (awsInstanceID, error) {
85
85
return "" , fmt .Errorf ("Invalid format for AWS instance (%s)" , name )
86
86
}
87
87
88
- return awsInstanceID (awsID ), nil
88
+ return InstanceID (awsID ), nil
89
89
}
90
90
91
- // mapToAWSInstanceID extracts the awsInstanceIDs from the Nodes, returning an error if a Node cannot be mapped
92
- func mapToAWSInstanceIDs (nodes []* v1.Node ) ([]awsInstanceID , error ) {
93
- var instanceIDs []awsInstanceID
91
+ // mapToAWSInstanceID extracts the InstanceIDs from the Nodes, returning an error if a Node cannot be mapped
92
+ func mapToAWSInstanceIDs (nodes []* v1.Node ) ([]InstanceID , error ) {
93
+ var instanceIDs []InstanceID
94
94
for _ , node := range nodes {
95
95
if node .Spec .ProviderID == "" {
96
96
return nil , fmt .Errorf ("node %q did not have ProviderID set" , node .Name )
97
97
}
98
- instanceID , err := kubernetesInstanceID (node .Spec .ProviderID ).mapToAWSInstanceID ()
98
+ instanceID , err := KubernetesInstanceID (node .Spec .ProviderID ).MapToAWSInstanceID ()
99
99
if err != nil {
100
100
return nil , fmt .Errorf ("unable to parse ProviderID %q for node %q" , node .Spec .ProviderID , node .Name )
101
101
}
@@ -105,15 +105,15 @@ func mapToAWSInstanceIDs(nodes []*v1.Node) ([]awsInstanceID, error) {
105
105
return instanceIDs , nil
106
106
}
107
107
108
- // mapToAWSInstanceIDsTolerant extracts the awsInstanceIDs from the Nodes, skipping Nodes that cannot be mapped
109
- func mapToAWSInstanceIDsTolerant (nodes []* v1.Node ) []awsInstanceID {
110
- var instanceIDs []awsInstanceID
108
+ // mapToAWSInstanceIDsTolerant extracts the InstanceIDs from the Nodes, skipping Nodes that cannot be mapped
109
+ func mapToAWSInstanceIDsTolerant (nodes []* v1.Node ) []InstanceID {
110
+ var instanceIDs []InstanceID
111
111
for _ , node := range nodes {
112
112
if node .Spec .ProviderID == "" {
113
113
klog .Warningf ("node %q did not have ProviderID set" , node .Name )
114
114
continue
115
115
}
116
- instanceID , err := kubernetesInstanceID (node .Spec .ProviderID ).mapToAWSInstanceID ()
116
+ instanceID , err := KubernetesInstanceID (node .Spec .ProviderID ).MapToAWSInstanceID ()
117
117
if err != nil {
118
118
klog .Warningf ("unable to parse ProviderID %q for node %q" , node .Spec .ProviderID , node .Name )
119
119
continue
@@ -125,7 +125,7 @@ func mapToAWSInstanceIDsTolerant(nodes []*v1.Node) []awsInstanceID {
125
125
}
126
126
127
127
// Gets the full information about this instance from the EC2 API
128
- func describeInstance (ec2Client EC2 , instanceID awsInstanceID ) (* ec2.Instance , error ) {
128
+ func describeInstance (ec2Client EC2 , instanceID InstanceID ) (* ec2.Instance , error ) {
129
129
request := & ec2.DescribeInstancesInput {
130
130
InstanceIds : []* string {instanceID .awsString ()},
131
131
}
@@ -164,9 +164,9 @@ func (c *instanceCache) describeAllInstancesUncached() (*allInstancesSnapshot, e
164
164
return nil , err
165
165
}
166
166
167
- m := make (map [awsInstanceID ]* ec2.Instance )
167
+ m := make (map [InstanceID ]* ec2.Instance )
168
168
for _ , i := range instances {
169
- id := awsInstanceID (aws .StringValue (i .InstanceId ))
169
+ id := InstanceID (aws .StringValue (i .InstanceId ))
170
170
m [id ] = i
171
171
}
172
172
@@ -191,9 +191,9 @@ type cacheCriteria struct {
191
191
// If set to 0 (i.e. unset), cached values will not time out because of age.
192
192
MaxAge time.Duration
193
193
194
- // HasInstances is a list of awsInstanceIDs that must be in a cached snapshot for it to be considered valid.
194
+ // HasInstances is a list of InstanceIDs that must be in a cached snapshot for it to be considered valid.
195
195
// If an instance is not found in the cached snapshot, the snapshot be ignored and we will re-fetch.
196
- HasInstances []awsInstanceID
196
+ HasInstances []InstanceID
197
197
}
198
198
199
199
// describeAllInstancesCached returns all instances, using cached results if applicable
@@ -257,12 +257,12 @@ func (s *allInstancesSnapshot) MeetsCriteria(criteria cacheCriteria) bool {
257
257
// along with the timestamp for cache-invalidation purposes
258
258
type allInstancesSnapshot struct {
259
259
timestamp time.Time
260
- instances map [awsInstanceID ]* ec2.Instance
260
+ instances map [InstanceID ]* ec2.Instance
261
261
}
262
262
263
263
// FindInstances returns the instances corresponding to the specified ids. If an id is not found, it is ignored.
264
- func (s * allInstancesSnapshot ) FindInstances (ids []awsInstanceID ) map [awsInstanceID ]* ec2.Instance {
265
- m := make (map [awsInstanceID ]* ec2.Instance )
264
+ func (s * allInstancesSnapshot ) FindInstances (ids []InstanceID ) map [InstanceID ]* ec2.Instance {
265
+ m := make (map [InstanceID ]* ec2.Instance )
266
266
for _ , id := range ids {
267
267
instance := s .instances [id ]
268
268
if instance != nil {
0 commit comments