@@ -105,15 +105,18 @@ func referSameObject(a, b v1.OwnerReference) bool {
105
105
// OperationType is the action result of a CreateOrUpdate call
106
106
type OperationType string
107
107
108
- const ( // They should complete the sentence "v1.Deployment has been ..."
109
- OperationNoop = "unchanged"
108
+ const ( // They should complete the sentence "Deployment default/foo has been ..."
109
+ // OperationNoop means that the resource has not been changed
110
+ OperationNoop = "unchanged"
111
+ // OperationCreated means that a new resource has been created
110
112
OperationCreated = "created"
113
+ // OperationUpdated means that an existing resource has been updated
111
114
OperationUpdated = "updated"
112
115
)
113
116
114
117
// CreateOrUpdate creates or updates a kuberenes resource. It takes in a key and
115
118
// a placeholder for the existing object and returns the modified object
116
- func CreateOrUpdate (c client. Client , ctx context. Context , key client.ObjectKey , existing runtime.Object , t TransformFn ) (runtime.Object , OperationType , error ) {
119
+ func CreateOrUpdate (ctx context. Context , c client. Client , key client.ObjectKey , existing runtime.Object , t TransformFn ) (runtime.Object , OperationType , error ) {
117
120
err := c .Get (ctx , key , existing )
118
121
var obj runtime.Object
119
122
@@ -124,11 +127,11 @@ func CreateOrUpdate(c client.Client, ctx context.Context, key client.ObjectKey,
124
127
}
125
128
126
129
err = c .Create (ctx , obj )
130
+
127
131
if err != nil {
128
132
return nil , OperationNoop , err
129
- } else {
130
- return obj , OperationCreated , err
131
133
}
134
+ return obj , OperationCreated , err
132
135
} else if err != nil {
133
136
return nil , OperationNoop , err
134
137
} else {
@@ -141,12 +144,10 @@ func CreateOrUpdate(c client.Client, ctx context.Context, key client.ObjectKey,
141
144
err = c .Update (ctx , obj )
142
145
if err != nil {
143
146
return nil , OperationNoop , err
144
- } else {
145
- return obj , OperationUpdated , err
146
147
}
147
- } else {
148
- return obj , OperationNoop , nil
148
+ return obj , OperationUpdated , err
149
149
}
150
+ return obj , OperationNoop , nil
150
151
}
151
152
}
152
153
0 commit comments