Skip to content

Commit

Permalink
pgupgrade: Use different service for postgres old (PROJQUAY-6672) (#981)
Browse files Browse the repository at this point in the history
Use a different service for the old postgres deployment during the upgrade process
This ensures that the service will not point to the terminating deployment

---------

Co-authored-by: Brandon Caton <[email protected]>
  • Loading branch information
jonathankingfc and bcaton85 authored Oct 22, 2024
1 parent d8bc894 commit 68c55fa
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 9 deletions.
28 changes: 28 additions & 0 deletions controllers/quay/quayregistry_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,34 @@ func (r *QuayRegistryReconciler) checkPostgresUpgradeStatus(
r.Log.Error(err, fmt.Sprintf("%s deployment could not be deleted", oldPostgresDeploymentName))
}

oldPostgresServiceName := fmt.Sprintf("%s-%s", quay.GetName(), "clair-postgres-old")
oldPostgresService := &corev1.Service{}
if err := r.Client.Get(
ctx,
types.NamespacedName{
Name: oldPostgresServiceName,
Namespace: quay.GetNamespace(),
},
oldPostgresService,
); err != nil {
r.Log.Info(fmt.Sprintf("%s service not found, skipping", oldPostgresServiceName))
continue
}

// Remove owner reference from old service
obj, err = v1.RemoveOwnerReference(quay, oldPostgresService)
if err != nil {
log.Error(err, "could not remove owner reference from old postgres service")
}

// Delete old postgres deployment
if err := r.Client.Delete(
ctx,
obj,
); err != nil {
r.Log.Error(err, fmt.Sprintf("%s service could not be deleted", oldPostgresServiceName))
}

// Remove owner reference from old pvc so user can delete when ready
var oldPostgresPVCName string
if jobName == clairPostgresUpgradeJobName {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ kind: Deployment
metadata:
name: clair-postgres-old
labels:
quay-component: clair-postgres
quay-component: clair-postgres-old
annotations:
quay-component: clair-postgres
quay-component: clair-postgres-old
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
quay-component: clair-postgres
quay-component: clair-postgres-old
template:
metadata:
labels:
quay-component: clair-postgres
quay-component: clair-postgres-old
spec:
terminationGracePeriodSeconds: 180
serviceAccountName: clair-postgres
Expand Down
17 changes: 17 additions & 0 deletions kustomize/components/clairpgupgrade/base/clair-pg-old.service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
name: clair-postgres-old
labels:
quay-component: clair-postgres-old
annotations:
quay-component: clair-postgres-old
spec:
type: ClusterIP
ports:
- port: 5432
protocol: TCP
name: postgres
targetPort: 5432
selector:
quay-component: clair-postgres-old
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
valueFrom:
secretKeyRef:
name: clair-config-secret
key: clair-db-host
key: clair-db-old-host
- name: POSTGRESQL_MIGRATION_ADMIN_PASSWORD
value: postgres
- name: POSTGRESQL_SHARED_BUFFERS
Expand All @@ -49,9 +49,9 @@ spec:
cpu: 500m
memory: 2Gi
command:
- "/bin/sh"
- "-c"
- "/bin/sh"
- "-c"
args:
- >
run-postgresql --version || (echo "postgres migration command failed, cleaning up..." && rm -rf /var/lib/pgsql/data/* && exit 1)
- >
run-postgresql --version || (echo "postgres migration command failed, cleaning up..." && rm -rf /var/lib/pgsql/data/* && exit 1)
backoffLimit: 50
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ resources:
- ./clair-pg-upgrade.job.yaml
- ./clair-pg-old.persistentvolumeclaim.yaml
- ./clair-pg-old.deployment.yaml
- ./clair-pg-old.service.yaml
patchesStrategicMerge:
- ./clair-pg.deployment.patch.yaml
1 change: 1 addition & 0 deletions pkg/kustomize/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ func componentConfigFilesFor(log logr.Logger, qctx *quaycontext.QuayRegistryCont
cfgFiles["config.yaml"] = cfg
cfgFiles["01_user_config.yaml"] = configFiles["clair-config.yaml"]
cfgFiles["clair-db-host"] = []byte(strings.TrimSpace(strings.Join([]string{quay.GetName(), "clair-postgres"}, "-")))
cfgFiles["clair-db-old-host"] = []byte(strings.TrimSpace(strings.Join([]string{quay.GetName(), "clair-postgres-old"}, "-")))

return cfgFiles, nil
default:
Expand Down

0 comments on commit 68c55fa

Please sign in to comment.