Skip to content

Commit 1b5b4dd

Browse files
committed
fix: update Poll to be pointer
1 parent 5ac23d4 commit 1b5b4dd

File tree

9 files changed

+76
-38
lines changed

9 files changed

+76
-38
lines changed

pkg/api/apis/operators/catalogsource_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type CatalogSourceSpec struct {
5151
// The catalog operator polls to see if a new version of the catalog source is available.
5252
// If available, the latest image is pulled and gRPC traffic is directed to the latest catalog source.
5353
// +Optional
54-
Poll Poll
54+
Poll *Poll
5555

5656
// Secrets represent set of secrets that can be used to access the contents of the catalog.
5757
// It is best to keep this list small, since each will need to be tried for every catalog entry.

pkg/api/apis/operators/v1alpha1/catalogsource_types.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type CatalogSourceSpec struct {
5959
// The catalog operator polls to see if a new version of the catalog source is available.
6060
// If available, the latest image is pulled and gRPC traffic is directed to the latest catalog source.
6161
// +Optional
62-
Poll Poll `json:"poll,omitempty"`
62+
Poll *Poll `json:"poll,omitempty"`
6363

6464
// Secrets represent set of secrets that can be used to access the contents of the catalog.
6565
// It is best to keep this list small, since each will need to be tried for every catalog entry.
@@ -158,6 +158,9 @@ func (c *CatalogSource) SetLastUpdateTime() {
158158

159159
// Check if it is time to update based on polling setting
160160
func (c *CatalogSource) ReadyToUpdate() bool {
161+
if !c.PollingEnabled() {
162+
return false
163+
}
161164
interval := c.Spec.Poll.Interval.Duration
162165
logrus.WithField("CatalogSource", c.Name).Infof("polling interval %v", interval)
163166
latest := c.Status.LatestImageRegistryPoll
@@ -185,13 +188,17 @@ func (c *CatalogSource) ReadyToUpdate() bool {
185188
}
186189

187190
// CatalogPollingEnabled determines whether the polling feature is enabled on the particular catalog source
188-
func CatalogPollingEnabled(interval time.Duration, image string) bool {
191+
func (c *CatalogSource) PollingEnabled() bool {
189192
// if polling interval is zero polling will not be done
190-
if interval == time.Duration(0) {
193+
if c.Spec.Poll == nil {
191194
return false
192195
}
193196
// if catalog source is not backed by an image polling will not be done
194-
if image == "" {
197+
if c.Spec.Image == "" {
198+
return false
199+
}
200+
// if image is not type gRPC polling will not be done
201+
if c.Spec.SourceType != SourceTypeGrpc {
195202
return false
196203
}
197204
return true

pkg/api/apis/operators/v1alpha1/types_test.go

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,15 @@ func TestCatalogSource_ReadyToUpdate(t *testing.T) {
112112
result bool
113113
sleep time.Duration
114114
}{
115-
//{
116-
// description: "poll interval set to zero: do not check for updates",
117-
// catsrc: CatalogSource{Spec: CatalogSourceSpec{Poll: Poll{Interval: metav1.Duration{}}}},
118-
// result: false,
119-
//},
120-
//{
121-
// description: "not image based catalog source: do not check for updates",
122-
// catsrc: CatalogSource{Spec: CatalogSourceSpec{Poll: Poll{Interval: metav1.Duration{Duration: 1 * time.Second}},
123-
// Address: "127.0.0.1:8080"}},
124-
// result: false,
125-
//},
126115
{
127116
description: "polling interval set: last update time zero: update for the first time",
128117
catsrc: CatalogSource{
129118
ObjectMeta: metav1.ObjectMeta{CreationTimestamp: metav1.Time{Time: time.Now()}},
130119
Spec: CatalogSourceSpec{
131-
Poll: Poll{Interval: metav1.Duration{Duration: 1 * time.Second}},
132-
Image: "mycatsrcimage"}},
120+
Poll: &Poll{Interval: metav1.Duration{Duration: 1 * time.Second}},
121+
Image: "mycatsrcimage",
122+
SourceType: SourceTypeGrpc},
123+
},
133124
result: true,
134125
sleep: 2 * time.Second,
135126
},
@@ -138,8 +129,10 @@ func TestCatalogSource_ReadyToUpdate(t *testing.T) {
138129
catsrc: CatalogSource{
139130
ObjectMeta: metav1.ObjectMeta{CreationTimestamp: metav1.Time{Time: time.Now()}},
140131
Spec: CatalogSourceSpec{
141-
Poll: Poll{Interval: metav1.Duration{Duration: 1 * time.Second}},
142-
Image: "mycatsrcimage"},
132+
Poll: &Poll{Interval: metav1.Duration{Duration: 1 * time.Second}},
133+
Image: "mycatsrcimage",
134+
SourceType: SourceTypeGrpc,
135+
},
143136
Status: CatalogSourceStatus{LatestImageRegistryPoll: &metav1.Time{Time: time.Now()}},
144137
},
145138
result: true,
@@ -150,8 +143,10 @@ func TestCatalogSource_ReadyToUpdate(t *testing.T) {
150143
catsrc: CatalogSource{
151144
ObjectMeta: metav1.ObjectMeta{CreationTimestamp: metav1.Time{Time: time.Now()}},
152145
Spec: CatalogSourceSpec{
153-
Poll: Poll{Interval: metav1.Duration{Duration: 1 * time.Second}},
154-
Image: "mycatsrcimage"},
146+
Poll: &Poll{Interval: metav1.Duration{Duration: 1 * time.Second}},
147+
Image: "mycatsrcimage",
148+
SourceType: SourceTypeGrpc,
149+
},
155150
Status: CatalogSourceStatus{LatestImageRegistryPoll: &metav1.Time{Time: time.Now()}},
156151
},
157152
result: true,
@@ -164,3 +159,37 @@ func TestCatalogSource_ReadyToUpdate(t *testing.T) {
164159
require.Equal(t, tt.result, table[i].catsrc.ReadyToUpdate(), table[i].description)
165160
}
166161
}
162+
163+
func TestCatalogSource_PollingEnabled(t *testing.T) {
164+
var table = []struct {
165+
description string
166+
catsrc CatalogSource
167+
result bool
168+
}{
169+
{
170+
description: "poll interval set to zero: do not check for updates",
171+
catsrc: CatalogSource{Spec: CatalogSourceSpec{}},
172+
result: false,
173+
},
174+
{
175+
description: "not image based catalog source: do not check for updates",
176+
catsrc: CatalogSource{Spec: CatalogSourceSpec{SourceType: SourceTypeInternal,
177+
Address: "127.0.0.1:8080"}},
178+
result: false,
179+
},
180+
{
181+
description: "polling set with image based catalog: check for updates",
182+
catsrc: CatalogSource{Spec: CatalogSourceSpec{
183+
Image: "my-image",
184+
SourceType: SourceTypeGrpc,
185+
Poll: &Poll{Interval: metav1.Duration{
186+
Duration: 1 * time.Minute,
187+
}}},
188+
},
189+
result: true,
190+
},
191+
}
192+
for i, tt := range table {
193+
require.Equal(t, tt.result, table[i].catsrc.PollingEnabled(), table[i].description)
194+
}
195+
}

pkg/api/apis/operators/v1alpha1/zz_generated.conversion.go

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/api/apis/operators/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/api/apis/operators/zz_generated.deepcopy.go

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/registry/reconciler/grpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func (c *GrpcRegistryReconciler) ensurePod(source grpcCatalogSourceDecorator, ov
181181

182182
// ensureUpdatePod checks that for the same catalog source version the same imageID is running
183183
func (c *GrpcRegistryReconciler) ensureUpdatePod(source grpcCatalogSourceDecorator) error {
184-
if !v1alpha1.CatalogPollingEnabled(source.Spec.Poll.Interval.Duration, source.Spec.Image) {
184+
if !source.PollingEnabled() {
185185
return nil
186186
}
187187
var updateFlag bool

pkg/controller/registry/reconciler/reconciler.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
package reconciler
33

44
import (
5-
v1 "k8s.io/api/core/v1"
6-
"k8s.io/apimachinery/pkg/api/resource"
7-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8-
"time"
9-
105
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
116
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
127
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorlister"
8+
v1 "k8s.io/api/core/v1"
9+
"k8s.io/apimachinery/pkg/api/resource"
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1311
)
1412

1513
type nowFunc func() metav1.Time
@@ -90,7 +88,7 @@ func NewRegistryReconcilerFactory(lister operatorlister.OperatorLister, opClient
9088
func Pod(source *v1alpha1.CatalogSource, name string, image string, labels map[string]string, readinessDelay int32, livenessDelay int32) *v1.Pod {
9189
// ensure catalog image is pulled always if catalog polling is configured
9290
var pullPolicy v1.PullPolicy
93-
if source.Spec.Poll.Interval.Duration > time.Duration(0) {
91+
if source.Spec.Poll != nil {
9492
pullPolicy = v1.PullAlways
9593
} else {
9694
pullPolicy = v1.PullIfNotPresent

test/e2e/catalog_e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ func TestCatalogImageUpdate(t *testing.T) {
750750
Spec: v1alpha1.CatalogSourceSpec{
751751
SourceType: v1alpha1.SourceTypeGrpc,
752752
Image: oldImage[9:], // strip off docker://
753-
Poll: v1alpha1.Poll{
753+
Poll: &v1alpha1.Poll{
754754
Interval: metav1.Duration{
755755
Duration: 1 * time.Minute},
756756
},

0 commit comments

Comments
 (0)