Skip to content

Commit 796a8a1

Browse files
committed
[RFC-0004] imagerepo: add support for insecure registries
Add a new field `.spec.insecure` to the `ImageRepository` API to allow indicating that the registry is an insecure registry, i.e. hosted at an HTTP endpoint. Furthermore, add a new flag `--insecure-allow-http` to allow the controller to make HTTP requests. By default, it is set to true to ensure backwards compatibility. Implements [RFC-0004](https://github.com/fluxcd/flux2/tree/main/rfcs/0004-insecure-http). Signed-off-by: Sanskar Jaiswal <[email protected]>
1 parent e797b56 commit 796a8a1

File tree

9 files changed

+158
-53
lines changed

9 files changed

+158
-53
lines changed

api/v1beta2/imagerepository_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ type ImageRepositorySpec struct {
9898
// +kubebuilder:default:=generic
9999
// +optional
100100
Provider string `json:"provider,omitempty"`
101+
102+
// Insecure, if set to true indicates that the image registry is hosted at an
103+
// HTTP endpoint.
104+
// +optional
105+
Insecure bool `json:"insecure,omitempty"`
101106
}
102107

103108
type ScanResult struct {

config/crd/bases/image.toolkit.fluxcd.io_imagerepositories.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ spec:
313313
image:
314314
description: Image is the name of the image repository
315315
type: string
316+
insecure:
317+
description: Insecure, if set to true indicates that the image registry
318+
is hosted at an HTTP endpoint.
319+
type: boolean
316320
interval:
317321
description: Interval is the length of time to wait between scans
318322
of the image repository.

docs/api/image-reflector.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,19 @@ string
540540
When not specified, defaults to &lsquo;generic&rsquo;.</p>
541541
</td>
542542
</tr>
543+
<tr>
544+
<td>
545+
<code>insecure</code><br>
546+
<em>
547+
bool
548+
</em>
549+
</td>
550+
<td>
551+
<em>(Optional)</em>
552+
<p>Insecure, if set to true indicates that the image registry is hosted at an
553+
HTTP endpoint.</p>
554+
</td>
555+
</tr>
543556
</table>
544557
</td>
545558
</tr>
@@ -725,6 +738,19 @@ string
725738
When not specified, defaults to &lsquo;generic&rsquo;.</p>
726739
</td>
727740
</tr>
741+
<tr>
742+
<td>
743+
<code>insecure</code><br>
744+
<em>
745+
bool
746+
</em>
747+
</td>
748+
<td>
749+
<em>(Optional)</em>
750+
<p>Insecure, if set to true indicates that the image registry is hosted at an
751+
HTTP endpoint.</p>
752+
</td>
753+
</tr>
728754
</tbody>
729755
</table>
730756
</div>

docs/spec/v1beta2/imagerepositories.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,16 @@ spec:
297297
- "1.1.1|1.0.0"
298298
```
299299

300+
### Insecure
301+
302+
`.spec.insecure` is an optional field to specify that the image registry is
303+
hosted at a non-TLS endpoint and thus the controller should use plain HTTP
304+
requests to communicate with the registry.
305+
306+
> If an ImageRepository has `.spec.insecure` as `true` and the controller has
307+
`--insecure-allow-http` set to `false`, then the object is marked as stalled.
308+
For more details, see: https://github.com/fluxcd/flux2/tree/ddcc301ab6289e0640174cb9f3d46f1eeab57927/rfcs/0004-insecure-http#design-details
309+
300310
### Provider
301311

302312
`.spec.provider` is an optional field that allows specifying an OIDC provider

go.mod

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ require (
1010
github.com/dgraph-io/badger/v3 v3.2103.5
1111
github.com/fluxcd/image-reflector-controller/api v0.28.0
1212
github.com/fluxcd/pkg/apis/acl v0.1.0
13-
github.com/fluxcd/pkg/apis/event v0.5.0
14-
github.com/fluxcd/pkg/apis/meta v1.1.0
13+
github.com/fluxcd/pkg/apis/event v0.5.1
14+
github.com/fluxcd/pkg/apis/meta v1.1.1
1515
github.com/fluxcd/pkg/oci v0.26.1
16-
github.com/fluxcd/pkg/runtime v0.38.1
16+
github.com/fluxcd/pkg/runtime v0.40.0
1717
github.com/fluxcd/pkg/version v0.2.2
1818
github.com/google/go-containerregistry v0.15.2
1919
github.com/google/go-containerregistry/pkg/authn/k8schain v0.0.0-20230523181351-c3f8a49229d3
2020
github.com/onsi/ginkgo v1.16.5
21-
github.com/onsi/gomega v1.27.7
21+
github.com/onsi/gomega v1.27.8
2222
github.com/spf13/pflag v1.0.5
2323
go.uber.org/zap v1.24.0
24-
k8s.io/api v0.27.2
25-
k8s.io/apimachinery v0.27.2
26-
k8s.io/client-go v0.27.2
24+
k8s.io/api v0.27.3
25+
k8s.io/apimachinery v0.27.3
26+
k8s.io/client-go v0.27.3
2727
k8s.io/utils v0.0.0-20230505201702-9f6742963106
2828
sigs.k8s.io/controller-runtime v0.15.0
2929
)
@@ -106,7 +106,7 @@ require (
106106
github.com/google/uuid v1.3.0 // indirect
107107
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
108108
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
109-
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
109+
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
110110
github.com/imdario/mergo v0.3.15 // indirect
111111
github.com/inconshreveable/mousetrap v1.1.0 // indirect
112112
github.com/jmespath/go-jmespath v0.4.0 // indirect
@@ -131,10 +131,10 @@ require (
131131
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
132132
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
133133
github.com/pkg/errors v0.9.1 // indirect
134-
github.com/prometheus/client_golang v1.15.1 // indirect
134+
github.com/prometheus/client_golang v1.16.0 // indirect
135135
github.com/prometheus/client_model v0.4.0 // indirect
136136
github.com/prometheus/common v0.44.0 // indirect
137-
github.com/prometheus/procfs v0.10.0 // indirect
137+
github.com/prometheus/procfs v0.10.1 // indirect
138138
github.com/russross/blackfriday/v2 v2.1.0 // indirect
139139
github.com/sirupsen/logrus v1.9.2 // indirect
140140
github.com/spf13/cobra v1.7.0 // indirect
@@ -159,9 +159,9 @@ require (
159159
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
160160
gopkg.in/yaml.v2 v2.4.0 // indirect
161161
gopkg.in/yaml.v3 v3.0.1 // indirect
162-
k8s.io/apiextensions-apiserver v0.27.2 // indirect
162+
k8s.io/apiextensions-apiserver v0.27.3 // indirect
163163
k8s.io/cli-runtime v0.27.2 // indirect
164-
k8s.io/component-base v0.27.2 // indirect
164+
k8s.io/component-base v0.27.3 // indirect
165165
k8s.io/klog/v2 v2.100.1 // indirect
166166
k8s.io/kube-openapi v0.0.0-20230515203736-54b630e78af5 // indirect
167167
k8s.io/kubectl v0.27.2 // indirect

go.sum

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f/go.mod h1:OSY
157157
github.com/flowstack/go-jsonschema v0.1.1/go.mod h1:yL7fNggx1o8rm9RlgXv7hTBWxdBM0rVwpMwimd3F3N0=
158158
github.com/fluxcd/pkg/apis/acl v0.1.0 h1:EoAl377hDQYL3WqanWCdifauXqXbMyFuK82NnX6pH4Q=
159159
github.com/fluxcd/pkg/apis/acl v0.1.0/go.mod h1:zfEZzz169Oap034EsDhmCAGgnWlcWmIObZjYMusoXS8=
160-
github.com/fluxcd/pkg/apis/event v0.5.0 h1:aAoo3AcWMh6hFfhxFED2TbyIk9590C7l17eh3Ys5I3I=
161-
github.com/fluxcd/pkg/apis/event v0.5.0/go.mod h1:hiVliecUNHIeE128NFEgyoNxLcv/TWzrYHtf0ODj8fw=
162-
github.com/fluxcd/pkg/apis/meta v1.1.0 h1:vYU1mvUzztnQyTzZOLHQ3wm/tXd7E1QZ2V91zuVJPsQ=
163-
github.com/fluxcd/pkg/apis/meta v1.1.0/go.mod h1:/QwCotRKL/BT6RSa4O75FlYW14fU8eRfKnoagzbkmL4=
160+
github.com/fluxcd/pkg/apis/event v0.5.1 h1:UrEmKwTK/lt42gMZunl8BQBMzjf8PSqGbWDs/GB839c=
161+
github.com/fluxcd/pkg/apis/event v0.5.1/go.mod h1:GzBAzS8bq7751wvNkaSnr3kuwFVuWTPL20D77UgSNJQ=
162+
github.com/fluxcd/pkg/apis/meta v1.1.1 h1:sLAKLbEu7rRzJ+Mytffu3NcpfdbOBTa6hcpOQzFWm+M=
163+
github.com/fluxcd/pkg/apis/meta v1.1.1/go.mod h1:soCfzjFWbm1mqybDcOywWKTCEYlH3skpoNGTboVk234=
164164
github.com/fluxcd/pkg/oci v0.26.1 h1:MMEo751h8FF7yTbRkbJ1piXbOyFjlBOaGpPCmaWDWAg=
165165
github.com/fluxcd/pkg/oci v0.26.1/go.mod h1:WJRW6EbcYv5DC8PCGbIIviv1SxgCtyY9xai7GOERIKs=
166-
github.com/fluxcd/pkg/runtime v0.38.1 h1:deY7LP2e1UfHXmxNFFzY6MAbqdLWlRgvK9f/PIXyY5Y=
167-
github.com/fluxcd/pkg/runtime v0.38.1/go.mod h1:x7bNbCDuvErmqD3gPNgGDI/ovjHBwvNPiwmAJuIMqNM=
166+
github.com/fluxcd/pkg/runtime v0.40.0 h1:uGiiEbMZwd7xmbKaVmcH7iilCFW9betWbz0r1taK3G0=
167+
github.com/fluxcd/pkg/runtime v0.40.0/go.mod h1:BqHEOVrZmt19p0q1OlGFWAYh3rZ28+IBpxLB2yPjjQ4=
168168
github.com/fluxcd/pkg/version v0.2.2 h1:ZpVXECeLA5hIQMft11iLp6gN3cKcz6UNuVTQPw/bRdI=
169169
github.com/fluxcd/pkg/version v0.2.2/go.mod h1:NGnh/no8S6PyfCDxRFrPY3T5BUnqP48MxfxNRU0z8C0=
170170
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
@@ -262,8 +262,8 @@ github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9n
262262
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
263263
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
264264
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
265-
github.com/hashicorp/go-retryablehttp v0.7.2 h1:AcYqCvkpalPnPF2pn0KamgwamS42TqUDDYFRKq/RAd0=
266-
github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
265+
github.com/hashicorp/go-retryablehttp v0.7.4 h1:ZQgVdpTdAL7WpMIwLzCfbalOcSUdkDZnpUv3/+BxzFA=
266+
github.com/hashicorp/go-retryablehttp v0.7.4/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
267267
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
268268
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
269269
github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM=
@@ -327,11 +327,11 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
327327
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
328328
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
329329
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
330-
github.com/onsi/ginkgo/v2 v2.9.5 h1:+6Hr4uxzP4XIUyAkg61dWBw8lb/gc4/X5luuxN/EC+Q=
330+
github.com/onsi/ginkgo/v2 v2.9.7 h1:06xGQy5www2oN160RtEZoTvnP2sPhEfePYmCDc2szss=
331331
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
332332
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
333-
github.com/onsi/gomega v1.27.7 h1:fVih9JD6ogIiHUN6ePK7HJidyEDpWGVB5mzM7cWNXoU=
334-
github.com/onsi/gomega v1.27.7/go.mod h1:1p8OOlwo2iUUDsHnOrjE5UKYJ+e3W8eQ3qSlRahPmr4=
333+
github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc=
334+
github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJKFnNQ=
335335
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
336336
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
337337
github.com/opencontainers/image-spec v1.1.0-rc3 h1:fzg1mXZFj8YdPeNkRXMg+zb88BFV0Ys52cJydRwBkb8=
@@ -346,15 +346,15 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
346346
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
347347
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
348348
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
349-
github.com/prometheus/client_golang v1.15.1 h1:8tXpTmJbyH5lydzFPoxSIJ0J46jdh3tylbvM1xCv0LI=
350-
github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk=
349+
github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8=
350+
github.com/prometheus/client_golang v1.16.0/go.mod h1:Zsulrv/L9oM40tJ7T815tM89lFEugiJ9HzIqaAx4LKc=
351351
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
352352
github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY=
353353
github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
354354
github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY=
355355
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
356-
github.com/prometheus/procfs v0.10.0 h1:UkG7GPYkO4UZyLnyXjaWYcgOSONqwdBqFUT95ugmt6I=
357-
github.com/prometheus/procfs v0.10.0/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
356+
github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg=
357+
github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
358358
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
359359
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
360360
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
@@ -392,7 +392,7 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
392392
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
393393
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
394394
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
395-
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
395+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
396396
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
397397
github.com/urfave/cli v1.22.12/go.mod h1:sSBEIC79qR6OvcmsD4U3KABeOTxDqQtdDnaFuUN30b8=
398398
github.com/vbatts/tar-split v0.11.3 h1:hLFqsOLQ1SsppQNTMpkpPXClLDfC2A3Zgy9OUU+RVck=
@@ -597,18 +597,18 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
597597
gotest.tools/v3 v3.1.0 h1:rVV8Tcg/8jHUkPUorwjaMTtemIMVXfIPKiOqnhEhakk=
598598
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
599599
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
600-
k8s.io/api v0.27.2 h1:+H17AJpUMvl+clT+BPnKf0E3ksMAzoBBg7CntpSuADo=
601-
k8s.io/api v0.27.2/go.mod h1:ENmbocXfBT2ADujUXcBhHV55RIT31IIEvkntP6vZKS4=
602-
k8s.io/apiextensions-apiserver v0.27.2 h1:iwhyoeS4xj9Y7v8YExhUwbVuBhMr3Q4bd/laClBV6Bo=
603-
k8s.io/apiextensions-apiserver v0.27.2/go.mod h1:Oz9UdvGguL3ULgRdY9QMUzL2RZImotgxvGjdWRq6ZXQ=
604-
k8s.io/apimachinery v0.27.2 h1:vBjGaKKieaIreI+oQwELalVG4d8f3YAMNpWLzDXkxeg=
605-
k8s.io/apimachinery v0.27.2/go.mod h1:XNfZ6xklnMCOGGFNqXG7bUrQCoR04dh/E7FprV6pb+E=
600+
k8s.io/api v0.27.3 h1:yR6oQXXnUEBWEWcvPWS0jQL575KoAboQPfJAuKNrw5Y=
601+
k8s.io/api v0.27.3/go.mod h1:C4BNvZnQOF7JA/0Xed2S+aUyJSfTGkGFxLXz9MnpIpg=
602+
k8s.io/apiextensions-apiserver v0.27.3 h1:xAwC1iYabi+TDfpRhxh4Eapl14Hs2OftM2DN5MpgKX4=
603+
k8s.io/apiextensions-apiserver v0.27.3/go.mod h1:BH3wJ5NsB9XE1w+R6SSVpKmYNyIiyIz9xAmBl8Mb+84=
604+
k8s.io/apimachinery v0.27.3 h1:Ubye8oBufD04l9QnNtW05idcOe9Z3GQN8+7PqmuVcUM=
605+
k8s.io/apimachinery v0.27.3/go.mod h1:XNfZ6xklnMCOGGFNqXG7bUrQCoR04dh/E7FprV6pb+E=
606606
k8s.io/cli-runtime v0.27.2 h1:9HI8gfReNujKXt16tGOAnb8b4NZ5E+e0mQQHKhFGwYw=
607607
k8s.io/cli-runtime v0.27.2/go.mod h1:9UecpyPDTkhiYY4d9htzRqN+rKomJgyb4wi0OfrmCjw=
608-
k8s.io/client-go v0.27.2 h1:vDLSeuYvCHKeoQRhCXjxXO45nHVv2Ip4Fe0MfioMrhE=
609-
k8s.io/client-go v0.27.2/go.mod h1:tY0gVmUsHrAmjzHX9zs7eCjxcBsf8IiNe7KQ52biTcQ=
610-
k8s.io/component-base v0.27.2 h1:neju+7s/r5O4x4/txeUONNTS9r1HsPbyoPBAtHsDCpo=
611-
k8s.io/component-base v0.27.2/go.mod h1:5UPk7EjfgrfgRIuDBFtsEFAe4DAvP3U+M8RTzoSJkpo=
608+
k8s.io/client-go v0.27.3 h1:7dnEGHZEJld3lYwxvLl7WoehK6lAq7GvgjxpA3nv1E8=
609+
k8s.io/client-go v0.27.3/go.mod h1:2MBEKuTo6V1lbKy3z1euEGnhPfGZLKTS9tiJ2xodM48=
610+
k8s.io/component-base v0.27.3 h1:g078YmdcdTfrCE4fFobt7qmVXwS8J/3cI1XxRi/2+6k=
611+
k8s.io/component-base v0.27.3/go.mod h1:JNiKYcGImpQ44iwSYs6dysxzR9SxIIgQalk4HaCNVUY=
612612
k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
613613
k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
614614
k8s.io/kube-openapi v0.0.0-20230515203736-54b630e78af5 h1:azYPdzztXxPSa8wb+hksEKayiz0o+PPisO/d+QhWnoo=

internal/controller/imagerepository_controller.go

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ const (
8686
scanReasonInterval = "triggered by interval"
8787
)
8888

89+
// insecureHTTPError occurs when insecure HTTP communication is tried
90+
// and such behaviour is blocked.
91+
var insecureHTTPError = errors.New("use of insecure plain HTTP connections is blocked")
92+
8993
// getPatchOptions composes patch options based on the given parameters.
9094
// It is used as the options used when patching an object.
9195
func getPatchOptions(ownedConditions []string, controllerName string) []patch.Option {
@@ -113,6 +117,7 @@ type ImageRepositoryReconciler struct {
113117
DatabaseReader
114118
}
115119
DeprecatedLoginOpts login.ProviderOptions
120+
AllowInsecureHTTP bool
116121

117122
patchOptions []patch.Option
118123
}
@@ -249,9 +254,15 @@ func (r *ImageRepositoryReconciler) reconcile(ctx context.Context, sp *patch.Ser
249254
}
250255

251256
// Parse image reference.
252-
ref, err := parseImageReference(obj.Spec.Image)
257+
ref, err := r.parseImageReference(obj.Spec.Image, obj.Spec.Insecure)
253258
if err != nil {
254-
conditions.MarkStalled(obj, imagev1.ImageURLInvalidReason, err.Error())
259+
var reason string
260+
if errors.Is(err, insecureHTTPError) {
261+
reason = meta.InsecureConnectionsDisallowedReason
262+
} else {
263+
reason = imagev1.ImageURLInvalidReason
264+
}
265+
conditions.MarkStalled(obj, reason, err.Error())
255266
result, retErr = ctrl.Result{}, nil
256267
return
257268
}
@@ -268,11 +279,18 @@ func (r *ImageRepositoryReconciler) reconcile(ctx context.Context, sp *patch.Ser
268279
// Check if it can be scanned now.
269280
ok, when, reasonMsg, err := r.shouldScan(*obj, startTime)
270281
if err != nil {
271-
e := fmt.Errorf("failed to determine if it's scan time: %w", err)
272-
conditions.MarkFalse(obj, meta.ReadyCondition, metav1.StatusFailure, e.Error())
282+
var e error
283+
if errors.Is(err, insecureHTTPError) {
284+
e = err
285+
conditions.MarkStalled(obj, meta.InsecureConnectionsDisallowedReason, e.Error())
286+
} else {
287+
e = fmt.Errorf("failed to determine if it's scan time: %w", err)
288+
conditions.MarkFalse(obj, meta.ReadyCondition, metav1.StatusFailure, e.Error())
289+
}
273290
result, retErr = ctrl.Result{}, e
274291
return
275292
}
293+
conditions.Delete(obj, meta.StalledCondition)
276294

277295
// Scan the repository if it's scan time. No scan is a no-op reconciliation.
278296
// The next scan time is not reset in case of no-op reconciliation.
@@ -458,7 +476,7 @@ func (r *ImageRepositoryReconciler) shouldScan(obj imagev1.ImageRepository, now
458476

459477
// If the canonical image name of the image is different from the last
460478
// observed name, scan now.
461-
ref, err := parseImageReference(obj.Spec.Image)
479+
ref, err := r.parseImageReference(obj.Spec.Image, obj.Spec.Insecure)
462480
if err != nil {
463481
return false, scanInterval, "", err
464482
}
@@ -560,13 +578,23 @@ func eventLogf(ctx context.Context, r kuberecorder.EventRecorder, obj runtime.Ob
560578
}
561579

562580
// parseImageReference parses the given URL into a container registry repository
563-
// reference.
564-
func parseImageReference(url string) (name.Reference, error) {
581+
// reference. If insecure is set to true, then the registry is deemed to be
582+
// located at an HTTP endpoint.
583+
func (r *ImageRepositoryReconciler) parseImageReference(url string, insecure bool) (name.Reference, error) {
565584
if s := strings.Split(url, "://"); len(s) > 1 {
566585
return nil, fmt.Errorf(".spec.image value should not start with URL scheme; remove '%s://'", s[0])
567586
}
568587

569-
ref, err := name.ParseReference(url)
588+
var opts []name.Option
589+
if insecure {
590+
if r.AllowInsecureHTTP {
591+
opts = append(opts, name.Insecure)
592+
} else {
593+
return nil, insecureHTTPError
594+
}
595+
}
596+
597+
ref, err := name.ParseReference(url, opts...)
570598
if err != nil {
571599
return nil, err
572600
}

0 commit comments

Comments
 (0)