Skip to content

Commit e1ad5a6

Browse files
committed
Add spec.insecure to OCIRepository API
Signed-off-by: Stefan Prodan <[email protected]>
1 parent 181b217 commit e1ad5a6

File tree

6 files changed

+47
-5
lines changed

6 files changed

+47
-5
lines changed

api/v1beta2/ocirepository_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ type OCIRepositorySpec struct {
113113
// +optional
114114
Ignore *string `json:"ignore,omitempty"`
115115

116+
// Insecure allows connecting to a non-TLS HTTP container registry.
117+
// +optional
118+
Insecure bool `json:"insecure,omitempty"`
119+
116120
// This flag tells the controller to suspend the reconciliation of this source.
117121
// +optional
118122
Suspend bool `json:"suspend,omitempty"`

config/crd/bases/source.toolkit.fluxcd.io_ocirepositories.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ spec:
7272
a default will be used, consult the documentation for your version
7373
to find out what those are.
7474
type: string
75+
insecure:
76+
description: Insecure allows connecting to a non-TLS HTTP container
77+
registry.
78+
type: boolean
7579
interval:
7680
description: The interval at which to check for image updates.
7781
type: string

controllers/ocirepository_controller.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, obj *sour
301301
ctxTimeout, cancel := context.WithTimeout(ctx, obj.Spec.Timeout.Duration)
302302
defer cancel()
303303

304-
options := r.craneOptions(ctxTimeout)
304+
options := r.craneOptions(ctxTimeout, obj.Spec.Insecure)
305305

306306
// Generate the registry credential keychain either from static credentials or using cloud OIDC
307307
keychain, err := r.keychain(ctx, obj)
@@ -684,12 +684,16 @@ func (r *OCIRepositoryReconciler) oidcAuth(ctx context.Context, obj *sourcev1.OC
684684

685685
// craneOptions sets the auth headers, timeout and user agent
686686
// for all operations against remote container registries.
687-
func (r *OCIRepositoryReconciler) craneOptions(ctx context.Context) []crane.Option {
687+
func (r *OCIRepositoryReconciler) craneOptions(ctx context.Context, insecure bool) []crane.Option {
688688
options := []crane.Option{
689689
crane.WithContext(ctx),
690690
crane.WithUserAgent(oci.UserAgent),
691691
}
692-
options = append(options, crane.Insecure)
692+
693+
if insecure {
694+
options = append(options, crane.Insecure)
695+
}
696+
693697
return options
694698
}
695699

controllers/ocirepository_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ func TestOCIRepository_reconcileSource_authStrategy(t *testing.T) {
623623
Storage: testStorage,
624624
}
625625

626-
opts := r.craneOptions(ctx)
626+
opts := r.craneOptions(ctx, true)
627627
opts = append(opts, crane.WithAuthFromKeychain(authn.DefaultKeychain))
628628
repoURL, err := r.getArtifactURL(obj, opts)
629629
g.Expect(err).To(BeNil())
@@ -1158,7 +1158,7 @@ func TestOCIRepository_getArtifactURL(t *testing.T) {
11581158
obj.Spec.Reference = tt.reference
11591159
}
11601160

1161-
opts := r.craneOptions(ctx)
1161+
opts := r.craneOptions(ctx, true)
11621162
opts = append(opts, crane.WithAuthFromKeychain(authn.DefaultKeychain))
11631163
got, err := r.getArtifactURL(obj, opts)
11641164
if tt.wantErr {

docs/api/source.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,18 @@ consult the documentation for your version to find out what those are.</p>
11071107
</tr>
11081108
<tr>
11091109
<td>
1110+
<code>insecure</code><br>
1111+
<em>
1112+
bool
1113+
</em>
1114+
</td>
1115+
<td>
1116+
<em>(Optional)</em>
1117+
<p>Insecure allows connecting to a non-TLS HTTP container registry.</p>
1118+
</td>
1119+
</tr>
1120+
<tr>
1121+
<td>
11101122
<code>suspend</code><br>
11111123
<em>
11121124
bool
@@ -2839,6 +2851,18 @@ consult the documentation for your version to find out what those are.</p>
28392851
</tr>
28402852
<tr>
28412853
<td>
2854+
<code>insecure</code><br>
2855+
<em>
2856+
bool
2857+
</em>
2858+
</td>
2859+
<td>
2860+
<em>(Optional)</em>
2861+
<p>Insecure allows connecting to a non-TLS HTTP container registry.</p>
2862+
</td>
2863+
</tr>
2864+
<tr>
2865+
<td>
28422866
<code>suspend</code><br>
28432867
<em>
28442868
bool

docs/spec/v1beta2/ocirepositories.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ kubectl create secret generic tls-certs \
287287
--from-file=caFile=ca.crt
288288
```
289289

290+
### Insecure
291+
292+
`.spec.insecure` is an optional field to allow connecting to an insecure (HTTP)
293+
container registry server, if set to `true`. The default value is `false`,
294+
denying insecure (HTTP) connections.
295+
290296
### Interval
291297

292298
`.spec.interval` is a required field that specifies the interval at which the

0 commit comments

Comments
 (0)