Files
my-rook-config/pkg/operator/ceph/cluster/nodedaemon/pruner_test.go
T
Oded Viner 8817a1a703 core: add tolerations to crashcollector pruner cronJob pod
This PR addresses an issue where the CrashCollector Pruner
CronJob pods were stuck in a Pending state due to missing
tolerations in their PodTemplateSpec.
These tolerations were not being propagated from the
cephClusterSpec.placement.all field.
Added tolerations to the PodTemplateSpec of the
CrashCollector Pruner CronJob.

Signed-off-by: Oded Viner <oviner@redhat.com>
2025-01-16 16:17:20 +02:00

92 lines
2.5 KiB
Go

/*
Copyright 2022 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package nodedaemon
import (
"context"
"testing"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
rookclient "github.com/rook/rook/pkg/client/clientset/versioned/fake"
"github.com/rook/rook/pkg/client/clientset/versioned/scheme"
"github.com/rook/rook/pkg/clusterd"
"github.com/rook/rook/pkg/operator/test"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)
func TestCreateOrUpdateCephCron(t *testing.T) {
tolerations := []corev1.Toleration{
{
Key: "key",
Operator: corev1.TolerationOpEqual,
Value: "value",
Effect: corev1.TaintEffectNoSchedule,
},
}
cephCluster := cephv1.CephCluster{
ObjectMeta: metav1.ObjectMeta{
Namespace: "rook-ceph",
},
Spec: cephv1.ClusterSpec{
Placement: cephv1.PlacementSpec{
"all": {
Tolerations: tolerations,
},
},
},
}
ctx := context.TODO()
context := &clusterd.Context{
Clientset: test.New(t, 1),
RookClientset: rookclient.NewSimpleClientset(),
}
s := scheme.Scheme
err := v1.AddToScheme(s)
if err != nil {
assert.Fail(t, "failed to build scheme")
}
r := &ReconcileNode{
scheme: s,
client: fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects().Build(),
context: context,
}
cronV1 := &v1.CronJob{
ObjectMeta: metav1.ObjectMeta{
Name: prunerName,
Namespace: "rook-ceph",
},
}
// check if cronJob is created
cntrlutil, err := r.createOrUpdateCephCron(cephCluster, tolerations)
assert.NoError(t, err)
assert.Equal(t, cntrlutil, controllerutil.OperationResult("created"))
err = r.client.Get(ctx, types.NamespacedName{Namespace: "rook-ceph", Name: prunerName}, cronV1)
assert.NoError(t, err)
assert.Equal(t, tolerations, cronV1.Spec.JobTemplate.Spec.Template.Spec.Tolerations, "Tolerations do not match")
}