Skip to content

Commit 662ff51

Browse files
controller/registry: use static copy-content binary for copy
Signed-off-by: Steve Kuznetsov <[email protected]>
1 parent 44935f1 commit 662ff51

File tree

8 files changed

+46
-35
lines changed

8 files changed

+46
-35
lines changed

cmd/copy-content/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ func main() {
1313
catalogDestination := flag.String("catalog.to", "", "Path to where catalog contents should be copied.")
1414
cacheSource := flag.String("cache.from", "", "Path to cache contents to copy.")
1515
cacheDestination := flag.String("cache.to", "", "Path to where cache contents should be copied.")
16+
flag.Parse()
1617

1718
for flagName, value := range map[string]*string{
1819
"catalog.from": catalogSource,

e2e.Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ./pkg/controller/bundle/bundle_unpacker.go requires "/bin/cp"
22
FROM busybox
3-
COPY olm catalog package-server wait cpb /bin/
3+
COPY olm catalog package-server wait cpb copy-content /bin/
44
EXPOSE 8080
55
EXPOSE 5443
66
USER 1001

pkg/controller/operators/catalog/operator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
215215
op.sources = grpc.NewSourceStore(logger, 10*time.Second, 10*time.Minute, op.syncSourceState)
216216
op.sourceInvalidator = resolver.SourceProviderFromRegistryClientProvider(op.sources, logger)
217217
resolverSourceProvider := NewOperatorGroupToggleSourceProvider(op.sourceInvalidator, logger, op.lister.OperatorsV1().OperatorGroupLister())
218-
op.reconciler = reconciler.NewRegistryReconcilerFactory(lister, opClient, configmapRegistryImage, op.now, ssaClient, workloadUserID, opmImage)
218+
op.reconciler = reconciler.NewRegistryReconcilerFactory(lister, opClient, configmapRegistryImage, op.now, ssaClient, workloadUserID, opmImage, utilImage)
219219
res := resolver.NewOperatorStepResolver(lister, crClient, operatorNamespace, resolverSourceProvider, logger)
220220
op.resolver = resolver.NewInstrumentedResolver(res, metrics.RegisterDependencyResolutionSuccess, metrics.RegisterDependencyResolutionFailure)
221221

pkg/controller/operators/catalog/operator_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,7 @@ func NewFakeOperator(ctx context.Context, namespace string, namespaces []string,
17731773
}
17741774
applier := controllerclient.NewFakeApplier(s, "testowner")
17751775

1776-
op.reconciler = reconciler.NewRegistryReconcilerFactory(lister, op.opClient, "test:pod", op.now, applier, 1001, "")
1776+
op.reconciler = reconciler.NewRegistryReconcilerFactory(lister, op.opClient, "test:pod", op.now, applier, 1001, "", "")
17771777
}
17781778

17791779
op.RunInformers(ctx)
@@ -1929,7 +1929,7 @@ func toManifest(t *testing.T, obj runtime.Object) string {
19291929
}
19301930

19311931
func pod(s v1alpha1.CatalogSource) *corev1.Pod {
1932-
pod := reconciler.Pod(&s, "registry-server", "central-opm", s.Spec.Image, s.GetName(), s.GetLabels(), s.GetAnnotations(), 5, 10, 1001)
1932+
pod := reconciler.Pod(&s, "registry-server", "central-opm", "central-util", s.Spec.Image, s.GetName(), s.GetLabels(), s.GetAnnotations(), 5, 10, 1001)
19331933
ownerutil.AddOwner(pod, &s, false, true)
19341934
return pod
19351935
}

pkg/controller/registry/reconciler/configmap.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (s *configMapCatalogSourceDecorator) Service() *corev1.Service {
106106
}
107107

108108
func (s *configMapCatalogSourceDecorator) Pod(image string) *corev1.Pod {
109-
pod := Pod(s.CatalogSource, "configmap-registry-server", "", image, "", s.Labels(), s.Annotations(), 5, 5, s.runAsUser)
109+
pod := Pod(s.CatalogSource, "configmap-registry-server", "", "", image, "", s.Labels(), s.Annotations(), 5, 5, s.runAsUser)
110110
pod.Spec.ServiceAccountName = s.GetName() + ConfigMapServerPostfix
111111
pod.Spec.Containers[0].Command = []string{"configmap-server", "-c", s.Spec.ConfigMap, "-n", s.GetNamespace()}
112112
ownerutil.AddOwner(pod, s.CatalogSource, false, true)

pkg/controller/registry/reconciler/grpc.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type grpcCatalogSourceDecorator struct {
3636
*v1alpha1.CatalogSource
3737
createPodAsUser int64
3838
opmImage string
39+
utilImage string
3940
}
4041

4142
type UpdateNotReadyErr struct {
@@ -129,7 +130,7 @@ func (s *grpcCatalogSourceDecorator) ServiceAccount() *corev1.ServiceAccount {
129130
}
130131

131132
func (s *grpcCatalogSourceDecorator) Pod(saName string) *corev1.Pod {
132-
pod := Pod(s.CatalogSource, "registry-server", s.opmImage, s.Spec.Image, saName, s.Labels(), s.Annotations(), 5, 10, s.createPodAsUser)
133+
pod := Pod(s.CatalogSource, "registry-server", s.opmImage, s.utilImage, s.Spec.Image, saName, s.Labels(), s.Annotations(), 5, 10, s.createPodAsUser)
133134
ownerutil.AddOwner(pod, s.CatalogSource, false, true)
134135
return pod
135136
}
@@ -141,6 +142,7 @@ type GrpcRegistryReconciler struct {
141142
SSAClient *controllerclient.ServerSideApplier
142143
createPodAsUser int64
143144
opmImage string
145+
utilImage string
144146
}
145147

146148
var _ RegistryReconciler = &GrpcRegistryReconciler{}
@@ -207,7 +209,7 @@ func (c *GrpcRegistryReconciler) currentPodsWithCorrectImageAndSpec(source grpcC
207209

208210
func correctImages(source grpcCatalogSourceDecorator, pod *corev1.Pod) bool {
209211
if source.CatalogSource.Spec.GrpcPodConfig != nil && source.CatalogSource.Spec.GrpcPodConfig.ExtractContent != nil {
210-
return pod.Spec.InitContainers[0].Image == source.opmImage &&
212+
return pod.Spec.InitContainers[0].Image == source.utilImage &&
211213
pod.Spec.InitContainers[1].Image == source.CatalogSource.Spec.Image &&
212214
pod.Spec.Containers[0].Image == source.opmImage
213215
}
@@ -216,7 +218,7 @@ func correctImages(source grpcCatalogSourceDecorator, pod *corev1.Pod) bool {
216218

217219
// EnsureRegistryServer ensures that all components of registry server are up to date.
218220
func (c *GrpcRegistryReconciler) EnsureRegistryServer(catalogSource *v1alpha1.CatalogSource) error {
219-
source := grpcCatalogSourceDecorator{CatalogSource: catalogSource, createPodAsUser: c.createPodAsUser, opmImage: c.opmImage}
221+
source := grpcCatalogSourceDecorator{CatalogSource: catalogSource, createPodAsUser: c.createPodAsUser, opmImage: c.opmImage, utilImage: c.utilImage}
220222

221223
// if service status is nil, we force create every object to ensure they're created the first time
222224
overwrite := source.Status.RegistryServiceStatus == nil || !isRegistryServiceStatusValid(&source)
@@ -465,7 +467,7 @@ func (c *GrpcRegistryReconciler) removePods(pods []*corev1.Pod, namespace string
465467

466468
// CheckRegistryServer returns true if the given CatalogSource is considered healthy; false otherwise.
467469
func (c *GrpcRegistryReconciler) CheckRegistryServer(catalogSource *v1alpha1.CatalogSource) (healthy bool, err error) {
468-
source := grpcCatalogSourceDecorator{CatalogSource: catalogSource, createPodAsUser: c.createPodAsUser, opmImage: c.opmImage}
470+
source := grpcCatalogSourceDecorator{CatalogSource: catalogSource, createPodAsUser: c.createPodAsUser, opmImage: c.opmImage, utilImage: c.utilImage}
469471
// Check on registry resources
470472
// TODO: add gRPC health check
471473
if len(c.currentPodsWithCorrectImageAndSpec(source, source.ServiceAccount().GetName())) < 1 ||

pkg/controller/registry/reconciler/reconciler.go

+16-13
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type registryReconcilerFactory struct {
6666
SSAClient *controllerclient.ServerSideApplier
6767
createPodAsUser int64
6868
opmImage string
69+
utilImage string
6970
}
7071

7172
// ReconcilerForSource returns a RegistryReconciler based on the configuration of the given CatalogSource.
@@ -89,6 +90,7 @@ func (r *registryReconcilerFactory) ReconcilerForSource(source *operatorsv1alpha
8990
SSAClient: r.SSAClient,
9091
createPodAsUser: r.createPodAsUser,
9192
opmImage: r.opmImage,
93+
utilImage: r.utilImage,
9294
}
9395
} else if source.Spec.Address != "" {
9496
return &GrpcAddressRegistryReconciler{
@@ -100,7 +102,7 @@ func (r *registryReconcilerFactory) ReconcilerForSource(source *operatorsv1alpha
100102
}
101103

102104
// NewRegistryReconcilerFactory returns an initialized RegistryReconcilerFactory.
103-
func NewRegistryReconcilerFactory(lister operatorlister.OperatorLister, opClient operatorclient.ClientInterface, configMapServerImage string, now nowFunc, ssaClient *controllerclient.ServerSideApplier, createPodAsUser int64, opmImage string) RegistryReconcilerFactory {
105+
func NewRegistryReconcilerFactory(lister operatorlister.OperatorLister, opClient operatorclient.ClientInterface, configMapServerImage string, now nowFunc, ssaClient *controllerclient.ServerSideApplier, createPodAsUser int64, opmImage, utilImage string) RegistryReconcilerFactory {
104106
return &registryReconcilerFactory{
105107
now: now,
106108
Lister: lister,
@@ -109,10 +111,11 @@ func NewRegistryReconcilerFactory(lister operatorlister.OperatorLister, opClient
109111
SSAClient: ssaClient,
110112
createPodAsUser: createPodAsUser,
111113
opmImage: opmImage,
114+
utilImage: utilImage,
112115
}
113116
}
114117

115-
func Pod(source *operatorsv1alpha1.CatalogSource, name, opmImg, img, saName string, labels, annotations map[string]string, readinessDelay, livenessDelay int32, runAsUser int64) *corev1.Pod {
118+
func Pod(source *operatorsv1alpha1.CatalogSource, name, opmImg, utilImage, img, saName string, labels, annotations map[string]string, readinessDelay, livenessDelay int32, runAsUser int64) *corev1.Pod {
116119
// make a copy of the labels and annotations to avoid mutating the input parameters
117120
podLabels := make(map[string]string)
118121
podAnnotations := make(map[string]string)
@@ -265,21 +268,21 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name, opmImg, img, saName stri
265268
MountPath: catalogPath,
266269
}
267270
pod.Spec.InitContainers = append(pod.Spec.InitContainers, corev1.Container{
268-
Name: "extract-utilities",
269-
Image: opmImg,
270-
Command: []string{"sh", "-c"},
271-
Args: []string{fmt.Sprintf("cp $( command -v sh ) %s/sh && cp $( command -v cp ) %s/cp",
272-
utilitiesPath, utilitiesPath,
273-
)},
271+
Name: "extract-utilities",
272+
Image: utilImage,
273+
Command: []string{"cp"},
274+
Args: []string{"/bin/copy-content", fmt.Sprintf("%s/copy-content", utilitiesPath)},
274275
VolumeMounts: []corev1.VolumeMount{utilitiesVolumeMount},
275276
}, corev1.Container{
276277
Name: "extract-content",
277278
Image: img,
278-
Command: []string{utilitiesPath + "/sh", "-c"},
279-
Args: []string{fmt.Sprintf("%s/cp -r %s %s/catalog && %s/cp -r %s %s/cache",
280-
utilitiesPath, grpcPodConfig.ExtractContent.CatalogDir, catalogPath,
281-
utilitiesPath, grpcPodConfig.ExtractContent.CacheDir, catalogPath,
282-
)},
279+
Command: []string{utilitiesPath + "/copy-content"},
280+
Args: []string{
281+
"--catalog.from=" + grpcPodConfig.ExtractContent.CatalogDir,
282+
"--catalog.to=" + fmt.Sprintf("%s/catalog", catalogPath),
283+
"--cache.from=" + grpcPodConfig.ExtractContent.CacheDir,
284+
"--cache.to=" + fmt.Sprintf("%s/cache", catalogPath),
285+
},
283286
VolumeMounts: []corev1.VolumeMount{utilitiesVolumeMount, contentVolumeMount},
284287
})
285288

pkg/controller/registry/reconciler/reconciler_test.go

+18-13
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func TestPodMemoryTarget(t *testing.T) {
167167
}
168168

169169
for _, testCase := range testCases {
170-
pod := Pod(testCase.input, "name", "opmImage", "image", "service-account", map[string]string{}, map[string]string{}, int32(0), int32(0), int64(workloadUserID))
170+
pod := Pod(testCase.input, "name", "opmImage", "utilImage", "image", "service-account", map[string]string{}, map[string]string{}, int32(0), int32(0), int64(workloadUserID))
171171
if diff := cmp.Diff(pod, testCase.expected); diff != "" {
172172
t.Errorf("got incorrect pod: %v", diff)
173173
}
@@ -267,7 +267,7 @@ func TestPodExtractContent(t *testing.T) {
267267
ObjectMeta: metav1.ObjectMeta{
268268
GenerateName: "test-",
269269
Namespace: "testns",
270-
Labels: map[string]string{"olm.pod-spec-hash": "c748655d4", "olm.managed": "true"},
270+
Labels: map[string]string{"olm.pod-spec-hash": "667f4b9769", "olm.managed": "true"},
271271
Annotations: map[string]string{"cluster-autoscaler.kubernetes.io/safe-to-evict": "true"},
272272
},
273273
Spec: corev1.PodSpec{
@@ -284,16 +284,21 @@ func TestPodExtractContent(t *testing.T) {
284284
InitContainers: []corev1.Container{
285285
{
286286
Name: "extract-utilities",
287-
Image: "opmImage",
288-
Command: []string{"sh", "-c"},
289-
Args: []string{"cp $( command -v sh ) /utilities/sh && cp $( command -v cp ) /utilities/cp"},
287+
Image: "utilImage",
288+
Command: []string{"cp"},
289+
Args: []string{"/bin/copy-content", "/utilities/copy-content"},
290290
VolumeMounts: []corev1.VolumeMount{{Name: "utilities", MountPath: "/utilities"}},
291291
},
292292
{
293293
Name: "extract-content",
294294
Image: "image",
295-
Command: []string{"/utilities/sh", "-c"},
296-
Args: []string{"/utilities/cp -r /catalog /extracted-catalog/catalog && /utilities/cp -r /tmp/cache /extracted-catalog/cache"},
295+
Command: []string{"/utilities/copy-content"},
296+
Args: []string{
297+
"--catalog.from=/catalog",
298+
"--catalog.to=/extracted-catalog/catalog",
299+
"--cache.from=/tmp/cache",
300+
"--cache.to=/extracted-catalog/cache",
301+
},
297302
VolumeMounts: []corev1.VolumeMount{
298303
{Name: "utilities", MountPath: "/utilities"},
299304
{Name: "catalog-content", MountPath: "/extracted-catalog"},
@@ -357,7 +362,7 @@ func TestPodExtractContent(t *testing.T) {
357362
}
358363

359364
for _, testCase := range testCases {
360-
pod := Pod(testCase.input, "name", "opmImage", "image", "service-account", map[string]string{}, map[string]string{}, int32(0), int32(0), int64(workloadUserID))
365+
pod := Pod(testCase.input, "name", "opmImage", "utilImage", "image", "service-account", map[string]string{}, map[string]string{}, int32(0), int32(0), int64(workloadUserID))
361366
if diff := cmp.Diff(pod, testCase.expected); diff != "" {
362367
t.Errorf("got incorrect pod: %v", diff)
363368
}
@@ -375,7 +380,7 @@ func TestPodNodeSelector(t *testing.T) {
375380
key := "kubernetes.io/os"
376381
value := "linux"
377382

378-
gotCatSrcPod := Pod(catsrc, "hello", "opmImage", "busybox", "", map[string]string{}, map[string]string{}, int32(0), int32(0), int64(workloadUserID))
383+
gotCatSrcPod := Pod(catsrc, "hello", "utilImage", "opmImage", "busybox", "", map[string]string{}, map[string]string{}, int32(0), int32(0), int64(workloadUserID))
379384
gotCatSrcPodSelector := gotCatSrcPod.Spec.NodeSelector
380385

381386
if gotCatSrcPodSelector[key] != value {
@@ -423,7 +428,7 @@ func TestPullPolicy(t *testing.T) {
423428
}
424429

425430
for _, tt := range table {
426-
p := Pod(source, "catalog", "opmImage", tt.image, "", nil, nil, int32(0), int32(0), int64(workloadUserID))
431+
p := Pod(source, "catalog", "opmImage", "utilImage", tt.image, "", nil, nil, int32(0), int32(0), int64(workloadUserID))
427432
policy := p.Spec.Containers[0].ImagePullPolicy
428433
if policy != tt.policy {
429434
t.Fatalf("expected pull policy %s for image %s", tt.policy, tt.image)
@@ -535,7 +540,7 @@ func TestPodContainerSecurityContext(t *testing.T) {
535540
},
536541
}
537542
for _, testcase := range testcases {
538-
outputPod := Pod(testcase.inputCatsrc, "hello", "opmImage", "busybox", "", map[string]string{}, map[string]string{}, int32(0), int32(0), int64(workloadUserID))
543+
outputPod := Pod(testcase.inputCatsrc, "hello", "utilImage", "opmImage", "busybox", "", map[string]string{}, map[string]string{}, int32(0), int32(0), int64(workloadUserID))
539544
if testcase.expectedSecurityContext != nil {
540545
require.Equal(t, testcase.expectedSecurityContext, outputPod.Spec.SecurityContext)
541546
}
@@ -565,7 +570,7 @@ func TestPodAvoidsConcurrentWrite(t *testing.T) {
565570
"annotation": "somethingelse",
566571
}
567572

568-
gotPod := Pod(catsrc, "hello", "opmImage", "busybox", "", labels, annotations, int32(0), int32(0), int64(workloadUserID))
573+
gotPod := Pod(catsrc, "hello", "opmImage", "utilImage", "busybox", "", labels, annotations, int32(0), int32(0), int64(workloadUserID))
569574

570575
// check labels and annotations point to different addresses between parameters and what's in the pod
571576
require.NotEqual(t, &labels, &gotPod.Labels)
@@ -794,7 +799,7 @@ func TestPodSchedulingOverrides(t *testing.T) {
794799
}
795800

796801
for _, testCase := range testCases {
797-
pod := Pod(testCase.catalogSource, "hello", "opmImage", "busybox", "", map[string]string{}, testCase.annotations, int32(0), int32(0), int64(workloadUserID))
802+
pod := Pod(testCase.catalogSource, "hello", "opmImage", "utilImage", "busybox", "", map[string]string{}, testCase.annotations, int32(0), int32(0), int64(workloadUserID))
798803
require.Equal(t, testCase.expectedNodeSelectors, pod.Spec.NodeSelector)
799804
require.Equal(t, testCase.expectedPriorityClassName, pod.Spec.PriorityClassName)
800805
require.Equal(t, testCase.expectedTolerations, pod.Spec.Tolerations)

0 commit comments

Comments
 (0)