Skip to content

Commit 2d968c4

Browse files
committed
Fix the version checker job update errors out with field is immutable
Currently, In version checker job we reconcile the job and create the job if not present and update the job if there is some change in existing job. However updating the template of the job is not allowed and we get the "Field is immutable" error. I have fixed it by recreating the job instead of updating it.
1 parent 1e1df53 commit 2d968c4

File tree

14 files changed

+70
-7
lines changed

14 files changed

+70
-7
lines changed

.bazelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
build --workspace_status_command hack/build/print-workspace-status.sh
2-
test --test_output=errors --test_timeout=-1,-1,-1,2400
2+
test --test_output=errors --test_timeout=-1,-1,-1,3600

config/manager/patches/image.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,5 @@ spec:
218218
value: cockroachdb/cockroach:v23.1.1
219219
- name: RELATED_IMAGE_COCKROACH_v23_1_2
220220
value: cockroachdb/cockroach:v23.1.2
221+
- name: RELATED_IMAGE_COCKROACH_v23_1_3
222+
value: cockroachdb/cockroach:v23.1.3

config/manifests/bases/cockroach-operator.clusterserviceversion.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,5 @@ spec:
375375
image: registry.connect.redhat.com/cockroachdb/cockroach@sha256:bc4b75ed71845d5b18e1d9163d480fd9d0d3cb5ebbcfed00a2e4e1b174c0a5de
376376
- name: RELATED_IMAGE_COCKROACH_v23_1_2
377377
image: registry.connect.redhat.com/cockroachdb/cockroach@sha256:0b0e0588c1aadf0c3826cd584bd2b3a7d6781882dcb5c5e037b47ff5cb84509b
378+
- name: RELATED_IMAGE_COCKROACH_v23_1_3
379+
image: registry.connect.redhat.com/cockroachdb/cockroach@sha256:40f00476b63cb9e370fe85f01407173693213a9242fc117d28b06378ca0d98e0

config/manifests/patches/deployment_patch.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,6 @@ spec:
227227
value: registry.connect.redhat.com/cockroachdb/cockroach@sha256:bc4b75ed71845d5b18e1d9163d480fd9d0d3cb5ebbcfed00a2e4e1b174c0a5de
228228
- name: RELATED_IMAGE_COCKROACH_v23_1_2
229229
value: registry.connect.redhat.com/cockroachdb/cockroach@sha256:0b0e0588c1aadf0c3826cd584bd2b3a7d6781882dcb5c5e037b47ff5cb84509b
230+
- name: RELATED_IMAGE_COCKROACH_v23_1_3
231+
value: registry.connect.redhat.com/cockroachdb/cockroach@sha256:40f00476b63cb9e370fe85f01407173693213a9242fc117d28b06378ca0d98e0
230232
image: RH_COCKROACH_OP_IMAGE_PLACEHOLDER

config/samples/crdb-tls-example.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ kind: CrdbCluster
1919
metadata:
2020
name: crdb-tls-example
2121
spec:
22-
cockroachDBVersion: v23.1.2
22+
cockroachDBVersion: v23.1.3
2323
dataStore:
2424
pvc:
2525
spec:

crdb-versions.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,6 @@ CrdbVersions:
310310
- image: cockroachdb/cockroach:v23.1.2
311311
redhatImage: registry.connect.redhat.com/cockroachdb/cockroach@sha256:0b0e0588c1aadf0c3826cd584bd2b3a7d6781882dcb5c5e037b47ff5cb84509b
312312
tag: v23.1.2
313+
- image: cockroachdb/cockroach:v23.1.3
314+
redhatImage: registry.connect.redhat.com/cockroachdb/cockroach@sha256:40f00476b63cb9e370fe85f01407173693213a9242fc117d28b06378ca0d98e0
315+
tag: v23.1.3

examples/client-secure-operator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ spec:
2323
serviceAccountName: cockroachdb-sa
2424
containers:
2525
- name: cockroachdb-client-secure
26-
image: cockroachdb/cockroach:v23.1.2
26+
image: cockroachdb/cockroach:v23.1.3
2727
imagePullPolicy: IfNotPresent
2828
volumeMounts:
2929
- name: client-certs

examples/example.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ spec:
4040
memory: 8Gi
4141
tlsEnabled: true
4242
# You can set either a version of the db or a specific image name
43-
# cockroachDBVersion: v23.1.2
43+
# cockroachDBVersion: v23.1.3
4444
image:
45-
name: cockroachdb/cockroach:v23.1.2
45+
name: cockroachdb/cockroach:v23.1.3
4646
# nodes refers to the number of crdb pods that are created
4747
# via the statefulset
4848
nodes: 3

examples/smoketest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ spec:
3939
memory: 300Mi
4040
tlsEnabled: true
4141
image:
42-
name: cockroachdb/cockroach:v23.1.2
42+
name: cockroachdb/cockroach:v23.1.3
4343
nodes: 3

hack/bin/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ genrule(
4242
name = "fetch_preflight",
4343
srcs = select({
4444
":k8": ["@preflight_linux//file"],
45+
":m1": ["@preflight_linux//file"],
4546
}),
4647
outs = ["preflight"],
4748
cmd = "cp $(SRCS) $@",

install/operator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,8 @@ spec:
576576
value: cockroachdb/cockroach:v23.1.1
577577
- name: RELATED_IMAGE_COCKROACH_v23_1_2
578578
value: cockroachdb/cockroach:v23.1.2
579+
- name: RELATED_IMAGE_COCKROACH_v23_1_3
580+
value: cockroachdb/cockroach:v23.1.3
579581
- name: OPERATOR_NAME
580582
value: cockroachdb
581583
- name: POD_NAME

pkg/actor/validate_version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (v *versionChecker) Act(ctx context.Context, cluster *resource.Cluster, log
8686

8787
log.V(DEBUGLEVEL).Info("starting to check the crdb version of the container provided")
8888

89-
r := resource.NewManagedKubeResource(ctx, v.client, cluster, kube.AnnotatingPersister)
89+
r := resource.NewManagedKubeResource(ctx, v.client, cluster, kube.RecreatingPersister)
9090
owner := cluster.Unwrap()
9191

9292
// If the image.name is set use that value and do not check that the

pkg/kube/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ go_library(
1111
importpath = "github.com/cockroachdb/cockroach-operator/pkg/kube",
1212
visibility = ["//visibility:public"],
1313
deps = [
14+
"//pkg/ptr:go_default_library",
1415
"@com_github_banzaicloud_k8s_objectmatcher//patch:go_default_library",
1516
"@com_github_cenkalti_backoff//:go_default_library",
1617
"@com_github_cockroachdb_errors//:go_default_library",

pkg/kube/helpers.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/banzaicloud/k8s-objectmatcher/patch"
2828
"github.com/cenkalti/backoff"
29+
"github.com/cockroachdb/cockroach-operator/pkg/ptr"
2930
"github.com/cockroachdb/errors"
3031
"github.com/go-logr/logr"
3132
"go.uber.org/zap/zapcore"
@@ -140,6 +141,12 @@ var AnnotatingPersister PersistFn = func(ctx context.Context, cl client.Client,
140141
})
141142
}
142143

144+
var RecreatingPersister PersistFn = func(ctx context.Context, cl client.Client, obj client.Object, f MutateFn) (upserted bool, err error) {
145+
return ReCreateAnnotated(ctx, cl, obj, func() error {
146+
return f()
147+
})
148+
}
149+
143150
// MutateFn is a function which mutates the existing object into it's desired state.
144151
type MutateFn func() error
145152

@@ -190,6 +197,49 @@ func CreateOrUpdateAnnotated(ctx context.Context, c client.Client, obj client.Ob
190197
return true, nil
191198
}
192199

200+
func ReCreateAnnotated(ctx context.Context, c client.Client, obj client.Object, f MutateFn) (upserted bool, err error) {
201+
key := client.ObjectKeyFromObject(obj)
202+
203+
if err := c.Get(ctx, key, obj); err == nil {
204+
existing := obj.DeepCopyObject()
205+
if err := mutate(f, key, obj); err != nil {
206+
return false, err
207+
}
208+
209+
changed, err := ObjectChanged(existing, obj)
210+
if err != nil {
211+
return false, err
212+
}
213+
if !changed {
214+
return false, nil
215+
}
216+
217+
dp := metav1.DeletePropagationForeground
218+
if err := c.Delete(ctx, existing.(client.Object), &client.DeleteOptions{GracePeriodSeconds: ptr.Int64(0),
219+
PropagationPolicy: &dp}); err != nil {
220+
return false, err
221+
}
222+
223+
return false, nil
224+
} else if err != nil && !apierrors.IsNotFound(err) {
225+
return false, err
226+
}
227+
228+
if err := mutate(f, key, obj); err != nil {
229+
return false, err
230+
}
231+
232+
if err := annotator.SetLastAppliedAnnotation(obj); err != nil {
233+
return false, err
234+
}
235+
236+
if err := c.Create(ctx, obj); err != nil {
237+
return false, err
238+
}
239+
240+
return true, nil
241+
}
242+
193243
func ObjectChanged(current, updated runtime.Object) (bool, error) {
194244
opts := []patch.CalculateOption{
195245
patch.IgnoreStatusFields(),

0 commit comments

Comments
 (0)