Skip to content

Commit 523d91f

Browse files
committed
Adds tolertions to GitRepo
When applying a `GitRepo` in a cluster where all the nodes are tainted the pod created to call `fleet apply` remans waiting as Pending. This PR adds tolerations to the `GitRepo` spec. Those tolerations will be added to the job spec when running `fleet apply` so the pod is scheduled. Refers to: rancher#3313 Signed-off-by: Xavi Garcia <[email protected]>
1 parent 42e75e9 commit 523d91f

File tree

5 files changed

+143
-0
lines changed

5 files changed

+143
-0
lines changed

charts/fleet-crd/templates/crds.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6604,6 +6604,63 @@ spec:
66046604
type: string
66056605
type: object
66066606
type: array
6607+
tolerations:
6608+
description: Tolerations specifies tolerations to be added when
6609+
running fleet apply
6610+
items:
6611+
description: 'The pod this Toleration is attached to tolerates
6612+
any taint that matches
6613+
6614+
the triple <key,value,effect> using the matching operator <operator>.'
6615+
properties:
6616+
effect:
6617+
description: 'Effect indicates the taint effect to match.
6618+
Empty means match all taint effects.
6619+
6620+
When specified, allowed values are NoSchedule, PreferNoSchedule
6621+
and NoExecute.'
6622+
type: string
6623+
key:
6624+
description: 'Key is the taint key that the toleration applies
6625+
to. Empty means match all taint keys.
6626+
6627+
If the key is empty, operator must be Exists; this combination
6628+
means to match all values and all keys.'
6629+
type: string
6630+
operator:
6631+
description: 'Operator represents a key''s relationship to
6632+
the value.
6633+
6634+
Valid operators are Exists and Equal. Defaults to Equal.
6635+
6636+
Exists is equivalent to wildcard for value, so that a pod
6637+
can
6638+
6639+
tolerate all taints of a particular category.'
6640+
type: string
6641+
tolerationSeconds:
6642+
description: 'TolerationSeconds represents the period of time
6643+
the toleration (which must be
6644+
6645+
of effect NoExecute, otherwise this field is ignored) tolerates
6646+
the taint. By default,
6647+
6648+
it is not set, which means tolerate the taint forever (do
6649+
not evict). Zero and
6650+
6651+
negative values will be treated as 0 (evict immediately)
6652+
by the system.'
6653+
format: int64
6654+
type: integer
6655+
value:
6656+
description: 'Value is the taint value the toleration matches
6657+
to.
6658+
6659+
If the operator is Exists, the value should be empty, otherwise
6660+
just a regular string.'
6661+
type: string
6662+
type: object
6663+
type: array
66076664
type: object
66086665
status:
66096666
properties:

internal/cmd/controller/gitops/reconciler/gitjob_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,9 @@ func (r *GitJobReconciler) newGitJob(ctx context.Context, obj *v1alpha1.GitRepo)
548548
return nil, err
549549
}
550550

551+
// Add user defined tolerations
552+
jobSpec.Template.Spec.Tolerations = append(jobSpec.Template.Spec.Tolerations, obj.Spec.Tolerations...)
553+
551554
job := &batchv1.Job{
552555
ObjectMeta: metav1.ObjectMeta{
553556
Annotations: map[string]string{

internal/cmd/controller/gitops/reconciler/gitjob_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ func TestNewJob(t *testing.T) { // nolint:funlen
683683
expectedInitContainers []corev1.Container
684684
expectedVolumes []corev1.Volume
685685
expectedErr error
686+
expectedTolerations []corev1.Toleration
686687
}{
687688
"simple (no credentials, no ca, no skip tls)": {
688689
gitrepo: &fleetv1.GitRepo{
@@ -725,6 +726,77 @@ func TestNewJob(t *testing.T) { // nolint:funlen
725726
},
726727
client: fake.NewFakeClient(),
727728
},
729+
"simple with custom gitrepo tolerations": {
730+
gitrepo: &fleetv1.GitRepo{
731+
Spec: fleetv1.GitRepoSpec{
732+
Repo: "repo",
733+
Tolerations: []corev1.Toleration{
734+
{
735+
Key: "key1",
736+
Value: "value1",
737+
Operator: "Equals",
738+
Effect: "NoSchedule",
739+
},
740+
{
741+
Key: "key2",
742+
Value: "value2",
743+
Operator: "Exists",
744+
Effect: "NoExecute",
745+
},
746+
},
747+
},
748+
},
749+
expectedInitContainers: []corev1.Container{
750+
{
751+
Command: []string{
752+
"fleet",
753+
},
754+
Args: []string{"gitcloner", "repo", "/workspace", "--branch", "master"},
755+
Image: "test",
756+
Name: "gitcloner-initializer",
757+
VolumeMounts: []corev1.VolumeMount{
758+
{
759+
Name: gitClonerVolumeName,
760+
MountPath: "/workspace",
761+
},
762+
{
763+
Name: emptyDirVolumeName,
764+
MountPath: "/tmp",
765+
},
766+
},
767+
SecurityContext: securityContext,
768+
},
769+
},
770+
expectedVolumes: []corev1.Volume{
771+
{
772+
Name: gitClonerVolumeName,
773+
VolumeSource: corev1.VolumeSource{
774+
EmptyDir: &corev1.EmptyDirVolumeSource{},
775+
},
776+
},
777+
{
778+
Name: emptyDirVolumeName,
779+
VolumeSource: corev1.VolumeSource{
780+
EmptyDir: &corev1.EmptyDirVolumeSource{},
781+
},
782+
},
783+
},
784+
client: fake.NewFakeClient(),
785+
expectedTolerations: []corev1.Toleration{
786+
{
787+
Key: "key1",
788+
Value: "value1",
789+
Operator: "Equals",
790+
Effect: "NoSchedule",
791+
},
792+
{
793+
Key: "key2",
794+
Value: "value2",
795+
Operator: "Exists",
796+
Effect: "NoExecute",
797+
},
798+
},
799+
},
728800
"simple with custom branch": {
729801
gitrepo: &fleetv1.GitRepo{
730802
Spec: fleetv1.GitRepoSpec{

pkg/apis/fleet.cattle.io/v1alpha1/gitrepo_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package v1alpha1
22

33
import (
4+
corev1 "k8s.io/api/core/v1"
45
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
56
)
67

@@ -135,6 +136,9 @@ type GitRepoSpec struct {
135136
// Disables git polling. When enabled only webhooks will be used.
136137
DisablePolling bool `json:"disablePolling,omitempty"`
137138

139+
// Tolerations specifies tolerations to be added when running fleet apply
140+
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
141+
138142
// OCIRegistry specifies the OCI registry related parameters
139143
OCIRegistry *OCIRegistrySpec `json:"ociRegistry,omitempty"`
140144
}

pkg/apis/fleet.cattle.io/v1alpha1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)