Skip to content

Commit 0a9a0e0

Browse files
committed
Fix duplicated configs with custom_pulp_settings
[noissue]
1 parent 0ead5d8 commit 0a9a0e0

File tree

8 files changed

+92
-56
lines changed

8 files changed

+92
-56
lines changed

.github/workflows/upgrade.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
jobs:
77
bundle-upgrade:
88
runs-on: ubuntu-latest
9+
if: github.ref_name != 'main'
910
steps:
1011
- uses: actions/checkout@v4
1112
- name: Setup Go environment
@@ -27,12 +28,12 @@ jobs:
2728
- name: Build bundle image
2829
run: make bundle-build bundle-push BUNDLE_IMG=localhost:5001/pulp-operator-bundle:old
2930
- name: Install the operator
30-
run: /tmp/operator-sdk run bundle --skip-tls localhost:5001/pulp-operator-bundle:old
31+
run: /tmp/operator-sdk run bundle --skip-tls localhost:5001/pulp-operator-bundle:old --timeout 4m
3132
- uses: actions/checkout@v4
3233
- name: Build bundle image
3334
run: make docker-build docker-push bundle bundle-build bundle-push VERSION=1.0.0-dev IMG=localhost:5001/pulp-operator:upgrade BUNDLE_IMG=localhost:5001/pulp-operator-bundle:new
3435
- name: Upgrade the operator
35-
run: /tmp/operator-sdk run bundle-upgrade --use-http localhost:5001/pulp-operator-bundle:new
36+
run: /tmp/operator-sdk run bundle-upgrade --use-http localhost:5001/pulp-operator-bundle:new --timeout 4m
3637
- name: Logs
3738
if: always()
3839
run: .github/workflows/scripts/show_logs.sh --kind

CHANGES/1411.fix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed an issue with duplicate configuration when custom_pulp_settings is defined.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# To re-generate a bundle for another specific version without changing the standard setup, you can:
44
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
55
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
6-
VERSION ?= 1.0.0
6+
VERSION ?= 1.0.1
77
DATE := $(shell date '+%Y%m%d')
88
BUILD_VERSION := $(VERSION)-$(DATE)
99

bundle/manifests/pulp-operator.clusterserviceversion.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ metadata:
6464
capabilities: Full Lifecycle
6565
categories: Integration & Delivery
6666
containerImage: quay.io/pulp/pulp-operator:v1.0.0
67-
createdAt: "2025-04-22T19:46:18Z"
67+
createdAt: "2025-04-30T14:46:36Z"
6868
description: Pulp is a platform for managing repositories of software packages
6969
and making them available to a large number of consumers.
7070
metadata.annotations.support: Community
7171
operators.operatorframework.io/builder: operator-sdk-v1.31.0
7272
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
7373
repository: https://github.com/pulp/pulp-operator
74-
name: pulp-operator.v1.0.0
74+
name: pulp-operator.v1.0.1
7575
namespace: placeholder
7676
spec:
7777
apiservicedefinitions: {}
@@ -1175,7 +1175,7 @@ spec:
11751175
valueFrom:
11761176
fieldRef:
11771177
fieldPath: metadata.annotations['olm.targetNamespaces']
1178-
image: quay.io/pulp/pulp-operator:v1.0.0
1178+
image: quay.io/pulp/pulp-operator:v1.0.1
11791179
livenessProbe:
11801180
httpGet:
11811181
path: /healthz
@@ -1421,4 +1421,4 @@ spec:
14211421
name: pulp-redis
14221422
- image: docker.io/library/postgres:13
14231423
name: pulp-postgres
1424-
version: 1.0.0
1424+
version: 1.0.1

config/manager/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ kind: Kustomization
1313
images:
1414
- name: controller
1515
newName: quay.io/pulp/pulp-operator
16-
newTag: v1.0.0
16+
newTag: v1.0.1

controllers/repo_manager/secret.go

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -121,44 +121,41 @@ func (r *RepoManagerReconciler) createSecrets(ctx context.Context, pulp *pulpv1.
121121
func pulpServerSecret(resources controllers.FunctionResources) client.Object {
122122

123123
pulp := resources.Pulp
124-
pulp_settings := ""
124+
pulp_settings := controllers.DotNotEditMessage
125125

126-
// default settings.py configuration
127-
defaultPulpSettings(resources, &pulp_settings)
126+
// add custom settings to the secret
127+
customSettings := addCustomPulpSettings(resources, &pulp_settings)
128128

129129
// pulpcore debug log
130130
debugLogging(resources, &pulp_settings)
131131

132132
// db settings
133-
databaseSettings(resources, &pulp_settings)
133+
databaseSettings(resources, &pulp_settings, customSettings)
134134

135135
// add cache settings
136136
cacheSettings(resources, &pulp_settings)
137137

138138
// azure settings
139-
azureSettings(resources, &pulp_settings)
139+
azureSettings(resources, &pulp_settings, customSettings)
140140

141141
// s3 settings
142-
s3Settings(resources, &pulp_settings)
142+
s3Settings(resources, &pulp_settings, customSettings)
143143

144144
// configure settings.py with keycloak integration variables
145145
ssoConfig(resources, &pulp_settings)
146146

147147
// configure TOKEN_SERVER based on ingress_type
148-
tokenSettings(resources, &pulp_settings)
148+
tokenSettings(resources, &pulp_settings, customSettings)
149149

150150
// django SECRET_KEY
151-
secretKeySettings(resources, &pulp_settings)
151+
secretKeySettings(resources, &pulp_settings, customSettings)
152152

153153
// allowed content checksum
154-
allowedContentChecksumsSettings(resources, &pulp_settings)
154+
allowedContentChecksumsSettings(resources, &pulp_settings, customSettings)
155155

156156
// ldap auth config
157157
ldapSettings(resources, &pulp_settings)
158158

159-
// add custom settings to the secret
160-
addCustomPulpSettings(resources, &pulp_settings)
161-
162159
sec := &corev1.Secret{
163160
ObjectMeta: metav1.ObjectMeta{
164161
Name: settings.PulpServerSecret(pulp.Name),
@@ -244,22 +241,6 @@ func pulpContainerAuth(resources controllers.FunctionResources) client.Object {
244241
}
245242
}
246243

247-
// defaultPulpSettings appends some common settings into pulpSettings
248-
func defaultPulpSettings(resources controllers.FunctionResources, pulpSettings *string) {
249-
rootUrl := getRootURL(resources)
250-
*pulpSettings = *pulpSettings + controllers.DotNotEditMessage + `
251-
DB_ENCRYPTION_KEY = "/etc/pulp/keys/database_fields.symmetric.key"
252-
ANSIBLE_API_HOSTNAME = "` + rootUrl + `"
253-
ANSIBLE_CERTS_DIR = "/etc/pulp/keys/"
254-
CONTENT_ORIGIN = "` + rootUrl + `"
255-
PRIVATE_KEY_PATH = "/etc/pulp/keys/container_auth_private_key.pem"
256-
PUBLIC_KEY_PATH = "/etc/pulp/keys/container_auth_public_key.pem"
257-
STATIC_ROOT = "/var/lib/operator/static/"
258-
TOKEN_AUTH_DISABLED = False
259-
TOKEN_SIGNATURE_ALGORITHM = "ES256"
260-
`
261-
}
262-
263244
// cacheSettings appends redis/cache settings into pulpSettings
264245
func cacheSettings(resources controllers.FunctionResources, pulpSettings *string) {
265246
pulp := resources.Pulp
@@ -296,7 +277,11 @@ REDIS_DB = "` + cacheDB + `"
296277
}
297278

298279
// databaseSettings appends postgres settings into pulpSettings
299-
func databaseSettings(resources controllers.FunctionResources, pulpSettings *string) {
280+
func databaseSettings(resources controllers.FunctionResources, pulpSettings *string, customSettings map[string]struct{}) {
281+
if _, exists := customSettings["DATABASES"]; exists {
282+
return
283+
}
284+
300285
pulp := resources.Pulp
301286
logger := resources.Logger
302287
context := resources.Context
@@ -352,7 +337,11 @@ func databaseSettings(resources controllers.FunctionResources, pulpSettings *str
352337
}
353338

354339
// azureSettings appends azure blob object storage settings into pulpSettings
355-
func azureSettings(resources controllers.FunctionResources, pulpSettings *string) {
340+
func azureSettings(resources controllers.FunctionResources, pulpSettings *string, customSettings map[string]struct{}) {
341+
if _, exists := customSettings["STORAGES"]; exists {
342+
return
343+
}
344+
356345
pulp := resources.Pulp
357346
logger := resources.Logger
358347
context := resources.Context
@@ -392,7 +381,10 @@ STORAGES = {
392381
}
393382

394383
// s3Settings appends s3 object storage settings into pulpSettings
395-
func s3Settings(resources controllers.FunctionResources, pulpSettings *string) {
384+
func s3Settings(resources controllers.FunctionResources, pulpSettings *string, customSettings map[string]struct{}) {
385+
if _, exists := customSettings["STORAGES"]; exists {
386+
return
387+
}
396388
pulp := resources.Pulp
397389
logger := resources.Logger
398390
context := resources.Context
@@ -459,9 +451,13 @@ STORAGES = {
459451
}
460452

461453
// tokenSettings appends the TOKEN_SERVER setting into pulpSettings
462-
func tokenSettings(resources controllers.FunctionResources, pulpSettings *string) {
454+
func tokenSettings(resources controllers.FunctionResources, pulpSettings *string, customSettings map[string]struct{}) {
455+
if _, exists := customSettings["TOKEN_SERVER"]; exists {
456+
return
457+
}
458+
463459
pulp := resources.Pulp
464-
rootUrl := getRootURL(resources)
460+
rootUrl := getRootURL(*pulp)
465461

466462
// configure TOKEN_SERVER based on ingress_type
467463
tokenServer := "http://" + pulp.Name + "-api-svc." + pulp.Namespace + ".svc.cluster.local:24817/token/"
@@ -478,7 +474,11 @@ func tokenSettings(resources controllers.FunctionResources, pulpSettings *string
478474
}
479475

480476
// secretKeySettings appends djange SECRET_KEY setting into pulpSettings
481-
func secretKeySettings(resources controllers.FunctionResources, pulpSettings *string) {
477+
func secretKeySettings(resources controllers.FunctionResources, pulpSettings *string, customSettings map[string]struct{}) {
478+
if _, exists := customSettings["SECRET_KEY"]; exists {
479+
return
480+
}
481+
482482
pulp := resources.Pulp
483483
logger := resources.Logger
484484
pulpSecretKey := pulp.Spec.PulpSecretKey
@@ -494,7 +494,11 @@ func secretKeySettings(resources controllers.FunctionResources, pulpSettings *st
494494
}
495495

496496
// allowedContentChecksumsSettings appends the allowed_content_checksums into pulpSettings
497-
func allowedContentChecksumsSettings(resources controllers.FunctionResources, pulpSettings *string) {
497+
func allowedContentChecksumsSettings(resources controllers.FunctionResources, pulpSettings *string, customSettings map[string]struct{}) {
498+
if _, exists := customSettings["ALLOWED_CONTENT_CHECKSUMS"]; exists {
499+
return
500+
}
501+
498502
pulp := resources.Pulp
499503
if len(pulp.Spec.AllowedContentChecksums) == 0 {
500504
return
@@ -503,23 +507,38 @@ func allowedContentChecksumsSettings(resources controllers.FunctionResources, pu
503507
*pulpSettings = *pulpSettings + fmt.Sprintln("ALLOWED_CONTENT_CHECKSUMS = ", string(settings))
504508
}
505509

506-
func addCustomPulpSettings(resources controllers.FunctionResources, pulpSettings *string) {
510+
// addCustomPulpSettings defines settings.py with the configurations defined in custom_pulp_settings configmap
511+
// and returns a map with all the custom keys defined
512+
func addCustomPulpSettings(resources controllers.FunctionResources, pulpSettings *string) map[string]struct{} {
507513
pulp := resources.Pulp
514+
rootUrl := getRootURL(*pulp)
515+
defaultSettings := settings.DefaultPulpSettings(rootUrl)
508516

517+
// if custom_pulp_settings is not defined, append the default values and return
509518
if pulp.Spec.CustomPulpSettings == "" {
510-
return
519+
for _, k := range sortKeys(defaultSettings) {
520+
*pulpSettings = *pulpSettings + fmt.Sprintf("%v = %v\n", k, defaultSettings[k])
521+
}
522+
return nil
511523
}
512524

513525
settingsCM := &corev1.ConfigMap{}
514526
resources.Client.Get(resources.Context, types.NamespacedName{Name: pulp.Spec.CustomPulpSettings, Namespace: pulp.Namespace}, settingsCM)
515527

516-
settings := ""
528+
// store the keys found in custom_pulp_settings configmap
529+
settings := map[string]struct{}{}
517530
for _, k := range sortKeys(settingsCM.Data) {
518-
settings = settings + fmt.Sprintf("%v = %v\n", strings.ToUpper(k), settingsCM.Data[k])
519-
}
531+
*pulpSettings = *pulpSettings + fmt.Sprintf("%v = %v\n", strings.ToUpper(k), settingsCM.Data[k])
532+
settings[strings.ToUpper(k)] = struct{}{}
520533

521-
*pulpSettings = *pulpSettings + settings
534+
// remove the settings from defaultSettings dict to avoid duplicate config
535+
delete(defaultSettings, strings.ToUpper(k))
536+
}
522537

538+
for _, k := range sortKeys(defaultSettings) {
539+
*pulpSettings = *pulpSettings + fmt.Sprintf("%v = %v\n", k, defaultSettings[k])
540+
}
541+
return settings
523542
}
524543

525544
// debugLogging will set the log level from Pulpcore pods to DEBUG

controllers/repo_manager/utils.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,20 +371,20 @@ func (r *RepoManagerReconciler) isNginxIngress(pulp *pulpv1.Pulp) bool {
371371
}
372372

373373
// getRootURL handles user facing URLs
374-
func getRootURL(resource controllers.FunctionResources) string {
374+
func getRootURL(pulp pulpv1.Pulp) string {
375375
scheme := "https"
376-
if isIngress(resource.Pulp) {
377-
if resource.Pulp.Spec.IngressTLSSecret == "" {
376+
if isIngress(&pulp) {
377+
if pulp.Spec.IngressTLSSecret == "" {
378378
scheme = "http"
379379
}
380-
hostname := resource.Pulp.Spec.IngressHost
380+
hostname := pulp.Spec.IngressHost
381381
return scheme + "://" + hostname
382382
}
383-
if isRoute(resource.Pulp) {
384-
return "https://" + pulp_ocp.GetRouteHost(resource.Pulp)
383+
if isRoute(&pulp) {
384+
return "https://" + pulp_ocp.GetRouteHost(&pulp)
385385
}
386386

387-
return "http://" + settings.PulpWebService(resource.Pulp.Name) + "." + resource.Pulp.Namespace + ".svc.cluster.local:24880"
387+
return "http://" + settings.PulpWebService(pulp.Name) + "." + pulp.Namespace + ".svc.cluster.local:24880"
388388
}
389389

390390
// ignoreUpdateCRStatusPredicate filters update events on pulpbackup CR status

controllers/settings/secrets.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,18 @@ func RedHatOperatorPullSecret(pulpName string) string {
3939
func DefaultDBSecret(pulpName string) string {
4040
return pulpName + "-" + postgresConfiguration
4141
}
42+
43+
// Default configurations for settings.py
44+
func DefaultPulpSettings(rootUrl string) map[string]string {
45+
return map[string]string{
46+
"DB_ENCRYPTION_KEY": `"/etc/pulp/keys/database_fields.symmetric.key"`,
47+
"ANSIBLE_CERTS_DIR": `"/etc/pulp/keys/"`,
48+
"PRIVATE_KEY_PATH": `"/etc/pulp/keys/container_auth_private_key.pem"`,
49+
"PUBLIC_KEY_PATH": `"/etc/pulp/keys/container_auth_public_key.pem"`,
50+
"STATIC_ROOT": `"/var/lib/operator/static/"`,
51+
"TOKEN_AUTH_DISABLED": "False",
52+
"TOKEN_SIGNATURE_ALGORITHM": `"ES256"`,
53+
"ANSIBLE_API_HOSTNAME": `"` + rootUrl + `"`,
54+
"CONTENT_ORIGIN": `"` + rootUrl + `"`,
55+
}
56+
}

0 commit comments

Comments
 (0)