You can run the make build command to get the learn-operator binary. As follow:
$ make build
mkdir -p "build/_output/bin/"
export GO111MODULE=on && export GOPROXY=https://goproxy.io && go build -o "build/_output/bin//learn-operator" "./cmd/manager/main.go"
$ ls -l build/_output/bin/learn-operator
-rwxr-xr-x. 1 root root 39674923 Oct 22 22:23 build/_output/bin/learn-operator
$ ./build/_output/bin/learn-operator --help
Usage of ./build/_output/bin/learn-operator:
--kubeconfig string Paths to a kubeconfig. Only required if out-of-cluster.
--master --kubeconfig (Deprecated: switch to --kubeconfig) The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.
--zap-devel Enable zap development mode (changes defaults to console encoder, debug log level, and disables sampling)
--zap-encoder encoder Zap log encoding ('json' or 'console')
--zap-level level Zap log level (one of 'debug', 'info', 'error' or any integer value > 0) (default info)
--zap-sample sample Enable zap log sampling. Sampling will be disabled for integer log levels > 1
--zap-time-encoding timeEncoding Sets the zap time format ('epoch', 'millis', 'nano', or 'iso8601') (default )
pflag: help requested
2. Push this image to the Quay.io registry, and make it public.
```console
$ docker push quay.io/olmqe/learn-operator-bundle:v1
The push refers to repository [quay.io/olmqe/learn-operator-bundle]
2f161fcac2d0: Pushed
8b4c261611af: Pushed
v1: digest: sha256:5a0a4d18a1ac46b22e09e5052e42aeabbe603006b603e08297f8a8e50ee2c343 size: 732
oc get catalogsource
NAME DISPLAY TYPE PUBLISHER AGE
certified-operators Certified Operators grpc Red Hat 41m
community-operators Community Operators grpc Red Hat 41m
demo-learn Jian Test grpc Jian 7s
qe-app-registry Production Operators grpc OpenShift QE 22m
redhat-marketplace Red Hat Marketplace grpc Red Hat 41m
redhat-operators Red Hat Operators grpc Red Hat 41m
oc get sub -n default
NAME PACKAGE SOURCE CHANNEL
learn learn demo-learn 0.0.1
$ oc get ip -n default
NAME CSV APPROVAL APPROVED
install-26wbx learn-operator.v0.0.1 Automatic true
$ oc get csv -n default
NAME DISPLAY VERSION REPLACES PHASE
learn-operator.v0.0.1 Learn Operator 0.0.1 Succeeded
### Create the Learn CR
You will get an `example-learn` instance and its two pods, as follows:
```console
# cat learn-instance.yaml
apiVersion: app.learn.com/v1
kind: Learn
metadata:
name: example-learn
namespace: default
spec:
size: 2
$ oc get learn -n default
NAME AGE
example-learn 34m
$ oc get pods -n default
NAME READY STATUS RESTARTS AGE
example-learn-85fc47cf75-7fq2m 1/1 Running 0 34m
example-learn-85fc47cf75-jv9mg 1/1 Running 0 34m
learn-operator-9cd7b7d5c-ffxs9 1/1 Running 0 40m
Compile the Binary
You can run the
make build
command to get thelearn-operator
binary. As follow:Create a Docker image for this binary
You can use this Dockerfile, as follows:
Create Bundle Image
Each Bundle image for a single operator version. You can use the tool opm to do this. Steps as follows:
opm alpha bundle build
command: ```console $ opm alpha bundle build -c 0.0.1, 0.0.2 -e 0.0.1 -d ./ manifests/learn/0.0.1/ -p learn -t quay.io/olmqe/learn-operator-bundle:v1 INFO[0000] Building annotations.yamlINFO[0000] Writing annotations.yaml in /data/goproject/src/github.com/jianzhangbjz/learn-operator/manifests/learn/metadata INFO[0000] Building Dockerfile
INFO[0000] Writing bundle.Dockerfile in /data/goproject/src/github.com/jianzhangbjz/learn-operator/manifests INFO[0000] Building bundle image
Sending build context to Docker daemon 179.7kB Step 1/9 : FROM scratch
—> Step 2/9 : LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 —> Using cache —> 7e95ac289bf7 Step 3/9 : LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ —> Using cache —> c7798578d997 Step 4/9 : LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ —> Using cache —> a4cf559f3fb0 Step 5/9 : LABEL operators.operatorframework.io.bundle.package.v1=learn —> Running in 359602eb2125 Removing intermediate container 359602eb2125 —> 284edc1a52d6 Step 6/9 : LABEL operators.operatorframework.io.bundle.channels.v1=0.0.1, —> Running in c94d5babcb7d Removing intermediate container c94d5babcb7d —> 053dffd07355 Step 7/9 : LABEL operators.operatorframework.io.bundle.channel.default.v1=0.0.1 —> Running in f5d7e48665f8 Removing intermediate container f5d7e48665f8 —> 9477882f546b Step 8/9 : COPY learn/0.0.1 /manifests/ —> c5fd2cb76085 Step 9/9 : COPY learn/metadata /metadata/ —> 84d985ca43c5 Successfully built 84d985ca43c5 Successfully tagged quay.io/olmqe/learn-operator-bundle:v1
Create Index Image
opm index add
command, likeDeploy it on OCP4.x
oc get catalogsource NAME DISPLAY TYPE PUBLISHER AGE certified-operators Certified Operators grpc Red Hat 41m community-operators Community Operators grpc Red Hat 41m demo-learn Jian Test grpc Jian 7s qe-app-registry Production Operators grpc OpenShift QE 22m redhat-marketplace Red Hat Marketplace grpc Red Hat 41m redhat-operators Red Hat Operators grpc Red Hat 41m
ocgetpackagemanifest∣greplearnlearnJianTest31s‘‘‘2.Subscribethis‘learn−operator‘,youcandothisonWebConsoletoo.Inthebackend,youneedtocreatetheOperatorGroupobjectfirst,likebelow:‘‘‘consolecat og.yaml apiVersion: operators.coreos.com/v1 kind: OperatorGroup metadata: name: test-og namespace: default spec: targetNamespaces:
oc get sub -n default NAME PACKAGE SOURCE CHANNEL learn learn demo-learn 0.0.1 $ oc get ip -n default NAME CSV APPROVAL APPROVED install-26wbx learn-operator.v0.0.1 Automatic true $ oc get csv -n default NAME DISPLAY VERSION REPLACES PHASE learn-operator.v0.0.1 Learn Operator 0.0.1 Succeeded