Skip to content
Merged
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
8 changes: 6 additions & 2 deletions controllers/logging/secret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ func (r *SecretReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
return ctrl.Result{}, err
}

err = k8shandler.SecretReconcile(cluster, r.Client)
ok, err := k8shandler.SecretReconcile(cluster, r.Client)
if !ok {
return ctrl.Result{}, err
}

return ctrl.Result{}, err
}

Expand All @@ -60,7 +64,7 @@ func esSecretUpdatePredicate(r client.Client) predicate.Predicate {
return true
},
CreateFunc: func(e event.CreateEvent) bool {
return false
return true
},
DeleteFunc: func(e event.DeleteEvent) bool {
return false
Expand Down
39 changes: 36 additions & 3 deletions internal/k8shandler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,42 @@ func (er *ElasticsearchRequest) L() logr.Logger {
return er.ll
}

func SecretReconcile(requestCluster *elasticsearchv1.Elasticsearch, requestClient client.Client) error {
// SecretReconcile returns false if the event needs to be requeued
func SecretReconcile(requestCluster *elasticsearchv1.Elasticsearch, requestClient client.Client) (bool, error) {
var secretChanged bool

elasticsearchRequest := ElasticsearchRequest{
client: requestClient,
cluster: requestCluster,
ll: log.WithValues("cluster", requestCluster.Name, "namespace", requestCluster.Namespace),
}

// check if cluster is in the mid of cert redeploy
certRestartNodes := elasticsearchRequest.getScheduledCertRedeployNodes()
stillRecovering := containsClusterCondition(elasticsearchv1.Recovering, corev1.ConditionTrue, &elasticsearchRequest.cluster.Status)
if len(certRestartNodes) > 0 || stillRecovering {
// Requeue if there are nodes being scheduled CertRedeploy or under recovering
// and reset the certRedeploy status
for _, node := range nodes[nodeMapKey(requestCluster.Name, requestCluster.Namespace)] {
_, nodeStatus := getNodeStatus(node.name(), &elasticsearchRequest.cluster.Status)
nodeStatus.UpgradeStatus.ScheduledForCertRedeploy = corev1.ConditionFalse
}

updateESNodeCondition(&elasticsearchRequest.cluster.Status, &elasticsearchv1.ClusterCondition{
Type: elasticsearchv1.Recovering,
Status: corev1.ConditionFalse,
})
updateESNodeCondition(&elasticsearchRequest.cluster.Status, &elasticsearchv1.ClusterCondition{
Type: elasticsearchv1.Restarting,
Status: corev1.ConditionFalse,
})

if err := requestClient.Status().Update(context.TODO(), elasticsearchRequest.cluster); err != nil {
return true, err
}
return false, nil
}

newSecretHash := getSecretDataHash(requestCluster.Name, requestCluster.Namespace, requestClient)

nretries := -1
Expand Down Expand Up @@ -66,12 +99,12 @@ func SecretReconcile(requestCluster *elasticsearchv1.Elasticsearch, requestClien
})

if retryErr != nil {
return kverrors.Wrap(retryErr, "failed to update status for cert redeploys",
return false, kverrors.Wrap(retryErr, "failed to update status for cert redeploys",
"cluster", requestCluster.Name,
"retries", nretries)
}

return nil
return true, nil
}

func Reconcile(requestCluster *elasticsearchv1.Elasticsearch, requestClient client.Client) error {
Expand Down