Skip to content

Commit 070eb9f

Browse files
committed
immutable fields
1 parent aa02f6a commit 070eb9f

File tree

8 files changed

+37
-45
lines changed

8 files changed

+37
-45
lines changed

config/samples/simple-external-cache.yaml

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
1-
apiVersion: repo-manager.pulpproject.org/v1beta2
1+
---
2+
apiVersion: v1
3+
data:
4+
REDIS_DB: ""
5+
REDIS_HOST: bXktcmVkaXMtaG9zdC5leGFtcGxlLmNvbQ==
6+
REDIS_PASSWORD: ""
7+
REDIS_PORT: NjM3OQ==
8+
kind: Secret
9+
metadata:
10+
name: external-redis
11+
type: Opaque
12+
13+
---
14+
apiVersion: repo-manager.pulpproject.org/v1
215
kind: Pulp
316
metadata:
417
name: pulp
518
spec:
6-
deployment_type: pulp
7-
image_version: stable
8-
image_web_version: stable
9-
api:
10-
replicas: 1
11-
content:
12-
replicas: 1
13-
worker:
14-
replicas: 1
15-
web:
16-
replicas: 1
19+
20+
database:
21+
external_db_secret: external-database
1722

1823
file_storage_access_mode: "ReadWriteOnce"
1924
file_storage_size: "2Gi"
2025
file_storage_storage_class: standard
21-
signing_secret: "signing-galaxy"
22-
signing_scripts: "signing-scripts"
23-
image_web: "quay.io/pulp/galaxy-web"
24-
25-
ingress_type: nodeport
26-
pulp_settings:
27-
api_root: "/pulp/"
28-
allowed_export_paths:
29-
- /tmp
30-
allowed_import_paths:
31-
- /tmp
3226

3327
cache:
3428
enabled: true

controllers/deployment.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package controllers
1818

1919
import (
20-
"context"
2120
"os"
2221
"reflect"
2322
"strconv"
@@ -1108,7 +1107,7 @@ func (d *CommonDeployment) setTelemetryConfig(resources any, pulpcoreType settin
11081107
func AddHashLabel(r FunctionResources, deployment *appsv1.Deployment) {
11091108
// if the object does not exist yet we need to mutate the object to get the
11101109
// default values (I think they are added by the admission controller)
1111-
if err := r.Create(context.TODO(), deployment, client.DryRunAll); err != nil {
1110+
if err := r.Create(r.Context, deployment, client.DryRunAll); err != nil {
11121111
SetHashLabel(HashFromMutated(deployment, r), deployment)
11131112
} else {
11141113
SetHashLabel(CalculateHash(deployment.Spec), deployment)

controllers/repo_manager/job.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ func (r *RepoManagerReconciler) updateAdminPasswordJob(ctx context.Context, pulp
4141
log.Error(err, "Failed to find "+adminSecretName+" Secret!")
4242
}
4343

44-
// if the secret is already set (it is not the first execution) and it
44+
// if the secret is the same and its content
4545
// didn't change, there is nothing to do
4646
calculatedHash := controllers.CalculateHash(adminSecret.Data)
4747
currentHash := controllers.GetCurrentHash(adminSecret)
48-
if pulp.Status.AdminPasswordSecret != "" && currentHash == calculatedHash {
48+
if pulp.Status.AdminPasswordSecret == pulp.Spec.AdminPasswordSecret && currentHash == calculatedHash {
4949
return
5050
}
5151

controllers/repo_manager/precheck.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ func prechecks(ctx context.Context, r *RepoManagerReconciler, pulp *pulpv1.Pulp)
6060
}
6161

6262
// verify if a change in an immutable field has been tried
63-
if reconcile := checkImmutableFields(ctx, r, pulp); reconcile != nil {
64-
return reconcile, nil
65-
}
63+
//if reconcile := checkImmutableFields(ctx, r, pulp); reconcile != nil {
64+
// return reconcile, nil
65+
//}
6666

6767
// verify if all secrets defined in pulp cr are available
6868
if reconcile := checkSecretsAvailability(ctx, r, pulp); reconcile != nil {

controllers/repo_manager/secret.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (r *RepoManagerReconciler) createSecrets(ctx context.Context, pulp *pulpv1.
109109
expectedServerSecret := pulpServerSecret(funcResources)
110110
if requeue, err := controllers.ReconcileObject(funcResources, expectedServerSecret, serverSecret, conditionType, controllers.PulpSecret{}); err != nil || requeue {
111111
// restart pulpcore pods if the secret has changed
112-
r.restartPulpCorePods(pulp)
112+
r.restartPulpCorePods(ctx, pulp)
113113
return &ctrl.Result{Requeue: requeue}, err
114114
}
115115

@@ -464,7 +464,7 @@ func secretKeySettings(resources controllers.FunctionResources, pulpSettings *st
464464
return
465465
}
466466

467-
*pulpSettings = *pulpSettings + fmt.Sprintln("SECRET_KEY = \""+secretKey["secret_key"]+"\"")
467+
*pulpSettings = *pulpSettings + fmt.Sprintf("SECRET_KEY = \"%v\"\n", secretKey["secret_key"])
468468
}
469469

470470
// allowedContentChecksumsSettings appends the allowed_content_checksums into pulpSettings

controllers/repo_manager/status.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (r *RepoManagerReconciler) setStatusConditions(ctx context.Context, pulp *p
141141
Message: "All tasks ran successfully",
142142
})
143143

144-
if err := r.Status().Update(context.Background(), pulp); err != nil && errors.IsConflict(err) {
144+
if err := r.Status().Update(ctx, pulp); err != nil && errors.IsConflict(err) {
145145
log.V(1).Info("Failed to update pulp status", "error", err)
146146
return &ctrl.Result{Requeue: true}
147147
}
@@ -236,7 +236,7 @@ func objS3SecretCondition() func(*pulpv1.Pulp) bool {
236236
// dbFieldsEncrSecretCondition returns the function to verify if a new pulp.Status.DBFieldsEncryptionSecret should be set
237237
func dbFieldsEncrSecretCondition() func(*pulpv1.Pulp) bool {
238238
return func(pulp *pulpv1.Pulp) bool {
239-
return len(pulp.Status.DBFieldsEncryptionSecret) == 0 && len(pulp.Spec.DBFieldsEncryptionSecret) > 0
239+
return len(pulp.Status.DBFieldsEncryptionSecret) == 0 || pulp.Spec.DBFieldsEncryptionSecret != pulp.Status.DBFieldsEncryptionSecret
240240
}
241241
}
242242

@@ -248,21 +248,21 @@ func ingressTypeCondition() func(*pulpv1.Pulp) bool {
248248
// containerTokenSecretCondition returns the function to verify if a new pulp.Status.ContainerTokenSecret should be set
249249
func containerTokenSecretCondition() func(*pulpv1.Pulp) bool {
250250
return func(pulp *pulpv1.Pulp) bool {
251-
return len(pulp.Status.ContainerTokenSecret) == 0 && len(pulp.Spec.ContainerTokenSecret) > 0
251+
return len(pulp.Status.ContainerTokenSecret) == 0 || pulp.Spec.ContainerTokenSecret != pulp.Status.ContainerTokenSecret
252252
}
253253
}
254254

255255
// adminPwdSecretCondition returns the function to verify if a new pulp.Status.AdminPasswordSecret should be set
256256
func adminPwdSecretCondition() func(*pulpv1.Pulp) bool {
257257
return func(pulp *pulpv1.Pulp) bool {
258-
return len(pulp.Status.AdminPasswordSecret) == 0 && len(pulp.Spec.AdminPasswordSecret) > 0
258+
return len(pulp.Status.AdminPasswordSecret) == 0 || pulp.Spec.AdminPasswordSecret != pulp.Status.AdminPasswordSecret
259259
}
260260
}
261261

262262
// externalCacheSecretCondition returns the function to verify if a new pulp.Status.ExternalCacheSecret should be set
263263
func externalCacheSecretCondition() func(*pulpv1.Pulp) bool {
264264
return func(pulp *pulpv1.Pulp) bool {
265-
return len(pulp.Status.ExternalCacheSecret) == 0 && len(pulp.Spec.Cache.ExternalCacheSecret) > 0
265+
return len(pulp.Status.ExternalCacheSecret) == 0 || pulp.Spec.Cache.ExternalCacheSecret != pulp.Status.ExternalCacheSecret
266266
}
267267
}
268268

@@ -283,7 +283,7 @@ func telemetryEnabledCondition() func(*pulpv1.Pulp) bool {
283283
// pulpSecretKeyCondition returns the function to verify if a new pulp.Status.PulpSecretKey should be set
284284
func pulpSecretKeyCondition() func(*pulpv1.Pulp) bool {
285285
return func(pulp *pulpv1.Pulp) bool {
286-
return len(pulp.Status.PulpSecretKey) == 0 && len(pulp.Spec.PulpSecretKey) > 0
286+
return len(pulp.Status.PulpSecretKey) == 0 || pulp.Spec.PulpSecretKey != pulp.Status.PulpSecretKey
287287
}
288288
}
289289

controllers/repo_manager/utils.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ func (r *RepoManagerReconciler) findPulpDependentObjects(ctx context.Context, ob
458458
FieldSelector: fields.OneTermEqualSelector("objects", obj.GetName()),
459459
Namespace: obj.GetNamespace(),
460460
}
461-
if err := r.List(context.TODO(), &associatedPulp, opts); err != nil {
461+
if err := r.List(ctx, &associatedPulp, opts); err != nil {
462462
return []reconcile.Request{}
463463
}
464464
if len(associatedPulp.Items) > 0 {
@@ -474,11 +474,10 @@ func (r *RepoManagerReconciler) findPulpDependentObjects(ctx context.Context, ob
474474
}
475475

476476
// restartPulpCorePods will redeploy all pulpcore (API,content,worker) pods.
477-
func (r *RepoManagerReconciler) restartPulpCorePods(pulp *pulpv1.Pulp) {
478-
log := r.RawLogger
479-
log.Info("Reprovisioning pulpcore pods to get the new settings ...")
477+
func (r *RepoManagerReconciler) restartPulpCorePods(ctx context.Context, pulp *pulpv1.Pulp) {
478+
r.RawLogger.Info("Reprovisioning pulpcore pods to get the new settings ...")
480479
pulp.Status.LastDeploymentUpdate = time.Now().Format(time.RFC3339)
481-
r.Status().Update(context.TODO(), pulp)
480+
r.Status().Update(ctx, pulp)
482481
}
483482

484483
// runMigration deploys a k8s Job to run django migrations in case of pulpcore image change
@@ -630,7 +629,7 @@ func (r *RepoManagerReconciler) runSigningSecretTasks(ctx context.Context, pulp
630629
return nil
631630
}
632631

633-
r.restartPulpCorePods(pulp)
632+
r.restartPulpCorePods(ctx, pulp)
634633
secret := &corev1.Secret{}
635634
if err := r.Get(ctx, types.NamespacedName{Name: secretName, Namespace: pulp.Namespace}, secret); err != nil {
636635
r.RawLogger.Error(err, "Failed to find "+secretName+" Secret!")

controllers/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ func GetCurrentHash(obj client.Object) string {
814814
func HashFromMutated(dep *appsv1.Deployment, resources FunctionResources) string {
815815
// execute a "dry run" to update the local "deploy" variable with all
816816
// mutated configurations
817-
resources.Update(context.TODO(), dep, client.DryRunAll)
817+
resources.Update(resources.Context, dep, client.DryRunAll)
818818
return CalculateHash(dep.Spec)
819819
}
820820

0 commit comments

Comments
 (0)