@@ -54,15 +54,18 @@ func SetControllerReference(owner, object v1.Object, scheme *runtime.Scheme) err
54
54
// OperationType is the action result of a CreateOrUpdate call
55
55
type OperationType string
56
56
57
- const ( // They should complete the sentence "v1.Deployment has been ..."
58
- OperationNoop = "unchanged"
57
+ const ( // They should complete the sentence "Deployment default/foo has been ..."
58
+ // OperationNoop means that the resource has not been changed
59
+ OperationNoop = "unchanged"
60
+ // OperationCreated means that a new resource has been created
59
61
OperationCreated = "created"
62
+ // OperationUpdated means that an existing resource has been updated
60
63
OperationUpdated = "updated"
61
64
)
62
65
63
66
// CreateOrUpdate creates or updates a kuberenes resource. It takes in a key and
64
67
// a placeholder for the existing object and returns the modified object
65
- func CreateOrUpdate (c client. Client , ctx context. Context , key client.ObjectKey , existing runtime.Object , t TransformFn ) (runtime.Object , OperationType , error ) {
68
+ func CreateOrUpdate (ctx context. Context , c client. Client , key client.ObjectKey , existing runtime.Object , t TransformFn ) (runtime.Object , OperationType , error ) {
66
69
err := c .Get (ctx , key , existing )
67
70
var obj runtime.Object
68
71
@@ -73,11 +76,11 @@ func CreateOrUpdate(c client.Client, ctx context.Context, key client.ObjectKey,
73
76
}
74
77
75
78
err = c .Create (ctx , obj )
79
+
76
80
if err != nil {
77
81
return nil , OperationNoop , err
78
- } else {
79
- return obj , OperationCreated , err
80
82
}
83
+ return obj , OperationCreated , err
81
84
} else if err != nil {
82
85
return nil , OperationNoop , err
83
86
} else {
@@ -90,12 +93,10 @@ func CreateOrUpdate(c client.Client, ctx context.Context, key client.ObjectKey,
90
93
err = c .Update (ctx , obj )
91
94
if err != nil {
92
95
return nil , OperationNoop , err
93
- } else {
94
- return obj , OperationUpdated , err
95
96
}
96
- } else {
97
- return obj , OperationNoop , nil
97
+ return obj , OperationUpdated , err
98
98
}
99
+ return obj , OperationNoop , nil
99
100
}
100
101
}
101
102
0 commit comments