diff --git a/kustomize/components/clairpgupgrade/clair-pg-old.deployment.yaml b/kustomize/components/clairpgupgrade/base/clair-pg-old.deployment.yaml similarity index 100% rename from kustomize/components/clairpgupgrade/clair-pg-old.deployment.yaml rename to kustomize/components/clairpgupgrade/base/clair-pg-old.deployment.yaml diff --git a/kustomize/components/clairpgupgrade/clair-pg-old.persistentvolumeclaim.yaml b/kustomize/components/clairpgupgrade/base/clair-pg-old.persistentvolumeclaim.yaml similarity index 100% rename from kustomize/components/clairpgupgrade/clair-pg-old.persistentvolumeclaim.yaml rename to kustomize/components/clairpgupgrade/base/clair-pg-old.persistentvolumeclaim.yaml diff --git a/kustomize/components/clairpgupgrade/clair-pg-upgrade.job.yaml b/kustomize/components/clairpgupgrade/base/clair-pg-upgrade.job.yaml similarity index 100% rename from kustomize/components/clairpgupgrade/clair-pg-upgrade.job.yaml rename to kustomize/components/clairpgupgrade/base/clair-pg-upgrade.job.yaml diff --git a/kustomize/components/clairpgupgrade/clair-pg.deployment.patch.yaml b/kustomize/components/clairpgupgrade/base/clair-pg.deployment.patch.yaml similarity index 100% rename from kustomize/components/clairpgupgrade/clair-pg.deployment.patch.yaml rename to kustomize/components/clairpgupgrade/base/clair-pg.deployment.patch.yaml diff --git a/kustomize/components/clairpgupgrade/kustomization.yaml b/kustomize/components/clairpgupgrade/base/kustomization.yaml similarity index 71% rename from kustomize/components/clairpgupgrade/kustomization.yaml rename to kustomize/components/clairpgupgrade/base/kustomization.yaml index daf2f2b11..d4fe25137 100644 --- a/kustomize/components/clairpgupgrade/kustomization.yaml +++ b/kustomize/components/clairpgupgrade/base/kustomization.yaml @@ -1,4 +1,3 @@ -# Overlay variant for upgrading to current Project Quay release. apiVersion: kustomize.config.k8s.io/v1alpha1 kind: Component resources: @@ -6,5 +5,4 @@ resources: - ./clair-pg-old.persistentvolumeclaim.yaml - ./clair-pg-old.deployment.yaml patchesStrategicMerge: - - ./clair.deployment.patch.yaml - ./clair-pg.deployment.patch.yaml diff --git a/kustomize/components/clairpgupgrade/clair.deployment.patch.yaml b/kustomize/components/clairpgupgrade/scale-down-clair/clair.deployment.patch.yaml similarity index 100% rename from kustomize/components/clairpgupgrade/clair.deployment.patch.yaml rename to kustomize/components/clairpgupgrade/scale-down-clair/clair.deployment.patch.yaml diff --git a/kustomize/components/clairpgupgrade/scale-down-clair/kustomization.yaml b/kustomize/components/clairpgupgrade/scale-down-clair/kustomization.yaml new file mode 100644 index 000000000..c81ba473a --- /dev/null +++ b/kustomize/components/clairpgupgrade/scale-down-clair/kustomization.yaml @@ -0,0 +1,6 @@ +apiVersion: kustomize.config.k8s.io/v1alpha1 +kind: Component +patchesStrategicMerge: + - ./clair.deployment.patch.yaml +resources: + - "../base" diff --git a/pkg/kustomize/kustomize.go b/pkg/kustomize/kustomize.go index 7d89257e7..389e28b53 100644 --- a/pkg/kustomize/kustomize.go +++ b/pkg/kustomize/kustomize.go @@ -434,7 +434,11 @@ func KustomizationFor( } if ctx.NeedsPgUpgrade { - componentPaths = append(componentPaths, "../components/pgupgrade") + if v1.ComponentIsManaged(quay.Spec.Components, v1.ComponentClair) { + componentPaths = append(componentPaths, "../components/pgupgrade/scale-down-clair") + } else { + componentPaths = append(componentPaths, "../components/pgupgrade/base") + } } if ctx.NeedsClairPgUpgrade { componentPaths = append(componentPaths, "../components/clairpgupgrade") diff --git a/pkg/kustomize/kustomize_test.go b/pkg/kustomize/kustomize_test.go index 3e55d7ff4..db1fb266d 100644 --- a/pkg/kustomize/kustomize_test.go +++ b/pkg/kustomize/kustomize_test.go @@ -189,7 +189,42 @@ var kustomizationForTests = []struct { "../components/clair", "../components/redis", "../components/postgres", - "../components/pgupgrade", + "../components/pgupgrade/scale-down-clair", + }, + Images: []types.Image{ + {Name: "quay.io/projectquay/quay", NewName: "quay", NewTag: "latest"}, + {Name: "quay.io/projectquay/clair", NewName: "clair", NewTag: "alpine"}, + {Name: "docker.io/library/redis", NewName: "redis", NewTag: "buster"}, + {Name: "quay.io/sclorg/postgresql-13-c9s", NewName: "postgres", NewTag: "latest"}, + {Name: "centos/postgresql-10-centos7", NewName: "postgres_previous", NewTag: "latest"}, + }, + SecretGenerator: []types.SecretArgs{}, + }, + "", + }, + { + "ClairPostgresUpgradeUnmanagedClair", + &v1.QuayRegistry{ + Spec: v1.QuayRegistrySpec{ + Components: []v1.Component{ + {Kind: "postgres", Managed: true}, + {Kind: "clair", Managed: false}, + {Kind: "redis", Managed: true}, + }, + }, + }, + quaycontext.QuayRegistryContext{ + NeedsPgUpgrade: true, + }, + &types.Kustomization{ + TypeMeta: types.TypeMeta{ + APIVersion: types.KustomizationVersion, + Kind: types.KustomizationKind, + }, + Components: []string{ + "../components/redis", + "../components/postgres", + "../components/pgupgrade/base", }, Images: []types.Image{ {Name: "quay.io/projectquay/quay", NewName: "quay", NewTag: "latest"},