Skip to content

Commit 4cb846e

Browse files
Merge pull request #1252 from njhale/fix-bundle-extract
Bug 1798645: fix(bundles): execute opm from tooling container
2 parents 9964312 + e6d7c55 commit 4cb846e

File tree

14 files changed

+317
-65
lines changed

14 files changed

+317
-65
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: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ func (c *ConfigMapUnpacker) job(cmRef *corev1.ObjectReference, bundlePath string
5454
RestartPolicy: corev1.RestartPolicyOnFailure,
5555
Containers: []corev1.Container{
5656
{
57-
Name: cmRef.Name,
58-
Image: bundlePath,
59-
Command: []string{"/injected/opm", "alpha", "bundle", "extract", "-n", cmRef.Namespace, "-c", cmRef.Name},
57+
Name: "extract",
58+
Image: c.opmImage,
59+
Command: []string{"opm", "alpha", "bundle", "extract", "-m", "/bundle/", "-n", cmRef.Namespace, "-c", cmRef.Name},
6060
Env: []corev1.EnvVar{
6161
{
6262
Name: configmap.EnvContainerImage,
@@ -65,28 +65,49 @@ func (c *ConfigMapUnpacker) job(cmRef *corev1.ObjectReference, bundlePath string
6565
},
6666
VolumeMounts: []corev1.VolumeMount{
6767
{
68-
Name: "copydir",
69-
MountPath: "/injected",
68+
Name: "bundle", // Expected bundle content mount
69+
MountPath: "/bundle",
7070
},
7171
},
7272
},
7373
},
7474
InitContainers: []corev1.Container{
7575
{
76-
Name: "copy-binary",
77-
Image: c.copyImage,
78-
Command: []string{"/bin/cp", "/bin/opm", "/copy-dest"},
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
79+
VolumeMounts: []corev1.VolumeMount{
80+
{
81+
Name: "util",
82+
MountPath: "/util",
83+
},
84+
},
85+
},
86+
{
87+
Name: "pull",
88+
Image: bundlePath,
89+
Command: []string{"/util/cpb", "/bundle"}, // Copy bundle content to its mount
7990
VolumeMounts: []corev1.VolumeMount{
8091
{
81-
Name: "copydir",
82-
MountPath: "/copy-dest",
92+
Name: "bundle",
93+
MountPath: "/bundle",
94+
},
95+
{
96+
Name: "util",
97+
MountPath: "/util",
8398
},
8499
},
85100
},
86101
},
87102
Volumes: []corev1.Volume{
88103
{
89-
Name: "copydir",
104+
Name: "bundle", // Used to share bundle content
105+
VolumeSource: corev1.VolumeSource{
106+
EmptyDir: &corev1.EmptyDirVolumeSource{},
107+
},
108+
},
109+
{
110+
Name: "util", // Used to share utils
90111
VolumeSource: corev1.VolumeSource{
91112
EmptyDir: &corev1.EmptyDirVolumeSource{},
92113
},
@@ -110,7 +131,8 @@ type Unpacker interface {
110131
}
111132

112133
type ConfigMapUnpacker struct {
113-
copyImage string
134+
opmImage string
135+
utilImage string
114136
client kubernetes.Interface
115137
csLister listersoperatorsv1alpha1.CatalogSourceLister
116138
cmLister listerscorev1.ConfigMapLister
@@ -136,9 +158,15 @@ func NewConfigmapUnpacker(options ...ConfigMapUnpackerOption) (*ConfigMapUnpacke
136158
return unpacker, nil
137159
}
138160

139-
func WithCopyImage(copyImage string) ConfigMapUnpackerOption {
161+
func WithOPMImage(opmImage string) ConfigMapUnpackerOption {
162+
return func(unpacker *ConfigMapUnpacker) {
163+
unpacker.opmImage = opmImage
164+
}
165+
}
166+
167+
func WithUtilImage(utilImage string) ConfigMapUnpackerOption {
140168
return func(unpacker *ConfigMapUnpacker) {
141-
unpacker.copyImage = copyImage
169+
unpacker.utilImage = utilImage
142170
}
143171
}
144172

@@ -192,8 +220,10 @@ func (c *ConfigMapUnpacker) apply(options ...ConfigMapUnpackerOption) {
192220

193221
func (c *ConfigMapUnpacker) validate() (err error) {
194222
switch {
195-
case c.copyImage == "":
196-
err = fmt.Errorf("no copy image given")
223+
case c.opmImage == "":
224+
err = fmt.Errorf("no opm image given")
225+
case c.utilImage == "":
226+
err = fmt.Errorf("no util image given")
197227
case c.client == nil:
198228
err = fmt.Errorf("client is nil")
199229
case c.csLister == nil:

0 commit comments

Comments
 (0)