Skip to content

Commit e6d7c55

Browse files
committed
feat(util): add cpb command
Adds cpb "copy bundle", a utility command for copying bundle content. It's included as a statically linked binary in OLM's container image and is used in an intermediate copy step of bundle unpacking.
1 parent 6756467 commit e6d7c55

File tree

13 files changed

+217
-43
lines changed

13 files changed

+217
-43
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ COPY OLM_VERSION OLM_VERSION
1818
COPY pkg pkg
1919
COPY vendor vendor
2020
COPY cmd cmd
21+
COPY util util
2122
COPY test test
2223
COPY go.mod go.mod
2324
COPY go.sum go.sum
2425
RUN CGO_ENABLED=1 make build
26+
RUN make build-util
2527

2628
FROM openshift/origin-base
2729

@@ -32,6 +34,7 @@ LABEL io.openshift.release.operator=true
3234
COPY --from=builder /build/bin/olm /bin/olm
3335
COPY --from=builder /build/bin/catalog /bin/catalog
3436
COPY --from=builder /build/bin/package-server /bin/package-server
37+
COPY --from=builder /build/bin/cpb /bin/cpb
3538

3639
# This image doesn't need to run as root user.
3740
USER 1001

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ build-wait: clean bin/wait
7575
bin/wait:
7676
GOOS=linux GOARCH=386 go build -o $@ $(PKG)/test/e2e/wait
7777

78+
build-util-linux: arch_flags=GOOS=linux GOARCH=386
79+
build-util-linux: build-util
80+
81+
build-util: bin/cpb
82+
83+
bin/cpb:
84+
CGO_ENABLED=0 $(arch_flags) go build $(MOD_FLAGS) -ldflags '-extldflags "-static"' -o $@ ./util/cpb
85+
7886
$(CMDS): version_flags=-ldflags "-X $(PKG)/pkg/version.GitCommit=$(GIT_COMMIT) -X $(PKG)/pkg/version.OLMVersion=`cat OLM_VERSION`"
7987
$(CMDS):
8088
$(arch_flags) go $(build_cmd) $(MOD_FLAGS) $(version_flags) -o bin/$(shell basename $@) $@
@@ -84,7 +92,7 @@ build: clean $(CMDS)
8492
$(TCMDS):
8593
go test -c $(BUILD_TAGS) $(MOD_FLAGS) -o bin/$(shell basename $@) $@
8694

87-
run-local: build-linux build-wait
95+
run-local: build-linux build-wait build-util-linux
8896
rm -rf build
8997
. ./scripts/build_local.sh
9098
mkdir -p build/resources

cmd/catalog/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const (
3131
defaultWakeupInterval = 15 * time.Minute
3232
defaultCatalogNamespace = "openshift-operator-lifecycle-manager"
3333
defaultConfigMapServerImage = "quay.io/operatorframework/configmap-operator-registry:latest"
34+
defaultUtilImage = "quay.io/operator-framework/olm:latest"
3435
defaultOperatorName = ""
3536
)
3637

@@ -48,6 +49,9 @@ var (
4849
configmapServerImage = flag.String(
4950
"configmapServerImage", defaultConfigMapServerImage, "the image to use for serving the operator registry api for a configmap")
5051

52+
utilImage = flag.String(
53+
"util-image", defaultUtilImage, "an image containing custom olm utilities")
54+
5155
writeStatusName = flag.String(
5256
"writeStatusName", defaultOperatorName, "ClusterOperator name in which to write status, set to \"\" to disable.")
5357

@@ -168,7 +172,7 @@ func main() {
168172
}
169173

170174
// Create a new instance of the operator.
171-
op, err := catalog.NewOperator(ctx, *kubeConfigPath, utilclock.RealClock{}, logger, *wakeupInterval, *configmapServerImage, *catalogNamespace)
175+
op, err := catalog.NewOperator(ctx, *kubeConfigPath, utilclock.RealClock{}, logger, *wakeupInterval, *configmapServerImage, *utilImage, *catalogNamespace)
172176
if err != nil {
173177
log.Panicf("error configuring operator: %s", err.Error())
174178
}

deploy/chart/templates/0000_50_olm_08-catalog-operator.deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ spec:
3434
{{- if .Values.catalog.commandArgs }}
3535
- {{ .Values.catalog.commandArgs }}
3636
{{- end }}
37+
- -util-image
38+
- {{ .Values.catalog.image.ref }}
3739
{{- if .Values.writeStatusNameCatalog }}
3840
- -writeStatusName
3941
- {{ .Values.writeStatusNameCatalog }}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/openshift/api v3.9.1-0.20190924102528-32369d4db2ad+incompatible
1616
github.com/openshift/client-go v0.0.0-20190923180330-3b6373338c9b
1717
github.com/operator-framework/operator-registry v1.5.8
18+
github.com/otiai10/copy v1.0.1
1819
github.com/pkg/errors v0.8.1
1920
github.com/prometheus/client_golang v1.2.1
2021
github.com/sirupsen/logrus v1.4.2
@@ -23,6 +24,7 @@ require (
2324
golang.org/x/sys v0.0.0-20191210023423-ac6580df4449 // indirect
2425
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
2526
google.golang.org/grpc v1.24.0
27+
gopkg.in/yaml.v2 v2.2.4
2628
helm.sh/helm/v3 v3.0.1
2729
k8s.io/api v0.17.1
2830
k8s.io/apiextensions-apiserver v0.17.1

local.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ WORKDIR /
33
COPY olm /bin/olm
44
COPY catalog /bin/catalog
55
COPY package-server /bin/package-server
6+
COPY cpb /bin/cpb
67
EXPOSE 8080
78
EXPOSE 5443
89
CMD ["/bin/olm"]

manifests/0000_50_olm_08-catalog-operator.deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ spec:
2727
- '-namespace'
2828
- openshift-marketplace
2929
- -configmapServerImage=quay.io/operator-framework/configmap-operator-registry:latest
30+
- -util-image
31+
- quay.io/operator-framework/olm@sha256:0d15ffb5d10a176ef6e831d7865f98d51255ea5b0d16403618c94a004d049373
3032
- -writeStatusName
3133
- operator-lifecycle-manager-catalog
3234
- -tls-cert

pkg/controller/bundle/bundle_unpacker.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,28 +73,28 @@ func (c *ConfigMapUnpacker) job(cmRef *corev1.ObjectReference, bundlePath string
7373
},
7474
InitContainers: []corev1.Container{
7575
{
76-
Name: "tools",
77-
Image: "busybox",
78-
Command: []string{"/bin/cp", "-Rv", "/bin/cp", "/tools/cp"}, // Copy tooling for the bundle container to use
76+
Name: "util",
77+
Image: c.utilImage,
78+
Command: []string{"/bin/cp", "-Rv", "/bin/cpb", "/util/cpb"}, // Copy tooling for the bundle container to use
7979
VolumeMounts: []corev1.VolumeMount{
8080
{
81-
Name: "tools",
82-
MountPath: "/tools",
81+
Name: "util",
82+
MountPath: "/util",
8383
},
8484
},
8585
},
8686
{
8787
Name: "pull",
8888
Image: bundlePath,
89-
Command: []string{"/tools/cp", "-Rv", "/manifests", "/metadata", "/bundle"}, // Copy bundle content to its mount
89+
Command: []string{"/util/cpb", "/bundle"}, // Copy bundle content to its mount
9090
VolumeMounts: []corev1.VolumeMount{
9191
{
9292
Name: "bundle",
9393
MountPath: "/bundle",
9494
},
9595
{
96-
Name: "tools",
97-
MountPath: "/tools",
96+
Name: "util",
97+
MountPath: "/util",
9898
},
9999
},
100100
},
@@ -107,7 +107,7 @@ func (c *ConfigMapUnpacker) job(cmRef *corev1.ObjectReference, bundlePath string
107107
},
108108
},
109109
{
110-
Name: "tools", // Used to share tool
110+
Name: "util", // Used to share utils
111111
VolumeSource: corev1.VolumeSource{
112112
EmptyDir: &corev1.EmptyDirVolumeSource{},
113113
},
@@ -132,6 +132,7 @@ type Unpacker interface {
132132

133133
type ConfigMapUnpacker struct {
134134
opmImage string
135+
utilImage string
135136
client kubernetes.Interface
136137
csLister listersoperatorsv1alpha1.CatalogSourceLister
137138
cmLister listerscorev1.ConfigMapLister
@@ -163,6 +164,12 @@ func WithOPMImage(opmImage string) ConfigMapUnpackerOption {
163164
}
164165
}
165166

167+
func WithUtilImage(utilImage string) ConfigMapUnpackerOption {
168+
return func(unpacker *ConfigMapUnpacker) {
169+
unpacker.utilImage = utilImage
170+
}
171+
}
172+
166173
func WithClient(client kubernetes.Interface) ConfigMapUnpackerOption {
167174
return func(unpacker *ConfigMapUnpacker) {
168175
unpacker.client = client
@@ -214,7 +221,9 @@ func (c *ConfigMapUnpacker) apply(options ...ConfigMapUnpackerOption) {
214221
func (c *ConfigMapUnpacker) validate() (err error) {
215222
switch {
216223
case c.opmImage == "":
217-
err = fmt.Errorf("no copy image given")
224+
err = fmt.Errorf("no opm image given")
225+
case c.utilImage == "":
226+
err = fmt.Errorf("no util image given")
218227
case c.client == nil:
219228
err = fmt.Errorf("client is nil")
220229
case c.csLister == nil:

pkg/controller/bundle/bundle_unpacker_test.go

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const (
2727
etcdCluster = "{\"apiVersion\":\"apiextensions.k8s.io/v1beta1\",\"kind\":\"CustomResourceDefinition\",\"metadata\":{\"name\":\"etcdclusters.etcd.database.coreos.com\"},\"spec\":{\"group\":\"etcd.database.coreos.com\",\"names\":{\"kind\":\"EtcdCluster\",\"listKind\":\"EtcdClusterList\",\"plural\":\"etcdclusters\",\"shortNames\":[\"etcdclus\",\"etcd\"],\"singular\":\"etcdcluster\"},\"scope\":\"Namespaced\",\"version\":\"v1beta2\"}}"
2828
etcdRestore = "{\"apiVersion\":\"apiextensions.k8s.io/v1beta1\",\"kind\":\"CustomResourceDefinition\",\"metadata\":{\"name\":\"etcdrestores.etcd.database.coreos.com\"},\"spec\":{\"group\":\"etcd.database.coreos.com\",\"names\":{\"kind\":\"EtcdRestore\",\"listKind\":\"EtcdRestoreList\",\"plural\":\"etcdrestores\",\"singular\":\"etcdrestore\"},\"scope\":\"Namespaced\",\"version\":\"v1beta2\"}}"
2929
opmImage = "opm-image"
30+
utilImage = "util-image"
3031
bundlePath = "bundle-path"
3132
)
3233

@@ -198,28 +199,28 @@ func TestConfigMapUnpacker(t *testing.T) {
198199
},
199200
InitContainers: []corev1.Container{
200201
{
201-
Name: "tools",
202-
Image: "busybox",
203-
Command: []string{"/bin/cp", "-Rv", "/bin/cp", "/tools/cp"},
202+
Name: "util",
203+
Image: utilImage,
204+
Command: []string{"/bin/cp", "-Rv", "/bin/cpb", "/util/cpb"}, // Copy tooling for the bundle container to use
204205
VolumeMounts: []corev1.VolumeMount{
205206
{
206-
Name: "tools",
207-
MountPath: "/tools",
207+
Name: "util",
208+
MountPath: "/util",
208209
},
209210
},
210211
},
211212
{
212213
Name: "pull",
213214
Image: bundlePath,
214-
Command: []string{"/tools/cp", "-Rv", "/manifests", "/metadata", "/bundle"},
215+
Command: []string{"/util/cpb", "/bundle"}, // Copy bundle content to its mount
215216
VolumeMounts: []corev1.VolumeMount{
216217
{
217218
Name: "bundle",
218219
MountPath: "/bundle",
219220
},
220221
{
221-
Name: "tools",
222-
MountPath: "/tools",
222+
Name: "util",
223+
MountPath: "/util",
223224
},
224225
},
225226
},
@@ -232,7 +233,7 @@ func TestConfigMapUnpacker(t *testing.T) {
232233
},
233234
},
234235
{
235-
Name: "tools",
236+
Name: "util",
236237
VolumeSource: corev1.VolumeSource{
237238
EmptyDir: &corev1.EmptyDirVolumeSource{},
238239
},
@@ -354,28 +355,28 @@ func TestConfigMapUnpacker(t *testing.T) {
354355
},
355356
InitContainers: []corev1.Container{
356357
{
357-
Name: "tools",
358-
Image: "busybox",
359-
Command: []string{"/bin/cp", "-Rv", "/bin/cp", "/tools/cp"},
358+
Name: "util",
359+
Image: utilImage,
360+
Command: []string{"/bin/cp", "-Rv", "/bin/cpb", "/util/cpb"}, // Copy tooling for the bundle container to use
360361
VolumeMounts: []corev1.VolumeMount{
361362
{
362-
Name: "tools",
363-
MountPath: "/tools",
363+
Name: "util",
364+
MountPath: "/util",
364365
},
365366
},
366367
},
367368
{
368369
Name: "pull",
369370
Image: bundlePath,
370-
Command: []string{"/tools/cp", "-Rv", "/manifests", "/metadata", "/bundle"},
371+
Command: []string{"/util/cpb", "/bundle"}, // Copy bundle content to its mount
371372
VolumeMounts: []corev1.VolumeMount{
372373
{
373374
Name: "bundle",
374375
MountPath: "/bundle",
375376
},
376377
{
377-
Name: "tools",
378-
MountPath: "/tools",
378+
Name: "util",
379+
MountPath: "/util",
379380
},
380381
},
381382
},
@@ -388,7 +389,7 @@ func TestConfigMapUnpacker(t *testing.T) {
388389
},
389390
},
390391
{
391-
Name: "tools",
392+
Name: "util",
392393
VolumeSource: corev1.VolumeSource{
393394
EmptyDir: &corev1.EmptyDirVolumeSource{},
394395
},
@@ -549,28 +550,28 @@ func TestConfigMapUnpacker(t *testing.T) {
549550
},
550551
InitContainers: []corev1.Container{
551552
{
552-
Name: "tools",
553-
Image: "busybox",
554-
Command: []string{"/bin/cp", "-Rv", "/bin/cp", "/tools/cp"},
553+
Name: "util",
554+
Image: utilImage,
555+
Command: []string{"/bin/cp", "-Rv", "/bin/cpb", "/util/cpb"}, // Copy tooling for the bundle container to use
555556
VolumeMounts: []corev1.VolumeMount{
556557
{
557-
Name: "tools",
558-
MountPath: "/tools",
558+
Name: "util",
559+
MountPath: "/util",
559560
},
560561
},
561562
},
562563
{
563564
Name: "pull",
564565
Image: bundlePath,
565-
Command: []string{"/tools/cp", "-Rv", "/manifests", "/metadata", "/bundle"},
566+
Command: []string{"/util/cpb", "/bundle"}, // Copy bundle content to its mount
566567
VolumeMounts: []corev1.VolumeMount{
567568
{
568569
Name: "bundle",
569570
MountPath: "/bundle",
570571
},
571572
{
572-
Name: "tools",
573-
MountPath: "/tools",
573+
Name: "util",
574+
MountPath: "/util",
574575
},
575576
},
576577
},
@@ -583,7 +584,7 @@ func TestConfigMapUnpacker(t *testing.T) {
583584
},
584585
},
585586
{
586-
Name: "tools",
587+
Name: "util",
587588
VolumeSource: corev1.VolumeSource{
588589
EmptyDir: &corev1.EmptyDirVolumeSource{},
589590
},
@@ -705,6 +706,7 @@ func TestConfigMapUnpacker(t *testing.T) {
705706
WithRoleLister(roleLister),
706707
WithRoleBindingLister(rbLister),
707708
WithOPMImage(opmImage),
709+
WithUtilImage(utilImage),
708710
WithNow(now),
709711
)
710712
require.NoError(t, err)

pkg/controller/operators/catalog/operator.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,12 @@ type Operator struct {
9292
clientAttenuator *scoped.ClientAttenuator
9393
serviceAccountQuerier *scoped.UserDefinedServiceAccountQuerier
9494
bundleUnpacker bundle.Unpacker
95-
bundleUnpackerImage string
9695
}
9796

9897
type CatalogSourceSyncFunc func(logger *logrus.Entry, in *v1alpha1.CatalogSource) (out *v1alpha1.CatalogSource, continueSync bool, syncError error)
9998

10099
// NewOperator creates a new Catalog Operator.
101-
func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clock, logger *logrus.Logger, resyncPeriod time.Duration, configmapRegistryImage, operatorNamespace string) (*Operator, error) {
100+
func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clock, logger *logrus.Logger, resyncPeriod time.Duration, configmapRegistryImage, utilImage string, operatorNamespace string) (*Operator, error) {
102101
config, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath)
103102
if err != nil {
104103
return nil, err
@@ -144,7 +143,6 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
144143
catalogSubscriberIndexer: map[string]cache.Indexer{},
145144
serviceAccountQuerier: scoped.NewUserDefinedServiceAccountQuerier(logger, crClient),
146145
clientAttenuator: scoped.NewClientAttenuator(logger, config, opClient, crClient, dynamicClient),
147-
bundleUnpackerImage: configmapRegistryImage, // Assume the configmapRegistryImage contains the unpacker for now.
148146
}
149147
op.sources = grpc.NewSourceStore(logger, 10*time.Second, 10*time.Minute, op.syncSourceState)
150148
op.reconciler = reconciler.NewRegistryReconcilerFactory(lister, opClient, configmapRegistryImage, op.now)
@@ -313,7 +311,8 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
313311
bundle.WithJobLister(jobInformer.Lister()),
314312
bundle.WithRoleLister(roleInformer.Lister()),
315313
bundle.WithRoleBindingLister(roleBindingInformer.Lister()),
316-
bundle.WithOPMImage(op.bundleUnpackerImage),
314+
bundle.WithOPMImage(configmapRegistryImage),
315+
bundle.WithUtilImage(utilImage),
317316
bundle.WithNow(op.now),
318317
)
319318
if err != nil {

0 commit comments

Comments
 (0)