Skip to content

Commit 2c0e282

Browse files
authored
OLMv1 Operator install/uninstall (#85)
* OLMv1 Operator install/uninstall Fixes #83 Implements OLM-2863 and OLM-2869 Signed-off-by: Todd Short <[email protected]>
1 parent 3df32d1 commit 2c0e282

File tree

12 files changed

+290
-23
lines changed

12 files changed

+290
-23
lines changed

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ GO_BUILD_ARGS = \
2222
.PHONY: all
2323
all: install
2424

25+
.PHONY: vet
26+
vet:
27+
go vet ./...
28+
29+
.PHONY: fmt
30+
fmt:
31+
go fmt ./...
32+
2533
.PHONY: build
26-
build:
34+
build: vet fmt
2735
go build $(GO_BUILD_ARGS) -o bin/kubectl-operator
2836

2937
.PHONY: test

go.mod

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ go 1.19
55
require (
66
github.com/containerd/containerd v1.6.10
77
github.com/onsi/ginkgo v1.16.5
8-
github.com/onsi/gomega v1.20.1
8+
github.com/onsi/gomega v1.22.1
99
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799
1010
github.com/operator-framework/api v0.17.3
11+
github.com/operator-framework/operator-controller v0.0.0-20230126191401-75482d92c136
1112
github.com/operator-framework/operator-lifecycle-manager v0.23.1
12-
github.com/operator-framework/operator-registry v1.17.5
13+
github.com/operator-framework/operator-registry v1.26.2
1314
github.com/sirupsen/logrus v1.8.1
14-
github.com/spf13/cobra v1.4.0
15+
github.com/spf13/cobra v1.6.1
1516
github.com/spf13/pflag v1.0.5
1617
k8s.io/api v0.25.4
1718
k8s.io/apiextensions-apiserver v0.25.4
@@ -27,6 +28,8 @@ require (
2728
github.com/Microsoft/hcsshim v0.9.5 // indirect
2829
github.com/PuerkitoBio/purell v1.1.1 // indirect
2930
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
31+
github.com/adrg/xdg v0.4.0 // indirect
32+
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220418222510-f25a4f6275ed // indirect
3033
github.com/beorn7/perks v1.0.1 // indirect
3134
github.com/blang/semver v3.5.1+incompatible // indirect
3235
github.com/blang/semver/v4 v4.0.0 // indirect
@@ -35,7 +38,7 @@ require (
3538
github.com/containerd/continuity v0.3.0 // indirect
3639
github.com/containerd/ttrpc v1.1.0 // indirect
3740
github.com/davecgh/go-spew v1.1.1 // indirect
38-
github.com/docker/cli v20.10.11+incompatible // indirect
41+
github.com/docker/cli v20.10.12+incompatible // indirect
3942
github.com/docker/distribution v2.8.1+incompatible // indirect
4043
github.com/docker/docker v20.10.14+incompatible // indirect
4144
github.com/docker/docker-credential-helpers v0.6.4 // indirect
@@ -46,21 +49,27 @@ require (
4649
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
4750
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
4851
github.com/fsnotify/fsnotify v1.5.4 // indirect
52+
github.com/go-git/gcfg v1.5.0 // indirect
53+
github.com/go-git/go-billy/v5 v5.1.0 // indirect
54+
github.com/go-git/go-git/v5 v5.3.0 // indirect
4955
github.com/go-logr/logr v1.2.3 // indirect
5056
github.com/go-openapi/jsonpointer v0.19.5 // indirect
5157
github.com/go-openapi/jsonreference v0.19.5 // indirect
5258
github.com/go-openapi/swag v0.19.14 // indirect
5359
github.com/gogo/protobuf v1.3.2 // indirect
5460
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
5561
github.com/golang/protobuf v1.5.2 // indirect
62+
github.com/google/cel-go v0.12.5 // indirect
5663
github.com/google/gnostic v0.5.7-v3refs // indirect
5764
github.com/google/go-cmp v0.5.8 // indirect
5865
github.com/google/gofuzz v1.2.0 // indirect
5966
github.com/gorilla/mux v1.8.0 // indirect
6067
github.com/h2non/filetype v1.1.1 // indirect
6168
github.com/h2non/go-is-svg v0.0.0-20160927212452-35e8c4b0612c // indirect
6269
github.com/imdario/mergo v0.3.12 // indirect
63-
github.com/inconshreveable/mousetrap v1.0.0 // indirect
70+
github.com/inconshreveable/mousetrap v1.0.1 // indirect
71+
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
72+
github.com/joelanford/ignore v0.0.0-20210607151042-0d25dc18b62d // indirect
6473
github.com/josharian/intern v1.0.0 // indirect
6574
github.com/json-iterator/go v1.1.12 // indirect
6675
github.com/klauspost/compress v1.13.6 // indirect
@@ -80,6 +89,7 @@ require (
8089
github.com/prometheus/client_model v0.2.0 // indirect
8190
github.com/prometheus/common v0.32.1 // indirect
8291
github.com/prometheus/procfs v0.7.3 // indirect
92+
github.com/stoewer/go-strcase v1.2.0 // indirect
8393
go.etcd.io/bbolt v1.3.6 // indirect
8494
go.opencensus.io v0.23.0 // indirect
8595
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
@@ -95,6 +105,7 @@ require (
95105
google.golang.org/protobuf v1.28.0 // indirect
96106
gopkg.in/inf.v0 v0.9.1 // indirect
97107
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
108+
gopkg.in/warnings.v0 v0.1.2 // indirect
98109
gopkg.in/yaml.v2 v2.4.0 // indirect
99110
gopkg.in/yaml.v3 v3.0.1 // indirect
100111
k8s.io/klog/v2 v2.80.1 // indirect

go.sum

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d h1:UrqY+r/O
9494
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ=
9595
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
9696
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
97+
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
98+
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
9799
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
98100
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
99101
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
@@ -106,6 +108,8 @@ github.com/alexflint/go-filemutex v0.0.0-20171022225611-72bdc8eae2ae/go.mod h1:C
106108
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
107109
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
108110
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
111+
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220418222510-f25a4f6275ed h1:ue9pVfIcP+QMEjfgo/Ez4ZjNZfonGgR6NgjMaJMu1Cg=
112+
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220418222510-f25a4f6275ed/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
109113
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
110114
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
111115
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
@@ -287,6 +291,7 @@ github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwc
287291
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
288292
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
289293
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
294+
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
290295
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
291296
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
292297
github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw=
@@ -322,6 +327,8 @@ github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017/go.mod h1:JLrzqnKDaYBop
322327
github.com/docker/cli v0.0.0-20200130152716-5d0cf8839492/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
323328
github.com/docker/cli v20.10.11+incompatible h1:tXU1ezXcruZQRrMP8RN2z9N91h+6egZTS1gsPsKantc=
324329
github.com/docker/cli v20.10.11+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
330+
github.com/docker/cli v20.10.12+incompatible h1:lZlz0uzG+GH+c0plStMUdF/qk3ppmgnswpR5EbqzVGA=
331+
github.com/docker/cli v20.10.12+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
325332
github.com/docker/distribution v0.0.0-20190905152932-14b96e55d84c/go.mod h1:0+TTO4EOBfRPhZXAeF1Vu+W3hHZ8eLp8PgKVZlcvtFY=
326333
github.com/docker/distribution v2.7.0+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
327334
github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
@@ -548,6 +555,8 @@ github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995/go.mod h1:lJgMEyOkY
548555
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk=
549556
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
550557
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
558+
github.com/google/cel-go v0.12.5 h1:DmzaiSgoaqGCjtpPQWl26/gND+yRpim56H1jCVev6d8=
559+
github.com/google/cel-go v0.12.5/go.mod h1:Jk7ljRzLBhkmiAwBoUxB1sZSCVBAzkqPF25olK/iRDw=
551560
github.com/google/gnostic v0.5.7-v3refs h1:FhTMOKj2VhjpouxvWJAV1TL304uMlb9zcDqkl6cEI54=
552561
github.com/google/gnostic v0.5.7-v3refs/go.mod h1:73MKFl6jIHelAJNaBGFzt3SPtZULs9dYrGFt8OiIsHQ=
553562
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@@ -652,6 +661,8 @@ github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
652661
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
653662
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
654663
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
664+
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
665+
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
655666
github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA=
656667
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80sQsxDoMokWK1W5TQtxBFNpzWTD84ibQ=
657668
github.com/jackc/pgx v3.2.0+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I=
@@ -818,6 +829,8 @@ github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
818829
github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc=
819830
github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q=
820831
github.com/onsi/gomega v1.20.1/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo=
832+
github.com/onsi/gomega v1.22.1 h1:pY8O4lBfsHKZHM/6nrxkhVPUznOlIu3quZcKP/M20KI=
833+
github.com/onsi/gomega v1.22.1/go.mod h1:x6n7VNe4hw0vkyYUM4mjIXx3JbLiPaBPNgB7PRQ1tuM=
821834
github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
822835
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
823836
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
@@ -850,10 +863,14 @@ github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJ
850863
github.com/operator-framework/api v0.7.1/go.mod h1:L7IvLd/ckxJEJg/t4oTTlnHKAJIP/p51AvEslW3wYdY=
851864
github.com/operator-framework/api v0.17.3 h1:wddE1SLKTNiIzwt28DbBIO+vPG2GOV6dkB9xBkDfT3o=
852865
github.com/operator-framework/api v0.17.3/go.mod h1:34tb98EwTN5SZLkgoxwvRkhMJKLHUWHOrrcv1ZwvEeA=
866+
github.com/operator-framework/operator-controller v0.0.0-20230126191401-75482d92c136 h1:IoIvbOfIPmVHQysuJph2zwQ2Iua384857hx//z/a2ZQ=
867+
github.com/operator-framework/operator-controller v0.0.0-20230126191401-75482d92c136/go.mod h1:oGC3cFxKMPvEoWA2kW9cy+7x0OZTl+hJJWOMBGiVHhU=
853868
github.com/operator-framework/operator-lifecycle-manager v0.23.1 h1:Xw2ml1T4W2ieoFaVwanW/eFlZ11yAOJZUpUI8RLSql8=
854869
github.com/operator-framework/operator-lifecycle-manager v0.23.1/go.mod h1:q/QgVi/WooEyOFw8ipQrb2A/InjM4djCwPf7IlCpSOQ=
855870
github.com/operator-framework/operator-registry v1.17.5 h1:LR8m1rFz5Gcyje8WK6iYt+gIhtzqo52zMRALdmTYHT0=
856871
github.com/operator-framework/operator-registry v1.17.5/go.mod h1:sRQIgDMZZdUcmHltzyCnM6RUoDF+WS8Arj1BQIARDS8=
872+
github.com/operator-framework/operator-registry v1.26.2 h1:kQToR/hPqdivljaRXM0olPllNIcc/GUk1VBoGwagJmk=
873+
github.com/operator-framework/operator-registry v1.26.2/go.mod h1:Z7XIb/3ZkhBQCvMD/rJphyuY4LmU/eWpZS+o0Mm1WAk=
857874
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
858875
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
859876
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
@@ -959,6 +976,8 @@ github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHN
959976
github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI=
960977
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
961978
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
979+
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
980+
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
962981
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
963982
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
964983
github.com/spf13/pflag v1.0.1-0.20171106142849-4c012f6dcd95/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
@@ -970,6 +989,7 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM
970989
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
971990
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
972991
github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980/go.mod h1:AO3tvPzVZ/ayst6UlUKUv6rcPQInYe3IknH3jYhAKu8=
992+
github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU=
973993
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
974994
github.com/stretchr/objx v0.0.0-20180129172003-8a3f7159479f/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
975995
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package olmv1
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
7+
experimentalaction "github.com/operator-framework/kubectl-operator/internal/pkg/experimental/action"
8+
"github.com/operator-framework/kubectl-operator/pkg/action"
9+
)
10+
11+
func NewOperatorInstallCmd(cfg *action.Configuration) *cobra.Command {
12+
i := experimentalaction.NewOperatorInstall(cfg)
13+
i.Logf = log.Printf
14+
15+
cmd := &cobra.Command{
16+
Use: "install <operator>",
17+
Short: "Install an operator",
18+
Args: cobra.ExactArgs(1),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
i.Package = args[0]
21+
_, err := i.Run(cmd.Context())
22+
if err != nil {
23+
log.Fatalf("failed to install operator: %v", err)
24+
}
25+
log.Printf("operator %q created", i.Package)
26+
},
27+
}
28+
29+
return cmd
30+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package olmv1
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log"
7+
experimentalaction "github.com/operator-framework/kubectl-operator/internal/pkg/experimental/action"
8+
"github.com/operator-framework/kubectl-operator/pkg/action"
9+
)
10+
11+
func NewOperatorUninstallCmd(cfg *action.Configuration) *cobra.Command {
12+
u := experimentalaction.NewOperatorUninstall(cfg)
13+
u.Logf = log.Printf
14+
15+
cmd := &cobra.Command{
16+
Use: "uninstall <operator>",
17+
Short: "Uninstall an operator",
18+
Long: `Uninstall deletes the named Operator object.
19+
20+
Warning: this command permanently deletes objects from the cluster. If the
21+
uninstalled Operator bundle contains CRDs, the CRDs will be deleted, which
22+
cascades to the deletion of all operands.
23+
`,
24+
Args: cobra.ExactArgs(1),
25+
Run: func(cmd *cobra.Command, args []string) {
26+
u.Package = args[0]
27+
if err := u.Run(cmd.Context()); err != nil {
28+
log.Fatalf("uninstall operator: %v", err)
29+
}
30+
log.Printf("deleted operator %q", u.Package)
31+
},
32+
}
33+
return cmd
34+
}

internal/cmd/olmv1.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cmd
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/operator-framework/kubectl-operator/internal/cmd/internal/olmv1"
7+
"github.com/operator-framework/kubectl-operator/pkg/action"
8+
)
9+
10+
func newOlmV1Cmd(cfg *action.Configuration) *cobra.Command {
11+
cmd := &cobra.Command{
12+
Use: "olmv1",
13+
Short: "Manage operators via OLMv1 in a cluster from the command line",
14+
Long: "Manage operators via OLMv1 in a cluster from the command line.",
15+
}
16+
17+
cmd.AddCommand(
18+
olmv1.NewOperatorInstallCmd(cfg),
19+
olmv1.NewOperatorUninstallCmd(cfg),
20+
)
21+
22+
return cmd
23+
}

internal/cmd/root.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package cmd
22

33
import (
44
"context"
5-
"reflect"
65
"time"
7-
"unsafe"
86

97
"github.com/spf13/cobra"
108

@@ -43,10 +41,7 @@ operators from the installed catalogs.`,
4341
var ctx context.Context
4442
ctx, cancel = context.WithTimeout(cmd.Context(), timeout)
4543

46-
// This sets the unexported cmd.ctx value using unsafe. If
47-
// https://github.com/spf13/cobra/pull/1118 gets merged, we
48-
// should use cmd.SetContext() instead.
49-
setContext(cmd, ctx)
44+
cmd.SetContext(ctx)
5045

5146
return cfg.Load()
5247
}
@@ -63,15 +58,9 @@ operators from the installed catalogs.`,
6358
newOperatorListAvailableCmd(&cfg),
6459
newOperatorListOperandsCmd(&cfg),
6560
newOperatorDescribeCmd(&cfg),
61+
newOlmV1Cmd(&cfg),
6662
newVersionCmd(),
6763
)
6864

6965
return cmd
7066
}
71-
72-
func setContext(cmd *cobra.Command, ctx context.Context) { //nolint:golint
73-
rs := reflect.ValueOf(cmd).Elem()
74-
rf := rs.FieldByName("ctx")
75-
rf = reflect.NewAt(rf.Type(), unsafe.Pointer(rf.UnsafeAddr())).Elem()
76-
rf.Set(reflect.ValueOf(ctx))
77-
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package action
2+
3+
import (
4+
"time"
5+
)
6+
7+
const (
8+
pollTimeout = 250 * time.Millisecond
9+
)

0 commit comments

Comments
 (0)