@@ -45,11 +45,11 @@ type ConfigMapMutator func(*v1.ConfigMap) error
45
45
func CreateOrUpdateConfigMap (client clientset.Interface , cm * v1.ConfigMap ) error {
46
46
if _ , err := client .CoreV1 ().ConfigMaps (cm .ObjectMeta .Namespace ).Create (cm ); err != nil {
47
47
if ! apierrors .IsAlreadyExists (err ) {
48
- return errors .Wrap (err , "unable to create configmap " )
48
+ return errors .Wrap (err , "unable to create ConfigMap " )
49
49
}
50
50
51
51
if _ , err := client .CoreV1 ().ConfigMaps (cm .ObjectMeta .Namespace ).Update (cm ); err != nil {
52
- return errors .Wrap (err , "unable to update configmap " )
52
+ return errors .Wrap (err , "unable to update ConfigMap " )
53
53
}
54
54
}
55
55
return nil
@@ -60,13 +60,27 @@ func CreateOrUpdateConfigMap(client clientset.Interface, cm *v1.ConfigMap) error
60
60
// to conflicts, and a retry will be issued if the ConfigMap was modified on the server between the refresh and the update (while the mutation was
61
61
// taking place)
62
62
func CreateOrMutateConfigMap (client clientset.Interface , cm * v1.ConfigMap , mutator ConfigMapMutator ) error {
63
- if _ , err := client .CoreV1 ().ConfigMaps (cm .ObjectMeta .Namespace ).Create (cm ); err != nil {
64
- if ! apierrors .IsAlreadyExists (err ) {
65
- return errors .Wrap (err , "unable to create ConfigMap" )
63
+ var lastError error
64
+ err := wait .ExponentialBackoff (wait.Backoff {
65
+ Steps : 20 ,
66
+ Duration : 500 * time .Millisecond ,
67
+ Factor : 1.0 ,
68
+ Jitter : 0.1 ,
69
+ }, func () (bool , error ) {
70
+ if _ , err := client .CoreV1 ().ConfigMaps (cm .ObjectMeta .Namespace ).Create (cm ); err != nil {
71
+ lastError = err
72
+ if apierrors .IsAlreadyExists (err ) {
73
+ lastError = MutateConfigMap (client , metav1.ObjectMeta {Namespace : cm .ObjectMeta .Namespace , Name : cm .ObjectMeta .Name }, mutator )
74
+ return lastError == nil , nil
75
+ }
76
+ return false , nil
66
77
}
67
- return MutateConfigMap (client , metav1.ObjectMeta {Namespace : cm .ObjectMeta .Namespace , Name : cm .ObjectMeta .Name }, mutator )
78
+ return true , nil
79
+ })
80
+ if err == nil {
81
+ return nil
68
82
}
69
- return nil
83
+ return lastError
70
84
}
71
85
72
86
// MutateConfigMap takes a ConfigMap Object Meta (namespace and name), retrieves the resource from the server and tries to mutate it
@@ -100,7 +114,7 @@ func CreateOrRetainConfigMap(client clientset.Interface, cm *v1.ConfigMap, confi
100
114
}
101
115
if _ , err := client .CoreV1 ().ConfigMaps (cm .ObjectMeta .Namespace ).Create (cm ); err != nil {
102
116
if ! apierrors .IsAlreadyExists (err ) {
103
- return errors .Wrap (err , "unable to create configmap " )
117
+ return errors .Wrap (err , "unable to create ConfigMap " )
104
118
}
105
119
}
106
120
}
0 commit comments