Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,11 @@ func (c *Controller) Run() error {
}

func (c *Controller) init() error {
err := c.k8sclient.CreateKubernetesCustomResourceDefinition()
crd, err := c.k8sclient.CreateKubernetesCustomResourceDefinition()
if err != nil {
return err
}

err = c.k8sclient.CreateNodeInitDaemonset("default")
return c.k8sclient.CreateNodeInitDaemonset(crd.ObjectMeta.Namespace)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting this error:

time="2018-05-24T00:39:25Z" level=info msg="Daemonset  not found, creating..."
time="2018-05-24T00:39:25Z" level=error msg="Error in init(): an empty namespace may not be set during creation"

CRD does not have a namespace as it is cluster-wide.

Would this work to just create it in the same namespace as the controller?

ns, _ := os.LookupEnv("NAMESPACE")
return c.k8sclient.CreateNodeInitDaemonset(ns)


if err != nil {
return err
}

return nil
}
18 changes: 17 additions & 1 deletion pkg/k8sutil/daemonsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
package k8sutil

import (
"fmt"

"github.com/Sirupsen/logrus"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
Expand All @@ -36,14 +38,28 @@ const (
esOperatorSysctlName = "elasticsearch-operator-sysctl"
)

// DeleteNodeInitDaemonset delete the node init daemonset
func (k *K8sutil) DeleteNodeInitDaemonset(namespace string) error {

ds, err := k.Kclient.ExtensionsV1beta1().DaemonSets(namespace).Get(esOperatorSysctlName, metav1.GetOptions{})
Copy link
Contributor

@danisla danisla May 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the .Delete() function, not the.Get().


if err != nil {
return fmt.Errorf("Could not delete daemonset: %s ", ds.Name)
}

logrus.Infof("Deleted daemonset: %s", ds.Name)
return nil

}

// CreateNodeInitDaemonset creates the node init daemonset
func (k *K8sutil) CreateNodeInitDaemonset(namespace string) error {

ds, err := k.Kclient.ExtensionsV1beta1().DaemonSets(namespace).Get(esOperatorSysctlName, metav1.GetOptions{})

if err != nil && len(ds.Name) == 0 {

logrus.Infof("Daemonset %s not found, creating...", ds)
logrus.Infof("Daemonset %s not found, creating...", ds.Name)

resourceCPU, _ := resource.ParseQuantity("10m")
resourceMemory, _ := resource.ParseQuantity("50Mi")
Expand Down
8 changes: 4 additions & 4 deletions pkg/k8sutil/k8sutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func newKubeClient(kubeCfgFile string) (genclient.Interface, kubernetes.Interfac
}

// CreateKubernetesCustomResourceDefinition checks if ElasticSearch CRD exists. If not, create
func (k *K8sutil) CreateKubernetesCustomResourceDefinition() error {
func (k *K8sutil) CreateKubernetesCustomResourceDefinition() (*apiextensionsv1beta1.CustomResourceDefinition, error) {

crd, err := k.KubeExt.ApiextensionsV1beta1().CustomResourceDefinitions().Get(elasticsearchoperator.Name, metav1.GetOptions{})
if err != nil {
Expand Down Expand Up @@ -208,9 +208,9 @@ func (k *K8sutil) CreateKubernetesCustomResourceDefinition() error {
if err != nil {
deleteErr := k.KubeExt.ApiextensionsV1beta1().CustomResourceDefinitions().Delete(elasticsearchoperator.Name, nil)
if deleteErr != nil {
return errors.NewAggregate([]error{err, deleteErr})
return nil, errors.NewAggregate([]error{err, deleteErr})
}
return err
return nil, err
}

logrus.Info("CRD ready!")
Expand All @@ -221,7 +221,7 @@ func (k *K8sutil) CreateKubernetesCustomResourceDefinition() error {
logrus.Infof("SKIPPING: already exists %#v\n", crd.ObjectMeta.Name)
}

return nil
return crd, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be: return crd, nil otherwise on first install, if the CRD doesn't exist, it will return the value of err from the first test. This breaks the controller init() function.

}

// MonitorElasticSearchEvents watches for new or removed clusters
Expand Down
4 changes: 4 additions & 0 deletions pkg/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ func (p *Processor) deleteElasticSearchCluster(c *myspec.ElasticsearchCluster) {
logrus.Errorf("Could not delete storage class %s: %v", c.ObjectMeta.Name, err)
}

if err := p.k8sclient.DeleteNodeInitDaemonset(c.ObjectMeta.Name); err != nil {
logrus.Errorf("Could not delete daemonset %s: %v", c.ObjectMeta.Namespace, err)
}

p.clusters[fmt.Sprintf("%s-%s", c.ObjectMeta.Name, c.ObjectMeta.Namespace)].Scheduler.Stop()

if !c.Spec.KeepSecretsOnDelete {
Expand Down
5 changes: 4 additions & 1 deletion pkg/snapshot/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func (s *Scheduler) deleteCronJob(namespace, clusterName string) {
func (s *Scheduler) CreateCronJob(namespace, clusterName, action, cronSchedule string) error {
snapshotName := getSnapshotname(clusterName, action)

var jobHistorySize int32 = 20
// Check if CronJob exists
cronJob, err := s.Kclient.BatchV1beta1().CronJobs(namespace).Get(snapshotName, metav1.GetOptions{})

Expand All @@ -187,7 +188,9 @@ func (s *Scheduler) CreateCronJob(namespace, clusterName, action, cronSchedule s
},
},
Spec: v1beta1.CronJobSpec{
Schedule: cronSchedule,
Schedule: cronSchedule,
SuccessfulJobsHistoryLimit: &jobHistorySize,
FailedJobsHistoryLimit: &jobHistorySize,
JobTemplate: v1beta1.JobTemplateSpec{
Spec: batchv1.JobSpec{
Template: apicore.PodTemplateSpec{
Expand Down