@@ -64,7 +64,24 @@ func (r _resource) GetExistingResourceNames(ctx component.OperatorContext, etcdO
64
64
}
65
65
66
66
// PreSync is a no-op for the configmap component.
67
- func (r _resource ) PreSync (_ component.OperatorContext , _ * druidv1alpha1.Etcd ) error {
67
+ // TODO: @anveshreddy18: Remove the functionality in the below PreSync method after 3 releases i.e in v0.31.0
68
+ // This is a temporary functionality to remove the old configmaps from the cluster that are created by the etcd-druid.
69
+ func (r _resource ) PreSync (ctx component.OperatorContext , etcd * druidv1alpha1.Etcd ) error {
70
+ oldConfigMap := emptyConfigMap (getOldObjectKey (etcd .ObjectMeta ))
71
+ ctx .Logger .Info ("PreSync: Deleting old configmap" , "name" , oldConfigMap .Name )
72
+ if err := r .client .Delete (ctx , oldConfigMap ); err != nil {
73
+ if errors .IsNotFound (err ) {
74
+ ctx .Logger .Info ("No old configmap found, ConfigMap PreSync is a no-op" , "name" , oldConfigMap .Name )
75
+ return nil
76
+ }
77
+ return druiderr .WrapError (
78
+ err ,
79
+ ErrDeleteConfigMap ,
80
+ component .OperationPreSync ,
81
+ fmt .Sprintf ("Failed to delete old configmap %s" , oldConfigMap .Name ),
82
+ )
83
+ }
84
+ ctx .Logger .Info ("deleted" , "component" , "configmap" , "name" , oldConfigMap .Name )
68
85
return nil
69
86
}
70
87
@@ -142,6 +159,13 @@ func getObjectKey(obj metav1.ObjectMeta) client.ObjectKey {
142
159
}
143
160
}
144
161
162
+ func getOldObjectKey (obj metav1.ObjectMeta ) client.ObjectKey {
163
+ return client.ObjectKey {
164
+ Name : druidv1alpha1 .GetOldConfigMapName (obj ),
165
+ Namespace : obj .Namespace ,
166
+ }
167
+ }
168
+
145
169
func emptyConfigMap (objectKey client.ObjectKey ) * corev1.ConfigMap {
146
170
return & corev1.ConfigMap {
147
171
ObjectMeta : metav1.ObjectMeta {
0 commit comments