Skip to content

Commit

Permalink
adding downstream official Red Hat container images for components
Browse files Browse the repository at this point in the history
  • Loading branch information
alecmerdler committed Oct 15, 2020
1 parent d5a8ac3 commit 6664acf
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 65 deletions.
107 changes: 84 additions & 23 deletions apis/quay/v1/quayregistry_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ package v1

import (
"errors"
"os"
"strings"

"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
)

type QuayVersion string

const (
SupportsRoutesAnnotation = "supports-routes"
ClusterHostnameAnnotation = "router-canonical-hostname"
Expand All @@ -36,28 +35,76 @@ const (
StorageBucketNameAnnotation = "storage-bucketname"
StorageAccessKeyAnnotation = "storage-access-key"
StorageSecretKeyAnnotation = "storage-secret-key"

defaultVersionStreamKey = "DEFAULT_STREAM"
)

type QuayStream string

const (
QuayUpstream QuayStream = "upstream"
QuayDownstream QuayStream = "downstream"

QuayStreamNone QuayStream = ""
)

type QuayVersion string

const (
QuayVersionVader QuayVersion = "vader"
QuayVersionQuiGon QuayVersion = "qui-gon"
// Upstream versions
QuayVersionVader QuayVersion = "vader"

// Downstream versions
QuayVersion340 QuayVersion = "v3.4.0"

// QuayVersionDev is used to provide Kustomize overrides.
QuayVersionDev QuayVersion = "dev"

QuayVersionNone QuayVersion = ""
)

var quayVersions = map[QuayVersion]int{
QuayVersionDev: 0,
QuayVersionQuiGon: 1,
QuayVersionVader: 2,
var quayVersions = map[QuayVersion]struct {
Next QuayVersion
Stream QuayStream
}{
QuayVersionVader: {
Next: "",
Stream: QuayUpstream,
},
QuayVersion340: {
Next: "",
Stream: QuayDownstream,
},
QuayVersionDev: {
Next: QuayVersionDev,
Stream: QuayStreamNone,
},
QuayVersionNone: {
Next: QuayVersionNone,
Stream: QuayStreamNone,
},
}

// Next returns the version that succeeds this version.
func (version QuayVersion) Next() QuayVersion {
return quayVersions[version].Next
}

// Stream returns the source for this version.
func (version QuayVersion) Stream() QuayStream {
return quayVersions[version].Stream
}

func mostRecentVersion() QuayVersion {
var mostRecent QuayVersion
mostRecentRank := 0
for v, rank := range quayVersions {
if rank > mostRecentRank {
mostRecent = v
mostRecentRank = rank
defaultVersionStream := QuayUpstream
if os.Getenv(defaultVersionStreamKey) == string(QuayDownstream) {
defaultVersionStream = QuayDownstream
}

mostRecent := QuayVersionNone
for version, info := range quayVersions {
if info.Stream == defaultVersionStream && info.Next == QuayVersionNone {
mostRecent = version
}
}

Expand Down Expand Up @@ -197,18 +244,32 @@ func ComponentsMatch(firstComponents, secondComponents []Component) bool {
func EnsureDesiredVersion(quay *QuayRegistry) (*QuayRegistry, error) {
updatedQuay := quay.DeepCopy()

if updatedQuay.Spec.DesiredVersion == "" {
updatedQuay.Spec.DesiredVersion = mostRecentVersion()
if quay.Status.CurrentVersion == QuayVersionNone {
if updatedQuay.Spec.DesiredVersion == QuayVersionNone {
updatedQuay.Spec.DesiredVersion = mostRecentVersion()
return updatedQuay, nil
}

return updatedQuay, nil
}
if _, ok := quayVersions[updatedQuay.Spec.DesiredVersion]; !ok {
return updatedQuay, errors.New("invalid `desiredVersion`: " + string(updatedQuay.Spec.DesiredVersion))
}
} else {
if updatedQuay.Spec.DesiredVersion == QuayVersionNone {
updatedQuay.Spec.DesiredVersion = quay.Status.CurrentVersion
return updatedQuay, nil
}

if quay.Status.CurrentVersion != "" && quayVersions[quay.Status.CurrentVersion] > quayVersions[updatedQuay.Spec.DesiredVersion] {
return updatedQuay, errors.New("cannot downgrade from `currentVersion`: " + string(quay.Status.CurrentVersion) + " > " + string(updatedQuay.Spec.DesiredVersion))
}
if quay.Spec.DesiredVersion == quay.Status.CurrentVersion {
return updatedQuay, nil
}

if _, ok := quayVersions[updatedQuay.Spec.DesiredVersion]; !ok {
return updatedQuay, errors.New("invalid `desiredVersion`: " + string(updatedQuay.Spec.DesiredVersion))
if _, ok := quayVersions[updatedQuay.Spec.DesiredVersion]; !ok {
return updatedQuay, errors.New("invalid `desiredVersion`: " + string(updatedQuay.Spec.DesiredVersion))
}

if updatedQuay.Spec.DesiredVersion != quay.Status.CurrentVersion.Next() {
return updatedQuay, errors.New("cannot downgrade from `currentVersion`: " + string(quay.Status.CurrentVersion) + " > " + string(updatedQuay.Spec.DesiredVersion))
}
}

return updatedQuay, nil
Expand Down
39 changes: 31 additions & 8 deletions apis/quay/v1/quayregistry_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,22 @@ var ensureDesiredVersionTests = []struct {
expected QuayVersion
expectedErr error
}{
{
"DesiredVersionEmptyCurrentVersionEmpty",
QuayRegistry{},
QuayVersionVader,
nil,
},
{
"DesiredVersionEmptyCurrentVersionSet",
QuayRegistry{
Status: QuayRegistryStatus{
CurrentVersion: QuayVersionVader,
},
},
QuayVersionVader,
nil,
},
{
"InvalidDesiredVersion",
QuayRegistry{
Expand All @@ -205,33 +221,40 @@ var ensureDesiredVersionTests = []struct {
errors.New("invalid `desiredVersion`: not-a-real-version"),
},
{
"EmptyDesiredVersion",
QuayRegistry{},
QuayVersionVader,
"DevOverrideDesiredVersionCurrentVersionEmpty",
QuayRegistry{
Spec: QuayRegistrySpec{
DesiredVersion: QuayVersionDev,
},
},
QuayVersionDev,
nil,
},
{
"DevOverrideDesiredVersion",
"DevOverrideDesiredVersionCurrentVersionSet",
QuayRegistry{
Spec: QuayRegistrySpec{
DesiredVersion: QuayVersionDev,
},
Status: QuayRegistryStatus{
CurrentVersion: QuayVersionVader,
},
},
QuayVersionDev,
nil,
QuayVersionVader,
errors.New("cannot downgrade from `currentVersion`: vader > dev"),
},
{
"DowngradeProhibited",
QuayRegistry{
Spec: QuayRegistrySpec{
DesiredVersion: QuayVersionQuiGon,
DesiredVersion: QuayVersionDev,
},
Status: QuayRegistryStatus{
CurrentVersion: QuayVersionVader,
},
},
QuayVersionVader,
errors.New("cannot downgrade from `currentVersion`: qui-gon > vader"),
errors.New("cannot downgrade from `currentVersion`: vader > dev"),
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ metadata:
"name": "example-registry"
},
"spec": {
"desiredVersion": "v3.4.0",
"configBundleSecret": "example-registry-config-bundle",
"components": [
{"kind": "clair", "managed": true},
{"kind": "postgres", "managed": true},
{"kind": "objectstorage", "managed": true},
{"kind": "redis", "managed": true},
{"kind": "horizontalpodautoscaler", "managed": true},
{"kind": "route", "managed": true}
{"kind": "route", "managed": true},
{"kind": "mirror", "managed": true}
]
}
}
Expand Down Expand Up @@ -62,8 +64,7 @@ spec:
displayName: Desired Version
description: Declares the version of Quay that should deployed and managed. Defaults to latest version.
x-descriptors:
- 'urn:alm:descriptor:com.tectonic.ui:select:padme'
- 'urn:alm:descriptor:com.tectonic.ui:select:qui-gon'
- 'urn:alm:descriptor:com.tectonic.ui:select:v3.4.0'
- 'urn:alm:descriptor:com.tectonic.ui:advanced'
- path: components
displayName: Components
Expand Down Expand Up @@ -116,6 +117,9 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.annotations['olm.targetNamespaces']
# NOTE: This controls the default value for `desiredVersion` if left blank.
- name: DEFAULT_STREAM
value: downstream
image: quay.io/projectquay/quay-operator@sha256:4f88b7231dcac284893e7c6371ee631fccf592b553d0df76e624068bc9bb7553
name: quay-operator
volumeMounts:
Expand Down
19 changes: 19 additions & 0 deletions kustomize/overlays/downstream/v3.4.0/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Overlay variant for Project Quay "padme" release.
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
commonAnnotations:
quay-version: v3.4.0
bases:
- ../../../tmp
images:
- name: quay.io/projectquay/quay
newName: quay.io/quay/quay
newTag: v3.4.0-osbs
- name: quay.io/projectquay/clair
newName: quay.io/quay/clair
newTag: v3.4.0-osbs
- name: redis
newName: registry.access.redhat.com/rhscl/redis-32-rhel7
- name: postgres
newName: registry.access.redhat.com/rhscl/postgresql-10-rhel7
newTag: 1-35
24 changes: 24 additions & 0 deletions kustomize/overlays/downstream/v3.4.0/upgrade/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Overlay variant for upgrading to Red Hat Quay "v3.4.0" release.
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
commonAnnotations:
quay-version: v3.4.0
bases:
- ../../../../tmp
patchesStrategicMerge:
# Scale the app deployment to 0 pods in order to run all migrations present in the new container image using the "upgrade" deployment.
- ./quay.deployment.patch.yaml
- ./upgrade.deployment.patch.yaml
images:
- name: quay.io/projectquay/quay
newName: quay.io/quay/quay
newTag: v3.4.0-osbs
- name: quay.io/projectquay/clair
newName: quay.io/quay/clair
newTag: v3.4.0-osbs
- name: redis
newName: registry.access.redhat.com/rhscl/redis-32-rhel7
- name: postgres
newName: registry.access.redhat.com/rhscl/postgresql-10-rhel7
newTag: 1-35
# FIXME(alecmerdler): Need to handle `redhat-pull-secret` (potentially with a `secretGenerator`?)...
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ kind: Deployment
metadata:
name: quay-app
annotations:
quay-upgrade: qui-gon
quay-upgrade: v3.4.0
spec:
replicas: 0
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ kind: Deployment
metadata:
name: quay-app-upgrade
annotations:
quay-upgrade: qui-gon
quay-upgrade: v3.4.0
spec:
replicas: 1
12 changes: 0 additions & 12 deletions kustomize/overlays/upstream/qui-gon/kustomization.yaml

This file was deleted.

16 changes: 0 additions & 16 deletions kustomize/overlays/upstream/qui-gon/upgrade/kustomization.yaml

This file was deleted.

4 changes: 3 additions & 1 deletion pkg/kustomize/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ func appDir() string {
}

func overlayDir(desiredVersion v1.QuayVersion) string {
return filepath.Join(kustomizeDir(), "overlays", "upstream", string(desiredVersion))
overlayStream := desiredVersion.Stream()

return filepath.Join(kustomizeDir(), "overlays", overlayMode, string(desiredVersion))
}

func upgradeOverlayDir(desiredVersion v1.QuayVersion) string {
Expand Down

0 comments on commit 6664acf

Please sign in to comment.