Skip to content

Commit dcddbfb

Browse files
authored
CLOUDP-87698: perform check for readiness probe init container already existing (#431)
1 parent 0f07b20 commit dcddbfb

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
<img align="right" src="https://mongodb-kubernetes-operator.s3.amazonaws.com/img/Leaf-Forest%402x.png">
44

5+
###v0.6.0 has introduced breaking changes. If you are upgrading from a previous version, follow the upgrade instructions outlined [in the release notes](https://github.com/mongodb/mongodb-kubernetes-operator/releases/tag/v0.6.0)
6+
7+
58
This is a [Kubernetes Operator](https://coreos.com/operators/) which deploys MongoDB Community into Kubernetes clusters.
69

710
If you are a MongoDB Enterprise customer, or need Enterprise features such as Backup, you can use the [MongoDB Enterprise Operator for Kubernetes](https://github.com/mongodb/mongodb-enterprise-kubernetes).

controllers/construct/mongodbstatefulset.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525
MongodbName = "mongod"
2626

2727
versionUpgradeHookName = "mongod-posthook"
28-
readinessProbeContainerName = "mongodb-agent-readinessprobe"
28+
ReadinessProbeContainerName = "mongodb-agent-readinessprobe"
2929
dataVolumeName = "data-volume"
3030
logVolumeName = "logs-volume"
3131
readinessProbePath = "/opt/scripts/readinessprobe"
@@ -169,7 +169,7 @@ func BuildMongoDBReplicaSetStatefulSetModificationFunction(mdb MongoDBStatefulSe
169169
podtemplatespec.WithContainer(AgentName, mongodbAgentContainer(mdb.AutomationConfigSecretName(), mongodbAgentVolumeMounts)),
170170
podtemplatespec.WithContainer(MongodbName, mongodbContainer(mdb.GetMongoDBVersion(), mongodVolumeMounts)),
171171
podtemplatespec.WithInitContainer(versionUpgradeHookName, versionUpgradeHookInit([]corev1.VolumeMount{hooksVolumeMount})),
172-
podtemplatespec.WithInitContainer(readinessProbeContainerName, readinessProbeInit([]corev1.VolumeMount{scriptsVolumeMount})),
172+
podtemplatespec.WithInitContainer(ReadinessProbeContainerName, readinessProbeInit([]corev1.VolumeMount{scriptsVolumeMount})),
173173
),
174174
))
175175
}
@@ -261,7 +261,7 @@ func logsPvc() persistentvolumeclaim.Modification {
261261
// this container will copy the readiness probe binary into the /opt/scripts directory.
262262
func readinessProbeInit(volumeMount []corev1.VolumeMount) container.Modification {
263263
return container.Apply(
264-
container.WithName(readinessProbeContainerName),
264+
container.WithName(ReadinessProbeContainerName),
265265
container.WithCommand([]string{"cp", "/probes/readinessprobe", "/opt/scripts/readinessprobe"}),
266266
container.WithImage(os.Getenv(ReadinessProbeImageEnv)),
267267
container.WithImagePullPolicy(corev1.PullAlways),

controllers/replica_set_controller.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"fmt"
77
"os"
88

9+
"github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/container"
10+
911
"github.com/mongodb/mongodb-kubernetes-operator/pkg/util/functions"
1012

1113
"github.com/mongodb/mongodb-kubernetes-operator/pkg/agent"
@@ -313,6 +315,11 @@ func (r *ReplicaSetReconciler) deployAutomationConfig(mdb mdbv1.MongoDBCommunity
313315
return true, nil
314316
}
315317

318+
if isPreReadinessInitContainerStatefulSet(sts) {
319+
r.log.Debugf("The existing StatefulSet did not have the readiness probe init container, skipping pod annotation check.")
320+
return true, nil
321+
}
322+
316323
r.log.Debugf("Waiting for agents to reach version %d", ac.Version)
317324
// Note: we pass in the expected number of replicas this reconciliation as we scale members one at a time. If we were
318325
// to pass in the final member count, we would be waiting for agents that do not exist yet to be ready.
@@ -556,3 +563,9 @@ func getDomain(service, namespace, clusterName string) string {
556563
}
557564
return fmt.Sprintf("%s.%s.svc.%s", service, namespace, clusterName)
558565
}
566+
567+
// isPreReadinessInitContainerStatefulSet determines if the existing StatefulSet has been configured with the readiness probe init container.
568+
// if this is not the case, then we should ensure to skip past the annotation check otherwise the pods will remain in pending state forever.
569+
func isPreReadinessInitContainerStatefulSet(sts appsv1.StatefulSet) bool {
570+
return container.GetByName(construct.ReadinessProbeContainerName, sts.Spec.Template.Spec.InitContainers) == nil
571+
}

dev_notes/RELEASE_NOTES.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
11
*(Please use the [release template](release-notes-template.md) as the template for this document)*
22
<!-- Next release -->
3-
# MongoDB Kubernetes Operator 0.5.3
3+
# MongoDB Kubernetes Operator 0.6.0
44
## Kubernetes Operator
5+
6+
* Breaking Changes
7+
* A new VolumeClaimTemplate has been added `logs-volume`. When you deploy the operator, if there is an existing StatefulSet the operator will attempt to perform an invalid update. The existing StatefulSet must be deleted before upgrading the operator.
8+
9+
* The user of the mongod and mongodb-agent containers has changed. This means that there will be permissions
10+
issues when upgrading from an earlier version of the operator. In order to update the permissions in the volume, you can use an init container.
11+
12+
* Upgrade instructions
13+
14+
Remove the current operator deployment
15+
- `kubectl delete deployment <operator-deployment>`
16+
Delete the existing StatefulSet for the MongoDBCommunity resource
17+
Note: to ensure existing data is not lost, ensure that the retain policy of your Persistent Volumes is configured correctly.
18+
- `kubectl delete statefulset <mdb-resource-name>`
19+
Install the new operator
20+
- follow the regular [installation instruction](https://github.com/mongodb/mongodb-kubernetes-operator/blob/master/docs/install-upgrade.md)
21+
Patch the StatefulSet once it has been created. This will add an init container that will update the permissions of the existing volume.
22+
- `kubectl patch statefulset <sts-name> --type='json' --patch '[ {"op":"add","path":"/spec/template/spec/initContainers/-", "value": { "name": "change-data-dir-permissions", "image": "busybox", "command": [ "chown", "-R", "2000", "/data" ], "securityContext": { "runAsNonRoot": false, "runAsUser": 0, "runAsGroup":0 }, "volumeMounts": [ { "mountPath": "/data", "name" : "data-volume" } ] } } ]'`
23+
524
* Bug fixes
625
* Fixes an issue that prevented the agents from reaching goal state when upgrading minor version of MongoDB.
726

27+
## Updated Image Tags
28+
* mongodb-kubernetes-operator:0.6.0
29+
* mongodb-agent:0.29.0.6830-1
30+
31+
832
<!-- Past Releases -->
933
# MongoDB Kubernetes Operator 0.5.2
1034
## Kubernetes Operator

0 commit comments

Comments
 (0)