Skip to content

Commit 7f28e1e

Browse files
dtfranzopenshift-merge-bot[bot]
authored andcommitted
UPSTREAM: <carry>: Invalidate registries configuration cache to allow dynamic config updates without restart
Signed-off-by: dtfranz <[email protected]>
1 parent 74a2477 commit 7f28e1e

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

cmd/manager/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ func main() {
245245
return nil, fmt.Errorf("could not stat auth file, error: %w", err)
246246
}
247247
return srcContext, nil
248-
}}
248+
},
249+
}
249250

250251
clusterExtensionFinalizers := crfinalizer.NewFinalizers()
251252
if err := clusterExtensionFinalizers.Register(controllers.ClusterExtensionCleanupUnpackCacheFinalizer, finalizers.FinalizerFunc(func(ctx context.Context, obj client.Object) (crfinalizer.Result, error) {

internal/rukpak/source/containers_image.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/containers/image/v5/oci/layout"
1818
"github.com/containers/image/v5/pkg/blobinfocache/none"
1919
"github.com/containers/image/v5/pkg/compression"
20+
"github.com/containers/image/v5/pkg/sysregistriesv2"
2021
"github.com/containers/image/v5/signature"
2122
"github.com/containers/image/v5/types"
2223
"github.com/go-logr/logr"
@@ -41,6 +42,9 @@ func (i *ContainersImageRegistry) Unpack(ctx context.Context, bundle *BundleSour
4142
return nil, reconcile.TerminalError(fmt.Errorf("error parsing bundle, bundle %s has a nil image source", bundle.Name))
4243
}
4344

45+
// Reload registries cache in case of configuration update
46+
sysregistriesv2.InvalidateCache()
47+
4448
srcCtx, err := i.SourceContextFunc(l)
4549
if err != nil {
4650
return nil, err
@@ -250,6 +254,11 @@ func (i *ContainersImageRegistry) unpackImage(ctx context.Context, unpackPath st
250254
if err != nil {
251255
return fmt.Errorf("error creating image source: %w", err)
252256
}
257+
defer func() {
258+
if err := layoutSrc.Close(); err != nil {
259+
panic(err)
260+
}
261+
}()
253262

254263
if err := os.MkdirAll(unpackPath, 0700); err != nil {
255264
return fmt.Errorf("error creating unpack directory: %w", err)

test/e2e/cluster_extension_install_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,82 @@ func TestClusterExtensionInstallRegistry(t *testing.T) {
358358
}
359359
}
360360

361+
func TestClusterExtensionInstallRegistryDynamic(t *testing.T) {
362+
// NOTE: Like 'TestClusterExtensionInstallRegistry', this test also requires extra configuration in /etc/containers/registries.conf
363+
packageName := "dynamic"
364+
365+
t.Log("When a cluster extension is installed from a catalog")
366+
t.Log("When the extension bundle format is registry+v1")
367+
368+
clusterExtension, extensionCatalog, sa, ns := testInit(t)
369+
defer testCleanup(t, extensionCatalog, clusterExtension, sa, ns)
370+
defer getArtifactsOutput(t)
371+
372+
clusterExtension.Spec = ocv1.ClusterExtensionSpec{
373+
Source: ocv1.SourceConfig{
374+
SourceType: "Catalog",
375+
Catalog: &ocv1.CatalogSource{
376+
PackageName: packageName,
377+
Selector: &metav1.LabelSelector{
378+
MatchLabels: map[string]string{"olm.operatorframework.io/metadata.name": extensionCatalog.Name},
379+
},
380+
},
381+
},
382+
Namespace: ns.Name,
383+
ServiceAccount: ocv1.ServiceAccountReference{
384+
Name: sa.Name,
385+
},
386+
}
387+
t.Log("It updates the registries.conf file contents")
388+
cm := corev1.ConfigMap{
389+
ObjectMeta: metav1.ObjectMeta{
390+
Name: "e2e-registries-conf",
391+
Namespace: "olmv1-system",
392+
},
393+
Data: map[string]string{
394+
"registries.conf": `[[registry]]
395+
prefix = "dynamic-registry.operator-controller-e2e.svc.cluster.local:5000"
396+
location = "docker-registry.operator-controller-e2e.svc.cluster.local:5000"`,
397+
},
398+
}
399+
require.NoError(t, c.Update(context.Background(), &cm))
400+
401+
t.Log("It resolves the specified package with correct bundle path")
402+
t.Log("By creating the ClusterExtension resource")
403+
require.NoError(t, c.Create(context.Background(), clusterExtension))
404+
405+
t.Log("By eventually reporting a successful resolution and bundle path")
406+
require.EventuallyWithT(t, func(ct *assert.CollectT) {
407+
assert.NoError(ct, c.Get(context.Background(), types.NamespacedName{Name: clusterExtension.Name}, clusterExtension))
408+
}, 2*time.Minute, pollInterval)
409+
410+
// Give the check 2 minutes instead of the typical 1 for the pod's
411+
// files to update from the configmap change.
412+
// The theoretical max time is the kubelet sync period of 1 minute +
413+
// ConfigMap cache TTL of 1 minute = 2 minutes
414+
t.Log("By eventually reporting progressing as True")
415+
require.EventuallyWithT(t, func(ct *assert.CollectT) {
416+
assert.NoError(ct, c.Get(context.Background(), types.NamespacedName{Name: clusterExtension.Name}, clusterExtension))
417+
cond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1.TypeProgressing)
418+
if assert.NotNil(ct, cond) {
419+
assert.Equal(ct, metav1.ConditionTrue, cond.Status)
420+
assert.Equal(ct, ocv1.ReasonSucceeded, cond.Reason)
421+
}
422+
}, 2*time.Minute, pollInterval)
423+
424+
t.Log("By eventually installing the package successfully")
425+
require.EventuallyWithT(t, func(ct *assert.CollectT) {
426+
assert.NoError(ct, c.Get(context.Background(), types.NamespacedName{Name: clusterExtension.Name}, clusterExtension))
427+
cond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1.TypeInstalled)
428+
if assert.NotNil(ct, cond) {
429+
assert.Equal(ct, metav1.ConditionTrue, cond.Status)
430+
assert.Equal(ct, ocv1.ReasonSucceeded, cond.Reason)
431+
assert.Contains(ct, cond.Message, "Installed bundle")
432+
assert.NotEmpty(ct, clusterExtension.Status.Install.Bundle)
433+
}
434+
}, pollDuration, pollInterval)
435+
}
436+
361437
func TestClusterExtensionInstallRegistryMultipleBundles(t *testing.T) {
362438
t.Log("When a cluster extension is installed from a catalog")
363439

testdata/images/catalogs/test-catalog/v1/configs/catalog.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,23 @@ properties:
6969
value:
7070
packageName: test-mirrored
7171
version: 1.2.0
72+
---
73+
schema: olm.package
74+
name: dynamic
75+
defaultChannel: beta
76+
---
77+
schema: olm.channel
78+
name: beta
79+
package: dynamic
80+
entries:
81+
- name: dynamic-operator.1.2.0
82+
---
83+
schema: olm.bundle
84+
name: dynamic-operator.1.2.0
85+
package: dynamic
86+
image: dynamic-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/test-operator:v1.0.0
87+
properties:
88+
- type: olm.package
89+
value:
90+
packageName: dynamic
91+
version: 1.2.0

0 commit comments

Comments
 (0)