Skip to content

Commit 82cebe1

Browse files
committed
Bug 1909992: Allow private bundle images within private indexes
In #1878, the secrets passed in `spec.secrets` field of a catalogsource were attached to the catsrc's corresponding SA that was used by the registry pod, thereby having access to the secrets. This allowed for pulling of private index images. However, the job that unpacks the bundle images did not have access to the secrets, and as a result private bundle image included in the catsrc were not installable using the secrets. This PR attaches the secrets from the catsrc to the job that unpacks the bundles, thereby allowing the inclusion of private bundle images within index from private indexes.
1 parent 072a93f commit 82cebe1

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

pkg/controller/bundle/bundle_unpacker.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func newBundleUnpackResult(lookup *operatorsv1alpha1.BundleLookup) *BundleUnpack
6565
}
6666
}
6767

68-
func (c *ConfigMapUnpacker) job(cmRef *corev1.ObjectReference, bundlePath string) *batchv1.Job {
68+
func (c *ConfigMapUnpacker) job(cmRef *corev1.ObjectReference, bundlePath string, secrets []corev1.LocalObjectReference) *batchv1.Job {
6969
job := &batchv1.Job{
7070
Spec: batchv1.JobSpec{
7171
//ttlSecondsAfterFinished: 0 // can use in the future to not have to clean up job
@@ -74,7 +74,8 @@ func (c *ConfigMapUnpacker) job(cmRef *corev1.ObjectReference, bundlePath string
7474
Name: cmRef.Name,
7575
},
7676
Spec: corev1.PodSpec{
77-
RestartPolicy: corev1.RestartPolicyOnFailure,
77+
RestartPolicy: corev1.RestartPolicyOnFailure,
78+
ImagePullSecrets: secrets,
7879
Containers: []corev1.Container{
7980
{
8081
Name: "extract",
@@ -331,8 +332,12 @@ func (c *ConfigMapUnpacker) UnpackBundle(lookup *operatorsv1alpha1.BundleLookup)
331332
return
332333
}
333334

335+
secrets := make([]corev1.LocalObjectReference, 0)
336+
for _, secretName := range cs.Spec.Secrets {
337+
secrets = append(secrets, corev1.LocalObjectReference{Name: secretName})
338+
}
334339
var job *batchv1.Job
335-
job, err = c.ensureJob(cmRef, result.Path)
340+
job, err = c.ensureJob(cmRef, result.Path, secrets)
336341
if err != nil {
337342
return
338343
}
@@ -384,8 +389,8 @@ func (c *ConfigMapUnpacker) ensureConfigmap(csRef *corev1.ObjectReference, name
384389
return
385390
}
386391

387-
func (c *ConfigMapUnpacker) ensureJob(cmRef *corev1.ObjectReference, bundlePath string) (job *batchv1.Job, err error) {
388-
fresh := c.job(cmRef, bundlePath)
392+
func (c *ConfigMapUnpacker) ensureJob(cmRef *corev1.ObjectReference, bundlePath string, secrets []corev1.LocalObjectReference) (job *batchv1.Job, err error) {
393+
fresh := c.job(cmRef, bundlePath, secrets)
389394
job, err = c.jobLister.Jobs(fresh.GetNamespace()).Get(fresh.GetName())
390395
if err != nil {
391396
if apierrors.IsNotFound(err) {

pkg/controller/bundle/bundle_unpacker_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ func TestConfigMapUnpacker(t *testing.T) {
113113
Namespace: "ns-a",
114114
Name: "src-a",
115115
},
116+
Spec: operatorsv1alpha1.CatalogSourceSpec{
117+
Secrets: []string{"my-secret"},
118+
},
116119
},
117120
},
118121
},
@@ -193,7 +196,8 @@ func TestConfigMapUnpacker(t *testing.T) {
193196
Name: pathHash,
194197
},
195198
Spec: corev1.PodSpec{
196-
RestartPolicy: corev1.RestartPolicyOnFailure,
199+
RestartPolicy: corev1.RestartPolicyOnFailure,
200+
ImagePullSecrets: []corev1.LocalObjectReference{{Name: "my-secret"}},
197201
Containers: []corev1.Container{
198202
{
199203
Name: "extract",

0 commit comments

Comments
 (0)