From 509c5d05b3b06626946a33a4a8e82a382a7d53e9 Mon Sep 17 00:00:00 2001 From: alecmerdler Date: Wed, 22 Jul 2020 15:41:56 -0700 Subject: [PATCH] switch to using 'spec.components' from 'spec.managedComponents' --- api/v1/quayregistry_types.go | 65 +++++++- api/v1/quayregistry_types_test.go | 143 ++++++++++++++++++ api/v1/zz_generated.deepcopy.go | 14 +- .../bases/quay.redhat.com_quayregistries.yaml | 27 +++- config/samples/managed.quayregistry.yaml | 6 + .../quay.redhat.com_v1_quayregistry.yaml | 11 -- config/samples/unmanaged.quayregistry.yaml | 15 ++ controllers/quayregistry_controller.go | 16 +- controllers/quayregistry_controller_test.go | 15 +- .../quay-operator.clusterserviceversion.yaml | 26 ++-- .../quayregistries.quay.redhat.com.crd.yaml | 34 ++++- deploy/quay-operator.catalogsource.yaml | 2 +- pkg/kustomize/kustomize.go | 42 ++--- pkg/kustomize/kustomize_test.go | 81 +++++++--- pkg/kustomize/secrets_test.go | 10 +- 15 files changed, 407 insertions(+), 100 deletions(-) create mode 100644 api/v1/quayregistry_types_test.go create mode 100644 config/samples/managed.quayregistry.yaml delete mode 100644 config/samples/quay.redhat.com_v1_quayregistry.yaml create mode 100644 config/samples/unmanaged.quayregistry.yaml diff --git a/api/v1/quayregistry_types.go b/api/v1/quayregistry_types.go index 2221e4f9d..4fe97836a 100644 --- a/api/v1/quayregistry_types.go +++ b/api/v1/quayregistry_types.go @@ -20,16 +20,28 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +var allComponents = []string{ + "postgres", + "clair", + "redis", + "storage", +} + // QuayRegistrySpec defines the desired state of QuayRegistry. type QuayRegistrySpec struct { // ConfigBundleSecret is the name of the Kubernetes `Secret` in the same namespace which contains the base Quay config and extra certs. ConfigBundleSecret string `json:"configBundleSecret,omitempty"` - // ManagedComponents declare which supplemental services should be included in this Quay deployment. - ManagedComponents []ManagedComponent `json:"managedComponents,omitempty"` + // Components declare how the Operator should handle backing Quay services. + Components []Component `json:"components,omitempty"` } -type ManagedComponent struct { - Kind string `json:"kind,omitempty"` +// Component describes how the Operator should handle a backing Quay service. +type Component struct { + // Kind is the unique name of this type of component. + Kind string `json:"kind"` + // Managed indicates whether or not the Operator is responsible for the lifecycle of this component. + // Default is true. + Managed bool `json:"managed"` } // QuayRegistryStatus defines the observed state of QuayRegistry. @@ -57,6 +69,51 @@ type QuayRegistryList struct { Items []QuayRegistry `json:"items"` } +// EnsureDefaultComponents adds any `Components` which are missing from `Spec.Components` +// and returns a new `QuayRegistry` copy. +func EnsureDefaultComponents(quay *QuayRegistry) (*QuayRegistry, error) { + updatedQuay := quay.DeepCopy() + if updatedQuay.Spec.Components == nil { + updatedQuay.Spec.Components = []Component{} + } + + for _, component := range allComponents { + found := false + for _, definedComponent := range quay.Spec.Components { + if component == definedComponent.Kind { + found = true + break + } + } + if !found { + updatedQuay.Spec.Components = append(updatedQuay.Spec.Components, Component{Kind: component, Managed: true}) + } + } + + return updatedQuay, nil +} + +// ComponentsMatch returns true if both set of components are equivalent, and false otherwise. +func ComponentsMatch(firstComponents, secondComponents []Component) bool { + if len(firstComponents) != len(secondComponents) { + return false + } + + for _, compA := range firstComponents { + equal := false + for _, compB := range secondComponents { + if compA.Kind == compB.Kind && compA.Managed == compB.Managed { + equal = true + break + } + } + if !equal { + return false + } + } + return true +} + func init() { SchemeBuilder.Register(&QuayRegistry{}, &QuayRegistryList{}) } diff --git a/api/v1/quayregistry_types_test.go b/api/v1/quayregistry_types_test.go new file mode 100644 index 000000000..51952baf4 --- /dev/null +++ b/api/v1/quayregistry_types_test.go @@ -0,0 +1,143 @@ +package v1 + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +var ensureDefaultComponentsTests = []struct { + name string + quay QuayRegistry + expected []Component + expectedErr error +}{ + { + "AllComponentsProvided", + QuayRegistry{ + Spec: QuayRegistrySpec{ + Components: []Component{ + {Kind: "postgres", Managed: true}, + {Kind: "redis", Managed: true}, + {Kind: "clair", Managed: true}, + {Kind: "storage", Managed: true}, + }, + }, + }, + []Component{ + {Kind: "postgres", Managed: true}, + {Kind: "redis", Managed: true}, + {Kind: "clair", Managed: true}, + {Kind: "storage", Managed: true}, + }, + nil, + }, + { + "AllComponentsOmitted", + QuayRegistry{ + Spec: QuayRegistrySpec{}, + }, + []Component{ + {Kind: "postgres", Managed: true}, + {Kind: "redis", Managed: true}, + {Kind: "clair", Managed: true}, + {Kind: "storage", Managed: true}, + }, + nil, + }, + { + "SomeComponentsProvided", + QuayRegistry{ + Spec: QuayRegistrySpec{ + Components: []Component{ + {Kind: "postgres", Managed: false}, + {Kind: "storage", Managed: false}, + }, + }, + }, + []Component{ + {Kind: "postgres", Managed: false}, + {Kind: "redis", Managed: true}, + {Kind: "clair", Managed: true}, + {Kind: "storage", Managed: false}, + }, + nil, + }, +} + +func TestEnsureDefaultComponents(t *testing.T) { + assert := assert.New(t) + + for _, test := range ensureDefaultComponentsTests { + updatedQuay, err := EnsureDefaultComponents(&test.quay) + + assert.Nil(err, test.name) + assert.Equal(len(test.expected), len(updatedQuay.Spec.Components), test.name) + + for _, expectedComponent := range test.expected { + assert.Contains(updatedQuay.Spec.Components, expectedComponent, test.name) + } + } +} + +var componentsMatchTests = []struct { + name string + firstComponents []Component + secondComponents []Component + expected bool +}{ + { + "EmptyDoNotMatch", + []Component{}, + []Component{ + {Kind: "postgres", Managed: false}, + {Kind: "redis", Managed: false}, + {Kind: "storage", Managed: false}, + }, + false, + }, + { + "EmptyMatch", + []Component{}, + []Component{}, + true, + }, + { + "Match", + []Component{ + {Kind: "postgres", Managed: false}, + {Kind: "redis", Managed: false}, + {Kind: "storage", Managed: true}, + }, + []Component{ + {Kind: "postgres", Managed: false}, + {Kind: "redis", Managed: false}, + {Kind: "storage", Managed: true}, + }, + true, + }, + { + "DoNotMatch", + []Component{ + {Kind: "postgres", Managed: false}, + {Kind: "redis", Managed: false}, + {Kind: "storage", Managed: true}, + }, + []Component{ + {Kind: "postgres", Managed: false}, + {Kind: "redis", Managed: false}, + {Kind: "storage", Managed: false}, + }, + false, + }, +} + +func TestComponentsMatch(t *testing.T) { + assert := assert.New(t) + + for _, test := range componentsMatchTests { + match := ComponentsMatch(test.firstComponents, test.secondComponents) + + assert.Equal(test.expected, match, test.name) + } +} diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 2925d6d80..7f950a0d1 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -25,16 +25,16 @@ import ( ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ManagedComponent) DeepCopyInto(out *ManagedComponent) { +func (in *Component) DeepCopyInto(out *Component) { *out = *in } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ManagedComponent. -func (in *ManagedComponent) DeepCopy() *ManagedComponent { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Component. +func (in *Component) DeepCopy() *Component { if in == nil { return nil } - out := new(ManagedComponent) + out := new(Component) in.DeepCopyInto(out) return out } @@ -101,9 +101,9 @@ func (in *QuayRegistryList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *QuayRegistrySpec) DeepCopyInto(out *QuayRegistrySpec) { *out = *in - if in.ManagedComponents != nil { - in, out := &in.ManagedComponents, &out.ManagedComponents - *out = make([]ManagedComponent, len(*in)) + if in.Components != nil { + in, out := &in.Components, &out.Components + *out = make([]Component, len(*in)) copy(*out, *in) } } diff --git a/config/crd/bases/quay.redhat.com_quayregistries.yaml b/config/crd/bases/quay.redhat.com_quayregistries.yaml index e3f9b0953..cc8275033 100644 --- a/config/crd/bases/quay.redhat.com_quayregistries.yaml +++ b/config/crd/bases/quay.redhat.com_quayregistries.yaml @@ -36,20 +36,31 @@ spec: spec: description: QuayRegistrySpec defines the desired state of QuayRegistry. properties: - configBundleSecret: - description: ConfigBundleSecret is the name of the Kubernetes `Secret` - in the same namespace which contains the base Quay config and extra - certs. - type: string - managedComponents: - description: ManagedComponents declare which supplemental services should - be included in this Quay deployment. + components: + description: Components declare how the Operator should handle backing + Quay services. items: + description: Component describes how the Operator should handle a + backing Quay service. properties: kind: + description: Kind is the unique name of this type of component. type: string + managed: + description: Managed indicates whether or not the Operator is + responsible for the lifecycle of this component. Default is + true. + type: boolean + required: + - kind + - managed type: object type: array + configBundleSecret: + description: ConfigBundleSecret is the name of the Kubernetes `Secret` + in the same namespace which contains the base Quay config and extra + certs. + type: string type: object status: description: QuayRegistryStatus defines the observed state of QuayRegistry. diff --git a/config/samples/managed.quayregistry.yaml b/config/samples/managed.quayregistry.yaml new file mode 100644 index 000000000..1c4e5e6f0 --- /dev/null +++ b/config/samples/managed.quayregistry.yaml @@ -0,0 +1,6 @@ +apiVersion: quay.redhat.com/v1 +kind: QuayRegistry +metadata: + name: skynet +spec: + configBundleSecret: quay-config-bundle-abc123 diff --git a/config/samples/quay.redhat.com_v1_quayregistry.yaml b/config/samples/quay.redhat.com_v1_quayregistry.yaml deleted file mode 100644 index 05901397a..000000000 --- a/config/samples/quay.redhat.com_v1_quayregistry.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: quay.redhat.com/v1 -kind: QuayRegistry -metadata: - name: skynet -spec: - configBundleSecret: quay-config-secret-abc123 - managedComponents: - - kind: postgres - - kind: clair - - kind: redis - - kind: storage diff --git a/config/samples/unmanaged.quayregistry.yaml b/config/samples/unmanaged.quayregistry.yaml new file mode 100644 index 000000000..096895af8 --- /dev/null +++ b/config/samples/unmanaged.quayregistry.yaml @@ -0,0 +1,15 @@ +apiVersion: quay.redhat.com/v1 +kind: QuayRegistry +metadata: + name: unmanaged +spec: + configBundleSecret: quay-config-bundle-abc123 + components: + - kind: postgres + managed: false + - kind: redis + managed: false + - kind: clair + managed: false + - kind: storage + managed: false diff --git a/controllers/quayregistry_controller.go b/controllers/quayregistry_controller.go index ce50c7ec1..174fb6306 100644 --- a/controllers/quayregistry_controller.go +++ b/controllers/quayregistry_controller.go @@ -74,7 +74,21 @@ func (r *QuayRegistryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error log.Info("successfully retrieved referenced `configBundleSecret`", "configBundleSecret", configBundle.GetName(), "resourceVersion", configBundle.GetResourceVersion()) - deploymentObjects, err := kustomize.Inflate(&quay, &configBundle, &secretKeysBundle, log) + updatedQuay, err := v1.EnsureDefaultComponents(&quay) + if err != nil { + log.Error(err, "could not ensure default `spec.components`") + return ctrl.Result{}, err + } + if !v1.ComponentsMatch(quay.Spec.Components, updatedQuay.Spec.Components) { + log.Info("updating QuayRegistry `spec.components` to include defaults") + if err = r.Client.Update(ctx, updatedQuay); err != nil { + log.Error(err, "failed to update `spec.components` to include defaults") + return ctrl.Result{}, err + } + return ctrl.Result{}, nil + } + + deploymentObjects, err := kustomize.Inflate(updatedQuay, &configBundle, &secretKeysBundle, log) if err != nil { log.Error(err, "could not inflate QuayRegistry into Kubernetes objects") return ctrl.Result{}, err diff --git a/controllers/quayregistry_controller_test.go b/controllers/quayregistry_controller_test.go index efe103939..1f3593a54 100644 --- a/controllers/quayregistry_controller_test.go +++ b/controllers/quayregistry_controller_test.go @@ -43,11 +43,12 @@ func newQuayRegistry(name, namespace string) v1.QuayRegistry { Namespace: namespace, }, Spec: v1.QuayRegistrySpec{ - ManagedComponents: []v1.ManagedComponent{ - {Kind: "postgres"}, - {Kind: "clair"}, - {Kind: "redis"}, - {Kind: "storage"}, + Components: []v1.Component{ + // FIXME(alecmerdler): Test omitting components and marking some as disabled/unmanaged... + {Kind: "postgres", Managed: true}, + {Kind: "clair", Managed: true}, + {Kind: "redis", Managed: true}, + {Kind: "storage", Managed: true}, }, }, } @@ -173,6 +174,10 @@ var _ = Describe("QuayRegistryReconciler", func() { verifyOwnerRefs(persistentVolumeClaim.GetOwnerReferences()) } }) + + When("the `components` field is empty", func() { + // TODO(alecmerdler) + }) }) }) diff --git a/deploy/manifests/quay-operator/0.0.1/quay-operator.clusterserviceversion.yaml b/deploy/manifests/quay-operator/0.0.1/quay-operator.clusterserviceversion.yaml index 69ebf967b..2282ffc31 100644 --- a/deploy/manifests/quay-operator/0.0.1/quay-operator.clusterserviceversion.yaml +++ b/deploy/manifests/quay-operator/0.0.1/quay-operator.clusterserviceversion.yaml @@ -4,7 +4,7 @@ metadata: annotations: capabilities: Full Lifecycle categories: Integration & Delivery - containerImage: quay.io/projectquay/quay-operator@sha256:3ee5adbf381a167bf424f43281ff7c753b5a2a8a740ba47bd32f21fc67432454 + containerImage: quay.io/projectquay/quay-operator@sha256:27e7e052cdf72943d1f27f2d7c8cfbd4e1710a20b6e774eb5f4133be319d2789 createdAt: 2020-07-20 00:00:00 description: Opinionated deployment of Quay on Kubernetes. repository: https://github.com/quay/quay-operator @@ -19,11 +19,11 @@ metadata: }, "spec": { "configBundleSecret": "example-registry-config-bundle", - "managedComponents": [ - {"kind": "clair"}, - {"kind": "postgres"}, - {"kind": "storage"}, - {"kind": "redis"} + "components": [ + {"kind": "clair", "managed": true}, + {"kind": "postgres", "managed": true}, + {"kind": "storage", "managed": true}, + {"kind": "redis", "managed": true} ] } } @@ -55,9 +55,15 @@ spec: description: Name of the Quay config secret containing base configuration and custom SSL certificates. x-descriptors: - 'urn:alm:descriptor:io.kubernetes:Secret' - - path: managedComponents - displayName: ManagedComponents - description: Declares which supplemental services should be included in this Quay deployment. + - path: components + displayName: Components + description: Declares how the Operator should handle supplemental Quay services. + - path: components[0].kind + displayName: Kind + description: The unique name of this type of component. + - path: components[0].managed + displayName: Managed + description: Indicates whether lifecycle of this component is managed by the Operator or externally. description: Opinionated deployment of Quay on Kubernetes. displayName: Quay install: @@ -92,7 +98,7 @@ spec: valueFrom: fieldRef: fieldPath: metadata.annotations['olm.targetNamespaces'] - image: quay.io/projectquay/quay-operator@sha256:3ee5adbf381a167bf424f43281ff7c753b5a2a8a740ba47bd32f21fc67432454 + image: quay.io/projectquay/quay-operator@sha256:27e7e052cdf72943d1f27f2d7c8cfbd4e1710a20b6e774eb5f4133be319d2789 name: quay-operator serviceAccountName: quay-operator permissions: diff --git a/deploy/manifests/quay-operator/0.0.1/quayregistries.quay.redhat.com.crd.yaml b/deploy/manifests/quay-operator/0.0.1/quayregistries.quay.redhat.com.crd.yaml index 667ce6f7b..e7f7f0c7b 100644 --- a/deploy/manifests/quay-operator/0.0.1/quayregistries.quay.redhat.com.crd.yaml +++ b/deploy/manifests/quay-operator/0.0.1/quayregistries.quay.redhat.com.crd.yaml @@ -3,6 +3,7 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.2.5 + creationTimestamp: null name: quayregistries.quay.redhat.com spec: group: quay.redhat.com @@ -33,20 +34,31 @@ spec: spec: description: QuayRegistrySpec defines the desired state of QuayRegistry. properties: - configBundleSecret: - description: ConfigBundleSecret is the name of the Kubernetes `Secret` - in the same namespace which contains the base Quay config and extra - certs. - type: string - managedComponents: - description: ManagedComponents declare which supplemental services should - be included in this Quay deployment. + components: + description: Components declare how the Operator should handle backing + Quay services. items: + description: Component describes how the Operator should handle a + backing Quay service. properties: kind: + description: Kind is the unique name of this type of component. type: string + managed: + description: Managed indicates whether or not the Operator is + responsible for the lifecycle of this component. Default is + true. + type: boolean + required: + - kind + - managed type: object type: array + configBundleSecret: + description: ConfigBundleSecret is the name of the Kubernetes `Secret` + in the same namespace which contains the base Quay config and extra + certs. + type: string type: object status: description: QuayRegistryStatus defines the observed state of QuayRegistry. @@ -57,3 +69,9 @@ spec: - name: v1 served: true storage: true +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] diff --git a/deploy/quay-operator.catalogsource.yaml b/deploy/quay-operator.catalogsource.yaml index e56e51361..2f23502d2 100644 --- a/deploy/quay-operator.catalogsource.yaml +++ b/deploy/quay-operator.catalogsource.yaml @@ -4,4 +4,4 @@ metadata: name: quay-operator spec: sourceType: grpc - image: quay.io/projectquay/quay-operator-catalog@sha256:f64e1efa2e202b3727049f03537d1420fc03044aabfc8e49e9859ac4d27aa4a4 + image: quay.io/projectquay/quay-operator-catalog@sha256:f80dedd52a657200c4cdc0cc940a87ea6a35e88e7209c1441bd54be9a70d44f2 diff --git a/pkg/kustomize/kustomize.go b/pkg/kustomize/kustomize.go index 022cd844d..21c5f9ede 100644 --- a/pkg/kustomize/kustomize.go +++ b/pkg/kustomize/kustomize.go @@ -168,28 +168,32 @@ func KustomizationFor(quay *v1.QuayRegistry, quayConfigFiles map[string][]byte) }, }, } + components := []string{} - for _, managedComponent := range quay.Spec.ManagedComponents { - components = append(components, filepath.Join("..", "components", managedComponent.Kind)) - componentConfigFiles, err := componentConfigFilesFor(managedComponent.Kind, quay) - if componentConfigFiles == nil || err != nil { - continue - } + for _, component := range quay.Spec.Components { + if component.Managed { + components = append(components, filepath.Join("..", "components", component.Kind)) - sources := []string{} - for filename, fileValue := range componentConfigFiles { - sources = append(sources, strings.Join([]string{filename, string(fileValue)}, "=")) - } + componentConfigFiles, err := componentConfigFilesFor(component.Kind, quay) + if componentConfigFiles == nil || err != nil { + continue + } - generatedSecrets = append(generatedSecrets, types.SecretArgs{ - GeneratorArgs: types.GeneratorArgs{ - Name: managedComponent.Kind + "-config-secret", - Behavior: "merge", - KvPairSources: types.KvPairSources{ - LiteralSources: sources, + sources := []string{} + for filename, fileValue := range componentConfigFiles { + sources = append(sources, strings.Join([]string{filename, string(fileValue)}, "=")) + } + + generatedSecrets = append(generatedSecrets, types.SecretArgs{ + GeneratorArgs: types.GeneratorArgs{ + Name: component.Kind + "-config-secret", + Behavior: "merge", + KvPairSources: types.KvPairSources{ + LiteralSources: sources, + }, }, - }, - }) + }) + } } return &types.Kustomization{ @@ -258,7 +262,7 @@ func Inflate(quay *v1.QuayRegistry, baseConfigBundle *corev1.Secret, secretKeysS "SECRET_KEY": secretKey, }) - for _, component := range quay.Spec.ManagedComponents { + for _, component := range quay.Spec.Components { configFile, err := ConfigFileFor(component.Kind, quay) check(err) componentConfigFiles[component.Kind+".config.yaml"] = configFile diff --git a/pkg/kustomize/kustomize_test.go b/pkg/kustomize/kustomize_test.go index 78452cd7c..0130e72f4 100644 --- a/pkg/kustomize/kustomize_test.go +++ b/pkg/kustomize/kustomize_test.go @@ -32,11 +32,11 @@ var kustomizationForTests = []struct { "AllComponents", &v1.QuayRegistry{ Spec: v1.QuayRegistrySpec{ - ManagedComponents: []v1.ManagedComponent{ - {Kind: "postgres"}, - {Kind: "clair"}, - {Kind: "redis"}, - {Kind: "storage"}, + Components: []v1.Component{ + {Kind: "postgres", Managed: true}, + {Kind: "clair", Managed: true}, + {Kind: "redis", Managed: true}, + {Kind: "storage", Managed: true}, }, }, }, @@ -45,8 +45,13 @@ var kustomizationForTests = []struct { APIVersion: types.KustomizationVersion, Kind: types.KustomizationKind, }, - Resources: []string{}, - Components: []string{}, + Resources: []string{}, + Components: []string{ + "../components/postgres", + "../components/clair", + "../components/redis", + "../components/storage", + }, SecretGenerator: []types.SecretArgs{}, }, "", @@ -61,9 +66,14 @@ func TestKustomizationFor(t *testing.T) { if test.expectedErr != "" { assert.EqualError(err, test.expectedErr) - assert.Nil(kustomization) + assert.Nil(kustomization, test.name) } else { - assert.NotNil(kustomization) + assert.NotNil(kustomization, test.name) + + assert.Equal(len(test.expected.Components), len(kustomization.Components), test.name) + for _, expectedComponent := range test.expected.Components { + assert.Contains(kustomization.Components, expectedComponent, test.name) + } } } } @@ -154,14 +164,14 @@ var inflateTests = []struct { expectedErr error }{ { - "AllComponents", + "AllComponentsManagedExplicit", &v1.QuayRegistry{ Spec: v1.QuayRegistrySpec{ - ManagedComponents: []v1.ManagedComponent{ - {Kind: "postgres"}, - {Kind: "clair"}, - {Kind: "redis"}, - {Kind: "storage"}, + Components: []v1.Component{ + {Kind: "postgres", Managed: true}, + {Kind: "clair", Managed: true}, + {Kind: "redis", Managed: true}, + {Kind: "storage", Managed: true}, }, }, }, @@ -174,8 +184,17 @@ var inflateTests = []struct { nil, }, { - "OnlyBaseComponent", - &v1.QuayRegistry{}, + "AllComponentsUnmanaged", + &v1.QuayRegistry{ + Spec: v1.QuayRegistrySpec{ + Components: []v1.Component{ + {Kind: "postgres", Managed: false}, + {Kind: "clair", Managed: false}, + {Kind: "redis", Managed: false}, + {Kind: "storage", Managed: false}, + }, + }, + }, &corev1.Secret{ Data: map[string][]byte{ "config.yaml": encode(map[string]interface{}{"SERVER_HOSTNAME": "quay.io"}), @@ -184,6 +203,26 @@ var inflateTests = []struct { withComponents([]string{"base"}), nil, }, + { + "SomeComponentsUnmanaged", + &v1.QuayRegistry{ + Spec: v1.QuayRegistrySpec{ + Components: []v1.Component{ + {Kind: "postgres", Managed: true}, + {Kind: "clair", Managed: true}, + {Kind: "redis", Managed: false}, + {Kind: "storage", Managed: false}, + }, + }, + }, + &corev1.Secret{ + Data: map[string][]byte{ + "config.yaml": encode(map[string]interface{}{"SERVER_HOSTNAME": "quay.io"}), + }, + }, + withComponents([]string{"base", "postgres", "clair"}), + nil, + }, } func TestInflate(t *testing.T) { @@ -194,14 +233,14 @@ func TestInflate(t *testing.T) { for _, test := range inflateTests { pieces, err := Inflate(test.quayRegistry, test.configBundle, nil, log) - assert.NotNil(pieces) - assert.Equal(len(test.expected), len(pieces)) - assert.Nil(err) + assert.NotNil(pieces, test.name) + assert.Equal(len(test.expected), len(pieces), test.name) + assert.Nil(err, test.name) for _, obj := range pieces { objectMeta, _ := meta.Accessor(obj) - assert.Contains(objectMeta.GetName(), test.quayRegistry.GetName()+"-") + assert.Contains(objectMeta.GetName(), test.quayRegistry.GetName()+"-", test.name) } } } diff --git a/pkg/kustomize/secrets_test.go b/pkg/kustomize/secrets_test.go index 4128d0223..3e6420c58 100644 --- a/pkg/kustomize/secrets_test.go +++ b/pkg/kustomize/secrets_test.go @@ -15,11 +15,11 @@ func quayRegistry(name string) *v1.QuayRegistry { Name: name, }, Spec: v1.QuayRegistrySpec{ - ManagedComponents: []v1.ManagedComponent{ - {Kind: "postgres"}, - {Kind: "clair"}, - {Kind: "redis"}, - {Kind: "storage"}, + Components: []v1.Component{ + {Kind: "postgres", Managed: true}, + {Kind: "clair", Managed: true}, + {Kind: "redis", Managed: true}, + {Kind: "storage", Managed: true}, }, }, }