upmc-enterprises / elasticsearch-operator

manages elasticsearch clusters
Other
655 stars 133 forks source link

Kibana and Cerebro services are not deleted when deleting ElasticsearchCluster #291

Open xyphr opened 5 years ago

xyphr commented 5 years ago

Currently, when deleting an ElasticsearchCluster the services for Kibana and Cerebro are left behind. The delete services method doesn't have the code for deleting those two services.

xyphr commented 5 years ago

This seems to fix it

diff --git a/pkg/k8sutil/services.go b/pkg/k8sutil/services.go
index e9deabb0..8274697f 100644
--- a/pkg/k8sutil/services.go
+++ b/pkg/k8sutil/services.go
@@ -262,19 +262,17 @@ func (k *K8sutil) DeleteServices(clusterName, namespace string) error {

        for component, _ := range mgmtServices {

+               fullClientServiceName := fmt.Sprintf("%s-%s", component, clusterName)
                // Check if service exists
-               s, _ := k.Kclient.CoreV1().Services(namespace).Get(component, metav1.GetOptions{})
-
-               // Service exists, delete
-               if len(s.Name) >= 1 {
-                       fullClientServiceName := fmt.Sprintf("%s-%s", component, clusterName)
-
+               _, err := k.Kclient.CoreV1().Services(namespace).Get(fullClientServiceName, metav1.GetOptions{})
+               if err != nil {
+                       logrus.Error("Could not find service "+fullClientServiceName+":", err)
+               } else {
                        if err := k.Kclient.CoreV1().Services(namespace).Delete(fullClientServiceName, &metav1.DeleteOptions{}); err != nil {
                                logrus.Error("Could not delete service "+fullClientServiceName+":", err)
                        }
                        logrus.Infof("Deleted service: %s", fullClientServiceName)
                }
-
        }

        return nil
stevesloka commented 5 years ago

Hey @xyphr would you like to send up a PR?