diff --git a/pkg/controller/registry/reconciler/reconciler.go b/pkg/controller/registry/reconciler/reconciler.go index 22ca1504d4..493b3ffd2e 100644 --- a/pkg/controller/registry/reconciler/reconciler.go +++ b/pkg/controller/registry/reconciler/reconciler.go @@ -319,6 +319,22 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name, opmImg, utilImage, img s } if grpcPodConfig.ExtractContent.CacheDir != "" { containerArgs = append(containerArgs, "--cache-dir="+filepath.Join(catalogPath, "cache")) + } else { + // opm serve does not allow us to specify an empty cache directory, which means that it will + // only create new caches in /tmp/, so we need to provide adequate write access there + const tmpdirName = "tmpdir" + tmpdirVolumeMount := corev1.VolumeMount{ + Name: tmpdirName, + MountPath: "/tmp/", + } + pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{ + Name: tmpdirName, + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }) + + pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, tmpdirVolumeMount) } pod.Spec.Containers[0].Args = containerArgs pod.Spec.Containers[0].VolumeMounts = append(pod.Spec.Containers[0].VolumeMounts, contentVolumeMount) diff --git a/pkg/controller/registry/reconciler/reconciler_test.go b/pkg/controller/registry/reconciler/reconciler_test.go index 6079b8cb6c..601eaaad22 100644 --- a/pkg/controller/registry/reconciler/reconciler_test.go +++ b/pkg/controller/registry/reconciler/reconciler_test.go @@ -406,7 +406,7 @@ func TestPodExtractContent(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ GenerateName: "test-", Namespace: "testns", - Labels: map[string]string{"olm.pod-spec-hash": "5ToGGS7RLuy9Fq91z7IjESOJXfurg09nHAxtfK", "olm.managed": "true"}, + Labels: map[string]string{"olm.pod-spec-hash": "7W3t15wWurp7a9W1VVX392SnNYQu3OLbGDJ0wy", "olm.managed": "true"}, Annotations: map[string]string{"cluster-autoscaler.kubernetes.io/safe-to-evict": "true"}, }, Spec: corev1.PodSpec{ @@ -419,6 +419,10 @@ func TestPodExtractContent(t *testing.T) { Name: "catalog-content", VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}}, }, + { + Name: "tmpdir", + VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}}, + }, }, InitContainers: []corev1.Container{ { @@ -497,7 +501,7 @@ func TestPodExtractContent(t *testing.T) { }, ImagePullPolicy: image.InferImagePullPolicy("image"), TerminationMessagePolicy: "FallbackToLogsOnError", - VolumeMounts: []corev1.VolumeMount{{Name: "catalog-content", MountPath: "/extracted-catalog"}}, + VolumeMounts: []corev1.VolumeMount{{Name: "tmpdir", MountPath: "/tmp/"}, {Name: "catalog-content", MountPath: "/extracted-catalog"}}, }, }, NodeSelector: map[string]string{"kubernetes.io/os": "linux"}, @@ -733,7 +737,7 @@ func TestPodExtractContent(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ GenerateName: "test-", Namespace: "testns", - Labels: map[string]string{"olm.pod-spec-hash": "bhL1lOcUJhtisRddUp8tRQupbIii64C6qz9drn", "olm.managed": "true"}, + Labels: map[string]string{"olm.pod-spec-hash": "8ed7duDhuISxUmqWPMZfQu9rc02OOJaOeyT6ML", "olm.managed": "true"}, Annotations: map[string]string{"cluster-autoscaler.kubernetes.io/safe-to-evict": "true"}, }, Spec: corev1.PodSpec{ @@ -746,6 +750,10 @@ func TestPodExtractContent(t *testing.T) { Name: "catalog-content", VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}}, }, + { + Name: "tmpdir", + VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}}, + }, }, InitContainers: []corev1.Container{ { @@ -830,7 +838,7 @@ func TestPodExtractContent(t *testing.T) { ReadOnlyRootFilesystem: ptr.To(true), }, TerminationMessagePolicy: "FallbackToLogsOnError", - VolumeMounts: []corev1.VolumeMount{{Name: "catalog-content", MountPath: "/extracted-catalog"}}, + VolumeMounts: []corev1.VolumeMount{{Name: "tmpdir", MountPath: "/tmp/"}, {Name: "catalog-content", MountPath: "/extracted-catalog"}}, }, }, NodeSelector: map[string]string{"kubernetes.io/os": "linux"},