@@ -14,7 +14,10 @@ import (
14
14
15
15
" github.com/awslabs/aws-service-operator/pkg/config"
16
16
{{- if .Spec .Queue }}
17
- " github.com/awslabs/aws-service-operator/pkg/queue"
17
+ " github.com/awslabs/aws-service-operator/pkg/queue"
18
+ corev1 " k8s.io/api/core/v1"
19
+ " github.com/iancoleman/strcase"
20
+ " strings"
18
21
{{- end}}
19
22
opkit " github.com/christopherhein/operator-kit"
20
23
apiextensionsv1beta1 " k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
@@ -50,7 +53,7 @@ type Controller struct {
50
53
config *config.Config
51
54
context *opkit.Context
52
55
awsclientset awsclient.ServiceoperatorV1alpha1Interface
53
- topicARN string
56
+ topicARN string
54
57
}
55
58
56
59
// NewController create controller for watching object store custom resources created
@@ -106,27 +109,35 @@ func QueueUpdater(config *config.Config, msg *queue.MessageBody) error {
106
109
}
107
110
108
111
if name != " " && namespace != " " {
112
+ annotations := map [string ]string {
113
+ " StackID" : msg.ParsedMessage [" StackId" ],
114
+ " StackName" : msg.ParsedMessage [" StackName" ],
115
+ " ResourceType" : msg.ParsedMessage [" ResourceType" ],
116
+ }
109
117
if msg.ParsedMessage [" ResourceStatus" ] == " ROLLBACK_COMPLETE" {
110
- err := deleteStack (config, name, namespace, msg.ParsedMessage [" StackId" ])
118
+ obj , err := deleteStack (config, name, namespace, msg.ParsedMessage [" StackId" ])
111
119
if err != nil {
112
120
return err
113
121
}
122
+ config.Recorder .AnnotatedEventf (obj, annotations, corev1.EventTypeWarning , strcase.ToCamel (strings.ToLower (msg.ParsedMessage [" ResourceStatus" ])), msg.ParsedMessage [" ResourceStatusReason" ])
114
123
} else if msg.ParsedMessage [" ResourceStatus" ] == " DELETE_COMPLETE" {
115
- err := updateStatus (config, name, namespace, msg.ParsedMessage [" StackId" ], msg.ParsedMessage [" ResourceStatus" ], msg.ParsedMessage [" ResourceStatusReason" ])
124
+ obj , err := updateStatus (config, name, namespace, msg.ParsedMessage [" StackId" ], msg.ParsedMessage [" ResourceStatus" ], msg.ParsedMessage [" ResourceStatusReason" ])
116
125
if err != nil {
117
126
return err
118
127
}
119
-
128
+ config. Recorder . AnnotatedEventf (obj, annotations, corev1. EventTypeWarning , strcase. ToCamel (strings. ToLower (msg. ParsedMessage [ " ResourceStatus " ])), msg. ParsedMessage [ " ResourceStatusReason " ])
120
129
err = incrementRollbackCount (config, name, namespace)
121
130
if err != nil {
122
131
return err
123
132
}
124
133
} else {
125
- err := updateStatus (config, name, namespace, msg.ParsedMessage [" StackId" ], msg.ParsedMessage [" ResourceStatus" ], msg.ParsedMessage [" ResourceStatusReason" ])
134
+ obj , err := updateStatus (config, name, namespace, msg.ParsedMessage [" StackId" ], msg.ParsedMessage [" ResourceStatus" ], msg.ParsedMessage [" ResourceStatusReason" ])
126
135
if err != nil {
127
136
return err
128
137
}
138
+ config.Recorder .AnnotatedEventf (obj, annotations, corev1.EventTypeNormal , strcase.ToCamel (strings.ToLower (msg.ParsedMessage [" ResourceStatus" ])), msg.ParsedMessage [" ResourceStatusReason" ])
129
139
}
140
+
130
141
}
131
142
132
143
return nil
@@ -147,7 +158,7 @@ func (c *Controller) onAdd(obj interface{}) {
147
158
c.config .Logger .Infof (" added {{.Spec.Resource.Name}} '%s ' with stackID '%s '" , s.Name , string (*output.StackId ))
148
159
c.config .Logger .Infof (" view at https://console.aws.amazon.com/cloudformation/home?#/stack/detail?stackId=%s " , string (*output.StackId ))
149
160
150
- err = updateStatus (c.config , s.Name , s.Namespace , string (*output.StackId ), " CREATE_IN_PROGRESS" , " " )
161
+ _, err = updateStatus (c.config , s.Name , s.Namespace , string (*output.StackId ), " CREATE_IN_PROGRESS" , " " )
151
162
if err != nil {
152
163
c.config .Logger .WithError (err).Error (" error updating status" )
153
164
}
@@ -176,7 +187,7 @@ func (c *Controller) onUpdate(oldObj, newObj interface{}) {
176
187
c.config .Logger .Infof (" updated {{.Spec.Resource.Name}} '%s ' with params '%s '" , no.Name , string (*output.StackId ))
177
188
c.config .Logger .Infof (" view at https://console.aws.amazon.com/cloudformation/home?#/stack/detail?stackId=%s " , string (*output.StackId ))
178
189
179
- err = updateStatus (c.config , oo.Name , oo.Namespace , string (*output.StackId ), " UPDATE_IN_PROGRESS" , " " )
190
+ _, err = updateStatus (c.config , oo.Name , oo.Namespace , string (*output.StackId ), " UPDATE_IN_PROGRESS" , " " )
180
191
if err != nil {
181
192
c.config .Logger .WithError (err).Error (" error updating status" )
182
193
}
@@ -225,13 +236,13 @@ func incrementRollbackCount(config *config.Config, name string, namespace string
225
236
return nil
226
237
}
227
238
228
- func updateStatus (config *config .Config , name string , namespace string , stackID string , status string , reason string ) error {
239
+ func updateStatus (config *config .Config , name string , namespace string , stackID string , status string , reason string ) (* awsV1alpha1 .{{. Spec . Kind }}, error ) {
229
240
logger := config.Logger
230
241
clientSet , _ := awsclient.NewForConfig (config.RESTConfig )
231
242
resource , err := clientSet.{{.Spec .PluralName }}(namespace).Get (name, metav1.GetOptions {})
232
243
if err != nil {
233
244
logger.WithError (err).Error (" error getting {{.Spec.Resource.Plural}}" )
234
- return err
245
+ return nil , err
235
246
}
236
247
237
248
resourceCopy := resource.DeepCopy ()
@@ -259,7 +270,7 @@ func updateStatus(config *config.Config, name string, namespace string, stackID
259
270
_, err = clientSet.{{.Spec .PluralName }}(namespace).Update (resourceCopy)
260
271
if err != nil {
261
272
logger.WithError (err).Error (" error updating resource" )
262
- return err
273
+ return nil , err
263
274
}
264
275
265
276
if helpers.IsStackComplete (status, false ) {
@@ -268,26 +279,26 @@ func updateStatus(config *config.Config, name string, namespace string, stackID
268
279
logger.WithError (err).Info (" error syncing resources" )
269
280
}
270
281
}
271
- return nil
282
+ return resourceCopy, nil
272
283
}
273
284
274
- func deleteStack (config *config .Config , name string , namespace string , stackID string ) error {
285
+ func deleteStack (config *config .Config , name string , namespace string , stackID string ) (* awsV1alpha1 .{{. Spec . Kind }}, error ) {
275
286
logger := config.Logger
276
287
clientSet , _ := awsclient.NewForConfig (config.RESTConfig )
277
288
resource , err := clientSet.{{.Spec .PluralName }}(namespace).Get (name, metav1.GetOptions {})
278
289
if err != nil {
279
290
logger.WithError (err).Error (" error getting {{.Spec.Resource.Plural}}" )
280
- return err
291
+ return nil , err
281
292
}
282
293
283
294
cft := New (config, resource, " " )
284
295
err = cft.DeleteStack ()
285
296
if err != nil {
286
- return err
297
+ return nil , err
287
298
}
288
299
289
300
err = cft.WaitUntilStackDeleted ()
290
- return err
301
+ return resource, err
291
302
}
292
303
293
304
func syncAdditionalResources (config *config.Config , s *awsV1alpha1.{{.Spec .Kind }}) (err error ) {
0 commit comments