Skip to content

Commit 5ac23d4

Browse files
committed
feat: implementation of catalog polling feature with e2e test
1 parent 04b659c commit 5ac23d4

File tree

16 files changed

+798
-23
lines changed

16 files changed

+798
-23
lines changed

deploy/chart/templates/0000_50_olm_06-catalogsource.crd.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ spec:
1212
- name: v1alpha1
1313
served: true
1414
storage: true
15+
preserveUnknownFields: false
1516
scope: Namespaced
1617
names:
1718
plural: catalogsources
@@ -96,6 +97,16 @@ spec:
9697
a registry-server with. Only used when SourceType = SourceTypeGrpc.
9798
If present, the address field is ignored.
9899
type: string
100+
poll:
101+
description: Poll is used to determine the time interval between checks
102+
of the latest catalog source version. The catalog operator polls to
103+
see if a new version of the catalog source is available. If available,
104+
the latest image is pulled and gRPC traffic is directed to the latest
105+
catalog source.
106+
type: object
107+
properties:
108+
interval:
109+
type: string
99110
publisher:
100111
type: string
101112
secrets:
@@ -144,6 +155,11 @@ spec:
144155
format: date-time
145156
lastObservedState:
146157
type: string
158+
latestImageRegistryPoll:
159+
description: The last time the CatalogSource image registry has been
160+
polled to ensure the image is up-to-date
161+
type: string
162+
format: date-time
147163
message:
148164
description: A human readable message indicating details about why the
149165
ClusterServiceVersion is in this condition.

go.sum

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
66
cloud.google.com/go v0.37.4/go.mod h1:NHPJ89PdicEuT9hdPXMROBD91xc5uRDxsMtSB16k7hw=
77
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
88
github.com/Azure/azure-sdk-for-go v32.5.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
9+
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8=
910
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
1011
github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
1112
github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0=
@@ -24,6 +25,7 @@ github.com/GoogleCloudPlatform/k8s-cloud-provider v0.0.0-20190822182118-27a4ced3
2425
github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab/go.mod h1:3VYc5hodBMJ5+l/7J4xAyMeuM2PNuepvHlGs8yilUCA=
2526
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd/go.mod h1:64YHyfSL2R96J44Nlwm39UHepQbyR5q10x7iYa1ks2E=
2627
github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
28+
github.com/Microsoft/hcsshim v0.8.6 h1:ZfF0+zZeYdzMIVMZHKtDKJvLHj76XCuVae/jNkjj0IA=
2729
github.com/Microsoft/hcsshim v0.8.6/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg=
2830
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46 h1:lsxEuwrXEAokXB9qhlbKWPpo3KMLZQ5WB5WLQRW1uq0=
2931
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
@@ -79,6 +81,7 @@ github.com/codegangsta/negroni v1.0.0/go.mod h1:v0y3T5G7Y1UlFfyxFn/QLRU4a2EuNau2
7981
github.com/container-storage-interface/spec v1.1.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=
8082
github.com/containerd/console v0.0.0-20170925154832-84eeaae905fa/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw=
8183
github.com/containerd/containerd v1.0.2/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
84+
github.com/containerd/containerd v1.2.7 h1:8lqLbl7u1j3MmiL9cJ/O275crSq7bfwUayvvatEupQk=
8285
github.com/containerd/containerd v1.2.7/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
8386
github.com/containerd/typeurl v0.0.0-20190228175220-2a93cfde8c20/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc=
8487
github.com/containernetworking/cni v0.7.1/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY=
@@ -129,8 +132,10 @@ github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BU
129132
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
130133
github.com/docker/docker v0.7.3-0.20190103212154-2b7e084dc98b/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
131134
github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
135+
github.com/docker/docker v0.7.3-0.20190817195342-4760db040282 h1:mzrx39dGtGq0VEnTHjnakmczd4uFbhx2cZU3BJDsLdc=
132136
github.com/docker/docker v0.7.3-0.20190817195342-4760db040282/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
133137
github.com/docker/go-connections v0.3.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
138+
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
134139
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
135140
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
136141
github.com/docker/libnetwork v0.0.0-20180830151422-a9cd636e3789/go.mod h1:93m0aTqz6z+g32wla4l4WxTrdtvBRmVzYRkYvasA5Z8=
@@ -280,6 +285,7 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORR
280285
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
281286
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
282287
github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
288+
github.com/gorilla/mux v1.7.1 h1:Dw4jY2nghMMRsh1ol8dv1axHkDwMQK2DHerMNJsIpJU=
283289
github.com/gorilla/mux v1.7.1/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
284290
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
285291
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
@@ -373,6 +379,7 @@ github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVc
373379
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
374380
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
375381
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
382+
github.com/mattn/go-shellwords v1.0.5 h1:JhhFTIOslh5ZsPrpa3Wdg8bF0WI3b44EMblmU9wIsXc=
376383
github.com/mattn/go-shellwords v1.0.5/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
377384
github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o=
378385
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
@@ -389,6 +396,7 @@ github.com/mikefarah/yaml/v2 v2.4.0/go.mod h1:ahVqZF4n1W4NqwvVnZzC4es67xsW9uR/RR
389396
github.com/mikefarah/yq/v2 v2.4.1 h1:tajDonaFK6WqitSZExB6fKlWQy/yCkptqxh2AXEe3N4=
390397
github.com/mikefarah/yq/v2 v2.4.1/go.mod h1:i8SYf1XdgUvY2OFwSqGAtWOOgimD2McJ6iutoxRm4k0=
391398
github.com/mindprince/gonvml v0.0.0-20171110221305-fee913ce8fb2/go.mod h1:2eu9pRWp8mo84xCg6KswZ+USQHjwgRhNp06sozOdsTY=
399+
github.com/mistifyio/go-zfs v2.1.1+incompatible h1:gAMO1HM9xBRONLHHYnu5iFsOJUiJdNZo6oqSENd4eW8=
392400
github.com/mistifyio/go-zfs v2.1.1+incompatible/go.mod h1:8AuVvqP/mXw1px98n46wfvcGfQ4ci2FwoAjKYxuo3Z4=
393401
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
394402
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
@@ -404,6 +412,7 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
404412
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
405413
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
406414
github.com/mohae/deepcopy v0.0.0-20170603005431-491d3605edfb/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
415+
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c h1:nXxl5PrvVm2L/wCy8dQu6DMTwH4oIuGN8GJDAlqDdVE=
407416
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
408417
github.com/mrunalp/fileutils v0.0.0-20160930181131-4ee1cc9a8058/go.mod h1:x8F1gnqOkIEiO4rqoeEEEqQbo7HjGMTvyoq3gej4iT0=
409418
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
@@ -428,16 +437,16 @@ github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2i
428437
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
429438
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
430439
github.com/opencontainers/runc v1.0.0-rc2.0.20190611121236-6cc515888830/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
440+
github.com/opencontainers/runtime-spec v1.0.0 h1:O6L965K88AilqnxeYPks/75HLpp4IG+FjeSCI3cVdRg=
431441
github.com/opencontainers/runtime-spec v1.0.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
442+
github.com/opencontainers/selinux v1.2.2 h1:Kx9J6eDG5/24A6DtUquGSpJQ+m2MUTahn4FtGEe8bFg=
432443
github.com/opencontainers/selinux v1.2.2/go.mod h1:+BLncwf63G4dgOzykXAxcmnFlUaOlkDdmw/CqsW6pjs=
433444
github.com/openshift/api v3.9.1-0.20190924102528-32369d4db2ad+incompatible h1:6il8W875Oq9vycPkRV5TteLP9IfMEX3lyOl5yN+CtdI=
434445
github.com/openshift/api v3.9.1-0.20190924102528-32369d4db2ad+incompatible/go.mod h1:dh9o4Fs58gpFXGSYfnVxGR9PnV53I8TW84pQaJDdGiY=
435446
github.com/openshift/client-go v0.0.0-20190923180330-3b6373338c9b h1:E++qQ7W1/EdvuMo+YGVbMPn4HihEp7YT5Rghh0VmA9A=
436447
github.com/openshift/client-go v0.0.0-20190923180330-3b6373338c9b/go.mod h1:6rzn+JTr7+WYS2E1TExP4gByoABxMznR6y2SnUIkmxk=
437448
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
438449
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
439-
github.com/operator-framework/operator-registry v1.5.1 h1:8ruUOG6IBDVTAXYWKsv6hwr4yv/0SFPFPAYGCpcv97E=
440-
github.com/operator-framework/operator-registry v1.5.1/go.mod h1:agrQlkWOo1q8U1SAaLSS2WQ+Z9vswNT2M2HFib9iuLY=
441450
github.com/operator-framework/operator-registry v1.5.3 h1:az83WDwgB+tHsmVn+tFq72yQBbaUAye8e4+KkDQmzLs=
442451
github.com/operator-framework/operator-registry v1.5.3/go.mod h1:agrQlkWOo1q8U1SAaLSS2WQ+Z9vswNT2M2HFib9iuLY=
443452
github.com/otiai10/copy v1.0.1 h1:gtBjD8aq4nychvRZ2CyJvFWAw0aja+VHazDdruZKGZA=
@@ -463,7 +472,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
463472
github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA=
464473
github.com/pquerna/ffjson v0.0.0-20180717144149-af8b230fcd20/go.mod h1:YARuvh7BUWHNhzDq2OM5tzR2RiCcN2D7sapiKyCel/M=
465474
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
466-
github.com/prometheus/client_golang v0.9.2 h1:awm861/B8OKDd2I/6o1dy3ra4BamzKhYOiGItCeZ740=
467475
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=
468476
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829 h1:D+CiwcpGTW6pL6bv6KI3KbyEyCKyS+1JWS2h8PNDnGA=
469477
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
@@ -744,6 +752,7 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
744752
gopkg.in/yaml.v3 v3.0.0-20190905181640-827449938966 h1:B0J02caTR6tpSJozBJyiAzT6CtBzjclw4pgm9gg8Ys0=
745753
gopkg.in/yaml.v3 v3.0.0-20190905181640-827449938966/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
746754
gotest.tools v2.1.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
755+
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
747756
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
748757
gotest.tools/gotestsum v0.3.5/go.mod h1:Mnf3e5FUzXbkCfynWBGOwLssY7gTQgCHObK9tMpAriY=
749758
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

manifests/0000_50_olm_06-catalogsource.crd.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ spec:
1212
- name: v1alpha1
1313
served: true
1414
storage: true
15+
preserveUnknownFields: false
1516
scope: Namespaced
1617
names:
1718
plural: catalogsources
@@ -38,7 +39,6 @@ spec:
3839
- name: Age
3940
type: date
4041
JSONPath: .metadata.creationTimestamp
41-
preserveUnknownFields: false
4242
subresources:
4343
# status enables the status subresource.
4444
status: {}
@@ -97,6 +97,16 @@ spec:
9797
a registry-server with. Only used when SourceType = SourceTypeGrpc.
9898
If present, the address field is ignored.
9999
type: string
100+
poll:
101+
description: Poll is used to determine the time interval between checks
102+
of the latest catalog source version. The catalog operator polls to
103+
see if a new version of the catalog source is available. If available,
104+
the latest image is pulled and gRPC traffic is directed to the latest
105+
catalog source.
106+
type: object
107+
properties:
108+
interval:
109+
type: string
100110
publisher:
101111
type: string
102112
secrets:
@@ -145,6 +155,11 @@ spec:
145155
format: date-time
146156
lastObservedState:
147157
type: string
158+
latestImageRegistryPoll:
159+
description: The last time the CatalogSource image registry has been
160+
polled to ensure the image is up-to-date
161+
type: string
162+
format: date-time
148163
message:
149164
description: A human readable message indicating details about why the
150165
ClusterServiceVersion is in this condition.

pkg/api/apis/operators/catalogsource_types.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ type CatalogSourceSpec struct {
4747
// +Optional
4848
Image string
4949

50+
// Poll is used to determine the time interval between checks of the latest catalog source version.
51+
// The catalog operator polls to see if a new version of the catalog source is available.
52+
// If available, the latest image is pulled and gRPC traffic is directed to the latest catalog source.
53+
// +Optional
54+
Poll Poll
55+
5056
// Secrets represent set of secrets that can be used to access the contents of the catalog.
5157
// It is best to keep this list small, since each will need to be tried for every catalog entry.
5258
// +Optional
@@ -59,6 +65,10 @@ type CatalogSourceSpec struct {
5965
Icon Icon
6066
}
6167

68+
type Poll struct {
69+
Interval metav1.Duration
70+
}
71+
6272
type RegistryServiceStatus struct {
6373
Protocol string
6474
ServiceName string
@@ -78,11 +88,12 @@ func (s *RegistryServiceStatus) Address() string {
7888
}
7989

8090
type CatalogSourceStatus struct {
81-
Message string `json:"message,omitempty"`
82-
Reason ConditionReason `json:"reason,omitempty"`
83-
ConfigMapResource *ConfigMapResourceReference
84-
RegistryServiceStatus *RegistryServiceStatus
85-
GRPCConnectionState *GRPCConnectionState
91+
Message string `json:"message,omitempty"`
92+
Reason ConditionReason `json:"reason,omitempty"`
93+
ConfigMapResource *ConfigMapResourceReference
94+
RegistryServiceStatus *RegistryServiceStatus
95+
GRPCConnectionState *GRPCConnectionState
96+
LatestImageRegistryPoll *metav1.Time
8697
}
8798

8899
type ConfigMapResourceReference struct {

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

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package v1alpha1
22

33
import (
44
"fmt"
5-
5+
"github.com/sirupsen/logrus"
66
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
77
"k8s.io/apimachinery/pkg/types"
8+
"time"
89
)
910

1011
const (
@@ -54,6 +55,12 @@ type CatalogSourceSpec struct {
5455
// +Optional
5556
Image string `json:"image,omitempty"`
5657

58+
// Poll is used to determine the time interval between checks of the latest catalog source version.
59+
// The catalog operator polls to see if a new version of the catalog source is available.
60+
// If available, the latest image is pulled and gRPC traffic is directed to the latest catalog source.
61+
// +Optional
62+
Poll Poll `json:"poll,omitempty"`
63+
5764
// Secrets represent set of secrets that can be used to access the contents of the catalog.
5865
// It is best to keep this list small, since each will need to be tried for every catalog entry.
5966
// +Optional
@@ -66,6 +73,10 @@ type CatalogSourceSpec struct {
6673
Icon Icon `json:"icon,omitempty"`
6774
}
6875

76+
type Poll struct {
77+
Interval metav1.Duration `json:"interval,omitempty"`
78+
}
79+
6980
type RegistryServiceStatus struct {
7081
Protocol string `json:"protocol,omitempty"`
7182
ServiceName string `json:"serviceName,omitempty"`
@@ -92,6 +103,9 @@ type CatalogSourceStatus struct {
92103
// +optional
93104
Reason ConditionReason `json:"reason,omitempty"`
94105

106+
// The last time the CatalogSource image registry has been polled to ensure the image is up-to-date
107+
LatestImageRegistryPoll *metav1.Time `json:"latestImageRegistryPoll,omitempty"`
108+
95109
ConfigMapResource *ConfigMapResourceReference `json:"configMapReference,omitempty"`
96110
RegistryServiceStatus *RegistryServiceStatus `json:"registryService,omitempty"`
97111
GRPCConnectionState *GRPCConnectionState `json:"connectionState,omitempty"`
@@ -137,6 +151,52 @@ func (c *CatalogSource) SetError(reason ConditionReason, err error) {
137151
}
138152
}
139153

154+
func (c *CatalogSource) SetLastUpdateTime() {
155+
now := metav1.Now()
156+
c.Status.LatestImageRegistryPoll = &now
157+
}
158+
159+
// Check if it is time to update based on polling setting
160+
func (c *CatalogSource) ReadyToUpdate() bool {
161+
interval := c.Spec.Poll.Interval.Duration
162+
logrus.WithField("CatalogSource", c.Name).Infof("polling interval %v", interval)
163+
latest := c.Status.LatestImageRegistryPoll
164+
if latest == nil {
165+
logrus.WithField("CatalogSource", c.Name).Infof("latest poll %v", latest)
166+
} else {
167+
logrus.WithField("CatalogSource", c.Name).Infof("latest poll %v", *c.Status.LatestImageRegistryPoll)
168+
}
169+
170+
171+
logrus.WithField("CatalogSource", c.Name).Infof("polling interval is zero %t", c.Status.LatestImageRegistryPoll.IsZero())
172+
if c.Status.LatestImageRegistryPoll.IsZero() {
173+
logrus.WithField("CatalogSource", c.Name).Infof("creation interval plus interval before now %t", c.CreationTimestamp.Add(interval).Before(time.Now()))
174+
if c.CreationTimestamp.Add(interval).Before(time.Now()) {
175+
return true
176+
}
177+
} else {
178+
logrus.WithField("CatalogSource", c.Name).Infof("latest poll plus interval before now %t", c.Status.LatestImageRegistryPoll.Add(interval).Before(time.Now()))
179+
if c.Status.LatestImageRegistryPoll.Add(interval).Before(time.Now()) {
180+
return true
181+
}
182+
}
183+
184+
return false
185+
}
186+
187+
// CatalogPollingEnabled determines whether the polling feature is enabled on the particular catalog source
188+
func CatalogPollingEnabled(interval time.Duration, image string) bool {
189+
// if polling interval is zero polling will not be done
190+
if interval == time.Duration(0) {
191+
return false
192+
}
193+
// if catalog source is not backed by an image polling will not be done
194+
if image == "" {
195+
return false
196+
}
197+
return true
198+
}
199+
140200
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
141201

142202
// CatalogSourceList is a repository of CSVs, CRDs, and operator packages.

0 commit comments

Comments
 (0)