Skip to content

Commit

Permalink
kustomize: unblock rollout from Clair init (PROJQUAY-1610)
Browse files Browse the repository at this point in the history
Remove the 'initContainer' from the Quay migration pod which
blocks the deployment process until Clair responds. This is
no longer needed, as the config-tool now validates against
Clair's introspection server, which is live during init.

Signed-off-by: Alec Merdler <alecmerdler@gmail.com>
  • Loading branch information
alecmerdler committed Jun 4, 2021
1 parent 5db214e commit a749781
Show file tree
Hide file tree
Showing 26 changed files with 7,788 additions and 10,558 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bin
tmp
cover.out
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ifeq (, $(shell which controller-gen))
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.5 ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.5.0 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
Expand Down
46 changes: 20 additions & 26 deletions apis/quay/v1/quayregistry_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,47 +250,43 @@ func RequiredComponent(component ComponentKind) bool {
return false
}

// EnsureDefaultComponents adds any `Components` which are missing from `Spec.Components`
// and returns a new `QuayRegistry` copy.
// EnsureDefaultComponents adds any `Components` which are missing from `Spec.Components`.
// Returns an error if a component was declared as managed but is not supported in the current k8s cluster.
func EnsureDefaultComponents(ctx *quaycontext.QuayRegistryContext, quay *QuayRegistry) (*QuayRegistry, error) {
updatedQuay := quay.DeepCopy()
if updatedQuay.Spec.Components == nil {
updatedQuay.Spec.Components = []Component{}
}

if ComponentIsManaged(updatedQuay.Spec.Components, ComponentRoute) && !ctx.SupportsRoutes {
return nil, errors.New("cannot use `route` component when `Route` API not available")
type componentCheck struct {
check bool
msg string
}

if ComponentIsManaged(updatedQuay.Spec.Components, ComponentObjectStorage) && !ctx.SupportsObjectStorage {
return nil, errors.New("cannot use `objectstorage` component when `ObjectBucketClaims` API not available")
}

if ComponentIsManaged(updatedQuay.Spec.Components, ComponentMonitoring) && !ctx.SupportsMonitoring {
return nil, errors.New("cannot use `monitoring` component when `Prometheus` API not available")
componentChecks := map[ComponentKind]componentCheck{
ComponentRoute: {ctx.SupportsRoutes, "cannot use `route` component when `Route` API not available"},
ComponentObjectStorage: {ctx.SupportsObjectStorage, "cannot use `ObjectStorage` component when `ObjectStorage` API not available"},
ComponentMonitoring: {ctx.SupportsMonitoring, "cannot use `monitoring` component when `Prometheus` API not available"},
}

for _, component := range allComponents {
componentCheck, checkExists := componentChecks[component]
if (checkExists && !componentCheck.check) && ComponentIsManaged(quay.Spec.Components, component) {
return quay, errors.New(componentCheck.msg)
}

found := false
for _, definedComponent := range quay.Spec.Components {
if component == definedComponent.Kind {
for _, declaredComponent := range quay.Spec.Components {
if component == declaredComponent.Kind {
found = true
break
}
}

if !found {
if component == ComponentRoute && !ctx.SupportsRoutes {
continue
}
if component == ComponentObjectStorage && !ctx.SupportsObjectStorage {
continue
}
if component == ComponentMonitoring && !ctx.SupportsMonitoring {
continue
}

updatedQuay.Spec.Components = append(updatedQuay.Spec.Components, Component{Kind: component, Managed: true})
updatedQuay.Spec.Components = append(updatedQuay.Spec.Components, Component{
Kind: component,
Managed: !checkExists || componentCheck.check,
})
}
}

Expand All @@ -313,7 +309,6 @@ func EnsureRegistryEndpoint(ctx *quaycontext.QuayRegistryContext, quay *QuayRegi
ctx.ClusterHostname},
".")
}
// TODO: Retrieve load balancer IP from `Service`

return updatedQuay, quay.Status.RegistryEndpoint == updatedQuay.Status.RegistryEndpoint
}
Expand All @@ -328,7 +323,6 @@ func EnsureConfigEditorEndpoint(ctx *quaycontext.QuayRegistryContext, quay *Quay
ctx.ClusterHostname},
".")
}
// TODO: Retrieve load balancer IP from `Service`

return updatedQuay, quay.Status.ConfigEditorEndpoint == updatedQuay.Status.ConfigEditorEndpoint
}
Expand Down
33 changes: 18 additions & 15 deletions apis/quay/v1/quayregistry_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var ensureDefaultComponentsTests = []struct {
{Kind: "redis", Managed: true},
{Kind: "clair", Managed: true},
{Kind: "objectstorage", Managed: true},
{Kind: "route", Managed: true},
{Kind: "horizontalpodautoscaler", Managed: true},
{Kind: "mirror", Managed: true},
{Kind: "monitoring", Managed: true},
Expand All @@ -35,12 +36,14 @@ var ensureDefaultComponentsTests = []struct {
quaycontext.QuayRegistryContext{
SupportsObjectStorage: true,
SupportsMonitoring: true,
SupportsRoutes: true,
},
[]Component{
{Kind: "postgres", Managed: true},
{Kind: "redis", Managed: true},
{Kind: "clair", Managed: true},
{Kind: "objectstorage", Managed: true},
{Kind: "route", Managed: true},
{Kind: "horizontalpodautoscaler", Managed: true},
{Kind: "mirror", Managed: true},
{Kind: "monitoring", Managed: true},
Expand All @@ -56,6 +59,7 @@ var ensureDefaultComponentsTests = []struct {
{Kind: "redis", Managed: true},
{Kind: "clair", Managed: true},
{Kind: "objectstorage", Managed: true},
{Kind: "route", Managed: true},
{Kind: "horizontalpodautoscaler", Managed: true},
{Kind: "mirror", Managed: true},
},
Expand All @@ -67,29 +71,30 @@ var ensureDefaultComponentsTests = []struct {
{Kind: "redis", Managed: true},
{Kind: "clair", Managed: true},
{Kind: "objectstorage", Managed: true},
{Kind: "route", Managed: true},
{Kind: "horizontalpodautoscaler", Managed: true},
{Kind: "mirror", Managed: true},
},
errors.New("cannot use `objectstorage` component when `ObjectBucketClaims` API not available"),
},
{
"AllComponentsProvidedWithRoutes",
"AllComponentsProvidedWithoutRoutes",
QuayRegistry{
Spec: QuayRegistrySpec{
Components: []Component{
{Kind: "postgres", Managed: true},
{Kind: "redis", Managed: true},
{Kind: "clair", Managed: true},
{Kind: "objectstorage", Managed: true},
{Kind: "route", Managed: true},
{Kind: "horizontalpodautoscaler", Managed: true},
{Kind: "mirror", Managed: true},
{Kind: "monitoring", Managed: true},
},
},
},
quaycontext.QuayRegistryContext{
SupportsRoutes: true,
ClusterHostname: "apps.example.com",
SupportsRoutes: false,
SupportsObjectStorage: true,
SupportsMonitoring: true,
},
Expand All @@ -103,25 +108,23 @@ var ensureDefaultComponentsTests = []struct {
{Kind: "mirror", Managed: true},
{Kind: "monitoring", Managed: true},
},
nil,
errors.New("cannot use `route` component when `Route` API not available"),
},
{
"AllComponentsOmitted",
QuayRegistry{
Spec: QuayRegistrySpec{},
},
quaycontext.QuayRegistryContext{
SupportsObjectStorage: true,
SupportsMonitoring: true,
},
quaycontext.QuayRegistryContext{},
[]Component{
{Kind: "postgres", Managed: true},
{Kind: "redis", Managed: true},
{Kind: "clair", Managed: true},
{Kind: "objectstorage", Managed: true},
{Kind: "objectstorage", Managed: false},
{Kind: "route", Managed: false},
{Kind: "horizontalpodautoscaler", Managed: true},
{Kind: "mirror", Managed: true},
{Kind: "monitoring", Managed: true},
{Kind: "monitoring", Managed: false},
},
nil,
},
Expand All @@ -131,16 +134,15 @@ var ensureDefaultComponentsTests = []struct {
Spec: QuayRegistrySpec{},
},
quaycontext.QuayRegistryContext{
SupportsRoutes: true,
ClusterHostname: "apps.example.com",
SupportsObjectStorage: true,
SupportsMonitoring: true,
SupportsRoutes: true,
ClusterHostname: "apps.example.com",
SupportsMonitoring: true,
},
[]Component{
{Kind: "postgres", Managed: true},
{Kind: "redis", Managed: true},
{Kind: "clair", Managed: true},
{Kind: "objectstorage", Managed: true},
{Kind: "objectstorage", Managed: false},
{Kind: "route", Managed: true},
{Kind: "horizontalpodautoscaler", Managed: true},
{Kind: "mirror", Managed: true},
Expand All @@ -165,6 +167,7 @@ var ensureDefaultComponentsTests = []struct {
{Kind: "redis", Managed: true},
{Kind: "clair", Managed: true},
{Kind: "objectstorage", Managed: false},
{Kind: "route", Managed: false},
{Kind: "horizontalpodautoscaler", Managed: true},
{Kind: "mirror", Managed: true},
{Kind: "monitoring", Managed: false},
Expand Down
2 changes: 1 addition & 1 deletion apis/quay/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apis/redhatcop/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

// Package v1alpha1 contains API Schema definitions for the redhatcop.redhat.io v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=redhatcop.redhat.io.quay.redhat.com
// +groupName=redhatcop.redhat.io
package v1alpha1

import (
Expand Down
Loading

0 comments on commit a749781

Please sign in to comment.