Skip to content

Commit 06ba90e

Browse files
Merge pull request #835 from njhale/fix-registry-recreation
Fix gRPC registry pod recreation
2 parents 48a1875 + 5fff1e9 commit 06ba90e

File tree

14 files changed

+626
-229
lines changed

14 files changed

+626
-229
lines changed

pkg/api/client/clientset/versioned/fake/decorator.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package fake
1818
import (
1919
"k8s.io/apimachinery/pkg/runtime"
2020
"k8s.io/client-go/testing"
21+
22+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/clientfake"
2123
)
2224

2325
// ClientsetDecorator defines decorator methods for a Clientset.
@@ -38,14 +40,19 @@ type ReactionForwardingClientsetDecorator struct {
3840

3941
// NewReactionForwardingClientsetDecorator returns the ReactionForwardingClientsetDecorator wrapped Clientset result
4042
// of calling NewSimpleClientset with the given objects.
41-
func NewReactionForwardingClientsetDecorator(objects ...runtime.Object) *ReactionForwardingClientsetDecorator {
43+
func NewReactionForwardingClientsetDecorator(objects []runtime.Object, options ...clientfake.Option) *ReactionForwardingClientsetDecorator {
4244
decorator := &ReactionForwardingClientsetDecorator{
4345
Clientset: *NewSimpleClientset(objects...),
4446
}
4547

4648
// Swap out the embedded ReactionChain with a Reactor that reduces over the decorator's ReactionChain.
4749
decorator.ReactionChain = decorator.Clientset.ReactionChain
4850
decorator.Clientset.ReactionChain = []testing.Reactor{&testing.SimpleReactor{"*", "*", decorator.reduceReactions}}
51+
52+
// Apply options
53+
for _, option := range options {
54+
option(decorator)
55+
}
4956

5057
return decorator
5158
}

pkg/controller/operators/catalog/operator_test.go

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ import (
1616
rbacv1 "k8s.io/api/rbac/v1"
1717
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
1818
apiextensionsfake "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake"
19-
"k8s.io/apimachinery/pkg/api/meta"
2019
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2120
"k8s.io/apimachinery/pkg/runtime"
2221
"k8s.io/apimachinery/pkg/types"
2322
"k8s.io/client-go/informers"
2423
k8sfake "k8s.io/client-go/kubernetes/fake"
25-
clitesting "k8s.io/client-go/testing"
2624
"k8s.io/client-go/tools/cache"
2725
"k8s.io/client-go/util/workqueue"
2826
apiregistrationfake "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/fake"
@@ -34,6 +32,7 @@ import (
3432
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/reconciler"
3533
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver"
3634
"github.com/operator-framework/operator-lifecycle-manager/pkg/fakes"
35+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/clientfake"
3736
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
3837
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister"
3938
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
@@ -379,8 +378,6 @@ func TestSyncCatalogSources(t *testing.T) {
379378
}
380379
}
381380

382-
// TODO: CatalogSource tests for RegistryServiceStatus
383-
384381
func TestCompetingCRDOwnersExist(t *testing.T) {
385382

386383
testNamespace := "default"
@@ -465,43 +462,13 @@ func fakeConfigMapData() map[string]string {
465462
return data
466463
}
467464

468-
// fakeClientOption configures a fake option
469-
type fakeClientOption func(fake.ClientsetDecorator)
470-
471-
// withSelfLinks returns a fakeClientOption that configures a ClientsetDecorator to write selfLinks to all OLM types on create.
472-
func withSelfLinks(t *testing.T) fakeClientOption {
473-
return func(c fake.ClientsetDecorator) {
474-
c.PrependReactor("create", "*", func(a clitesting.Action) (bool, runtime.Object, error) {
475-
ca, ok := a.(clitesting.CreateAction)
476-
if !ok {
477-
t.Fatalf("expected CreateAction")
478-
}
479-
480-
obj := ca.GetObject()
481-
accessor, err := meta.Accessor(obj)
482-
if err != nil {
483-
return false, nil, err
484-
}
485-
if accessor.GetSelfLink() != "" {
486-
// SelfLink is already set
487-
return false, nil, nil
488-
}
489-
490-
gvr := ca.GetResource()
491-
accessor.SetSelfLink(buildSelfLink(gvr.GroupVersion().String(), gvr.Resource, accessor.GetNamespace(), accessor.GetName()))
492-
493-
return false, obj, nil
494-
})
495-
}
496-
}
497-
498465
// fakeOperatorConfig is the configuration for a fake operator.
499466
type fakeOperatorConfig struct {
500-
clientObjs []runtime.Object
501-
k8sObjs []runtime.Object
502-
extObjs []runtime.Object
503-
regObjs []runtime.Object
504-
fakeClientOptions []fakeClientOption
467+
clientObjs []runtime.Object
468+
k8sObjs []runtime.Object
469+
extObjs []runtime.Object
470+
regObjs []runtime.Object
471+
clientOptions []clientfake.Option
505472
}
506473

507474
// fakeOperatorOption applies an option to the given fake operator configuration.
@@ -525,9 +492,9 @@ func extObjs(extObjs ...runtime.Object) fakeOperatorOption {
525492
}
526493
}
527494

528-
func withFakeClientOptions(options ...fakeClientOption) fakeOperatorOption {
495+
func withFakeClientOptions(options ...clientfake.Option) fakeOperatorOption {
529496
return func(config *fakeOperatorConfig) {
530-
config.fakeClientOptions = options
497+
config.clientOptions = options
531498
}
532499
}
533500

@@ -540,11 +507,7 @@ func NewFakeOperator(namespace string, watchedNamespaces []string, stopCh <-chan
540507
}
541508

542509
// Create client fakes
543-
clientFake := fake.NewReactionForwardingClientsetDecorator(config.clientObjs...)
544-
for _, option := range config.fakeClientOptions {
545-
option(clientFake)
546-
}
547-
510+
clientFake := fake.NewReactionForwardingClientsetDecorator(config.clientObjs, config.clientOptions...)
548511
opClientFake := operatorclient.NewClient(k8sfake.NewSimpleClientset(config.k8sObjs...), apiextensionsfake.NewSimpleClientset(config.extObjs...), apiregistrationfake.NewSimpleClientset(config.regObjs...))
549512

550513
// Create operator namespace
@@ -707,11 +670,3 @@ func toManifest(obj runtime.Object) string {
707670
raw, _ := json.Marshal(obj)
708671
return string(raw)
709672
}
710-
711-
// selfLink returns a selfLink.
712-
func buildSelfLink(groupVersion, plural, namespace, name string) string {
713-
if namespace == metav1.NamespaceAll {
714-
return fmt.Sprintf("/apis/%s/%s/%s", groupVersion, plural, name)
715-
}
716-
return fmt.Sprintf("/apis/%s/namespaces/%s/%s/%s", groupVersion, namespace, plural, name)
717-
}

pkg/controller/operators/catalog/subscriptions_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ import (
1414
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/reconciler"
1515
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver"
1616
"github.com/operator-framework/operator-lifecycle-manager/pkg/fakes"
17+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/clientfake"
1718
)
1819

1920
func TestSyncSubscriptions(t *testing.T) {
2021
now := metav1.Date(2018, time.January, 26, 20, 40, 0, 0, time.UTC)
2122
timeNow = func() metav1.Time { return now }
22-
2323
testNamespace := "testNamespace"
24+
2425
type fields struct {
25-
fakeClientOptions []fakeClientOption
26+
clientOptions []clientfake.Option
2627
sourcesLastUpdate metav1.Time
2728
resolveSteps []*v1alpha1.Step
2829
resolveSubs []*v1alpha1.Subscription
@@ -51,7 +52,7 @@ func TestSyncSubscriptions(t *testing.T) {
5152
{
5253
name: "NoStatus/NoCurrentCSV/FoundInCatalog",
5354
fields: fields{
54-
fakeClientOptions: []fakeClientOption{withSelfLinks(t)},
55+
clientOptions: []clientfake.Option{clientfake.WithSelfLinks(t)},
5556
existingOLMObjs: []runtime.Object{
5657
&v1alpha1.Subscription{
5758
ObjectMeta: metav1.ObjectMeta{
@@ -182,7 +183,7 @@ func TestSyncSubscriptions(t *testing.T) {
182183
{
183184
name: "Status/HaveCurrentCSV/UpdateFoundInCatalog",
184185
fields: fields{
185-
fakeClientOptions: []fakeClientOption{withSelfLinks(t)},
186+
clientOptions: []clientfake.Option{clientfake.WithSelfLinks(t)},
186187
existingOLMObjs: []runtime.Object{
187188
&v1alpha1.ClusterServiceVersion{
188189
ObjectMeta: metav1.ObjectMeta{
@@ -322,7 +323,7 @@ func TestSyncSubscriptions(t *testing.T) {
322323
{
323324
name: "Status/HaveCurrentCSV/UpdateFoundInCatalog/UpdateRequiresDependency",
324325
fields: fields{
325-
fakeClientOptions: []fakeClientOption{withSelfLinks(t)},
326+
clientOptions: []clientfake.Option{clientfake.WithSelfLinks(t)},
326327
existingOLMObjs: []runtime.Object{
327328
&v1alpha1.ClusterServiceVersion{
328329
ObjectMeta: metav1.ObjectMeta{
@@ -514,7 +515,7 @@ func TestSyncSubscriptions(t *testing.T) {
514515
// Create test operator
515516
stopCh := make(chan struct{})
516517
defer func() { stopCh <- struct{}{} }()
517-
o, err := NewFakeOperator(testNamespace, []string{testNamespace}, stopCh, withClientObjs(tt.fields.existingOLMObjs...), withK8sObjs(tt.fields.existingObjects...), withFakeClientOptions(tt.fields.fakeClientOptions...))
518+
o, err := NewFakeOperator(testNamespace, []string{testNamespace}, stopCh, withClientObjs(tt.fields.existingOLMObjs...), withK8sObjs(tt.fields.existingObjects...), withFakeClientOptions(tt.fields.clientOptions...))
518519
require.NoError(t, err)
519520

520521
o.reconciler = &fakes.FakeRegistryReconcilerFactory{

pkg/controller/registry/reconciler/configmap.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ type configMapCatalogSourceDecorator struct {
2626
*v1alpha1.CatalogSource
2727
}
2828

29+
const (
30+
// ConfigMapServerPostfix is a postfix appended to the names of resources generated for a ConfigMap server.
31+
ConfigMapServerPostfix string = "-configmap-server"
32+
)
33+
2934
func (s *configMapCatalogSourceDecorator) serviceAccountName() string {
30-
return s.GetName() + "-configmap-server"
35+
return s.GetName() + ConfigMapServerPostfix
3136
}
3237

3338
func (s *configMapCatalogSourceDecorator) roleName() string {
@@ -36,16 +41,21 @@ func (s *configMapCatalogSourceDecorator) roleName() string {
3641

3742
func (s *configMapCatalogSourceDecorator) Selector() map[string]string {
3843
return map[string]string{
39-
"olm.catalogSource": s.GetName(),
44+
CatalogSourceLabelKey: s.GetName(),
4045
}
4146
}
4247

48+
const (
49+
// ConfigMapRVLabelKey is the key for a label used to track the resource version of a related ConfigMap.
50+
ConfigMapRVLabelKey string = "olm.configMapResourceVersion"
51+
)
52+
4353
func (s *configMapCatalogSourceDecorator) Labels() map[string]string {
4454
labels := map[string]string{
45-
"olm.catalogSource": s.GetName(),
55+
CatalogSourceLabelKey: s.GetName(),
4656
}
4757
if s.Spec.SourceType == v1alpha1.SourceTypeInternal || s.Spec.SourceType == v1alpha1.SourceTypeConfigmap {
48-
labels["olm.configMapResourceVersion"] = s.Status.ConfigMapResource.ResourceVersion
58+
labels[ConfigMapRVLabelKey] = s.Status.ConfigMapResource.ResourceVersion
4959
}
5060
return labels
5161
}
@@ -123,7 +133,7 @@ func (s *configMapCatalogSourceDecorator) Pod(image string) *v1.Pod {
123133
Operator: v1.TolerationOpExists,
124134
},
125135
},
126-
ServiceAccountName: s.GetName() + "-configmap-server",
136+
ServiceAccountName: s.GetName() + ConfigMapServerPostfix,
127137
},
128138
}
129139
ownerutil.AddOwner(pod, s.CatalogSource, false, false)
@@ -442,7 +452,7 @@ func (c *ConfigMapRegistryReconciler) CheckRegistryServer(catalogSource *v1alpha
442452
c.currentRole(source) == nil ||
443453
c.currentRoleBinding(source) == nil ||
444454
c.currentService(source) == nil ||
445-
len(c.currentPods(source, c.Image)) != 1 {
455+
len(c.currentPods(source, c.Image)) < 1 {
446456
healthy = false
447457
return
448458
}

0 commit comments

Comments
 (0)