Skip to content

Commit b66ee24

Browse files
committed
Adapting setupRegistryServer to be able to use https with the docker
registryClient Signed-off-by: Soule BA <[email protected]>
1 parent 992a230 commit b66ee24

File tree

10 files changed

+52
-100
lines changed

10 files changed

+52
-100
lines changed

api/v1beta2/helmrepository_types.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ type HelmRepositorySpec struct {
8080
// +optional
8181
Timeout *metav1.Duration `json:"timeout,omitempty"`
8282

83-
// InsecureSkipTLSVerify skips the validation of the TLS certificate of the
84-
// OCI registry endpoint.
85-
// +optional
86-
InsecureSkipTLSVerify bool `json:"insecureSkipTLSverify,omitempty"`
87-
8883
// Suspend tells the controller to suspend the reconciliation of this
8984
// HelmRepository.
9085
// +optional

docs/api/v1beta2/source.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -844,19 +844,6 @@ Its default value is 60s.</p>
844844
</tr>
845845
<tr>
846846
<td>
847-
<code>insecureSkipTLSverify</code><br>
848-
<em>
849-
bool
850-
</em>
851-
</td>
852-
<td>
853-
<em>(Optional)</em>
854-
<p>InsecureSkipTLSverify skips the validation of the TLS certificate of the
855-
OCI registry endpoint.</p>
856-
</td>
857-
</tr>
858-
<tr>
859-
<td>
860847
<code>suspend</code><br>
861848
<em>
862849
bool
@@ -2524,19 +2511,6 @@ Its default value is 60s.</p>
25242511
</tr>
25252512
<tr>
25262513
<td>
2527-
<code>insecureSkipTLSverify</code><br>
2528-
<em>
2529-
bool
2530-
</em>
2531-
</td>
2532-
<td>
2533-
<em>(Optional)</em>
2534-
<p>InsecureSkipTLSverify skips the validation of the TLS certificate of the
2535-
OCI registry endpoint.</p>
2536-
</td>
2537-
</tr>
2538-
<tr>
2539-
<td>
25402514
<code>suspend</code><br>
25412515
<em>
25422516
bool

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ require (
4949
github.com/fluxcd/pkg/untar v0.3.0
5050
github.com/fluxcd/pkg/version v0.2.2
5151
github.com/fluxcd/source-controller/api v1.0.0-rc.3
52+
github.com/foxcpp/go-mockdns v1.0.0
5253
github.com/go-git/go-billy/v5 v5.4.1
5354
github.com/go-logr/logr v1.2.4
5455
github.com/google/go-containerregistry v0.15.2
@@ -257,6 +258,7 @@ require (
257258
github.com/mattn/go-isatty v0.0.17 // indirect
258259
github.com/mattn/go-runewidth v0.0.14 // indirect
259260
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
261+
github.com/miekg/dns v1.1.50 // indirect
260262
github.com/miekg/pkcs11 v1.1.1 // indirect
261263
github.com/minio/md5-simd v1.1.2 // indirect
262264
github.com/minio/sha256-simd v1.0.0 // indirect

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ github.com/fluxcd/pkg/untar v0.3.0/go.mod h1:ClGpWYeDidYETkl048vCgHlsNtn5BHYHvMm
414414
github.com/fluxcd/pkg/version v0.2.2 h1:ZpVXECeLA5hIQMft11iLp6gN3cKcz6UNuVTQPw/bRdI=
415415
github.com/fluxcd/pkg/version v0.2.2/go.mod h1:NGnh/no8S6PyfCDxRFrPY3T5BUnqP48MxfxNRU0z8C0=
416416
github.com/foxcpp/go-mockdns v1.0.0 h1:7jBqxd3WDWwi/6WhDvacvH1XsN3rOLXyHM1uhvIx6FI=
417+
github.com/foxcpp/go-mockdns v1.0.0/go.mod h1:lgRN6+KxQBawyIghpnl5CezHFGS9VLzvtVlwxvzXTQ4=
417418
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
418419
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
419420
github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps=
@@ -860,7 +861,9 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
860861
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
861862
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
862863
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
864+
github.com/miekg/dns v1.1.25/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
863865
github.com/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA=
866+
github.com/miekg/dns v1.1.50/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME=
864867
github.com/miekg/pkcs11 v1.0.3-0.20190429190417-a667d056470f/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs=
865868
github.com/miekg/pkcs11 v1.1.1 h1:Ugu9pdy6vAYku5DEpVWVFPYnzV+bxB+iRdbuFSu7TvU=
866869
github.com/miekg/pkcs11 v1.1.1/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs=
@@ -1252,6 +1255,7 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
12521255
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
12531256
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
12541257
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
1258+
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
12551259
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
12561260
golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
12571261
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
@@ -1335,6 +1339,7 @@ golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLL
13351339
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
13361340
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
13371341
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
1342+
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
13381343
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
13391344
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
13401345
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@@ -1361,6 +1366,7 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd
13611366
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
13621367
golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
13631368
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
1369+
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
13641370
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
13651371
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
13661372
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
@@ -1430,6 +1436,8 @@ golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7w
14301436
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
14311437
golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
14321438
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1439+
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1440+
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
14331441
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
14341442
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
14351443
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -1555,6 +1563,7 @@ golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgw
15551563
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
15561564
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
15571565
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
1566+
golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
15581567
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
15591568
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
15601569
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
@@ -1597,6 +1606,7 @@ golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4f
15971606
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
15981607
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
15991608
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
1609+
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
16001610
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
16011611
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
16021612
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=

internal/controller/helmchart_controller.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -576,12 +576,6 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *
576576
}
577577
}
578578

579-
if tlsConfig == nil {
580-
tlsConfig = &tls.Config{}
581-
}
582-
583-
tlsConfig.InsecureSkipVerify = repo.Spec.InsecureSkipTLSVerify
584-
585579
loginOpt, err := makeLoginOption(authenticator, keychain, normalizedURL)
586580
if err != nil {
587581
e := &serror.Event{
@@ -1092,12 +1086,6 @@ func (r *HelmChartReconciler) namespacedChartRepositoryCallback(ctx context.Cont
10921086
}
10931087
}
10941088

1095-
if tlsConfig == nil {
1096-
tlsConfig = &tls.Config{}
1097-
}
1098-
1099-
tlsConfig.InsecureSkipVerify = obj.Spec.InsecureSkipTLSVerify
1100-
11011089
loginOpt, err := makeLoginOption(authenticator, keychain, normalizedURL)
11021090
if err != nil {
11031091
return nil, err

internal/controller/helmchart_controller_test.go

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,16 +2278,15 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_authStrategy(t *testing.T) {
22782278
}
22792279

22802280
tests := []struct {
2281-
name string
2282-
url string
2283-
registryOpts registryOptions
2284-
secretOpts secretOptions
2285-
insecureSkipTLSVerify bool
2286-
provider string
2287-
providerImg string
2288-
want sreconcile.Result
2289-
wantErr bool
2290-
assertConditions []metav1.Condition
2281+
name string
2282+
url string
2283+
registryOpts registryOptions
2284+
secretOpts secretOptions
2285+
provider string
2286+
providerImg string
2287+
want sreconcile.Result
2288+
wantErr bool
2289+
assertConditions []metav1.Condition
22912290
}{
22922291
{
22932292
name: "HTTP without basic auth",
@@ -2383,22 +2382,6 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_authStrategy(t *testing.T) {
23832382
*conditions.UnknownCondition(meta.ReadyCondition, meta.ProgressingReason, "building artifact: pulled 'helmchart' chart with version '0.1.0'"),
23842383
},
23852384
},
2386-
{
2387-
name: "HTTPS With InsecureSkipTLSVerify",
2388-
want: sreconcile.ResultSuccess,
2389-
registryOpts: registryOptions{
2390-
withBasicAuth: true,
2391-
},
2392-
secretOpts: secretOptions{
2393-
username: testRegistryUsername,
2394-
password: testRegistryPassword,
2395-
},
2396-
insecureSkipTLSVerify: true,
2397-
assertConditions: []metav1.Condition{
2398-
*conditions.TrueCondition(meta.ReconcilingCondition, meta.ProgressingReason, "building artifact: pulled 'helmchart' chart with version '0.1.0'"),
2399-
*conditions.UnknownCondition(meta.ReadyCondition, meta.ProgressingReason, "building artifact: pulled 'helmchart' chart with version '0.1.0'"),
2400-
},
2401-
},
24022385
}
24032386

24042387
for _, tt := range tests {
@@ -2445,8 +2428,6 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_authStrategy(t *testing.T) {
24452428
repo.Spec.URL = tt.providerImg
24462429
}
24472430

2448-
repo.Spec.InsecureSkipTLSVerify = tt.insecureSkipTLSVerify
2449-
24502431
var secret *corev1.Secret
24512432
if tt.secretOpts.username != "" && tt.secretOpts.password != "" {
24522433
secret = &corev1.Secret{

internal/controller/helmrepository_controller.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,6 @@ func (r *HelmRepositoryReconciler) reconcileSource(ctx context.Context, sp *patc
441441
}
442442
}
443443

444-
if obj.Spec.InsecureSkipTLSVerify {
445-
tlsConfig.InsecureSkipVerify = true
446-
}
447-
448444
// Construct Helm chart repository with options and download index
449445
newChartRepo, err := repository.NewChartRepository(obj.Spec.URL, "", r.Getters, tlsConfig, clientOpts...)
450446
if err != nil {

internal/controller/helmrepository_controller_oci.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,6 @@ func (r *HelmRepositoryOCIReconciler) reconcile(ctx context.Context, sp *patch.S
349349
}
350350
}
351351

352-
if tlsConfig == nil {
353-
tlsConfig = &tls.Config{}
354-
}
355-
356-
tlsConfig.InsecureSkipVerify = obj.Spec.InsecureSkipTLSVerify
357-
358352
loginOpt, err := makeLoginOption(authenticator, keychain, obj.Spec.URL)
359353
if err != nil {
360354
conditions.MarkFalse(obj, meta.ReadyCondition, sourcev1.AuthenticationFailedReason, err.Error())

internal/controller/helmrepository_controller_oci_test.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ func TestHelmRepositoryOCIReconciler_authStrategy(t *testing.T) {
172172
url string
173173
registryOpts registryOptions
174174
secretOpts secretOptions
175-
insecureSkipTLSVerify bool
176175
provider string
177176
providerImg string
178177
want ctrl.Result
@@ -272,21 +271,6 @@ func TestHelmRepositoryOCIReconciler_authStrategy(t *testing.T) {
272271
*conditions.TrueCondition(meta.ReadyCondition, meta.SucceededReason, "Helm repository is ready"),
273272
},
274273
},
275-
{
276-
name: "HTTPS With InsecureSkipTLSVerify",
277-
want: ctrl.Result{RequeueAfter: interval},
278-
registryOpts: registryOptions{
279-
withBasicAuth: true,
280-
},
281-
secretOpts: secretOptions{
282-
username: testRegistryUsername,
283-
password: testRegistryPassword,
284-
},
285-
insecureSkipTLSVerify: true,
286-
assertConditions: []metav1.Condition{
287-
*conditions.TrueCondition(meta.ReadyCondition, meta.SucceededReason, "Helm repository is ready"),
288-
},
289-
},
290274
}
291275

292276
for _, tt := range tests {
@@ -325,8 +309,6 @@ func TestHelmRepositoryOCIReconciler_authStrategy(t *testing.T) {
325309
obj.Spec.URL = tt.providerImg
326310
}
327311

328-
obj.Spec.InsecureSkipTLSVerify = tt.insecureSkipTLSVerify
329-
330312
var secret *corev1.Secret
331313
if tt.secretOpts.username != "" && tt.secretOpts.password != "" {
332314
secret = &corev1.Secret{

internal/controller/suite_test.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ import (
2222
"fmt"
2323
"io"
2424
"math/rand"
25+
"net"
2526
"os"
2627
"path/filepath"
2728
"testing"
2829
"time"
2930

31+
"github.com/foxcpp/go-mockdns"
3032
"github.com/phayes/freeport"
3133
"github.com/sirupsen/logrus"
3234
"golang.org/x/crypto/bcrypt"
@@ -115,6 +117,8 @@ type registryClientTestServer struct {
115117
registryHost string
116118
workspaceDir string
117119
registryClient *helmreg.Client
120+
// A mock DNS server needed for TLS connection testing.
121+
srv *mockdns.Server
118122
}
119123

120124
type registryOptions struct {
@@ -149,8 +153,25 @@ func setupRegistryServer(ctx context.Context, workspaceDir string, opts registry
149153
if err != nil {
150154
return nil, fmt.Errorf("failed to get free port: %s", err)
151155
}
152-
153156
server.registryHost = fmt.Sprintf("localhost:%d", port)
157+
if opts.withTLS {
158+
// docker `MatchLocalhost` is a host match function which returns true for
159+
// localhost, and is used to enforce http for localhost requests."
160+
// That function does not handle matching of ip addresses in octal,
161+
// decimal or hex form.
162+
server.registryHost = fmt.Sprintf("0x7f000001:%d", port)
163+
// As of Go 1.20, Go may lookup "0x7f000001" as a DNS entry and fail.
164+
// Using a mock DNS server to handle the address.
165+
server.srv, err = mockdns.NewServer(map[string]mockdns.Zone{
166+
"0x7f000001.": {
167+
A: []string{"127.0.0.1"},
168+
},
169+
}, false)
170+
if err != nil {
171+
return nil, fmt.Errorf("failed to create mock DNS server: %s", err)
172+
}
173+
server.srv.PatchNet(net.DefaultResolver)
174+
}
154175
config.HTTP.Addr = fmt.Sprintf("127.0.0.1:%d", port)
155176
config.HTTP.DrainTimeout = time.Duration(10) * time.Second
156177
config.Storage = map[string]configuration.Parameters{"inmemory": map[string]interface{}{}}
@@ -179,6 +200,7 @@ func setupRegistryServer(ctx context.Context, workspaceDir string, opts registry
179200
if opts.withTLS {
180201
config.HTTP.TLS.Certificate = "testdata/certs/server.pem"
181202
config.HTTP.TLS.Key = "testdata/certs/server-key.pem"
203+
config.HTTP.TLS.ClientCAs = []string{"testdata/certs/ca.pem"}
182204
}
183205

184206
// setup logger options
@@ -199,6 +221,13 @@ func setupRegistryServer(ctx context.Context, workspaceDir string, opts registry
199221
return server, nil
200222
}
201223

224+
func (s *registryClientTestServer) stopSrv() {
225+
if s.srv != nil {
226+
mockdns.UnpatchNet(net.DefaultResolver)
227+
s.srv.Close()
228+
}
229+
}
230+
202231
func TestMain(m *testing.M) {
203232
initTestTLS()
204233

@@ -235,6 +264,7 @@ func TestMain(m *testing.M) {
235264
if err != nil {
236265
panic(fmt.Sprintf("Failed to create a test registry server: %v", err))
237266
}
267+
defer testRegistryServer.stopSrv()
238268

239269
if err := (&GitRepositoryReconciler{
240270
Client: testEnv,

0 commit comments

Comments
 (0)