Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit a986f2e

Browse files
authored
CLOUDP-226357 - fix logRotate & add local dev imp & update examples (#1480)
1 parent 352329e commit a986f2e

File tree

8 files changed

+70
-22
lines changed

8 files changed

+70
-22
lines changed

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ AGENT_IMAGE_NAME := $(shell jq -r .agent_image_ubi < $(MONGODB_COMMUNITY_CONFIG)
1414
HELM_CHART ?= ./helm-charts/charts/community-operator
1515

1616
STRING_SET_VALUES := --set namespace=$(NAMESPACE),versionUpgradeHook.name=$(UPGRADE_HOOK_IMG),readinessProbe.name=$(READINESS_PROBE_IMG),registry.operator=$(REPO_URL),operator.operatorImageName=$(OPERATOR_IMAGE),operator.version=latest,registry.agent=$(REGISTRY),registry.versionUpgradeHook=$(REGISTRY),registry.readinessProbe=$(REGISTRY),registry.operator=$(REGISTRY),versionUpgradeHook.version=latest,readinessProbe.version=latest,agent.version=latest,agent.name=$(AGENT_IMAGE_NAME)
17+
STRING_SET_VALUES_LOCAL := $(STRING_SET_VALUES) --set operator.replicas=0
1718

1819
DOCKERFILE ?= operator
1920
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
@@ -101,11 +102,21 @@ install: manifests helm install-crd ## Install CRDs into a cluster
101102
install-crd:
102103
kubectl apply -f config/crd/bases/mongodbcommunity.mongodb.com_mongodbcommunity.yaml
103104

104-
install-chart:
105+
install-chart: uninstall-crd
105106
$(HELM) upgrade --install $(STRING_SET_VALUES) $(RELEASE_NAME_HELM) $(HELM_CHART) --namespace $(NAMESPACE) --create-namespace
106107

108+
install-chart-local-operator: uninstall-crd
109+
$(HELM) upgrade --install $(STRING_SET_VALUES_LOCAL) $(RELEASE_NAME_HELM) $(HELM_CHART) --namespace $(NAMESPACE) --create-namespace
110+
111+
prepare-local-dev: generate-env-file install-chart-local-operator install-rbac setup-sas
112+
113+
# patches all sas to use the local-image-registry
114+
setup-sas:
115+
scripts/dev/setup_sa.sh
116+
107117
install-chart-with-tls-enabled:
108118
$(HELM) upgrade --install --set createResource=true $(STRING_SET_VALUES) $(RELEASE_NAME_HELM) $(HELM_CHART) --namespace $(NAMESPACE) --create-namespace
119+
109120
install-rbac:
110121
$(HELM) template $(STRING_SET_VALUES) -s templates/database_roles.yaml $(HELM_CHART) | kubectl apply -f -
111122
$(HELM) template $(STRING_SET_VALUES) -s templates/operator_roles.yaml $(HELM_CHART) | kubectl apply -f -
@@ -165,6 +176,7 @@ cleanup-e2e: ## Cleans up e2e test env
165176
generate-env-file: ## generates a local-test.env for local testing
166177
mkdir -p .community-operator-dev
167178
{ python scripts/dev/get_e2e_env_vars.py | tee >(cut -d' ' -f2 > .community-operator-dev/local-test.env) ;} > .community-operator-dev/local-test.export.env
179+
. .community-operator-dev/local-test.export.env
168180

169181
##@ Image
170182

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ See the [documentation](docs) to learn how to:
4242

4343
The MongoDB Community Kubernetes Operator supports the following features:
4444

45-
> Warning: Currently the operator doesn't support Replicaset deployment with server version >= 7.0. We are working on adding the support for it.
46-
47-
4845
- Create [replica sets](https://www.mongodb.com/docs/manual/replication/)
4946
- Upgrade and downgrade MongoDB server version
5047
- Scale replica sets up and down
@@ -57,9 +54,6 @@ The MongoDB Community Kubernetes Operator supports the following features:
5754
- Create custom roles
5855
- Enable a [metrics target that can be used with Prometheus](docs/prometheus/README.md)
5956

60-
### Planned Features
61-
- Server internal authentication via keyfile
62-
6357
## Contribute
6458

6559
Before you contribute to the MongoDB Community Kubernetes Operator, please read:

config/samples/mongodb.com_v1_mongodbcommunity_cr_podantiaffinity.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ spec:
2222
db: admin
2323
scramCredentialsSecretName: my-scram
2424
statefulSet:
25+
# NOTE: Overwriting the "app" labelSelectors via the sts wrapper is not supported since this labelselector is not
26+
# getting propagated to the service. You can add others like defined below
2527
spec:
2628
selector:
2729
matchLabels:
28-
app: mongodb
30+
app.kubernetes.io/name: mongodb
2931
template:
3032
metadata:
3133
# label the pod which is used by the "labelSelector" in podAntiAffinty
3234
# you can label it witch some other labels as well -- make sure it change the podAntiAffinity labelselector accordingly
3335
labels:
34-
app: mongodb
36+
app.kubernetes.io/name: mongodb
3537
spec:
3638
affinity:
3739
podAntiAffinity:
@@ -40,7 +42,7 @@ spec:
4042
podAffinityTerm:
4143
labelSelector:
4244
matchExpressions:
43-
- key: app
45+
- key: app.kubernetes.io/name
4446
operator: In
4547
values:
4648
- mongodb

pkg/automationconfig/automation_config.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ type LogRotate struct {
127127
}
128128

129129
type Process struct {
130-
Name string `json:"name"`
131-
Disabled bool `json:"disabled"`
132-
HostName string `json:"hostname"`
133-
Args26 objx.Map `json:"args2_6"`
134-
FeatureCompatibilityVersion string `json:"featureCompatibilityVersion"`
135-
ProcessType ProcessType `json:"processType"`
136-
Version string `json:"version"`
137-
AuthSchemaVersion int `json:"authSchemaVersion"`
138-
LogRotate AcLogRotate `json:"LogRotate,omitempty"`
130+
Name string `json:"name"`
131+
Disabled bool `json:"disabled"`
132+
HostName string `json:"hostname"`
133+
Args26 objx.Map `json:"args2_6"`
134+
FeatureCompatibilityVersion string `json:"featureCompatibilityVersion"`
135+
ProcessType ProcessType `json:"processType"`
136+
Version string `json:"version"`
137+
AuthSchemaVersion int `json:"authSchemaVersion"`
138+
LogRotate *AcLogRotate `json:"LogRotate,omitempty"`
139139
}
140140

141141
func (p *Process) SetPort(port int) *Process {
@@ -181,12 +181,12 @@ func (p *Process) SetLogRotate(lr *CrdLogRotate) *Process {
181181
}
182182

183183
// ConvertCrdLogRotateToAC converts a CrdLogRotate to an AcLogRotate representation.
184-
func ConvertCrdLogRotateToAC(lr *CrdLogRotate) AcLogRotate {
184+
func ConvertCrdLogRotateToAC(lr *CrdLogRotate) *AcLogRotate {
185185
if lr == nil {
186-
return AcLogRotate{}
186+
return &AcLogRotate{}
187187
}
188188

189-
return AcLogRotate{
189+
return &AcLogRotate{
190190
LogRotate: LogRotate{
191191
TimeThresholdHrs: lr.TimeThresholdHrs,
192192
NumUncompressed: lr.NumUncompressed,

pkg/automationconfig/automation_config_secret_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,29 @@ func TestEnsureSecret(t *testing.T) {
7272
assert.Equal(t, float64(1), acFromBytes.Processes[0].LogRotate.PercentOfDiskspace)
7373
})
7474

75+
t.Run("test LogRotate marshal and unmarshal if not set", func(t *testing.T) {
76+
77+
desiredAutomationConfig, err = NewBuilder().SetMembers(3).AddProcessModification(func(i_ int, p *Process) {}).Build()
78+
assert.NoError(t, err)
79+
80+
s := secret.Builder().
81+
SetName(secretNsName.Name).
82+
SetNamespace(secretNsName.Namespace).
83+
Build()
84+
85+
secretGetUpdateCreator := &mockSecretGetUpdateCreator{secret: &s}
86+
87+
ac, err := EnsureSecret(secretGetUpdateCreator, secretNsName, []metav1.OwnerReference{}, desiredAutomationConfig)
88+
assert.NoError(t, err)
89+
assert.Equal(t, desiredAutomationConfig, ac, "The config should be returned if there is not one currently.")
90+
91+
bytes := s.Data[ConfigKey]
92+
acFromBytes, err := FromBytes(bytes)
93+
assert.NoError(t, err)
94+
assert.NotEqual(t, &AcLogRotate{}, acFromBytes.Processes[0].LogRotate)
95+
assert.Nil(t, acFromBytes.Processes[0].LogRotate)
96+
})
97+
7598
t.Run("When the existing Automation Config is different the Automation Config Changes", func(t *testing.T) {
7699

77100
oldAc, err := newAutomationConfig()

scripts/dev/dev_config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ def mongodb_image_repo_url(self) -> str:
120120
def agent_image(self) -> str:
121121
return self._config["agent_image"]
122122

123+
@property
124+
def local_operator(self) -> str:
125+
return self._config["mdb_local_operator"]
126+
127+
@property
128+
def kube_config(self) -> str:
129+
return self._config["kubeconfig"]
130+
123131
@property
124132
def agent_image_dev(self) -> str:
125133
return self._get_dev_image("agent_image_dev", "agent_image")

scripts/dev/get_e2e_env_vars.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def _get_e2e_test_envs(dev_config: DevConfig) -> Dict[str, str]:
3333
"MONGODB_REPO_URL": dev_config.mongodb_image_repo_url,
3434
"HELM_CHART_PATH": os.path.abspath("./helm-charts/charts/community-operator"),
3535
"MDB_IMAGE_TYPE": dev_config.image_type,
36+
"MDB_LOCAL_OPERATOR": dev_config.local_operator,
37+
"KUBECONFIG": dev_config.kube_config,
3638
}
3739

3840

scripts/dev/setup_sa.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
service_accounts=$(kubectl get serviceaccounts -n "${NAMESPACE}" -o jsonpath='{.items[*].metadata.name}')
4+
5+
for service_account in $service_accounts; do
6+
kubectl patch serviceaccount "$service_account" -n "${NAMESPACE}" -p "{\"imagePullSecrets\": [{\"name\": \"image-registries-secret\"}]}"
7+
done

0 commit comments

Comments
 (0)