@@ -25,23 +25,26 @@ import (
25
25
)
26
26
27
27
const (
28
- v2MetadataEndpoint = "http://169.254.170.2/v2/metadata"
29
- v2StatsEndpoint = "http://169.254.170.2/v2/stats"
30
- maxRetries = 4
31
- durationBetweenRetries = time .Second
28
+ v2MetadataEndpoint = "http://169.254.170.2/v2/metadata"
29
+ v2MetadataWithTagsEndpoint = "http://169.254.170.2/v2/metadataWithTags"
30
+ v2StatsEndpoint = "http://169.254.170.2/v2/stats"
31
+ maxRetries = 4
32
+ durationBetweenRetries = time .Second
32
33
)
33
34
34
35
// TaskResponse defines the schema for the task response JSON object
35
36
type TaskResponse struct {
36
- Cluster string
37
- TaskARN string
38
- Family string
39
- Revision string
40
- DesiredStatus string `json:",omitempty"`
41
- KnownStatus string
42
- AvailabilityZone string
43
- Containers []ContainerResponse `json:",omitempty"`
44
- Limits LimitsResponse `json:",omitempty"`
37
+ Cluster string
38
+ TaskARN string
39
+ Family string
40
+ Revision string
41
+ DesiredStatus string `json:",omitempty"`
42
+ KnownStatus string
43
+ AvailabilityZone string
44
+ Containers []ContainerResponse `json:",omitempty"`
45
+ Limits LimitsResponse `json:",omitempty"`
46
+ TaskTags map [string ]string `json:"TaskTags,omitempty"`
47
+ ContainerInstanceTags map [string ]string `json:"ContainerInstanceTags,omitempty"`
45
48
}
46
49
47
50
// ContainerResponse defines the schema for the container response
@@ -120,6 +123,23 @@ func taskMetadata(client *http.Client) (*TaskResponse, error) {
120
123
return & taskMetadata , nil
121
124
}
122
125
126
+ func taskWithTagsMetadata (client * http.Client ) (* TaskResponse , error ) {
127
+ body , err := metadataResponse (client , v2MetadataWithTagsEndpoint , "task with tags metadata" )
128
+ if err != nil {
129
+ return nil , err
130
+ }
131
+
132
+ fmt .Printf ("Received task with tags metadata: %s \n " , string (body ))
133
+
134
+ var taskMetadata TaskResponse
135
+ err = json .Unmarshal (body , & taskMetadata )
136
+ if err != nil {
137
+ return nil , fmt .Errorf ("task with tags metadata: unable to parse response body: %v" , err )
138
+ }
139
+
140
+ return & taskMetadata , nil
141
+ }
142
+
123
143
func containerMetadata (client * http.Client , id string ) (* ContainerResponse , error ) {
124
144
body , err := metadataResponse (client , v2MetadataEndpoint + "/" + id , "container metadata" )
125
145
if err != nil {
@@ -214,6 +234,21 @@ func main() {
214
234
// Wait for the Health information to be ready
215
235
time .Sleep (5 * time .Second )
216
236
237
+ // If the image is built with option to check Tags
238
+ argsWithoutProg := os .Args [1 :]
239
+ if len (argsWithoutProg ) > 0 && argsWithoutProg [0 ] == "CheckTags" {
240
+ taskWithTagsMetadata , err := taskWithTagsMetadata (client )
241
+ if err != nil {
242
+ fmt .Fprintf (os .Stderr , "Unable to get task stats: %v" , err )
243
+ os .Exit (1 )
244
+ }
245
+
246
+ if len (taskWithTagsMetadata .ContainerInstanceTags ) == 0 {
247
+ fmt .Fprintf (os .Stderr , "ContainerInstanceTags not found: %v" , err )
248
+ os .Exit (1 )
249
+ }
250
+ }
251
+
217
252
taskMetadata , err := taskMetadata (client )
218
253
if err != nil {
219
254
fmt .Fprintf (os .Stderr , "Unable to get task metadata: %v" , err )
0 commit comments