From 8e85f3290d4fa722ec2a9b8904a7a03c022e4e90 Mon Sep 17 00:00:00 2001 From: git-hyagi <45576767+git-hyagi@users.noreply.github.com> Date: Wed, 3 Jul 2024 17:41:15 -0300 Subject: [PATCH] Modified the way to provide custom Pulp settings Instead of providing custom configurations through the `pulp_settings` RawExtension field, this commit adds a new field called `custom_pulp_settings` which receives the name of a ConfigMap (that users should create manually) with the custom configurations. closes: #1271 --- CHANGES/1271.bugfix | 3 + .../v1beta2/pulp_types.go | 10 ++- .../pulp-operator.clusterserviceversion.yaml | 12 ++- .../repo-manager.pulpproject.org_pulps.yaml | 8 +- .../repo-manager.pulpproject.org_pulps.yaml | 8 +- .../pulp-operator.clusterserviceversion.yaml | 10 ++- controllers/deployment.go | 14 ++-- controllers/ocp/route.go | 4 +- controllers/repo_manager/README.md | 3 +- controllers/repo_manager/controller.go | 13 +++- controllers/repo_manager/ingress.go | 4 +- controllers/repo_manager/secret.go | 32 +++++++- controllers/repo_manager/utils.go | 10 +-- controllers/repo_manager/web.go | 4 +- controllers/utils.go | 77 ++++++++++++------- main.go | 2 +- .../admin/guides/configurations/database.md | 2 +- .../guides/configurations/pulp_settings.md | 28 +++++-- 18 files changed, 177 insertions(+), 67 deletions(-) create mode 100644 CHANGES/1271.bugfix diff --git a/CHANGES/1271.bugfix b/CHANGES/1271.bugfix new file mode 100644 index 000000000..0ea74597e --- /dev/null +++ b/CHANGES/1271.bugfix @@ -0,0 +1,3 @@ +Modified the way to provide custom Pulp settings. Instead of using a field of +type `RawExtension`, the new `custom_pulp_settings` field allow to pass the name +of a `ConfigMap` with the configurations. diff --git a/apis/repo-manager.pulpproject.org/v1beta2/pulp_types.go b/apis/repo-manager.pulpproject.org/v1beta2/pulp_types.go index 0d641eb67..b1f63c147 100644 --- a/apis/repo-manager.pulpproject.org/v1beta2/pulp_types.go +++ b/apis/repo-manager.pulpproject.org/v1beta2/pulp_types.go @@ -281,12 +281,20 @@ type PulpSpec struct { // +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:hidden"} Cache Cache `json:"cache,omitempty"` - // Definition of /etc/pulp/settings.py config file. + // [DEPRECATED] Definition of /etc/pulp/settings.py config file. + // This field is deprecated and will be removed in the future, use the + // custom_pulp_settings field instead. // +kubebuilder:pruning:PreserveUnknownFields // +kubebuilder:validation:Optional // +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:advanced"} PulpSettings runtime.RawExtension `json:"pulp_settings,omitempty"` + // Name of the ConfigMap to define Pulp configurations not available + // through this CR. + // +kubebuilder:validation:Optional + // +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:hidden"} + CustomPulpSettings string `json:"custom_pulp_settings,omitempty"` + // The image name (repo name) for the pulp webserver image. // Default: "quay.io/pulp/pulp-web" // +kubebuilder:validation:Optional diff --git a/bundle/manifests/pulp-operator.clusterserviceversion.yaml b/bundle/manifests/pulp-operator.clusterserviceversion.yaml index 17763c927..60090f8e1 100644 --- a/bundle/manifests/pulp-operator.clusterserviceversion.yaml +++ b/bundle/manifests/pulp-operator.clusterserviceversion.yaml @@ -168,7 +168,7 @@ metadata: capabilities: Full Lifecycle categories: Integration & Delivery containerImage: quay.io/pulp/pulp-operator:devel - createdAt: "2024-04-08T17:36:58Z" + createdAt: "2024-07-04T17:02:20Z" description: Pulp is a platform for managing repositories of software packages and making them available to a large number of consumers. operators.operatorframework.io/builder: operator-sdk-v1.29.0 @@ -604,6 +604,12 @@ spec: path: content.topology_spread_constraints x-descriptors: - urn:alm:descriptor:com.tectonic.ui:advanced + - description: Name of the ConfigMap to define Pulp configurations not available + through this CR. + displayName: Custom Pulp Settings + path: custom_pulp_settings + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:hidden - description: Database defines desired state of postgres resources displayName: Database path: database @@ -936,7 +942,9 @@ spec: path: pulp_secret_key x-descriptors: - urn:alm:descriptor:com.tectonic.ui:hidden - - description: Definition of /etc/pulp/settings.py config file. + - description: '[DEPRECATED] Definition of /etc/pulp/settings.py config file. + This field is deprecated and will be removed in the future, use the custom_pulp_settings + field instead.' displayName: Pulp Settings path: pulp_settings x-descriptors: diff --git a/bundle/manifests/repo-manager.pulpproject.org_pulps.yaml b/bundle/manifests/repo-manager.pulpproject.org_pulps.yaml index 5fb19914c..d6dbd0405 100644 --- a/bundle/manifests/repo-manager.pulpproject.org_pulps.yaml +++ b/bundle/manifests/repo-manager.pulpproject.org_pulps.yaml @@ -5895,6 +5895,10 @@ spec: type: object type: array type: object + custom_pulp_settings: + description: Name of the ConfigMap to define Pulp configurations not + available through this CR. + type: string database: description: Database defines desired state of postgres resources properties: @@ -7735,7 +7739,9 @@ spec: Default: "pulp-secret-key"' type: string pulp_settings: - description: Definition of /etc/pulp/settings.py config file. + description: '[DEPRECATED] Definition of /etc/pulp/settings.py config + file. This field is deprecated and will be removed in the future, + use the custom_pulp_settings field instead.' type: object x-kubernetes-preserve-unknown-fields: true pvc: diff --git a/config/crd/bases/repo-manager.pulpproject.org_pulps.yaml b/config/crd/bases/repo-manager.pulpproject.org_pulps.yaml index be48abc5e..d753ce189 100644 --- a/config/crd/bases/repo-manager.pulpproject.org_pulps.yaml +++ b/config/crd/bases/repo-manager.pulpproject.org_pulps.yaml @@ -5896,6 +5896,10 @@ spec: type: object type: array type: object + custom_pulp_settings: + description: Name of the ConfigMap to define Pulp configurations not + available through this CR. + type: string database: description: Database defines desired state of postgres resources properties: @@ -7736,7 +7740,9 @@ spec: Default: "pulp-secret-key"' type: string pulp_settings: - description: Definition of /etc/pulp/settings.py config file. + description: '[DEPRECATED] Definition of /etc/pulp/settings.py config + file. This field is deprecated and will be removed in the future, + use the custom_pulp_settings field instead.' type: object x-kubernetes-preserve-unknown-fields: true pvc: diff --git a/config/manifests/bases/pulp-operator.clusterserviceversion.yaml b/config/manifests/bases/pulp-operator.clusterserviceversion.yaml index a526d3996..c0d218ca6 100644 --- a/config/manifests/bases/pulp-operator.clusterserviceversion.yaml +++ b/config/manifests/bases/pulp-operator.clusterserviceversion.yaml @@ -600,6 +600,12 @@ spec: path: content.topology_spread_constraints x-descriptors: - urn:alm:descriptor:com.tectonic.ui:advanced + - description: Name of the ConfigMap to define Pulp configurations not available + through this CR. + displayName: Custom Pulp Settings + path: custom_pulp_settings + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:hidden - description: Database defines desired state of postgres resources displayName: Database path: database @@ -932,7 +938,9 @@ spec: path: pulp_secret_key x-descriptors: - urn:alm:descriptor:com.tectonic.ui:hidden - - description: Definition of /etc/pulp/settings.py config file. + - description: '[DEPRECATED] Definition of /etc/pulp/settings.py config file. + This field is deprecated and will be removed in the future, use the custom_pulp_settings + field instead.' displayName: Pulp Settings path: pulp_settings x-descriptors: diff --git a/controllers/deployment.go b/controllers/deployment.go index b3ec3bd75..4158713c0 100644 --- a/controllers/deployment.go +++ b/controllers/deployment.go @@ -728,7 +728,7 @@ func (d *CommonDeployment) setInitContainerResourceRequirements(pulp repomanager } // setReadinessProbe defines the container readinessprobe -func (d *CommonDeployment) setReadinessProbe(pulp repomanagerpulpprojectorgv1beta2.Pulp, pulpcoreType settings.PulpcoreType) { +func (d *CommonDeployment) setReadinessProbe(resources any, pulp repomanagerpulpprojectorgv1beta2.Pulp, pulpcoreType settings.PulpcoreType) { readinessProbe := reflect.ValueOf(pulp.Spec).FieldByName(string(pulpcoreType)).FieldByName("ReadinessProbe").Interface().(*corev1.Probe) switch pulpcoreType { case settings.API: @@ -738,7 +738,7 @@ func (d *CommonDeployment) setReadinessProbe(pulp repomanagerpulpprojectorgv1bet Exec: &corev1.ExecAction{ Command: []string{ "/usr/bin/readyz.py", - GetPulpSetting(&pulp, "api_root") + "api/v3/status/", + GetAPIRoot(resources.(FunctionResources).Client, &pulp) + "api/v3/status/", }, }, }, @@ -756,7 +756,7 @@ func (d *CommonDeployment) setReadinessProbe(pulp repomanagerpulpprojectorgv1bet Exec: &corev1.ExecAction{ Command: []string{ "/usr/bin/readyz.py", - GetPulpSetting(&pulp, "content_path_prefix"), + GetContentPathPrefix(resources.(FunctionResources).Client, &pulp), }, }, }, @@ -790,7 +790,7 @@ func (d *CommonDeployment) setReadinessProbe(pulp repomanagerpulpprojectorgv1bet } // setReadinessProbe defines the container livenessprobe -func (d *CommonDeployment) setLivenessProbe(pulp repomanagerpulpprojectorgv1beta2.Pulp, pulpcoreType settings.PulpcoreType) { +func (d *CommonDeployment) setLivenessProbe(resources any, pulp repomanagerpulpprojectorgv1beta2.Pulp, pulpcoreType settings.PulpcoreType) { livenessProbe := reflect.ValueOf(pulp.Spec).FieldByName(string(pulpcoreType)).FieldByName("LivenessProbe").Interface().(*corev1.Probe) switch pulpcoreType { case settings.API: @@ -799,7 +799,7 @@ func (d *CommonDeployment) setLivenessProbe(pulp repomanagerpulpprojectorgv1beta FailureThreshold: 10, ProbeHandler: corev1.ProbeHandler{ HTTPGet: &corev1.HTTPGetAction{ - Path: GetPulpSetting(&pulp, "api_root") + "api/v3/status/", + Path: GetAPIRoot(resources.(FunctionResources).Client, &pulp) + "api/v3/status/", Port: intstr.IntOrString{ IntVal: 24817, }, @@ -1126,8 +1126,8 @@ func (d *CommonDeployment) build(resources any, pulpcoreType settings.PulpcoreTy d.setVolumes(resources, pulpcoreType) d.setVolumeMounts(*pulp, pulpcoreType) d.setResourceRequirements(*pulp, pulpcoreType) - d.setLivenessProbe(*pulp, pulpcoreType) - d.setReadinessProbe(*pulp, pulpcoreType) + d.setLivenessProbe(resources, *pulp, pulpcoreType) + d.setReadinessProbe(resources, *pulp, pulpcoreType) d.setImage(*pulp) d.setTopologySpreadConstraints(*pulp, pulpcoreType) d.setInitContainerResourceRequirements(*pulp, pulpcoreType) diff --git a/controllers/ocp/route.go b/controllers/ocp/route.go index 8ed1bd05d..2af6237b4 100644 --- a/controllers/ocp/route.go +++ b/controllers/ocp/route.go @@ -113,13 +113,13 @@ func PulpRouteController(resources controllers.FunctionResources, restClient res defaultPlugins := []RoutePlugin{ { Name: pulp.Name + "-content", - Path: controllers.GetPulpSetting(pulp, "content_path_prefix"), + Path: controllers.GetContentPathPrefix(resources.Client, pulp), TargetPort: "content-24816", ServiceName: settings.ContentService(pulp.Name), }, { Name: pulp.Name + "-api-v3", - Path: controllers.GetPulpSetting(pulp, "api_root") + "api/v3/", + Path: controllers.GetAPIRoot(resources.Client, pulp) + "api/v3/", TargetPort: "api-24817", ServiceName: settings.ApiService(pulp.Name), }, diff --git a/controllers/repo_manager/README.md b/controllers/repo_manager/README.md index c78c53486..c22adf9c9 100644 --- a/controllers/repo_manager/README.md +++ b/controllers/repo_manager/README.md @@ -222,7 +222,8 @@ PulpSpec defines the desired state of Pulp | worker | Worker defines desired state of pulpcore-worker resources | [Worker](#worker) | false | | web | Web defines desired state of pulpcore-web (reverse-proxy) resources | [Web](#web) | false | | cache | Cache defines desired state of redis resources | [Cache](#cache) | false | -| pulp_settings | Definition of /etc/pulp/settings.py config file. | runtime.RawExtension | false | +| pulp_settings | [DEPRECATED] Definition of /etc/pulp/settings.py config file. This field is deprecated and will be removed in the future, use the custom_pulp_settings field instead. | runtime.RawExtension | false | +| custom_pulp_settings | Name of the ConfigMap to define Pulp configurations not available through this CR. | string | false | | image_web | The image name (repo name) for the pulp webserver image. Default: \"quay.io/pulp/pulp-web\" | string | false | | image_web_version | The image version for the pulp webserver image. Default: \"stable\" | string | false | | admin_password_secret | Secret where the administrator password can be found. Default: + \"-admin-password\" | string | false | diff --git a/controllers/repo_manager/controller.go b/controllers/repo_manager/controller.go index f7f76882b..61d36b64e 100644 --- a/controllers/repo_manager/controller.go +++ b/controllers/repo_manager/controller.go @@ -327,6 +327,10 @@ func indexerFunc(obj client.Object) []string { if pulp.Spec.LDAP.CA != "" { keys = append(keys, pulp.Spec.LDAP.CA) } + if customSettings := pulp.Spec.CustomPulpSettings; customSettings != "" { + keys = append(keys, customSettings) + } + return keys } @@ -337,7 +341,7 @@ func (r *RepoManagerReconciler) SetupWithManager(mgr ctrl.Manager) error { r.recorder = mgr.GetEventRecorderFor("Pulp") // adds an index to `object_storage_azure_secret` allowing to lookup `Pulp` by a referenced `Azure Object Storage Secret` name - if err := mgr.GetFieldIndexer().IndexField(context.Background(), &repomanagerpulpprojectorgv1beta2.Pulp{}, "secrets", indexerFunc); err != nil { + if err := mgr.GetFieldIndexer().IndexField(context.Background(), &repomanagerpulpprojectorgv1beta2.Pulp{}, "objects", indexerFunc); err != nil { return err } @@ -354,7 +358,12 @@ func (r *RepoManagerReconciler) SetupWithManager(mgr ctrl.Manager) error { Owns(&netv1.Ingress{}). Watches( &corev1.Secret{}, - handler.EnqueueRequestsFromMapFunc(r.findPulpDependentSecrets), + handler.EnqueueRequestsFromMapFunc(r.findPulpDependentObjects), + builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}), + ). + Watches( + &corev1.ConfigMap{}, + handler.EnqueueRequestsFromMapFunc(r.findPulpDependentObjects), builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}), ) diff --git a/controllers/repo_manager/ingress.go b/controllers/repo_manager/ingress.go index 54c9d4a28..22fd8ed38 100644 --- a/controllers/repo_manager/ingress.go +++ b/controllers/repo_manager/ingress.go @@ -86,13 +86,13 @@ func (r *RepoManagerReconciler) pulpIngressController(ctx context.Context, pulp defaultPlugins := []controllers.IngressPlugin{ { Name: pulp.Name + "-content", - Path: controllers.GetPulpSetting(pulp, "content_path_prefix"), + Path: controllers.GetContentPathPrefix(r.Client, pulp), TargetPort: "content-24816", ServiceName: settings.ContentService(pulp.Name), }, { Name: pulp.Name + "-api-v3", - Path: controllers.GetPulpSetting(pulp, "api_root") + "api/v3/", + Path: controllers.GetAPIRoot(r.Client, pulp) + "api/v3/", TargetPort: "api-24817", ServiceName: settings.ApiService(pulp.Name), }, diff --git a/controllers/repo_manager/secret.go b/controllers/repo_manager/secret.go index 1005b80f5..93f53ec65 100644 --- a/controllers/repo_manager/secret.go +++ b/controllers/repo_manager/secret.go @@ -160,7 +160,7 @@ func pulpServerSecret(resources controllers.FunctionResources) client.Object { ldapSettings(resources, &pulp_settings) // add custom settings to the secret - addCustomPulpSettings(pulp, &pulp_settings) + addCustomPulpSettings(resources, &pulp_settings) sec := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ @@ -520,8 +520,9 @@ func convertSettings(key string, settings interface{}) string { return converted } -// addCustomPulpSettings appends custom settings defined in Pulp CR into pulpSettings -func addCustomPulpSettings(pulp *repomanagerpulpprojectorgv1beta2.Pulp, pulpSettings *string) { +// [DEPRECATED] PulppSettings should not be used anymore. Keeping it to avoid compatibility issues +// oldCustomPulpSettings appends custom settings defined in Pulp CR into pulpSettings +func oldCustomPulpSettings(pulp *repomanagerpulpprojectorgv1beta2.Pulp, pulpSettings *string) { settings := pulp.Spec.PulpSettings.Raw var settingsJson map[string]interface{} json.Unmarshal(settings, &settingsJson) @@ -535,6 +536,31 @@ func addCustomPulpSettings(pulp *repomanagerpulpprojectorgv1beta2.Pulp, pulpSett *pulpSettings = *pulpSettings + convertedSettings } +func addCustomPulpSettings(resources controllers.FunctionResources, pulpSettings *string) { + pulp := resources.Pulp + + // [DEPRECATED] PulppSettings should not be used anymore. Keeping it to avoid compatibility issues + if pulp.Spec.PulpSettings.Raw != nil { + oldCustomPulpSettings(pulp, pulpSettings) + return + } + + if pulp.Spec.CustomPulpSettings == "" { + return + } + + settingsCM := &corev1.ConfigMap{} + resources.Client.Get(resources.Context, types.NamespacedName{Name: pulp.Spec.CustomPulpSettings, Namespace: pulp.Namespace}, settingsCM) + + settings := "" + for _, k := range sortKeys(settingsCM.Data) { + settings = settings + fmt.Sprintf("%v = %v\n", k, settingsCM.Data[k]) + } + + *pulpSettings = *pulpSettings + settings + +} + // debugLogging will set the log level from Pulpcore pods to DEBUG func debugLogging(resources controllers.FunctionResources, pulpSettings *string) { diff --git a/controllers/repo_manager/utils.go b/controllers/repo_manager/utils.go index 35ffcbfaa..6edfbfcf8 100644 --- a/controllers/repo_manager/utils.go +++ b/controllers/repo_manager/utils.go @@ -457,14 +457,14 @@ func ignoreCronjobStatus() predicate.Predicate { } } -// findPulpDependentSecrets will search for Pulp objects based on Secret names defined in Pulp CR. -// It is used to "link" these Secrets (not "owned" by Pulp operator) with Pulp object -func (r *RepoManagerReconciler) findPulpDependentSecrets(ctx context.Context, secret client.Object) []reconcile.Request { +// findPulpDependentObjects will search for Pulp objects based on Secret/ConfigMap names defined in Pulp CR. +// It is used to "link" these Secrets/ConfigMaps (not "owned" by Pulp operator) with Pulp object +func (r *RepoManagerReconciler) findPulpDependentObjects(ctx context.Context, obj client.Object) []reconcile.Request { associatedPulp := repomanagerpulpprojectorgv1beta2.PulpList{} opts := &client.ListOptions{ - FieldSelector: fields.OneTermEqualSelector("secrets", secret.GetName()), - Namespace: secret.GetNamespace(), + FieldSelector: fields.OneTermEqualSelector("objects", obj.GetName()), + Namespace: obj.GetNamespace(), } if err := r.List(context.TODO(), &associatedPulp, opts); err != nil { return []reconcile.Request{} diff --git a/controllers/repo_manager/web.go b/controllers/repo_manager/web.go index cd07afec0..c336bec9c 100644 --- a/controllers/repo_manager/web.go +++ b/controllers/repo_manager/web.go @@ -164,7 +164,7 @@ func (r *RepoManagerReconciler) deploymentForPulpWeb(m *repomanagerpulpprojector FailureThreshold: 2, ProbeHandler: corev1.ProbeHandler{ HTTPGet: &corev1.HTTPGetAction{ - Path: controllers.GetPulpSetting(m, "api_root") + "api/v3/status/", + Path: controllers.GetAPIRoot(funcResources.Client, m) + "api/v3/status/", Port: intstr.IntOrString{ IntVal: 8080, }, @@ -471,7 +471,7 @@ func (r *RepoManagerReconciler) pulpWebConfigMap(m *repomanagerpulpprojectorgv1b proxy_pass http://pulp-content; } - location ` + controllers.GetPulpSetting(m, "api_root") + `api/v3/ { + location ` + controllers.GetAPIRoot(r.Client, m) + `api/v3/ { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $http_host; diff --git a/controllers/utils.go b/controllers/utils.go index 8ce3d5095..430fddde1 100644 --- a/controllers/utils.go +++ b/controllers/utils.go @@ -25,6 +25,7 @@ import ( "fmt" "hash/fnv" "reflect" + "strconv" "strings" "time" @@ -323,36 +324,58 @@ func WaitAPIPods[T any](resource T, pulp *repomanagerpulpprojectorgv1beta2.Pulp, time.Sleep(time.Second) } } -func GetPulpSetting(pulp *repomanagerpulpprojectorgv1beta2.Pulp, key string) string { - settings := pulp.Spec.PulpSettings.Raw - var settingsJson map[string]interface{} - json.Unmarshal(settings, &settingsJson) - - v := settingsJson[key] - // default values - if v == nil { - switch key { - case "api_root": - return "/pulp/" - case "content_path_prefix": - domainEnabled := settingsJson[strings.ToLower("domain_enabled")] - if domainEnabled != nil && domainEnabled.(bool) { - return "/pulp/content/default/" - } - return "/pulp/content/" - case "galaxy_collection_signing_service": - return "ansible-default" - case "galaxy_container_signing_service": - return "container-default" + +// getPulpSetting returns the value of a Pulp setting field +func getPulpSetting(r client.Client, pulp *repomanagerpulpprojectorgv1beta2.Pulp, key string) string { + // [DEPRECATED] PulppSettings should not be used anymore. Keeping it to avoid compatibility issues + if settings := pulp.Spec.PulpSettings.Raw; settings != nil { + var settingsJson map[string]interface{} + json.Unmarshal(settings, &settingsJson) + if setting := settingsJson[key]; setting != nil && setting.(string) != "" { + return setting.(string) + } + } + + if pulp.Spec.CustomPulpSettings != "" { + settingsCM := &corev1.ConfigMap{} + r.Get(context.TODO(), types.NamespacedName{Name: pulp.Spec.CustomPulpSettings, Namespace: pulp.Namespace}, settingsCM) + if setting, found := settingsCM.Data[key]; found { + return setting } } - switch v.(type) { - case map[string]interface{}: - rawMapping, _ := json.Marshal(v) - return fmt.Sprintln(strings.Replace(string(rawMapping), "\"", "'", -1)) - default: - return fmt.Sprintf("%v", v) + + return "" +} + +// domainEnabled returns the definition of DOMAIN_ENABLED in settings.py +func domainEnabled(r client.Client, pulp *repomanagerpulpprojectorgv1beta2.Pulp) bool { + if domainEnabled := getPulpSetting(r, pulp, "domain_enabled"); domainEnabled != "" { + enabled, _ := strconv.ParseBool(domainEnabled) + return enabled + } + return false +} + +// GetAPIRoot returns the definition of API_ROOT in settings.py or /pulp/ +func GetAPIRoot(r client.Client, pulp *repomanagerpulpprojectorgv1beta2.Pulp) string { + if apiRoot := getPulpSetting(r, pulp, "api_root"); apiRoot != "" { + return apiRoot + } + return "/pulp/" +} + +// GetContentPathPrefix returns the definition of CONTENT_PATH_PREFIX in settings.py or +// * /pulp/content/default/ if domain is enabled +// * /pulp/content/ otherwise +func GetContentPathPrefix(r client.Client, pulp *repomanagerpulpprojectorgv1beta2.Pulp) string { + if contentPath := getPulpSetting(r, pulp, "content_path_prefix"); contentPath != "" { + return contentPath + } + + if domainEnabled(r, pulp) { + return "/pulp/content/default/" } + return "/pulp/content/" } // getSigningKeyFingerprint returns the signing key fingerprint from secret object diff --git a/main.go b/main.go index 87113bf5d..0dd7b958f 100644 --- a/main.go +++ b/main.go @@ -177,7 +177,7 @@ func main() { os.Exit(1) } - setupLog.Info("pulp-operator version: 1.0.1-beta.5") + setupLog.Info("pulp-operator version: 1.0.2-beta.5") setupLog.Info("starting manager") if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { setupLog.Error(err, "problem running manager") diff --git a/staging_docs/admin/guides/configurations/database.md b/staging_docs/admin/guides/configurations/database.md index 66155dce1..40a7928f8 100644 --- a/staging_docs/admin/guides/configurations/database.md +++ b/staging_docs/admin/guides/configurations/database.md @@ -15,7 +15,7 @@ If no `database` parameter is defined, Pulp operator will deploy PostgreSQL with * **no data will be persisted**, the container will mount an emptyDir (all data will be lost in case of pod restart) -A new `Secret` (<deployment-name>-postgres-configuration) will also be created with some information like: +A new `Secret` (-postgres-configuration) will also be created with some information like: * the database name * the admin user diff --git a/staging_docs/admin/guides/configurations/pulp_settings.md b/staging_docs/admin/guides/configurations/pulp_settings.md index 903bbaa0e..af926745e 100644 --- a/staging_docs/admin/guides/configurations/pulp_settings.md +++ b/staging_docs/admin/guides/configurations/pulp_settings.md @@ -31,7 +31,7 @@ based on the definitions of `Pulp CR`. There are 2 ways to configure the settings: * [via specific fields](#pulp-operator-defined-settings) -* [via `pulp_settings` field](#custom-settings) +* [via `custom_pulp_settings` field](#custom-settings) ## Pulp Operator Defined Settings @@ -189,16 +189,28 @@ API_ROOT = "/pulp/" ## Custom Settings !!! WARNING - Use `pulp_settings` field with caution. Since Pulp Operator will not manage - nor validate these settings, providing invalid values can cause disruption or + Use the `custom_pulp_settings` field with caution. Since Pulp Operator will not manage + nor validate the contents from the ConfigMap, providing invalid values can cause disruption or unexpected behaviors. Most of Pulp configurations should be done using the settings [presented before](/pulp_operator/configuring/pulp_settings/#pulp-operator-defined-settings), -but sometimes it is not possible. In this case, Pulp CR has the `pulp_settings` -field that can be used to define additional configurations. For example, to disable -[Pulp analytics](https://docs.pulpproject.org/pulpcore/configuration/settings.html#analytics): +but sometimes it is not possible. In this case, Pulp CR has the `custom_pulp_settings` +field that can be used to define a `ConfigMap` with the additional Pulp configurations. + +For example, to disable +[Pulp analytics](https://docs.pulpproject.org/pulpcore/configuration/settings.html#analytics), first create a new ConfigMap: +```bash +$ kubectl create configmap settings --from-literal=ANALYTICS=False +``` + +update Pulp CR with this new `ConfigMap`: + ```yaml spec: - pulp_settings: - analytics: false + custom_pulp_settings: settings ``` + + +!!! Info + The `pulp_settings` field is deprecated! + Use the `custom_pulp_settings` field instead.