From 65df4cc551ee64363299d26e3dd1b5ce8f522568 Mon Sep 17 00:00:00 2001 From: Michael Kleinhenz Date: Thu, 14 Feb 2019 13:47:25 +0100 Subject: [PATCH 1/3] Added stub tests and makefile setup. --- .gitignore | 97 ++--- Dockerfile.builder | 37 ++ Dockerfile.deploy | 18 + Dockerfile.deploy.rhel | 19 + Dockerfile.dev | 7 + Gopkg.lock | 282 ++++++-------- Gopkg.toml | 4 + Makefile | 271 ++++++++++++++ cmd/manager/main.go | 14 +- deploy/test/global-manifests.yaml | 57 +++ deploy/test/namespace-manifests.yaml | 99 +++++ make/Makefile.dev | 89 +++++ make/Makefile.lnx | 12 + make/Makefile.win | 11 + make/check_gopath.go | 46 +++ make/docker.mk | 108 ++++++ make/gofmt_exclude | 1 + make/test.mk | 350 ++++++++++++++++++ .../envdeployment_controller_test.go | 16 + test/README.md | 27 ++ test/e2e/example_test.go | 26 ++ test/e2e/main_test.go | 11 + 22 files changed, 1369 insertions(+), 233 deletions(-) create mode 100644 Dockerfile.builder create mode 100644 Dockerfile.deploy create mode 100644 Dockerfile.deploy.rhel create mode 100644 Dockerfile.dev create mode 100644 Makefile create mode 100644 deploy/test/global-manifests.yaml create mode 100644 deploy/test/namespace-manifests.yaml create mode 100644 make/Makefile.dev create mode 100644 make/Makefile.lnx create mode 100644 make/Makefile.win create mode 100644 make/check_gopath.go create mode 100644 make/docker.mk create mode 100644 make/gofmt_exclude create mode 100644 make/test.mk create mode 100644 pkg/controller/envdeployment/envdeployment_controller_test.go create mode 100644 test/README.md create mode 100644 test/e2e/example_test.go create mode 100644 test/e2e/main_test.go diff --git a/.gitignore b/.gitignore index 39bfe06..979c7cd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,55 +1,10 @@ -# Temporary Build Files -build/_output -build/_test -# Created by https://www.gitignore.io/api/go,vim,emacs,visualstudiocode -### Emacs ### -# -*- mode: gitignore; -*- -*~ -\#*\# -/.emacs.desktop -/.emacs.desktop.lock -*.elc -auto-save-list -tramp -.\#* -# Org-mode -.org-id-locations -*_archive -# flymake-mode -*_flymake.* -# eshell files -/eshell/history -/eshell/lastdir -# elpa packages -/elpa/ -# reftex files -*.rel -# AUCTeX auto folder -/auto/ -# cask packages -.cask/ -dist/ -# Flycheck -flycheck_*.el -# server auth directory -/server/ -# projectiles files -.projectile -projectile-bookmarks.eld -# directory configuration -.dir-locals.el -# saveplace -places -# url cache -url/cache/ -# cedet -ede-projects.el -# smex -smex-items -# company-statistics -company-statistics-cache.el -# anaconda-mode -anaconda-mode/ +### IntelliJ ### +.idea/ +*.iws +*.iml +/out/ +.idea_modules/ + ### Go ### # Binaries for programs and plugins *.exe @@ -57,26 +12,30 @@ anaconda-mode/ *.dll *.so *.dylib -# Test binary, build with 'go test -c' + +# Test binary, built with `go test -c` *.test + # Output of the go coverage tool, specifically when used with LiteIDE *.out -### Vim ### -# swap -.sw[a-p] -.*.sw[a-p] -# session -Session.vim -# temporary -.netrwhist -# auto-generated tag files -tags + +### Go Patch ### +/vendor/ +/Godeps/ + ### VisualStudioCode ### .vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +### VisualStudioCode Patch ### +# Ignore all local history of files .history -# End of https://www.gitignore.io/api/go,vim,emacs,visualstudiocode -### IDEA ### -.idea/* -### MISC ### -bin/* -vendor/* \ No newline at end of file + +# devconsole-operator binaries +bin/ +tmp/ + +# Generated assets diff --git a/Dockerfile.builder b/Dockerfile.builder new file mode 100644 index 0000000..05c72a3 --- /dev/null +++ b/Dockerfile.builder @@ -0,0 +1,37 @@ +FROM centos:7 +LABEL maintainer "Devtools " +LABEL author "Devtools " +ENV LANG=en_US.utf8 +ARG USE_GO_VERSION_FROM_WEBSITE=0 + +# Some packages might seem weird but they are required by the RVM installer. +RUN yum install epel-release -y \ + && yum --enablerepo=centosplus --enablerepo=epel install -y \ + findutils \ + git \ + $(test "$USE_GO_VERSION_FROM_WEBSITE" != 1 && echo "golang") \ + make \ + procps-ng \ + tar \ + wget \ + which \ + && yum clean all + +RUN if [[ "$USE_GO_VERSION_FROM_WEBSITE" = 1 ]]; then cd /tmp \ + && wget https://dl.google.com/go/go1.10.linux-amd64.tar.gz \ + && echo "b5a64335f1490277b585832d1f6c7f8c6c11206cba5cd3f771dcb87b98ad1a33 go1.10.linux-amd64.tar.gz" > checksum \ + && sha256sum -c checksum \ + && tar -C /usr/local -xzf go1.10.linux-amd64.tar.gz \ + && rm -f go1.10.linux-amd64.tar.gz; \ + fi +ENV PATH=$PATH:/usr/local/go/bin + +# Get dep for Go package management and make sure the directory has full rwz permissions for non-root users +ENV GOPATH /tmp/go +RUN mkdir -p $GOPATH/bin && chmod a+rwx $GOPATH +RUN cd $GOPATH/bin \ + curl -L -s https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 -o dep \ + echo "287b08291e14f1fae8ba44374b26a2b12eb941af3497ed0ca649253e21ba2f83 dep" > dep-linux-amd64.sha256 \ + sha256sum -c dep-linux-amd64.sha256 + +ENTRYPOINT ["/bin/bash"] diff --git a/Dockerfile.deploy b/Dockerfile.deploy new file mode 100644 index 0000000..7866751 --- /dev/null +++ b/Dockerfile.deploy @@ -0,0 +1,18 @@ +FROM centos:7 +LABEL maintainer "Devtools " +LABEL author "Devtools " +ENV LANG=en_US.utf8 +ENV F8_INSTALL_PREFIX=/usr/local/devconsole-operator + +# Create a non-root user and a group with the same name: "devconsole-operator" +ENV F8_USER_NAME=devconsole-operator +RUN useradd --no-create-home -s /bin/bash ${F8_USER_NAME} + +COPY bin/devconsole-operator ${F8_INSTALL_PREFIX}/bin/devconsole-operator + +# From here onwards, any RUN, CMD, or ENTRYPOINT will be run under the following user +USER ${F8_USER_NAME} + +WORKDIR ${F8_INSTALL_PREFIX} + +ENTRYPOINT [ "bin/devconsole-operator" ] diff --git a/Dockerfile.deploy.rhel b/Dockerfile.deploy.rhel new file mode 100644 index 0000000..7dd5f4e --- /dev/null +++ b/Dockerfile.deploy.rhel @@ -0,0 +1,19 @@ +FROM quay.io/openshiftio/rhel-base-golang:latest + +LABEL maintainer "Devtools " +LABEL author "Devtools " +ENV LANG=en_US.utf8 +ENV F8_INSTALL_PREFIX=/usr/local/devconsole-operator + +# Create a non-root user and a group with the same name: "devconsole-operator" +ENV F8_USER_NAME=devconsole-operator +RUN useradd --no-create-home -s /bin/bash ${F8_USER_NAME} + +COPY bin/devconsole-operator ${F8_INSTALL_PREFIX}/bin/devconsole-operator + +# From here onwards, any RUN, CMD, or ENTRYPOINT will be run under the following user +USER ${F8_USER_NAME} + +WORKDIR ${F8_INSTALL_PREFIX} + +ENTRYPOINT [ "bin/devconsole-operator" ] diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..1d9db20 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,7 @@ +# TODO: change this to a sane base image +FROM quay.io/openshiftio/toolchain-operator:faab15e + +ENV F8_INSTALL_PREFIX=/usr/local/devconsole-operator + +COPY bin/devconsole-operator ${F8_INSTALL_PREFIX}/bin/devconsole-operator +RUN echo chmod +x ${F8_INSTALL_PREFIX}/bin/devconsole-operator \ No newline at end of file diff --git a/Gopkg.lock b/Gopkg.lock index b3fa14d..9be5adc 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,318 +2,334 @@ [[projects]] - digest = "1:315ee4e58738f41b338a701e8acb4e991f6d30737c2ae757d2087a1d28d72810" name = "cloud.google.com/go" packages = ["compute/metadata"] - pruneopts = "NT" revision = "28a4bc8c44b3acbcc482cff0cdf7de29a4688b61" version = "v0.35.1" [[projects]] - digest = "1:d8ebbd207f3d3266d4423ce4860c9f3794956306ded6c7ba312ecc69cdfbf04c" + name = "github.com/BurntSushi/toml" + packages = ["."] + revision = "3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005" + version = "v0.3.1" + +[[projects]] name = "github.com/PuerkitoBio/purell" packages = ["."] - pruneopts = "NT" revision = "0bcb03f4b4d0a9428594752bd2a3b9aa0a9d4bd4" version = "v1.1.0" [[projects]] branch = "master" - digest = "1:8098cd40cd09879efbf12e33bcd51ead4a66006ac802cd563a66c4f3373b9727" name = "github.com/PuerkitoBio/urlesc" packages = ["."] - pruneopts = "NT" revision = "de5bf2ad457846296e2031421a34e2568e304e35" [[projects]] - digest = "1:4b8b5811da6970495e04d1f4e98bb89518cc3cfc3b3f456bdb876ed7b6c74049" + branch = "master" + name = "github.com/alexeykazakov/devconsole" + packages = [ + "pkg/apis", + "pkg/apis/clusterregistry/v1alpha1", + "pkg/apis/devconsole/v1alpha1", + "pkg/controller", + "pkg/controller/envdeployment" + ] + revision = "0b82a3bcdf453edf0b4b8f499bfd4ccbdaa148eb" + +[[projects]] name = "github.com/davecgh/go-spew" packages = ["spew"] - pruneopts = "NT" revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73" version = "v1.1.1" [[projects]] - digest = "1:3f718788c59f3ec687bcc963cb6034a132327387784c8c04392abaaea9ad7498" name = "github.com/emicklei/go-restful" packages = [ ".", - "log", + "log" ] - pruneopts = "NT" revision = "e37671aced663c8d3a395bd301857e26dcf4340c" version = "v2.8.1" [[projects]] - digest = "1:81466b4218bf6adddac2572a30ac733a9255919bc2f470b4827a317bd4ee1756" name = "github.com/ghodss/yaml" packages = ["."] - pruneopts = "NT" revision = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7" version = "v1.0.0" [[projects]] branch = "master" - digest = "1:d421af4c4fe51d399667d573982d663fe1fa67020a88d3ae43466ebfe8e2b5c9" name = "github.com/go-logr/logr" packages = ["."] - pruneopts = "NT" revision = "9fb12b3b21c5415d16ac18dc5cd42c1cfdd40c4e" [[projects]] - digest = "1:340497a512995aa69c0add901d79a2096b3449d35a44a6f1f1115091a9f8c687" name = "github.com/go-logr/zapr" packages = ["."] - pruneopts = "NT" revision = "7536572e8d55209135cd5e7ccf7fce43dca217ab" version = "v0.1.0" [[projects]] - digest = "1:260f7ebefc63024c8dfe2c9f1a2935a89fa4213637a1f522f592f80c001cc441" name = "github.com/go-openapi/jsonpointer" packages = ["."] - pruneopts = "NT" revision = "ef5f0afec364d3b9396b7b77b43dbe26bf1f8004" version = "v0.18.0" [[projects]] - digest = "1:98abd61947ff5c7c6fcfec5473d02a4821ed3a2dd99a4fbfdb7925b0dd745546" name = "github.com/go-openapi/jsonreference" packages = ["."] - pruneopts = "NT" revision = "8483a886a90412cd6858df4ea3483dce9c8e35a3" version = "v0.18.0" [[projects]] - digest = "1:4da4ea0a664ba528965683d350f602d0f11464e6bb2e17aad0914723bc25d163" name = "github.com/go-openapi/spec" packages = ["."] - pruneopts = "NT" revision = "5b6cdde3200976e3ecceb2868706ee39b6aff3e4" version = "v0.18.0" [[projects]] - digest = "1:dc0f590770e5a6c70ea086232324f7b7dc4857c60eca63ab8ff78e0a5cfcdbf3" name = "github.com/go-openapi/swag" packages = ["."] - pruneopts = "NT" revision = "1d29f06aebd59ccdf11ae04aa0334ded96e2d909" version = "v0.18.0" [[projects]] - digest = "1:932970e69f16e127aa0653b8263ae588cd127fa53273e19ba44332902c9826f2" + name = "github.com/gobuffalo/envy" + packages = ["."] + revision = "fa0dfdc10b5366ce365b7d9d1755a03e4e797bc5" + version = "v1.6.15" + +[[projects]] name = "github.com/gogo/protobuf" packages = [ "proto", - "sortkeys", + "sortkeys" ] - pruneopts = "NT" revision = "4cbf7e384e768b4e01799441fdf2a706a5635ae7" version = "v1.2.0" [[projects]] branch = "master" - digest = "1:e2b86e41f3d669fc36b50d31d32d22c8ac656c75aa5ea89717ce7177e134ff2a" name = "github.com/golang/glog" packages = ["."] - pruneopts = "NT" revision = "23def4e6c14b4da8ac2ed8007337bc5eb5007998" [[projects]] branch = "master" - digest = "1:20b774dcfdf0fff3148432beb828c52404f3eb3d70b7ce71ae0356ed6cbc2bae" name = "github.com/golang/groupcache" packages = ["lru"] - pruneopts = "NT" revision = "5b532d6fd5efaf7fa130d4e859a2fde0fc3a9e1b" [[projects]] - digest = "1:d7cb4458ea8782e6efacd8f4940796ec559c90833509c436f40c4085b98156dd" name = "github.com/golang/protobuf" packages = [ "proto", "ptypes", "ptypes/any", "ptypes/duration", - "ptypes/timestamp", + "ptypes/timestamp" ] - pruneopts = "NT" revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5" version = "v1.2.0" [[projects]] branch = "master" - digest = "1:05f95ffdfcf651bdb0f05b40b69e7f5663047f8da75c72d58728acb59b5cc107" name = "github.com/google/btree" packages = ["."] - pruneopts = "NT" revision = "4030bb1f1f0c35b30ca7009e9ebd06849dd45306" [[projects]] branch = "master" - digest = "1:52c5834e2bebac9030c97cc0798ac11c3aa8a39f098aeb419f142533da6cd3cc" name = "github.com/google/gofuzz" packages = ["."] - pruneopts = "NT" revision = "24818f796faf91cd76ec7bddd72458fbced7a6c1" [[projects]] - digest = "1:56a1f3949ebb7fa22fa6b4e4ac0fe0f77cc4faee5b57413e6fa9199a8458faf1" name = "github.com/google/uuid" packages = ["."] - pruneopts = "NT" revision = "9b3b1e0f5f99ae461456d768e7d301a7acdaa2d8" version = "v1.1.0" [[projects]] - digest = "1:289332c13b80edfefc88397cce5266c16845dcf204fa2f6ac7e464ee4c7f6e96" name = "github.com/googleapis/gnostic" packages = [ "OpenAPIv2", "compiler", - "extensions", + "extensions" ] - pruneopts = "NT" revision = "7c663266750e7d82587642f65e60bc4083f1f84e" version = "v0.2.0" [[projects]] branch = "master" - digest = "1:97972f03fbf34ec4247ddc78ddb681389c468c020492aa32b109744a54fc0c14" name = "github.com/gregjones/httpcache" packages = [ ".", - "diskcache", + "diskcache" ] - pruneopts = "NT" revision = "c63ab54fda8f77302f8d414e19933f2b6026a089" [[projects]] - digest = "1:b42cde0e1f3c816dd57f57f7bbcf05ca40263ad96f168714c130c611fc0856a6" name = "github.com/hashicorp/golang-lru" packages = [ ".", - "simplelru", + "simplelru" ] - pruneopts = "NT" revision = "20f1fb78b0740ba8c3cb143a61e86ba5c8669768" version = "v0.5.0" [[projects]] - digest = "1:aaa38889f11896ee3644d77e17dc7764cc47f5f3d3b488268df2af2b52541c5f" name = "github.com/imdario/mergo" packages = ["."] - pruneopts = "NT" revision = "7c29201646fa3de8506f701213473dd407f19646" version = "v0.3.7" [[projects]] - digest = "1:1d39c063244ad17c4b18e8da1551163b6ffb52bd1640a49a8ec5c3b7bf4dbd5d" + name = "github.com/joho/godotenv" + packages = ["."] + revision = "23d116af351c84513e1946b527c88823e476be13" + version = "v1.3.0" + +[[projects]] name = "github.com/json-iterator/go" packages = ["."] - pruneopts = "NT" revision = "1624edc4454b8682399def8740d46db5e4362ba4" version = "v1.1.5" +[[projects]] + name = "github.com/konsorten/go-windows-terminal-sequences" + packages = ["."] + revision = "5c8c8bd35d3832f5d134ae1e1e375b69a4d25242" + version = "v1.0.1" + [[projects]] branch = "master" - digest = "1:7d9fcac7f1228470c4ea0ee31cdfb662a758c44df691e39b3e76c11d3e12ba8f" name = "github.com/mailru/easyjson" packages = [ "buffer", "jlexer", - "jwriter", + "jwriter" ] - pruneopts = "NT" revision = "60711f1a8329503b04e1c88535f419d0bb440bff" +[[projects]] + name = "github.com/markbates/inflect" + packages = ["."] + revision = "24b83195037b3bc61fcda2d28b7b0518bce293b6" + version = "v1.0.4" + [[projects]] branch = "master" - digest = "1:0e9bfc47ab9941ecc3344e580baca5deb4091177e84dd9773b48b38ec26b93d5" name = "github.com/mattbaird/jsonpatch" packages = ["."] - pruneopts = "NT" revision = "81af80346b1a01caae0cbc27fd3c1ba5b11e189f" [[projects]] - digest = "1:2f42fa12d6911c7b7659738758631bec870b7e9b4c6be5444f963cdcfccc191f" name = "github.com/modern-go/concurrent" packages = ["."] - pruneopts = "NT" revision = "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94" version = "1.0.3" [[projects]] - digest = "1:c6aca19413b13dc59c220ad7430329e2ec454cc310bc6d8de2c7e2b93c18a0f6" name = "github.com/modern-go/reflect2" packages = ["."] - pruneopts = "NT" revision = "4b7aa43c6742a2c18fdef89dd197aaae7dac7ccd" version = "1.0.1" [[projects]] - digest = "1:b186c2fcf87d05c5129ad0d89ea062853b0bdf6d6bca1ed4a22157962f2ad8dd" name = "github.com/operator-framework/operator-sdk" packages = [ + "internal/util/fileutil", + "internal/util/k8sutil", "pkg/k8sutil", "pkg/leader", "pkg/ready", - "version", + "pkg/scaffold", + "pkg/scaffold/input", + "pkg/test", + "version" ] - pruneopts = "NT" revision = "d6541603f2219f33966078a087732ecfc7a1dde5" version = "v0.2.1" [[projects]] - digest = "1:93b1d84c5fa6d1ea52f4114c37714cddd84d5b78f151b62bb101128dd51399bf" name = "github.com/pborman/uuid" packages = ["."] - pruneopts = "NT" revision = "adf5a7427709b9deb95d29d3fa8a2bf9cfd388f1" version = "v1.2" [[projects]] branch = "master" - digest = "1:bf2ac97824a7221eb16b096aecc1c390d4c8a4e49524386aaa2e2dd215cbfb31" name = "github.com/petar/GoLLRB" packages = ["llrb"] - pruneopts = "NT" revision = "53be0d36a84c2a886ca057d34b6aa4468df9ccb4" [[projects]] - digest = "1:e4e9e026b8e4c5630205cd0208efb491b40ad40552e57f7a646bb8a46896077b" name = "github.com/peterbourgon/diskv" packages = ["."] - pruneopts = "NT" revision = "5f041e8faa004a95c88a202771f4cc3e991971e6" version = "v2.0.1" [[projects]] - digest = "1:9d8420bbf131d1618bde6530af37c3799340d3762cc47210c1d9532a4c3a2779" + name = "github.com/pmezard/go-difflib" + packages = ["difflib"] + revision = "792786c7400a136282c1664665ae0a8db921c6c2" + version = "v1.0.0" + +[[projects]] + name = "github.com/rogpeppe/go-internal" + packages = [ + "modfile", + "module", + "semver" + ] + revision = "1cf9852c553c5b7da2d5a4a091129a7822fed0c9" + version = "v1.2.2" + +[[projects]] + name = "github.com/sirupsen/logrus" + packages = ["."] + revision = "e1e72e9de974bd926e5c56f83753fba2df402ce5" + version = "v1.3.0" + +[[projects]] + name = "github.com/spf13/afero" + packages = [ + ".", + "mem" + ] + revision = "f4711e4db9e9a1d3887343acb72b2bbfc2f686f5" + version = "v1.2.1" + +[[projects]] name = "github.com/spf13/pflag" packages = ["."] - pruneopts = "NT" revision = "298182f68c66c05229eb03ac171abe6e309ee79a" version = "v1.0.3" [[projects]] - digest = "1:22f696cee54865fb8e9ff91df7b633f6b8f22037a8015253c6b6a71ca82219c7" + name = "github.com/stretchr/testify" + packages = [ + "assert", + "require" + ] + revision = "ffdc059bfe9ce6a4e144ba849dbedead332c6053" + version = "v1.3.0" + +[[projects]] name = "go.uber.org/atomic" packages = ["."] - pruneopts = "NT" revision = "1ea20fb1cbb1cc08cbd0d913a96dead89aa18289" version = "v1.3.2" [[projects]] - digest = "1:58ca93bdf81bac106ded02226b5395a0595d5346cdc4caa8d9c1f3a5f8f9976e" name = "go.uber.org/multierr" packages = ["."] - pruneopts = "NT" revision = "3c4937480c32f4c13a875a1829af76c98ca3d40a" version = "v1.1.0" [[projects]] - digest = "1:572fa4496563920f3e3107a2294cf2621d6cc4ffd03403fb6397b1bab9fa082a" name = "go.uber.org/zap" packages = [ ".", @@ -321,23 +337,19 @@ "internal/bufferpool", "internal/color", "internal/exit", - "zapcore", + "zapcore" ] - pruneopts = "NT" revision = "ff33455a0e382e8a81d14dd7c922020b6b5e7982" version = "v1.9.1" [[projects]] branch = "master" - digest = "1:23e299b9877c8592668486c61668132f954875f29633269874c592c3ea94ee92" name = "golang.org/x/crypto" packages = ["ssh/terminal"] - pruneopts = "NT" revision = "ccddf3741a0cfcee0a62d34c18c2c5417a3761af" [[projects]] branch = "master" - digest = "1:4010b78f0ab4fcc3ff81e30e6dba92fa68b8520df8dd21b393481fd791360b21" name = "golang.org/x/net" packages = [ "context", @@ -345,38 +357,32 @@ "http/httpguts", "http2", "http2/hpack", - "idna", + "idna" ] - pruneopts = "NT" revision = "d26f9f9a57f3fab6a695bec0d84433c2c50f8bbf" [[projects]] branch = "master" - digest = "1:9a9a8b8635685e9e4ff68c80bebf00726f5019fb41da508a56df54e6e7277eeb" name = "golang.org/x/oauth2" packages = [ ".", "google", "internal", "jws", - "jwt", + "jwt" ] - pruneopts = "NT" revision = "5dab4167f31cbd76b407f1486c86b40748bc5073" [[projects]] branch = "master" - digest = "1:680783030e10a31a8c2deb6f0860f13878295b5458908f4395868e1dbbfe6a87" name = "golang.org/x/sys" packages = [ "unix", - "windows", + "windows" ] - pruneopts = "NT" revision = "302c3dd5f1cc82baae8e44d9c3178e89b6e2b345" [[projects]] - digest = "1:8c74f97396ed63cc2ef04ebb5fc37bb032871b8fd890a25991ed40974b00cd2a" name = "golang.org/x/text" packages = [ "collate", @@ -393,23 +399,19 @@ "unicode/cldr", "unicode/norm", "unicode/rangetable", - "width", + "width" ] - pruneopts = "NT" revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" version = "v0.3.0" [[projects]] branch = "master" - digest = "1:9fdc2b55e8e0fafe4b41884091e51e77344f7dc511c5acedcfd98200003bff90" name = "golang.org/x/time" packages = ["rate"] - pruneopts = "NT" revision = "85acf8d2951cb2a3bde7632f9ff273ef0379bcbd" [[projects]] branch = "master" - digest = "1:9f9a9dbf521c3a339ac0b595f8718191a0b36929ff8ca05714d6863fcef088ec" name = "golang.org/x/tools" packages = [ "go/ast/astutil", @@ -423,13 +425,11 @@ "internal/fastwalk", "internal/gopathwalk", "internal/module", - "internal/semver", + "internal/semver" ] - pruneopts = "NT" revision = "9cefa6771f8f3c72b346adb1995b7432464d4038" [[projects]] - digest = "1:902ffa11f1d8c19c12b05cabffe69e1a16608ad03a8899ebcb9c6bde295660ae" name = "google.golang.org/appengine" packages = [ ".", @@ -441,30 +441,24 @@ "internal/modules", "internal/remote_api", "internal/urlfetch", - "urlfetch", + "urlfetch" ] - pruneopts = "NT" revision = "e9657d882bb81064595ca3b56cbe2546bbabf7b1" version = "v1.4.0" [[projects]] - digest = "1:2d1fbdc6777e5408cabeb02bf336305e724b925ff4546ded0fa8715a7267922a" name = "gopkg.in/inf.v0" packages = ["."] - pruneopts = "NT" revision = "d2d2541c53f18d2a059457998ce2876cc8e67cbf" version = "v0.9.1" [[projects]] - digest = "1:18108594151654e9e696b27b181b953f9a90b16bf14d253dd1b397b025a1487f" name = "gopkg.in/yaml.v2" packages = ["."] - pruneopts = "NT" revision = "51d6538a90f86fe93ac480b35f37b2be17fef232" version = "v2.2.2" [[projects]] - digest = "1:f11e5753e619f411a51a49d60d39b2bc4da6766f5f0af2e2291daa6a3d9385d5" name = "k8s.io/api" packages = [ "admission/v1beta1", @@ -496,13 +490,20 @@ "settings/v1alpha1", "storage/v1", "storage/v1alpha1", - "storage/v1beta1", + "storage/v1beta1" ] - pruneopts = "NT" revision = "2d6f90ab1293a1fb871cf149423ebb72aa7423aa" [[projects]] - digest = "1:b07bf863262aae765494d60f0d524483f211b29f9bb27d445a79c13af8676bf2" + name = "k8s.io/apiextensions-apiserver" + packages = [ + "pkg/apis/apiextensions", + "pkg/apis/apiextensions/v1beta1", + "pkg/client/clientset/clientset/scheme" + ] + revision = "408db4a50408e2149acbd657bceb2480c13cb0a4" + +[[projects]] name = "k8s.io/apimachinery" packages = [ "pkg/api/errors", @@ -546,16 +547,15 @@ "pkg/version", "pkg/watch", "third_party/forked/golang/json", - "third_party/forked/golang/reflect", + "third_party/forked/golang/reflect" ] - pruneopts = "NT" revision = "103fd098999dc9c0c88536f5c9ad2e5da39373ae" [[projects]] - digest = "1:1689a49a3ebc6e379849181f1e0899fccf143cab47586078721818bdcdb712bc" name = "k8s.io/client-go" packages = [ "discovery", + "discovery/cached", "dynamic", "kubernetes", "kubernetes/scheme", @@ -619,13 +619,11 @@ "util/integer", "util/jsonpath", "util/retry", - "util/workqueue", + "util/workqueue" ] - pruneopts = "NT" revision = "1f13a808da65775f22cbf47862c4e5898d8f4ca1" [[projects]] - digest = "1:8ab487a323486c8bbbaa3b689850487fdccc6cbea8690620e083b2d230a4447e" name = "k8s.io/code-generator" packages = [ "cmd/client-gen", @@ -651,14 +649,12 @@ "cmd/lister-gen/generators", "cmd/openapi-gen", "cmd/openapi-gen/args", - "pkg/util", + "pkg/util" ] - pruneopts = "T" revision = "6702109cc68eb6fe6350b83e14407c8d7309fd1a" [[projects]] branch = "master" - digest = "1:4e07c417d966628ee9e471354ad5e311c9c25ff357d42fd0dd2f81a40caf6aad" name = "k8s.io/gengo" packages = [ "args", @@ -668,22 +664,18 @@ "generator", "namer", "parser", - "types", + "types" ] - pruneopts = "NT" revision = "0689ccc1d7d65d9dd1bedcc3b0b1ed7df91ba266" [[projects]] - digest = "1:f3b42f307c7f49a1a7276c48d4b910db76e003220e88797f7acd41e3a9277ddf" name = "k8s.io/klog" packages = ["."] - pruneopts = "NT" revision = "a5bc97fbc634d635061f3146511332c7e313a55a" version = "v0.1.0" [[projects]] branch = "master" - digest = "1:653cd4cf804493513d5ec945e687639e5fe9a1f7adbcf2db5cd21da31a96674e" name = "k8s.io/kube-openapi" packages = [ "cmd/openapi-gen/args", @@ -691,13 +683,11 @@ "pkg/generators", "pkg/generators/rules", "pkg/util/proto", - "pkg/util/sets", + "pkg/util/sets" ] - pruneopts = "NT" revision = "ced9eb3070a5f1c548ef46e8dfe2a97c208d9f03" [[projects]] - digest = "1:a8fb38656b3b59a487e3f74c7d9ad4d90c4f7a3b45413284311f9751b6905448" name = "sigs.k8s.io/controller-runtime" packages = [ "pkg/cache", @@ -725,46 +715,14 @@ "pkg/source/internal", "pkg/webhook/admission", "pkg/webhook/admission/types", - "pkg/webhook/types", + "pkg/webhook/types" ] - pruneopts = "NT" revision = "53fc44b56078cd095b11bd44cfa0288ee4cf718f" version = "v0.1.4" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - input-imports = [ - "github.com/operator-framework/operator-sdk/pkg/k8sutil", - "github.com/operator-framework/operator-sdk/pkg/leader", - "github.com/operator-framework/operator-sdk/pkg/ready", - "github.com/operator-framework/operator-sdk/version", - "k8s.io/api/core/v1", - "k8s.io/apimachinery/pkg/api/errors", - "k8s.io/apimachinery/pkg/apis/meta/v1", - "k8s.io/apimachinery/pkg/runtime", - "k8s.io/apimachinery/pkg/runtime/schema", - "k8s.io/apimachinery/pkg/types", - "k8s.io/client-go/plugin/pkg/client/auth/gcp", - "k8s.io/code-generator/cmd/client-gen", - "k8s.io/code-generator/cmd/conversion-gen", - "k8s.io/code-generator/cmd/deepcopy-gen", - "k8s.io/code-generator/cmd/defaulter-gen", - "k8s.io/code-generator/cmd/informer-gen", - "k8s.io/code-generator/cmd/lister-gen", - "k8s.io/code-generator/cmd/openapi-gen", - "k8s.io/gengo/args", - "sigs.k8s.io/controller-runtime/pkg/client", - "sigs.k8s.io/controller-runtime/pkg/client/config", - "sigs.k8s.io/controller-runtime/pkg/controller", - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil", - "sigs.k8s.io/controller-runtime/pkg/handler", - "sigs.k8s.io/controller-runtime/pkg/manager", - "sigs.k8s.io/controller-runtime/pkg/reconcile", - "sigs.k8s.io/controller-runtime/pkg/runtime/log", - "sigs.k8s.io/controller-runtime/pkg/runtime/scheme", - "sigs.k8s.io/controller-runtime/pkg/runtime/signals", - "sigs.k8s.io/controller-runtime/pkg/source", - ] + inputs-digest = "4c108157deacc5272699a59206b6be110515a516aae9bb73b4f3267f9b7b403a" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index cbc6a98..46b154c 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -52,3 +52,7 @@ required = [ [[prune.project]] name = "k8s.io/code-generator" non-go = false + +[[constraint]] + name = "github.com/stretchr/testify" + version = "1.3.0" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a198ab8 --- /dev/null +++ b/Makefile @@ -0,0 +1,271 @@ +PROJECT_NAME=devopsconsole-operator +PACKAGE_NAME:=github.com/fabric8-services/$(PROJECT_NAME) +CUR_DIR=$(shell pwd) +TMP_PATH=$(CUR_DIR)/tmp +INSTALL_PREFIX=$(CUR_DIR)/bin +VENDOR_DIR=vendor +INCLUDE_DIR=make +SOURCE_DIR ?= . +SOURCES := $(shell find $(SOURCE_DIR) -path $(SOURCE_DIR)/vendor -prune -o -name '*.go' -print) + +ifeq ($(OS),Windows_NT) + include ./$(INCLUDE_DIR)/Makefile.win +else + include ./$(INCLUDE_DIR)/Makefile.lnx +endif + +# declares variable that are OS-sensitive +include ./$(INCLUDE_DIR)/test.mk +include ./$(INCLUDE_DIR)/Makefile.dev + +DOCKER_BIN := $(shell command -v $(DOCKER_BIN_NAME) 2> /dev/null) + +ifneq ($(OS),Windows_NT) + ifdef DOCKER_BIN + include ./$(INCLUDE_DIR)/docker.mk + endif +endif + +# This is a fix for a non-existing user in passwd file when running in a docker +# container and trying to clone repos of dependencies +GIT_COMMITTER_NAME ?= "user" +GIT_COMMITTER_EMAIL ?= "user@example.com" +export GIT_COMMITTER_NAME +export GIT_COMMITTER_EMAIL + +COMMIT=$(shell git rev-parse HEAD 2>/dev/null) +GITUNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no) +ifneq ($(GITUNTRACKEDCHANGES),) + COMMIT := $(COMMIT)-dirty +endif +BUILD_TIME=`date -u '+%Y-%m-%dT%H:%M:%SZ'` + +.DEFAULT_GOAL := help + +# Call this function with $(call log-info,"Your message") +define log-info = + @echo "INFO: $(1)" +endef + +# ------------------------------------------------------------------- +# Docker build +# ------------------------------------------------------------------- +BUILD_DIR = bin +REGISTRY_URI = quay.io +REGISTRY_NS = ${PROJECT_NAME} +REGISTRY_IMAGE = ${PROJECT_NAME} + +ifeq ($(TARGET),rhel) + REGISTRY_URL := ${REGISTRY_URI}/openshiftio/rhel-${REGISTRY_NS}-${REGISTRY_IMAGE} + DOCKERFILE := Dockerfile.rhel +else + REGISTRY_URL := ${REGISTRY_URI}/openshiftio/${REGISTRY_NS}-${REGISTRY_IMAGE} + DOCKERFILE := Dockerfile +endif + +$(BUILD_DIR): + mkdir $(BUILD_DIR) + +.PHONY: build-linux $(BUILD_DIR) +build-linux: makefiles prebuild-check deps ## Builds the Linux binary for the container image into bin/ folder + CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -v $(LDFLAGS) -o $(BUILD_DIR)/$(PROJECT_NAME) + +image: clean-artifacts build-linux + docker build -t $(REGISTRY_URL) \ + --build-arg BUILD_DIR=$(BUILD_DIR)\ + --build-arg PROJECT_NAME=$(PROJECT_NAME)\ + -f $(VENDOR_DIR)/github.com/fabric8-services/fabric8-common/makefile/$(DOCKERFILE) . + +# ------------------------------------------------------------------- +# help! +# ------------------------------------------------------------------- + +.PHONY: help +# Based on https://gist.github.com/rcmachado/af3db315e31383502660 +## Display this help text. +help:/ + $(info Available targets) + $(info -----------------) + @awk '/^[a-zA-Z\-\_0-9]+:/ { \ + helpMessage = match(lastLine, /^## (.*)/); \ + helpCommand = substr($$1, 0, index($$1, ":")-1); \ + if (helpMessage) { \ + helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \ + gsub(/##/, "\n ", helpMessage); \ + printf "%-35s - %s\n", helpCommand, helpMessage; \ + lastLine = "" \ + } \ + } \ + { hasComment = match(lastLine, /^## (.*)/); \ + if(hasComment) { \ + lastLine=lastLine$$0; \ + } \ + else { \ + lastLine = $$0 \ + } \ + }' $(MAKEFILE_LIST) +# ------------------------------------------------------------------- +# required tools +# ------------------------------------------------------------------- + +# Find all required tools: +GIT_BIN := $(shell command -v $(GIT_BIN_NAME) 2> /dev/null) +TMP_BIN_DIR := $(TMP_PATH)/bin +DEP_BIN := $(TMP_BIN_DIR)/$(DEP_BIN_NAME) +DEP_VERSION=v0.5.0 +GOLANGCI_LINT_VERSION=1.12 +GOLANGCI_LINT_BIN=$(TMP_BIN_DIR)/$(GOLANGCI_LINT_BIN_NAME) +GO_BIN := $(shell command -v $(GO_BIN_NAME) 2> /dev/null) + +$(INSTALL_PREFIX): + mkdir -p $(INSTALL_PREFIX) +$(TMP_PATH): + mkdir -p $(TMP_PATH) + +.PHONY: prebuild-check +prebuild-check: $(TMP_PATH) $(INSTALL_PREFIX) +# Check that all tools where found +ifndef GIT_BIN + $(error The "$(GIT_BIN_NAME)" executable could not be found in your PATH) +endif +ifndef DEP_BIN + $(error The "$(DEP_BIN_NAME)" executable could not be found in your PATH) +endif +ifndef GO_BIN + $(error The "$(GO_BIN_NAME)" executable could not be found in your PATH) +endif + +# ------------------------------------------------------------------- +# deps +# ------------------------------------------------------------------- + +.PHONY: deps +## Download build dependencies. +deps: $(DEP_BIN) $(VENDOR_DIR) + +# install dep in a the tmp/bin dir of the repo +$(DEP_BIN): + @echo "Installing 'dep' $(DEP_VERSION) at '$(TMP_BIN_DIR)'..." + mkdir -p $(TMP_BIN_DIR) +ifeq ($(UNAME_S),Darwin) + @curl -L -s https://github.com/golang/dep/releases/download/$(DEP_VERSION)/dep-darwin-amd64 -o $(DEP_BIN) + @cd $(TMP_BIN_DIR) && \ + curl -L -s https://github.com/golang/dep/releases/download/$(DEP_VERSION)/dep-darwin-amd64.sha256 -o $(TMP_BIN_DIR)/dep-darwin-amd64.sha256 && \ + echo "1a7bdb0d6c31ecba8b3fd213a1170adf707657123e89dff234871af9e0498be2 dep" > dep-darwin-amd64.sha256 && \ + shasum -a 256 --check dep-darwin-amd64.sha256 +else + @curl -L -s https://github.com/golang/dep/releases/download/$(DEP_VERSION)/dep-linux-amd64 -o $(DEP_BIN) + @cd $(TMP_BIN_DIR) && \ + echo "287b08291e14f1fae8ba44374b26a2b12eb941af3497ed0ca649253e21ba2f83 dep" > dep-linux-amd64.sha256 && \ + sha256sum -c dep-linux-amd64.sha256 +endif + @chmod +x $(DEP_BIN) + +$(VENDOR_DIR): Gopkg.toml + @echo "checking dependencies with $(DEP_BIN_NAME)" + @$(DEP_BIN) ensure -v + +# ------------------------------------------------------------------- +# Code format/check +# ------------------------------------------------------------------- +GOFORMAT_FILES := $(shell find . -name '*.go' | grep -vEf $(INCLUDE_DIR)/gofmt_exclude) + +.PHONY: check-go-format +# Exists with an error if there are files whose formatting differs from gofmt's +check-go-format: prebuild-check deps ## Exists with an error if there are files whose formatting differs from gofmt's + @gofmt -s -l ${GOFORMAT_FILES} 2>&1 \ + | tee /tmp/gofmt-errors \ + | read \ + && echo "ERROR: These files differ from gofmt's style (run 'make format-go-code' to fix this):" \ + && cat /tmp/gofmt-errors \ + && exit 1 \ + || true + +.PHONY: analyze-go-code +# Run golangci analysis over the code. +analyze-go-code: deps ## Run golangci analysis over the code. + $(info >>--- RESULTS: GOLANGCI CODE ANALYSIS ---<<) + @go get -u github.com/golangci/golangci-lint/cmd/golangci-lint + @golangci-lint run + +.PHONY: format-go-code +# Formats any go file that differs from gofmt's style +format-go-code: prebuild-check ## Formats any go file that differs from gofmt's style + @gofmt -s -l -w ${GOFORMAT_FILES} + +# ------------------------------------------------------------------- +# Code format/check with golangci-lint +# ------------------------------------------------------------------- +.PHONY: check-go-code +## Checks the code with golangci-lint (see .golangci.yaml) +check-go-code: $(GOLANGCI_LINT_BIN) + @echo "checking code..." + $(GOLANGCI_LINT_BIN) run + +# install golangci-lint in the 'tmp/bin' dir of the repo +$(GOLANGCI_LINT_BIN): + @echo "Installing 'golang-ci-lint' $(GOLANGCI_LINT_VERSION) at '$(TMP_BIN_DIR)' ..." + mkdir -p $(TMP_BIN_DIR) +ifeq ($(UNAME_S),Darwin) + @curl -L -s https://github.com/golangci/golangci-lint/releases/download/v$(GOLANGCI_LINT_VERSION)/golangci-lint-$(GOLANGCI_LINT_VERSION)-darwin-amd64.tar.gz -o $(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VERSION)-darwin-amd64.tar.gz && \ + cd $(TMP_BIN_DIR) && curl -L -s https://github.com/golangci/golangci-lint/releases/download/v$(GOLANGCI_LINT_VERSION)/golangci-lint-$(GOLANGCI_LINT_VERSION)-checksums.txt -o golangci-lint-$(GOLANGCI_LINT_VERSION)-checksums.txt && \ + grep "darwin-amd64" golangci-lint-$(GOLANGCI_LINT_VERSION)-checksums.txt > golangci-lint-$(GOLANGCI_LINT_VERSION)-checksum-darwin-amd64.txt && \ + shasum -a 256 --check golangci-lint-$(GOLANGCI_LINT_VERSION)-checksum-darwin-amd64.txt && \ + tar xvf $(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VERSION)-darwin-amd64.tar.gz -C $(TMP_BIN_DIR) && \ + mv $(TMP_BIN_DIR)/golangci-lint-$(GOLANGCI_LINT_VERSION)-darwin-amd64/golangci-lint $(GOLANGCI_LINT_BIN) +else + @curl -L -s https://github.com/golangci/golangci-lint/releases/download/v$(GOLANGCI_LINT_VERSION)/golangci-lint-$(GOLANGCI_LINT_VERSION)-linux-amd64.tar.gz -o $(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VERSION)-linux-amd64.tar.gz && \ + cd $(TMP_BIN_DIR) && curl -L -s https://github.com/golangci/golangci-lint/releases/download/v$(GOLANGCI_LINT_VERSION)/golangci-lint-$(GOLANGCI_LINT_VERSION)-checksums.txt -o golangci-lint-$(GOLANGCI_LINT_VERSION)-checksums.txt && \ + grep "linux-amd64" golangci-lint-$(GOLANGCI_LINT_VERSION)-checksums.txt > golangci-lint-$(GOLANGCI_LINT_VERSION)-checksum-linux-amd64.txt && \ + sha256sum -c golangci-lint-$(GOLANGCI_LINT_VERSION)-checksum-linux-amd64.txt && \ + tar xvf $(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VERSION)-linux-amd64.tar.gz -C $(TMP_BIN_DIR) && \ + mv $(TMP_BIN_DIR)/golangci-lint-$(GOLANGCI_LINT_VERSION)-linux-amd64/golangci-lint $(GOLANGCI_LINT_BIN) +endif + @chmod +x $(GOLANGCI_LINT_BIN) + + +# ------------------------------------------------------------------- +# clean +# ------------------------------------------------------------------- + +# For the global "clean" target all targets in this variable will be executed +CLEAN_TARGETS = + +CLEAN_TARGETS += clean-artifacts +.PHONY: clean-artifacts +# Removes the ./bin directory. +clean-artifacts: + -rm -rf $(INSTALL_PREFIX) + +CLEAN_TARGETS += clean-object-files +.PHONY: clean-object-files +# Runs go clean to remove any executables or other object files. +clean-object-files: + go clean ./... + +CLEAN_TARGETS += clean-vendor +.PHONY: clean-vendor +# Removes the ./vendor directory. +clean-vendor: + -rm -rf $(VENDOR_DIR) + +CLEAN_TARGETS += clean-tmp +.PHONY: clean-tmp +# Removes the ./vendor directory. +clean-tmp: + -rm -rf $(TMP_PATH) + +# Keep this "clean" target here after all `clean-*` sub tasks +.PHONY: clean +## Runs all clean-* targets. +clean: $(CLEAN_TARGETS) + +# ------------------------------------------------------------------- +# build the binary executable (to ship in prod) +# ------------------------------------------------------------------- + +.PHONY: build +## Build the server +build: prebuild-check deps + @echo "building $(BINARY_SERVER_BIN)..." + go build -v -o $(BINARY_SERVER_BIN) cmd/manager/main.go diff --git a/cmd/manager/main.go b/cmd/manager/main.go index 2321690..fafc94d 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -53,7 +53,11 @@ func main() { } // Become the leader before proceeding - leader.Become(context.TODO(), "devconsole-lock") + err = leader.Become(context.TODO(), "devconsole-lock") + if err != nil { + log.Error(err, "") + os.Exit(1) + } r := ready.NewFileReady() err = r.Set() @@ -61,7 +65,13 @@ func main() { log.Error(err, "") os.Exit(1) } - defer r.Unset() + defer func() { + err := r.Unset() + if err != nil { + log.Error(err, "") + os.Exit(1) + } + }() // Create a new Cmd to provide shared dependencies and start components mgr, err := manager.New(cfg, manager.Options{Namespace: namespace}) diff --git a/deploy/test/global-manifests.yaml b/deploy/test/global-manifests.yaml new file mode 100644 index 0000000..95b384a --- /dev/null +++ b/deploy/test/global-manifests.yaml @@ -0,0 +1,57 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: envdeployments.devconsole.openshift.io +spec: + group: devconsole.openshift.io + names: + kind: DevConsole + listKind: DevConsoleList + plural: envdeployments + singular: envdeployment + scope: Namespaced + version: v1alpha1 +--- +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: devconsole +rules: +- apiGroups: + - rbac.authorization.k8s.io + resources: + - clusterrolebindings + verbs: + - '*' +- apiGroups: + - oauth.openshift.io + resources: + - oauthclients + verbs: + - '*' +- apiGroups: + - "" + - project.openshift.io + resources: + - projectrequests + verbs: + - create +- apiGroups: + - codeready.io + resources: + - devconsole/finalizers + verbs: + - update +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: devconsole +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: devconsole +subjects: +- kind: ServiceAccount + name: devconsole + namespace: devconsole-e2e-test \ No newline at end of file diff --git a/deploy/test/namespace-manifests.yaml b/deploy/test/namespace-manifests.yaml new file mode 100644 index 0000000..221e13d --- /dev/null +++ b/deploy/test/namespace-manifests.yaml @@ -0,0 +1,99 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: devconsole + +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + creationTimestamp: null + name: devconsole +rules: +- apiGroups: + - "" + resources: + - pods + - services + - endpoints + - persistentvolumeclaims + - events + - configmaps + - secrets + verbs: + - '*' +- apiGroups: + - apps + resources: + - deployments + - daemonsets + - replicasets + - statefulsets + verbs: + - '*' +- apiGroups: + - monitoring.coreos.com + resources: + - servicemonitors + verbs: + - get + - create +- apiGroups: + - devconsole.openshift.io + resources: + - '*' + - envdeployments + verbs: + - '*' +- apiGroups: + - clusterregistry.k8s.io + resources: + - '*' + verbs: + - '*' + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: devconsole +spec: + replicas: 1 + selector: + matchLabels: + name: devconsole + template: + metadata: + labels: + name: devconsole + spec: + serviceAccountName: devconsole + containers: + - name: devconsole + # Replace this with the built image name + image: REPLACE_IMAGE + ports: + - containerPort: 60000 + name: metrics + command: + - devconsole + imagePullPolicy: Always + readinessProbe: + exec: + command: + - stat + - /tmp/operator-sdk-ready + initialDelaySeconds: 4 + periodSeconds: 10 + failureThreshold: 1 + env: + - name: WATCH_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: OPERATOR_NAME + value: "devconsole" diff --git a/make/Makefile.dev b/make/Makefile.dev new file mode 100644 index 0000000..58b7422 --- /dev/null +++ b/make/Makefile.dev @@ -0,0 +1,89 @@ +DOCKER_REPO?=quay.io/openshiftio +IMAGE_NAME?=devconsole-operator +SHORT_COMMIT=$(shell git rev-parse --short HEAD) +ifneq ($(GITUNTRACKEDCHANGES),) +SHORT_COMMIT := $(SHORT_COMMIT)-dirty +endif + +TIMESTAMP:=$(shell date +%s) +TAG?=$(SHORT_COMMIT)-$(TIMESTAMP) + +DEPLOY_DIR:=deploy + +.PHONY: create-resources +create-resources: + @echo "Logging using system:admin..." + @oc login -u system:admin + @echo "Creating sub resources..." + @echo "Creating CRDs..." + @oc create -f $(DEPLOY_DIR)/crds/devconsole_v1alpha1_envdeployment_crd.yaml + @echo "Creating Namespace" + @oc create -f $(DEPLOY_DIR)/namespace.yaml + @echo "oc project codeready-devconsole" + @oc project codeready-devconsole + @echo "Creating Service Account" + @oc create -f $(DEPLOY_DIR)/service_account.yaml + @echo "Creating Role" + @oc create -f $(DEPLOY_DIR)/role.yaml + @echo "Creating RoleBinding" + @oc create -f $(DEPLOY_DIR)/role_binding.yaml + @echo "Creating Cluster Role" + @oc create -f $(DEPLOY_DIR)/cluster_role.yaml + @echo "Creating ClusterRoleBinding" + @oc create -f $(DEPLOY_DIR)/cluster_role_binding.yaml + +.PHONY: create-cr +create-cr: + @echo "Creating Custom Resource..." + @oc create -f $(DEPLOY_DIR)/crds/devconsole_v1alpha1_envdeployment_crd.yaml + +.PHONY: build-image +build-image: + docker build -t $(DOCKER_REPO)/$(IMAGE_NAME):$(TAG) -f Dockerfile.dev . + docker tag $(DOCKER_REPO)/$(IMAGE_NAME):$(TAG) $(DOCKER_REPO)/$(IMAGE_NAME):test + +.PHONY: deploy-operator-only +deploy-operator-only: + @echo "Creating Deployment for Operator" + @cat minishift/operator.yaml | sed s/\:dev/:$(TAG)/ | oc create -f - + +.PHONY: clean-all +clean-all: clean-operator clean-resources + +.PHONY: clean-operator +clean-operator: + @echo "Deleting Deployment for Operator" + @cat minishift/operator.yaml | sed s/\:dev/:$(TAG)/ | oc delete -f - || true + +.PHONY: clean-resources +clean-resources: + @echo "Deleting sub resources..." + @echo "Deleting RoleBinding" + @oc delete -f $(DEPLOY_DIR)/role_binding.yaml || true + @echo "Deleting ClusterRoleBinding" + @oc delete -f $(DEPLOY_DIR)/cluster_role_binding.yaml || true + @echo "Deleting Role" + @oc delete -f $(DEPLOY_DIR)/role.yaml || true + @echo "Deleting ClusterRole" + @oc delete -f $(DEPLOY_DIR)/cluster_role.yaml || true + @echo "Deleting Service Account" + @oc delete -f $(DEPLOY_DIR)/service_account.yaml || true + @echo "Deleting Custom Resources..." + @oc delete -f $(DEPLOY_DIR)/crds/devconsole_v1alpha1_envdeployment_crd.yaml|| true + @echo "Deleting Namespace" + @oc delete -f $(DEPLOY_DIR)/namespace.yaml || true + @echo "Deleting Custom Resource Definitions..." + @oc delete -f $(DEPLOY_DIR)/crds/devconsole_v1alpha1_envdeployment_crd.yaml || true + @echo "Deleting OAuthClient 'codeready-devconsole'" + @oc delete oauthclient codeready-devconsole || true + +.PHONY: deploy-operator +deploy-operator: build build-image deploy-operator-only + +.PHONY: minishift-start +minishift-start: + minishift start --cpus 4 --memory 8GB + -eval `minishift docker-env` && oc login -u system:admin + +.PHONY: deploy-all +deploy-all: clean-resources create-resources deps prebuild-check deploy-operator create-cr diff --git a/make/Makefile.lnx b/make/Makefile.lnx new file mode 100644 index 0000000..be34ca0 --- /dev/null +++ b/make/Makefile.lnx @@ -0,0 +1,12 @@ +BINARY_SERVER_BIN=$(INSTALL_PREFIX)/devconsole-operator +GO_BIN_NAME=go +GIT_BIN_NAME=git +DEP_BIN_NAME=dep +DOCKER_BIN_NAME=docker +CHECK_GOPATH_BIN=$(INSTALL_PREFIX)/check_gopath +UNAME_S=$(shell uname -s) +GOCOV_BIN=$(VENDOR_DIR)/github.com/axw/gocov/gocov/gocov +GOCOVMERGE_BIN=$(VENDOR_DIR)/github.com/wadey/gocovmerge/gocovmerge +GOCYCLO_DIR=$(VENDOR_DIR)/github.com/fzipp/gocyclo +GOCYCLO_BIN=$(GOCYCLO_DIR)/gocyclo +GOLANGCI_LINT_BIN_NAME:=golangci-lint diff --git a/make/Makefile.win b/make/Makefile.win new file mode 100644 index 0000000..45ab6cf --- /dev/null +++ b/make/Makefile.win @@ -0,0 +1,11 @@ +BINARY_SERVER_BIN=$(INSTALL_PREFIX)/devconsole-operator.exe +GO_BIN_NAME=go.exe +GIT_BIN_NAME=git.exe +DEP_BIN_NAME=dep.exe +DOCKER_BIN_NAME=docker.exe +CHECK_GOPATH_BIN= $(INSTALL_PREFIX)/check_gopath.exe +GOCOV_BIN=$(VENDOR_DIR)/github.com/axw/gocov/gocov/gocov.exe +GOCOVMERGE_BIN=$(VENDOR_DIR)/github.com/wadey/gocovmerge/gocovmerge.exe +GOCYCLO_DIR=$(VENDOR_DIR)/github.com/fzipp/gocyclo +GOCYCLO_BIN=$(GOCYCLO_DIR)/gocyclo.exe +GOLANGCI_LINT_BIN_NAME:=golangci-lint.exe diff --git a/make/check_gopath.go b/make/check_gopath.go new file mode 100644 index 0000000..091c4c2 --- /dev/null +++ b/make/check_gopath.go @@ -0,0 +1,46 @@ +package main + +import ( + "flag" + "fmt" + "log" + "os" + "path" + "path/filepath" + "runtime" + "strings" +) + +// Checks if the packageName is checked out into one of the GOPATH entries +// under GOPATH[i]/src/packageName. +func main() { + var packageName string + flag.StringVar(&packageName, "packageName", "github.com/redhat-developers/devopsconsole-operator", "Package Name (e.g.)") + flag.Parse() + + wd, err := os.Getwd() + if err != nil { + log.Fatal(err) + } + + for _, p := range strings.Split(os.Getenv("GOPATH"), string(filepath.ListSeparator)) { + // Check if p is a directory + if info, err := os.Stat(p); err == nil && info.IsDir() { + // Make sure we have an absolute path + abs, err := filepath.Abs(p) + if err != nil { + log.Fatal(err) + } + if wd == filepath.Join(abs, "src", packageName) { + os.Exit(0) + } + } + } + + goPathStr := path.Join("$GOPATH", "src", packageName) + if runtime.GOOS == "windows" { + goPathStr = path.Join("%GOPATH%", "src", packageName) + } + log.Fatal(fmt.Errorf("Make sure you've checked out your project in %s", goPathStr)) + +} diff --git a/make/docker.mk b/make/docker.mk new file mode 100644 index 0000000..4696e5a --- /dev/null +++ b/make/docker.mk @@ -0,0 +1,108 @@ +DOCKER_IMAGE_CORE := $(PROJECT_NAME) +DOCKER_IMAGE_DEPLOY := $(PROJECT_NAME)-deploy + +ifeq ($(TARGET),rhel) + DOCKERFILE_DEPLOY := Dockerfile.deploy.rhel +else + DOCKERFILE_DEPLOY := Dockerfile.deploy +endif + +# If running in Jenkins we don't allow for interactively running the container +ifneq ($(BUILD_TAG),) + DOCKER_RUN_INTERACTIVE_SWITCH := +else + DOCKER_RUN_INTERACTIVE_SWITCH := -i +endif + +# The workspace environment is set by Jenkins and defaults to /tmp if not set +WORKSPACE ?= /tmp +DOCKER_BUILD_DIR := $(WORKSPACE)/$(PROJECT_NAME)-build + +# The BUILD_TAG environment variable will be set by jenkins +# to reflect jenkins-${JOB_NAME}-${BUILD_NUMBER} +BUILD_TAG ?= $(PROJECT_NAME)-local-build +DOCKER_CONTAINER_NAME := $(BUILD_TAG) + +# Where is the GOPATH inside the build container? +GOPATH_IN_CONTAINER=/tmp/go +PACKAGE_PATH=$(GOPATH_IN_CONTAINER)/src/$(PACKAGE_NAME) + +.PHONY: docker-image-builder +## Builds the docker image used to build the software. +docker-image-builder: + @echo "Building docker image $(DOCKER_IMAGE_CORE)" + docker build --build-arg USE_GO_VERSION_FROM_WEBSITE=$(USE_GO_VERSION_FROM_WEBSITE) -t $(DOCKER_IMAGE_CORE) -f $(CUR_DIR)/Dockerfile.builder $(CUR_DIR) + +.PHONY: docker-image-deploy +## Creates a runnable image using the artifacts from the bin directory. +docker-image-deploy: + docker build -t $(DOCKER_IMAGE_DEPLOY) -f $(CUR_DIR)/$(DOCKERFILE_DEPLOY) $(CUR_DIR) + +.PHONY: docker-build-dir +# Creates the docker build directory. +docker-build-dir: + @echo "Creating build directory $(BUILD_DIR)" + mkdir -p $(DOCKER_BUILD_DIR) + +CLEAN_TARGETS += clean-docker-build-container +.PHONY: clean-docker-build-container +# Removes any existing container used to build the software (if any). +clean-docker-build-container: + @echo "Removing container named \"$(DOCKER_CONTAINER_NAME)\" (if any)" +ifneq ($(strip $(shell docker ps -qa --filter "name=$(DOCKER_CONTAINER_NAME)" 2>/dev/null)),) + @docker rm -f $(DOCKER_CONTAINER_NAME) +else + @echo "No container named \"$(DOCKER_CONTAINER_NAME)\" to remove" +endif + +CLEAN_TARGETS += clean-docker-build-dir +.PHONY: clean-docker-build-dir +# Removes the docker build directory. +clean-docker-build-dir: + @echo "Cleaning build directory $(BUILD_DIR)" + -rm -rf $(DOCKER_BUILD_DIR) + +.PHONY: docker-start +## Starts the docker build container in the background (detached mode). +## After calling this command you can invoke all the make targets from the +## normal Makefile (e.g. deps, build) inside the build container +## by prefixing them with "docker-". For example to execute "make deps" +## inside the build container, just run "make docker-deps". +## To remove the container when no longer needed, call "make docker-rm". +docker-start: docker-build-dir docker-image-builder +ifneq ($(strip $(shell docker ps -qa --filter "name=$(DOCKER_CONTAINER_NAME)" 2>/dev/null)),) + @echo "Docker container \"$(DOCKER_CONTAINER_NAME)\" already exists. To recreate, run \"make docker-rm\"." +else + docker run \ + --detach=true \ + -t \ + $(DOCKER_RUN_INTERACTIVE_SWITCH) \ + --name="$(DOCKER_CONTAINER_NAME)" \ + -e ADMIN_POSTGRES_PORT=5432 \ + -v $(CUR_DIR):$(PACKAGE_PATH):Z \ + -u $(shell id -u $(USER)):$(shell id -g $(USER)) \ + -e GOPATH=$(GOPATH_IN_CONTAINER) \ + -w $(PACKAGE_PATH) \ + $(DOCKER_IMAGE_CORE) + @echo "Docker container \"$(DOCKER_CONTAINER_NAME)\" created. Continue with \"make docker-deps\"." +endif + +.PHONY: docker-rm +# Removes the docker build container, if any (see "make docker-start"). +docker-rm: +ifneq ($(strip $(shell docker ps -qa --filter "name=$(DOCKER_CONTAINER_NAME)" 2>/dev/null)),) + docker rm -f "$(DOCKER_CONTAINER_NAME)" +else + @echo "No container named \"$(DOCKER_CONTAINER_NAME)\" to remove." +endif + +# This is a wildcard target to let you call any make target from the normal makefile +# but it will run inside the docker container. This target will only get executed if +# there's no specialized form available. For example if you call "make docker-start" +# not this target gets executed but the "docker-start" target. +docker-%: + $(eval makecommand:=$(subst docker-,,$@)) +ifeq ($(strip $(shell docker ps -qa --filter "name=$(DOCKER_CONTAINER_NAME)" 2>/dev/null)),) + $(error No container name "$(DOCKER_CONTAINER_NAME)" exists to run the command "make $(makecommand)") +endif + docker exec -t $(DOCKER_RUN_INTERACTIVE_SWITCH) "$(DOCKER_CONTAINER_NAME)" bash -ec 'make $(makecommand)' diff --git a/make/gofmt_exclude b/make/gofmt_exclude new file mode 100644 index 0000000..6d03c3e --- /dev/null +++ b/make/gofmt_exclude @@ -0,0 +1 @@ +vendor/.* diff --git a/make/test.mk b/make/test.mk new file mode 100644 index 0000000..9fae986 --- /dev/null +++ b/make/test.mk @@ -0,0 +1,350 @@ +#=============================================================================== +# Testing has become a rather big and interconnected topic and that's why it +# has arrived in it's own file. +# +# We have to types of tests available: +# +# 1. unit tests +# +# The unit tests can be executed fairly simply be running `go test` +# +# Usage +# ----- +# If you want to run the unit tests, type +# +# $ make test-unit +# +# +# To run all tests, type +# +# $ make test-all +# +# To output unit-test coverage profile information for each function, type +# +# $ make coverage-unit +# +# To generate unit-test HTML representation of coverage profile (opens a browser), type +# +# $ make coverage-unit-html +# +# +# To output all coverage profile information for each function, type +# +# $ make coverage-all +# +# Artifacts and coverage modes +# ---------------------------- +# Each package generates coverage outputs under tmp/coverage/$(PACKAGE) where +# $(PACKAGE) resolves to the Go package. Here's an example of a coverage file +# for the package "github.com/fabric8-services/fabric8-auth/models" with coverage mode +# "set" generated by the unit tests: +# +# tmp/coverage/github.com/fabric8-services/fabric8-auth/models/coverage.unit.mode-set +# +# For unit-tests all results are combined into this file: +# +# tmp/coverage.unit.mode-$(COVERAGE_MODE) +# +# +# The overall coverage gets combined into this file: +# +# tmp/coverage.mode-$(COVERAGE_MODE) +# +# The $(COVERAGE_MODE) in each filename indicates what coverage mode was used. +# +# These are possible coverage modes (see https://blog.golang.org/cover): +# +# set: did each statement run? (default) +# count: how many times did each statement run? +# atomic: like count, but counts precisely in parallel programs +# +# To choose another coverage mode, simply prefix the invovation of `make`: +# +# $ COVERAGE_MODE=count make test-unit +#=============================================================================== + +# mode can be: set, count, or atomic +COVERAGE_MODE ?= set + +# By default no go test calls will use the -v switch when running tests. +# But if you want you can enable that by setting GO_TEST_VERBOSITY_FLAG=-v +GO_TEST_VERBOSITY_FLAG ?= + + +# By default reduce the amount of log output from tests +ADMIN_LOG_LEVEL ?= error + +# Output directory for coverage information +COV_DIR = $(TMP_PATH)/coverage + +# Files that combine package coverages for unit tests separately +COV_PATH_UNIT = $(TMP_PATH)/coverage.unit.mode-$(COVERAGE_MODE) + +# File that stores overall coverge for all packages and unit-tests +COV_PATH_OVERALL = $(TMP_PATH)/coverage.mode-$(COVERAGE_MODE) + +# This pattern excludes some folders from the coverage calculation (see grep -v) +ALL_PKGS_EXCLUDE_PATTERN = 'vendor\|app\|tool\/cli\|design\|client\|test' + +# This pattern excludes some folders from the go code analysis +GOANALYSIS_PKGS_EXCLUDE_PATTERN="vendor|app|client|tool/cli" +GOANALYSIS_DIRS=$(shell go list -f {{.Dir}} ./... | grep -v -E $(GOANALYSIS_PKGS_EXCLUDE_PATTERN)) + +#------------------------------------------------------------------------------- +# Normal test targets +# +# These test targets are the ones that will be invoked from the outside. If +# they are called and the artifacts already exist, then the artifacts will +# first be cleaned and recreated. This ensures that the tests are always +# executed. +#------------------------------------------------------------------------------- + +.PHONY: test-all +## Runs the test-unit targets. +test-all: prebuild-check test-unit + +.PHONY: test-unit-with-coverage +# Runs the unit tests and produces coverage files for each package. +test-unit-with-coverage: prebuild-check clean-coverage-unit $(COV_PATH_UNIT) + +.PHONY: test-unit +## Runs the unit tests and WITHOUT producing coverage files for each package. +test-unit: prebuild-check $(SOURCES) + $(call log-info,"Running test: $@") + $(eval TEST_PACKAGES:=$(shell go list ./... | grep -v $(ALL_PKGS_EXCLUDE_PATTERN))) + ADMIN_LOG_LEVEL=$(ADMIN_LOG_LEVEL) go test -vet off $(GO_TEST_VERBOSITY_FLAG) $(TEST_PACKAGES) + +.PHONY: test-e2e +## Runs the e2e tests and WITHOUT producing coverage files for each package. +test-e2e: build build-image e2e-setup + $(call log-info,"Running E2E test: $@") + go test ./test/e2e/... -root=$(PWD) -kubeconfig=$(HOME)/.kube/config -globalMan deploy/test/global-manifests.yaml -namespacedMan deploy/test/namespace-manifests.yaml -v -parallel=1 -singleNamespace + +.PHONY: e2e-setup +e2e-setup: e2e-cleanup + oc new-project devconsole-e2e-test || true + +.PHONY: e2e-cleanup +e2e-cleanup: + oc login -u system:admin + oc delete oauthclient codeready-devconsole || true + oc delete clusterrolebinding devconsole-enabler || true + oc delete clusterrole devconsole-enabler || true + oc delete project devconsole-e2e-test || true + +#------------------------------------------------------------------------------- +# Inspect coverage of unit tests, integration tests in either pure +# console mode or in a browser (*-html). +# +# If the test coverage files to be evaluated already exist, then no new +# tests are executed. If they don't exist, we first run the tests. +#------------------------------------------------------------------------------- + +# Prints the total coverage of a given package. +# The total coverage is printed as the last argument in the +# output of "go tool cover". If the requested test name (first argument) +# Is *, then unit, integration tests will be combined +define print-package-coverage +$(eval TEST_NAME:=$(1)) +$(eval PACKAGE_NAME:=$(2)) +$(eval COV_FILE:="$(COV_DIR)/$(PACKAGE_NAME)/coverage.$(TEST_NAME).mode-$(COVERAGE_MODE)") + @if [ "$(TEST_NAME)" == "*" ]; then \ + UNIT_FILE=`echo $(COV_FILE) | sed 's/*/unit/'`; \ + INTEGRATON_FILE=`echo $(COV_FILE) | sed 's/*/integration/'`; \ + COV_FILE=`echo $(COV_FILE) | sed 's/*/combined/'`; \ + if [ ! -e $${UNIT_FILE} ]; then \ + COV_FILE=$${INTEGRATION_FILE}; \ + else \ + if [ ! -e $${INTEGRATION_FILE} ]; then \ + COV_FILE=$${UNIT_FILE}; \ + else \ + $(GOCOVMERGE_BIN) $${UNIT_FILE} $${INTEGRATION_FILE} > $${COV_FILE}; \ + fi; \ + fi; \ +else \ + COV_FILE=$(COV_FILE); \ +fi; \ +if [ -e "$${COV_FILE}" ]; then \ + VAL=`go tool cover -func=$${COV_FILE} \ + | grep '^total:' \ + | grep '\S\+$$' -o \ + | sed 's/%//'`; \ + printf "%-80s %#5.2f%%\n" "$(PACKAGE_NAME)" "$${VAL}"; \ +else \ + printf "%-80s %6s\n" "$(PACKAGE_NAME)" "n/a"; \ +fi +endef + +# Iterates over every package and prints its test coverage +# for a given test name ("unit"). +define package-coverage +$(eval TEST_NAME:=$(1)) +@printf "\n\nPackage coverage:\n" +$(eval TEST_PACKAGES:=$(shell go list ./... | grep -v $(ALL_PKGS_EXCLUDE_PATTERN))) +$(foreach package, $(TEST_PACKAGES), $(call print-package-coverage,$(TEST_NAME),$(package))) +endef + +$(COV_PATH_OVERALL): $(GOCOVMERGE_BIN) + @$(GOCOVMERGE_BIN) $(COV_PATH_UNIT) > $(COV_PATH_OVERALL) + +# Console coverage output: + +# First parameter: file to do in-place replacement with. +define cleanup-coverage-file +@sed -i '/.*\/sqlbindata\.go.*/d' $(1) +@sed -i '/.*\/confbindata\.go.*/d' $(1) +endef + +.PHONY: coverage-unit +# Output coverage profile information for each function (only based on unit-tests). +# Re-runs unit-tests if coverage information is outdated. +coverage-unit: prebuild-check $(COV_PATH_UNIT) + $(call cleanup-coverage-file,$(COV_PATH_UNIT)) + @go tool cover -func=$(COV_PATH_UNIT) + $(call package-coverage,unit) + + +.PHONY: coverage-all +# Output coverage profile information for each function. +# Re-runs unit- and integration-tests if coverage information is outdated. +coverage-all: prebuild-check clean-coverage-overall $(COV_PATH_OVERALL) + $(call cleanup-coverage-file,$(COV_PATH_OVERALL)) + @go tool cover -func=$(COV_PATH_OVERALL) + $(call package-coverage,*) + +# HTML coverage output: + +.PHONY: coverage-unit-html +# Generate HTML representation (and show in browser) of coverage profile (based on unit tests). +# Re-runs unit tests if coverage information is outdated. +coverage-unit-html: prebuild-check $(COV_PATH_UNIT) + $(call cleanup-coverage-file,$(COV_PATH_UNIT)) + @go tool cover -html=$(COV_PATH_UNIT) + +.PHONY: coverage-all-html +# Output coverage profile information for each function. +# Re-runs unit if coverage information is outdated. +coverage-all-html: prebuild-check clean-coverage-overall $(COV_PATH_OVERALL) + $(call cleanup-coverage-file,$(COV_PATH_OVERALL)) + @go tool cover -html=$(COV_PATH_OVERALL) + +# Experimental: + +.PHONY: gocov-unit-annotate +# (EXPERIMENTAL) Show actual code and how it is covered with unit tests. +# This target only runs the tests if the coverage file does exist. +gocov-unit-annotate: prebuild-check $(GOCOV_BIN) $(COV_PATH_UNIT) + $(call cleanup-coverage-file,$(COV_PATH_UNIT)) + @$(GOCOV_BIN) convert $(COV_PATH_UNIT) | $(GOCOV_BIN) annotate - + +.PHONY: .gocov-unit-report +.gocov-unit-report: prebuild-check $(GOCOV_BIN) $(COV_PATH_UNIT) + $(call cleanup-coverage-file,$(COV_PATH_UNIT)) + @$(GOCOV_BIN) convert $(COV_PATH_UNIT) | $(GOCOV_BIN) report + + +#------------------------------------------------------------------------------- +# Test artifacts are coverage files for unit and integration tests. +#------------------------------------------------------------------------------- + +# The test-package function executes tests for a package and saves the collected +# coverage output to a directory. After storing the coverage information it is +# also appended to a file of choice (without the "mode"-line) +# +# Parameters: +# 1. Test name (e.g. "unit" or "integration") +# 2. package name "github.com/fabric8-services/fabric8-auth/model" +# 3. File in which to combine the output +# 4. Path to file in which to store names of packages that failed testing +# 5. Environment variable (in the form VAR=VALUE) to be specified for running +# the test. For multiple environment variables, pass "VAR1=VAL1 VAR2=VAL2". +define test-package +$(eval TEST_NAME := $(1)) +$(eval PACKAGE_NAME := $(2)) +$(eval COMBINED_OUT_FILE := $(3)) +$(eval ERRORS_FILE := $(4)) +$(eval ENV_VAR := $(5)) +$(eval ALL_PKGS_COMMA_SEPARATED := $(6)) +@mkdir -p $(COV_DIR)/$(PACKAGE_NAME); +$(eval COV_OUT_FILE := $(COV_DIR)/$(PACKAGE_NAME)/coverage.$(TEST_NAME).mode-$(COVERAGE_MODE)) +@$(ENV_VAR) ADMIN_LOG_LEVEL=$(ADMIN_LOG_LEVEL) \ + go test -vet off $(PACKAGE_NAME) \ + $(GO_TEST_VERBOSITY_FLAG) \ + -coverprofile $(COV_OUT_FILE) \ + -coverpkg $(ALL_PKGS_COMMA_SEPARATED) \ + -covermode=$(COVERAGE_MODE) \ + -timeout 10m \ + $(EXTRA_TEST_PARAMS) \ + || echo $(PACKAGE_NAME) >> $(ERRORS_FILE) + +@if [ -e "$(COV_OUT_FILE)" ]; then \ + if [ ! -e "$(COMBINED_OUT_FILE)" ]; then \ + cp $(COV_OUT_FILE) $(COMBINED_OUT_FILE); \ + else \ + cp $(COMBINED_OUT_FILE) $(COMBINED_OUT_FILE).tmp; \ + $(GOCOVMERGE_BIN) $(COV_OUT_FILE) $(COMBINED_OUT_FILE).tmp > $(COMBINED_OUT_FILE); \ + fi \ +fi +endef + +# Exits the makefile with an error if the file (first parameter) exists. +# Before exiting, the contents of the passed file is printed. +define check-test-results +$(eval ERRORS_FILE := $(1)) +@if [ -e "$(ERRORS_FILE)" ]; then \ +echo ""; \ +echo "ERROR: The following packages did not pass the tests:"; \ +echo "-----------------------------------------------------"; \ +cat $(ERRORS_FILE); \ +echo "-----------------------------------------------------"; \ +echo ""; \ +exit 1; \ +fi +endef + +# NOTE: We don't have prebuild-check as a dependency here because it would cause +# the recipe to be always executed. +$(COV_PATH_UNIT): $(SOURCES) $(GOCOVMERGE_BIN) + $(eval TEST_NAME := unit) + $(eval ERRORS_FILE := $(TMP_PATH)/errors.$(TEST_NAME)) + $(call log-info,"Running test: $(TEST_NAME)") + @mkdir -p $(COV_DIR) + @echo "mode: $(COVERAGE_MODE)" > $(COV_PATH_UNIT) + @-rm -f $(ERRORS_FILE) + $(eval TEST_PACKAGES:=$(shell go list ./... | grep -v $(ALL_PKGS_EXCLUDE_PATTERN))) + $(eval ALL_PKGS_COMMA_SEPARATED:=$(shell echo $(TEST_PACKAGES) | tr ' ' ,)) + $(foreach package, $(TEST_PACKAGES), $(call test-package,$(TEST_NAME),$(package),$(COV_PATH_UNIT),$(ERRORS_FILE),,$(ALL_PKGS_COMMA_SEPARATED))) + $(call check-test-results,$(ERRORS_FILE)) + +#------------------------------------------------------------------------------- +# Additional tools to build +#------------------------------------------------------------------------------- + +$(GOCOV_BIN): prebuild-check + @cd $(VENDOR_DIR)/github.com/axw/gocov/gocov/ && go build + +$(GOCOVMERGE_BIN): prebuild-check + @cd $(VENDOR_DIR)/github.com/wadey/gocovmerge && go build + + +#------------------------------------------------------------------------------- +# Clean targets +#------------------------------------------------------------------------------- + +CLEAN_TARGETS += clean-coverage +.PHONY: clean-coverage +# Removes all coverage files +clean-coverage: clean-coverage-unit clean-coverage-overall + -@rm -rf $(COV_DIR) + +CLEAN_TARGETS += clean-coverage-overall +.PHONY: clean-coverage-overall +# Removes overall coverage file +clean-coverage-overall: + -@rm -f $(COV_PATH_OVERALL) + +CLEAN_TARGETS += clean-coverage-unit +.PHONY: clean-coverage-unit +# Removes unit test coverage file +clean-coverage-unit: + -@rm -f $(COV_PATH_UNIT) diff --git a/pkg/controller/envdeployment/envdeployment_controller_test.go b/pkg/controller/envdeployment/envdeployment_controller_test.go new file mode 100644 index 0000000..19da5e7 --- /dev/null +++ b/pkg/controller/envdeployment/envdeployment_controller_test.go @@ -0,0 +1,16 @@ +package envdeployment + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestExample(t *testing.T) { + + require.True(t, true) + + t.Run("subtest example", func(t *testing.T) { + require.True(t, true) + }) +} \ No newline at end of file diff --git a/test/README.md b/test/README.md new file mode 100644 index 0000000..a17d56d --- /dev/null +++ b/test/README.md @@ -0,0 +1,27 @@ +## E2E Tests + +E2E tests are verifying successful deployment of the DevOps Console Operator and creation of self-provisioning service account. + +### How to Run + +#### TL;DR + +``` +make minishift-start +eval $(minishift docker-env) +make test-e2e +``` + +Make sure that you have minishift running. you can check it using `minishift status`. If not then start it using `make minishift-start` target. + +After successfully starting minishift, configure your shell to use docker daemon from minishift using `eval $(minishift docker-env)`. + +Now it's time to run E2E tests for `devopsconsole-operator` which will create it's required resources from `deploy/test/` on OpenShift use following command: + +``` +make test-e2e +``` + +This make target is building new docker image `$(DOCKER_REPO)/$(IMAGE_NAME):test`(e.g. `quay.io/openshiftio/devopsconsole-operator:test`) which is used in the operator's deployment manifests in e2e tests. + +Also remember that it uses the `system:admin` account for creating all required resources from `deploy/test` directory. \ No newline at end of file diff --git a/test/e2e/example_test.go b/test/e2e/example_test.go new file mode 100644 index 0000000..e43815e --- /dev/null +++ b/test/e2e/example_test.go @@ -0,0 +1,26 @@ +package e2e + +import ( + "testing" + + //framework "github.com/operator-framework/operator-sdk/pkg/test" + //"github.com/operator-framework/operator-sdk/pkg/test/e2eutil" + //"github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + //"golang.org/x/net/context" + //metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestExample(t *testing.T) { + + require.True(t, true) + + // get global framework variables + //f := framework.Global + + // this is a unit test stub, add tests here + + t.Run("subtest example", func(t *testing.T) { + require.True(t, true) + }) +} diff --git a/test/e2e/main_test.go b/test/e2e/main_test.go new file mode 100644 index 0000000..68218e3 --- /dev/null +++ b/test/e2e/main_test.go @@ -0,0 +1,11 @@ +package e2e + +import ( + "testing" + + framework "github.com/operator-framework/operator-sdk/pkg/test" +) + +func TestMain(m *testing.M) { + framework.MainEntry(m) +} \ No newline at end of file From 98d2b3f949673203dbca13e17b8c3b9ec9863e13 Mon Sep 17 00:00:00 2001 From: Michael Kleinhenz Date: Fri, 15 Feb 2019 11:16:03 +0100 Subject: [PATCH 2/3] Exposed more targets, removed windows make code, checked coverage, minor fixes. --- Gopkg.lock | 229 +++++++++++++++--- Gopkg.toml | 4 + Makefile | 45 ++-- make/Makefile.lnx | 12 - make/Makefile.win | 11 - make/check_gopath.go | 46 ---- make/docker.mk | 4 +- make/test.mk | 18 +- .../envdeployment_controller_test.go | 2 +- test/e2e/main_test.go | 2 +- 10 files changed, 230 insertions(+), 143 deletions(-) delete mode 100644 make/Makefile.lnx delete mode 100644 make/Makefile.win delete mode 100644 make/check_gopath.go diff --git a/Gopkg.lock b/Gopkg.lock index 9be5adc..55e3346 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,242 +2,297 @@ [[projects]] + digest = "1:315ee4e58738f41b338a701e8acb4e991f6d30737c2ae757d2087a1d28d72810" name = "cloud.google.com/go" packages = ["compute/metadata"] + pruneopts = "NT" revision = "28a4bc8c44b3acbcc482cff0cdf7de29a4688b61" version = "v0.35.1" [[projects]] + digest = "1:75d2b55b13298745ec068057251d05d65bbae0a668201fe45ad6986551a55601" name = "github.com/BurntSushi/toml" packages = ["."] + pruneopts = "NT" revision = "3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005" version = "v0.3.1" [[projects]] + digest = "1:d8ebbd207f3d3266d4423ce4860c9f3794956306ded6c7ba312ecc69cdfbf04c" name = "github.com/PuerkitoBio/purell" packages = ["."] + pruneopts = "NT" revision = "0bcb03f4b4d0a9428594752bd2a3b9aa0a9d4bd4" version = "v1.1.0" [[projects]] branch = "master" + digest = "1:8098cd40cd09879efbf12e33bcd51ead4a66006ac802cd563a66c4f3373b9727" name = "github.com/PuerkitoBio/urlesc" packages = ["."] + pruneopts = "NT" revision = "de5bf2ad457846296e2031421a34e2568e304e35" [[projects]] - branch = "master" - name = "github.com/alexeykazakov/devconsole" - packages = [ - "pkg/apis", - "pkg/apis/clusterregistry/v1alpha1", - "pkg/apis/devconsole/v1alpha1", - "pkg/controller", - "pkg/controller/envdeployment" - ] - revision = "0b82a3bcdf453edf0b4b8f499bfd4ccbdaa148eb" - -[[projects]] + digest = "1:4b8b5811da6970495e04d1f4e98bb89518cc3cfc3b3f456bdb876ed7b6c74049" name = "github.com/davecgh/go-spew" packages = ["spew"] + pruneopts = "NT" revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73" version = "v1.1.1" [[projects]] + digest = "1:3f718788c59f3ec687bcc963cb6034a132327387784c8c04392abaaea9ad7498" name = "github.com/emicklei/go-restful" packages = [ ".", - "log" + "log", ] + pruneopts = "NT" revision = "e37671aced663c8d3a395bd301857e26dcf4340c" version = "v2.8.1" [[projects]] + digest = "1:81466b4218bf6adddac2572a30ac733a9255919bc2f470b4827a317bd4ee1756" name = "github.com/ghodss/yaml" packages = ["."] + pruneopts = "NT" revision = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7" version = "v1.0.0" [[projects]] branch = "master" + digest = "1:d421af4c4fe51d399667d573982d663fe1fa67020a88d3ae43466ebfe8e2b5c9" name = "github.com/go-logr/logr" packages = ["."] + pruneopts = "NT" revision = "9fb12b3b21c5415d16ac18dc5cd42c1cfdd40c4e" [[projects]] + digest = "1:340497a512995aa69c0add901d79a2096b3449d35a44a6f1f1115091a9f8c687" name = "github.com/go-logr/zapr" packages = ["."] + pruneopts = "NT" revision = "7536572e8d55209135cd5e7ccf7fce43dca217ab" version = "v0.1.0" [[projects]] + digest = "1:260f7ebefc63024c8dfe2c9f1a2935a89fa4213637a1f522f592f80c001cc441" name = "github.com/go-openapi/jsonpointer" packages = ["."] + pruneopts = "NT" revision = "ef5f0afec364d3b9396b7b77b43dbe26bf1f8004" version = "v0.18.0" [[projects]] + digest = "1:98abd61947ff5c7c6fcfec5473d02a4821ed3a2dd99a4fbfdb7925b0dd745546" name = "github.com/go-openapi/jsonreference" packages = ["."] + pruneopts = "NT" revision = "8483a886a90412cd6858df4ea3483dce9c8e35a3" version = "v0.18.0" [[projects]] + digest = "1:4da4ea0a664ba528965683d350f602d0f11464e6bb2e17aad0914723bc25d163" name = "github.com/go-openapi/spec" packages = ["."] + pruneopts = "NT" revision = "5b6cdde3200976e3ecceb2868706ee39b6aff3e4" version = "v0.18.0" [[projects]] + digest = "1:dc0f590770e5a6c70ea086232324f7b7dc4857c60eca63ab8ff78e0a5cfcdbf3" name = "github.com/go-openapi/swag" packages = ["."] + pruneopts = "NT" revision = "1d29f06aebd59ccdf11ae04aa0334ded96e2d909" version = "v0.18.0" [[projects]] + digest = "1:9059915429f7f3a5f18cfa6b7cab9a28721d7ac6db4079a62044aa229eb7f2a8" name = "github.com/gobuffalo/envy" packages = ["."] + pruneopts = "NT" revision = "fa0dfdc10b5366ce365b7d9d1755a03e4e797bc5" version = "v1.6.15" [[projects]] + digest = "1:932970e69f16e127aa0653b8263ae588cd127fa53273e19ba44332902c9826f2" name = "github.com/gogo/protobuf" packages = [ "proto", - "sortkeys" + "sortkeys", ] + pruneopts = "NT" revision = "4cbf7e384e768b4e01799441fdf2a706a5635ae7" version = "v1.2.0" [[projects]] branch = "master" + digest = "1:e2b86e41f3d669fc36b50d31d32d22c8ac656c75aa5ea89717ce7177e134ff2a" name = "github.com/golang/glog" packages = ["."] + pruneopts = "NT" revision = "23def4e6c14b4da8ac2ed8007337bc5eb5007998" [[projects]] branch = "master" + digest = "1:20b774dcfdf0fff3148432beb828c52404f3eb3d70b7ce71ae0356ed6cbc2bae" name = "github.com/golang/groupcache" packages = ["lru"] + pruneopts = "NT" revision = "5b532d6fd5efaf7fa130d4e859a2fde0fc3a9e1b" [[projects]] + digest = "1:d7cb4458ea8782e6efacd8f4940796ec559c90833509c436f40c4085b98156dd" name = "github.com/golang/protobuf" packages = [ "proto", "ptypes", "ptypes/any", "ptypes/duration", - "ptypes/timestamp" + "ptypes/timestamp", ] + pruneopts = "NT" revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5" version = "v1.2.0" [[projects]] branch = "master" + digest = "1:05f95ffdfcf651bdb0f05b40b69e7f5663047f8da75c72d58728acb59b5cc107" name = "github.com/google/btree" packages = ["."] + pruneopts = "NT" revision = "4030bb1f1f0c35b30ca7009e9ebd06849dd45306" [[projects]] branch = "master" + digest = "1:52c5834e2bebac9030c97cc0798ac11c3aa8a39f098aeb419f142533da6cd3cc" name = "github.com/google/gofuzz" packages = ["."] + pruneopts = "NT" revision = "24818f796faf91cd76ec7bddd72458fbced7a6c1" [[projects]] + digest = "1:56a1f3949ebb7fa22fa6b4e4ac0fe0f77cc4faee5b57413e6fa9199a8458faf1" name = "github.com/google/uuid" packages = ["."] + pruneopts = "NT" revision = "9b3b1e0f5f99ae461456d768e7d301a7acdaa2d8" version = "v1.1.0" [[projects]] + digest = "1:289332c13b80edfefc88397cce5266c16845dcf204fa2f6ac7e464ee4c7f6e96" name = "github.com/googleapis/gnostic" packages = [ "OpenAPIv2", "compiler", - "extensions" + "extensions", ] + pruneopts = "NT" revision = "7c663266750e7d82587642f65e60bc4083f1f84e" version = "v0.2.0" [[projects]] branch = "master" + digest = "1:97972f03fbf34ec4247ddc78ddb681389c468c020492aa32b109744a54fc0c14" name = "github.com/gregjones/httpcache" packages = [ ".", - "diskcache" + "diskcache", ] + pruneopts = "NT" revision = "c63ab54fda8f77302f8d414e19933f2b6026a089" [[projects]] + digest = "1:b42cde0e1f3c816dd57f57f7bbcf05ca40263ad96f168714c130c611fc0856a6" name = "github.com/hashicorp/golang-lru" packages = [ ".", - "simplelru" + "simplelru", ] + pruneopts = "NT" revision = "20f1fb78b0740ba8c3cb143a61e86ba5c8669768" version = "v0.5.0" [[projects]] + digest = "1:aaa38889f11896ee3644d77e17dc7764cc47f5f3d3b488268df2af2b52541c5f" name = "github.com/imdario/mergo" packages = ["."] + pruneopts = "NT" revision = "7c29201646fa3de8506f701213473dd407f19646" version = "v0.3.7" [[projects]] + digest = "1:f5b9328966ccea0970b1d15075698eff0ddb3e75889560aad2e9f76b289b536a" name = "github.com/joho/godotenv" packages = ["."] + pruneopts = "NT" revision = "23d116af351c84513e1946b527c88823e476be13" version = "v1.3.0" [[projects]] + digest = "1:1d39c063244ad17c4b18e8da1551163b6ffb52bd1640a49a8ec5c3b7bf4dbd5d" name = "github.com/json-iterator/go" packages = ["."] + pruneopts = "NT" revision = "1624edc4454b8682399def8740d46db5e4362ba4" version = "v1.1.5" [[projects]] + digest = "1:4059c14e87a2de3a434430340521b5feece186c1469eff0834c29a63870de3ed" name = "github.com/konsorten/go-windows-terminal-sequences" packages = ["."] + pruneopts = "NT" revision = "5c8c8bd35d3832f5d134ae1e1e375b69a4d25242" version = "v1.0.1" [[projects]] branch = "master" + digest = "1:7d9fcac7f1228470c4ea0ee31cdfb662a758c44df691e39b3e76c11d3e12ba8f" name = "github.com/mailru/easyjson" packages = [ "buffer", "jlexer", - "jwriter" + "jwriter", ] + pruneopts = "NT" revision = "60711f1a8329503b04e1c88535f419d0bb440bff" [[projects]] + digest = "1:56dbf15e091bf7926cb33a57cb6bdfc658fc6d3498d2f76f10a97ce7856f1fde" name = "github.com/markbates/inflect" packages = ["."] + pruneopts = "NT" revision = "24b83195037b3bc61fcda2d28b7b0518bce293b6" version = "v1.0.4" [[projects]] branch = "master" + digest = "1:0e9bfc47ab9941ecc3344e580baca5deb4091177e84dd9773b48b38ec26b93d5" name = "github.com/mattbaird/jsonpatch" packages = ["."] + pruneopts = "NT" revision = "81af80346b1a01caae0cbc27fd3c1ba5b11e189f" [[projects]] + digest = "1:2f42fa12d6911c7b7659738758631bec870b7e9b4c6be5444f963cdcfccc191f" name = "github.com/modern-go/concurrent" packages = ["."] + pruneopts = "NT" revision = "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94" version = "1.0.3" [[projects]] + digest = "1:c6aca19413b13dc59c220ad7430329e2ec454cc310bc6d8de2c7e2b93c18a0f6" name = "github.com/modern-go/reflect2" packages = ["."] + pruneopts = "NT" revision = "4b7aa43c6742a2c18fdef89dd197aaae7dac7ccd" version = "1.0.1" [[projects]] + digest = "1:b186c2fcf87d05c5129ad0d89ea062853b0bdf6d6bca1ed4a22157962f2ad8dd" name = "github.com/operator-framework/operator-sdk" packages = [ "internal/util/fileutil", @@ -248,88 +303,112 @@ "pkg/scaffold", "pkg/scaffold/input", "pkg/test", - "version" + "version", ] + pruneopts = "NT" revision = "d6541603f2219f33966078a087732ecfc7a1dde5" version = "v0.2.1" [[projects]] + digest = "1:93b1d84c5fa6d1ea52f4114c37714cddd84d5b78f151b62bb101128dd51399bf" name = "github.com/pborman/uuid" packages = ["."] + pruneopts = "NT" revision = "adf5a7427709b9deb95d29d3fa8a2bf9cfd388f1" version = "v1.2" [[projects]] branch = "master" + digest = "1:bf2ac97824a7221eb16b096aecc1c390d4c8a4e49524386aaa2e2dd215cbfb31" name = "github.com/petar/GoLLRB" packages = ["llrb"] + pruneopts = "NT" revision = "53be0d36a84c2a886ca057d34b6aa4468df9ccb4" [[projects]] + digest = "1:e4e9e026b8e4c5630205cd0208efb491b40ad40552e57f7a646bb8a46896077b" name = "github.com/peterbourgon/diskv" packages = ["."] + pruneopts = "NT" revision = "5f041e8faa004a95c88a202771f4cc3e991971e6" version = "v2.0.1" [[projects]] + digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" name = "github.com/pmezard/go-difflib" packages = ["difflib"] + pruneopts = "NT" revision = "792786c7400a136282c1664665ae0a8db921c6c2" version = "v1.0.0" [[projects]] + digest = "1:fcef1ce61da6f8f6f115154fb0e0e5b159fe11656839ba1e6061372711c013ee" name = "github.com/rogpeppe/go-internal" packages = [ "modfile", "module", - "semver" + "semver", ] + pruneopts = "NT" revision = "1cf9852c553c5b7da2d5a4a091129a7822fed0c9" version = "v1.2.2" [[projects]] + digest = "1:1f84287a4ca2c8f729d8155ba4c45915f5854ebbd214e406070779753da68422" name = "github.com/sirupsen/logrus" packages = ["."] + pruneopts = "NT" revision = "e1e72e9de974bd926e5c56f83753fba2df402ce5" version = "v1.3.0" [[projects]] + digest = "1:1bc08ec221c4fb25e6f2c019b23fe989fb44573c696983d8e403a3b76cc378e1" name = "github.com/spf13/afero" packages = [ ".", - "mem" + "mem", ] + pruneopts = "NT" revision = "f4711e4db9e9a1d3887343acb72b2bbfc2f686f5" version = "v1.2.1" [[projects]] + digest = "1:9d8420bbf131d1618bde6530af37c3799340d3762cc47210c1d9532a4c3a2779" name = "github.com/spf13/pflag" packages = ["."] + pruneopts = "NT" revision = "298182f68c66c05229eb03ac171abe6e309ee79a" version = "v1.0.3" [[projects]] + digest = "1:8e8fc2cb42cfa0a18fda0c9c4034092faa7aac773da5efdde8828eb4b96c001d" name = "github.com/stretchr/testify" packages = [ "assert", - "require" + "require", ] + pruneopts = "NT" revision = "ffdc059bfe9ce6a4e144ba849dbedead332c6053" version = "v1.3.0" [[projects]] + digest = "1:22f696cee54865fb8e9ff91df7b633f6b8f22037a8015253c6b6a71ca82219c7" name = "go.uber.org/atomic" packages = ["."] + pruneopts = "NT" revision = "1ea20fb1cbb1cc08cbd0d913a96dead89aa18289" version = "v1.3.2" [[projects]] + digest = "1:58ca93bdf81bac106ded02226b5395a0595d5346cdc4caa8d9c1f3a5f8f9976e" name = "go.uber.org/multierr" packages = ["."] + pruneopts = "NT" revision = "3c4937480c32f4c13a875a1829af76c98ca3d40a" version = "v1.1.0" [[projects]] + digest = "1:572fa4496563920f3e3107a2294cf2621d6cc4ffd03403fb6397b1bab9fa082a" name = "go.uber.org/zap" packages = [ ".", @@ -337,19 +416,23 @@ "internal/bufferpool", "internal/color", "internal/exit", - "zapcore" + "zapcore", ] + pruneopts = "NT" revision = "ff33455a0e382e8a81d14dd7c922020b6b5e7982" version = "v1.9.1" [[projects]] branch = "master" + digest = "1:23e299b9877c8592668486c61668132f954875f29633269874c592c3ea94ee92" name = "golang.org/x/crypto" packages = ["ssh/terminal"] + pruneopts = "NT" revision = "ccddf3741a0cfcee0a62d34c18c2c5417a3761af" [[projects]] branch = "master" + digest = "1:4010b78f0ab4fcc3ff81e30e6dba92fa68b8520df8dd21b393481fd791360b21" name = "golang.org/x/net" packages = [ "context", @@ -357,32 +440,38 @@ "http/httpguts", "http2", "http2/hpack", - "idna" + "idna", ] + pruneopts = "NT" revision = "d26f9f9a57f3fab6a695bec0d84433c2c50f8bbf" [[projects]] branch = "master" + digest = "1:9a9a8b8635685e9e4ff68c80bebf00726f5019fb41da508a56df54e6e7277eeb" name = "golang.org/x/oauth2" packages = [ ".", "google", "internal", "jws", - "jwt" + "jwt", ] + pruneopts = "NT" revision = "5dab4167f31cbd76b407f1486c86b40748bc5073" [[projects]] branch = "master" + digest = "1:680783030e10a31a8c2deb6f0860f13878295b5458908f4395868e1dbbfe6a87" name = "golang.org/x/sys" packages = [ "unix", - "windows" + "windows", ] + pruneopts = "NT" revision = "302c3dd5f1cc82baae8e44d9c3178e89b6e2b345" [[projects]] + digest = "1:8c74f97396ed63cc2ef04ebb5fc37bb032871b8fd890a25991ed40974b00cd2a" name = "golang.org/x/text" packages = [ "collate", @@ -399,19 +488,23 @@ "unicode/cldr", "unicode/norm", "unicode/rangetable", - "width" + "width", ] + pruneopts = "NT" revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" version = "v0.3.0" [[projects]] branch = "master" + digest = "1:9fdc2b55e8e0fafe4b41884091e51e77344f7dc511c5acedcfd98200003bff90" name = "golang.org/x/time" packages = ["rate"] + pruneopts = "NT" revision = "85acf8d2951cb2a3bde7632f9ff273ef0379bcbd" [[projects]] branch = "master" + digest = "1:9f9a9dbf521c3a339ac0b595f8718191a0b36929ff8ca05714d6863fcef088ec" name = "golang.org/x/tools" packages = [ "go/ast/astutil", @@ -425,11 +518,13 @@ "internal/fastwalk", "internal/gopathwalk", "internal/module", - "internal/semver" + "internal/semver", ] + pruneopts = "NT" revision = "9cefa6771f8f3c72b346adb1995b7432464d4038" [[projects]] + digest = "1:902ffa11f1d8c19c12b05cabffe69e1a16608ad03a8899ebcb9c6bde295660ae" name = "google.golang.org/appengine" packages = [ ".", @@ -441,24 +536,30 @@ "internal/modules", "internal/remote_api", "internal/urlfetch", - "urlfetch" + "urlfetch", ] + pruneopts = "NT" revision = "e9657d882bb81064595ca3b56cbe2546bbabf7b1" version = "v1.4.0" [[projects]] + digest = "1:2d1fbdc6777e5408cabeb02bf336305e724b925ff4546ded0fa8715a7267922a" name = "gopkg.in/inf.v0" packages = ["."] + pruneopts = "NT" revision = "d2d2541c53f18d2a059457998ce2876cc8e67cbf" version = "v0.9.1" [[projects]] + digest = "1:18108594151654e9e696b27b181b953f9a90b16bf14d253dd1b397b025a1487f" name = "gopkg.in/yaml.v2" packages = ["."] + pruneopts = "NT" revision = "51d6538a90f86fe93ac480b35f37b2be17fef232" version = "v2.2.2" [[projects]] + digest = "1:f11e5753e619f411a51a49d60d39b2bc4da6766f5f0af2e2291daa6a3d9385d5" name = "k8s.io/api" packages = [ "admission/v1beta1", @@ -490,20 +591,24 @@ "settings/v1alpha1", "storage/v1", "storage/v1alpha1", - "storage/v1beta1" + "storage/v1beta1", ] + pruneopts = "NT" revision = "2d6f90ab1293a1fb871cf149423ebb72aa7423aa" [[projects]] + digest = "1:117a407949aaaad9f7fbe3da8d6c2055f2c223ac0cbebd39f47ff71899622a91" name = "k8s.io/apiextensions-apiserver" packages = [ "pkg/apis/apiextensions", "pkg/apis/apiextensions/v1beta1", - "pkg/client/clientset/clientset/scheme" + "pkg/client/clientset/clientset/scheme", ] + pruneopts = "NT" revision = "408db4a50408e2149acbd657bceb2480c13cb0a4" [[projects]] + digest = "1:b07bf863262aae765494d60f0d524483f211b29f9bb27d445a79c13af8676bf2" name = "k8s.io/apimachinery" packages = [ "pkg/api/errors", @@ -547,11 +652,13 @@ "pkg/version", "pkg/watch", "third_party/forked/golang/json", - "third_party/forked/golang/reflect" + "third_party/forked/golang/reflect", ] + pruneopts = "NT" revision = "103fd098999dc9c0c88536f5c9ad2e5da39373ae" [[projects]] + digest = "1:1689a49a3ebc6e379849181f1e0899fccf143cab47586078721818bdcdb712bc" name = "k8s.io/client-go" packages = [ "discovery", @@ -619,11 +726,13 @@ "util/integer", "util/jsonpath", "util/retry", - "util/workqueue" + "util/workqueue", ] + pruneopts = "NT" revision = "1f13a808da65775f22cbf47862c4e5898d8f4ca1" [[projects]] + digest = "1:8ab487a323486c8bbbaa3b689850487fdccc6cbea8690620e083b2d230a4447e" name = "k8s.io/code-generator" packages = [ "cmd/client-gen", @@ -649,12 +758,14 @@ "cmd/lister-gen/generators", "cmd/openapi-gen", "cmd/openapi-gen/args", - "pkg/util" + "pkg/util", ] + pruneopts = "T" revision = "6702109cc68eb6fe6350b83e14407c8d7309fd1a" [[projects]] branch = "master" + digest = "1:4e07c417d966628ee9e471354ad5e311c9c25ff357d42fd0dd2f81a40caf6aad" name = "k8s.io/gengo" packages = [ "args", @@ -664,18 +775,22 @@ "generator", "namer", "parser", - "types" + "types", ] + pruneopts = "NT" revision = "0689ccc1d7d65d9dd1bedcc3b0b1ed7df91ba266" [[projects]] + digest = "1:f3b42f307c7f49a1a7276c48d4b910db76e003220e88797f7acd41e3a9277ddf" name = "k8s.io/klog" packages = ["."] + pruneopts = "NT" revision = "a5bc97fbc634d635061f3146511332c7e313a55a" version = "v0.1.0" [[projects]] branch = "master" + digest = "1:653cd4cf804493513d5ec945e687639e5fe9a1f7adbcf2db5cd21da31a96674e" name = "k8s.io/kube-openapi" packages = [ "cmd/openapi-gen/args", @@ -683,11 +798,13 @@ "pkg/generators", "pkg/generators/rules", "pkg/util/proto", - "pkg/util/sets" + "pkg/util/sets", ] + pruneopts = "NT" revision = "ced9eb3070a5f1c548ef46e8dfe2a97c208d9f03" [[projects]] + digest = "1:a8fb38656b3b59a487e3f74c7d9ad4d90c4f7a3b45413284311f9751b6905448" name = "sigs.k8s.io/controller-runtime" packages = [ "pkg/cache", @@ -715,14 +832,48 @@ "pkg/source/internal", "pkg/webhook/admission", "pkg/webhook/admission/types", - "pkg/webhook/types" + "pkg/webhook/types", ] + pruneopts = "NT" revision = "53fc44b56078cd095b11bd44cfa0288ee4cf718f" version = "v0.1.4" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "4c108157deacc5272699a59206b6be110515a516aae9bb73b4f3267f9b7b403a" + input-imports = [ + "github.com/operator-framework/operator-sdk/pkg/k8sutil", + "github.com/operator-framework/operator-sdk/pkg/leader", + "github.com/operator-framework/operator-sdk/pkg/ready", + "github.com/operator-framework/operator-sdk/pkg/test", + "github.com/operator-framework/operator-sdk/version", + "github.com/stretchr/testify/require", + "k8s.io/api/core/v1", + "k8s.io/apimachinery/pkg/api/errors", + "k8s.io/apimachinery/pkg/apis/meta/v1", + "k8s.io/apimachinery/pkg/runtime", + "k8s.io/apimachinery/pkg/runtime/schema", + "k8s.io/apimachinery/pkg/types", + "k8s.io/client-go/plugin/pkg/client/auth/gcp", + "k8s.io/code-generator/cmd/client-gen", + "k8s.io/code-generator/cmd/conversion-gen", + "k8s.io/code-generator/cmd/deepcopy-gen", + "k8s.io/code-generator/cmd/defaulter-gen", + "k8s.io/code-generator/cmd/informer-gen", + "k8s.io/code-generator/cmd/lister-gen", + "k8s.io/code-generator/cmd/openapi-gen", + "k8s.io/gengo/args", + "sigs.k8s.io/controller-runtime/pkg/client", + "sigs.k8s.io/controller-runtime/pkg/client/config", + "sigs.k8s.io/controller-runtime/pkg/controller", + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil", + "sigs.k8s.io/controller-runtime/pkg/handler", + "sigs.k8s.io/controller-runtime/pkg/manager", + "sigs.k8s.io/controller-runtime/pkg/reconcile", + "sigs.k8s.io/controller-runtime/pkg/runtime/log", + "sigs.k8s.io/controller-runtime/pkg/runtime/scheme", + "sigs.k8s.io/controller-runtime/pkg/runtime/signals", + "sigs.k8s.io/controller-runtime/pkg/source", + ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 46b154c..18679e3 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -56,3 +56,7 @@ required = [ [[constraint]] name = "github.com/stretchr/testify" version = "1.3.0" + +[[constraint]] + branch = "master" + name = "github.com/wadey/gocovmerge" diff --git a/Makefile b/Makefile index a198ab8..4db17a2 100644 --- a/Makefile +++ b/Makefile @@ -8,23 +8,24 @@ INCLUDE_DIR=make SOURCE_DIR ?= . SOURCES := $(shell find $(SOURCE_DIR) -path $(SOURCE_DIR)/vendor -prune -o -name '*.go' -print) -ifeq ($(OS),Windows_NT) - include ./$(INCLUDE_DIR)/Makefile.win -else - include ./$(INCLUDE_DIR)/Makefile.lnx -endif +BINARY_SERVER_BIN=$(INSTALL_PREFIX)/devconsole-operator +GO_BIN_NAME=go +GIT_BIN_NAME=git +DEP_BIN_NAME=dep +DOCKER_BIN_NAME=docker +UNAME_S=$(shell uname -s) +GOCOV_BIN=$(VENDOR_DIR)/github.com/axw/gocov/gocov/gocov +GOCOVMERGE_BIN=$(VENDOR_DIR)/github.com/wadey/gocovmerge/gocovmerge +GOCYCLO_DIR=$(VENDOR_DIR)/github.com/fzipp/gocyclo +GOCYCLO_BIN=$(GOCYCLO_DIR)/gocyclo +GOLANGCI_LINT_BIN_NAME:=golangci-lint # declares variable that are OS-sensitive include ./$(INCLUDE_DIR)/test.mk include ./$(INCLUDE_DIR)/Makefile.dev DOCKER_BIN := $(shell command -v $(DOCKER_BIN_NAME) 2> /dev/null) - -ifneq ($(OS),Windows_NT) - ifdef DOCKER_BIN - include ./$(INCLUDE_DIR)/docker.mk - endif -endif +include ./$(INCLUDE_DIR)/docker.mk # This is a fix for a non-existing user in passwd file when running in a docker # container and trying to clone repos of dependencies @@ -82,7 +83,7 @@ image: clean-artifacts build-linux .PHONY: help # Based on https://gist.github.com/rcmachado/af3db315e31383502660 -## Display this help text. +## Display this help text help:/ $(info Available targets) $(info -----------------) @@ -140,7 +141,7 @@ endif # ------------------------------------------------------------------- .PHONY: deps -## Download build dependencies. +## Download build dependencies deps: $(DEP_BIN) $(VENDOR_DIR) # install dep in a the tmp/bin dir of the repo @@ -171,8 +172,8 @@ $(VENDOR_DIR): Gopkg.toml GOFORMAT_FILES := $(shell find . -name '*.go' | grep -vEf $(INCLUDE_DIR)/gofmt_exclude) .PHONY: check-go-format -# Exists with an error if there are files whose formatting differs from gofmt's -check-go-format: prebuild-check deps ## Exists with an error if there are files whose formatting differs from gofmt's +## Exits with an error if there are files that do not match formatting defined by gofmt +check-go-format: prebuild-check deps @gofmt -s -l ${GOFORMAT_FILES} 2>&1 \ | tee /tmp/gofmt-errors \ | read \ @@ -182,22 +183,22 @@ check-go-format: prebuild-check deps ## Exists with an error if there are files || true .PHONY: analyze-go-code -# Run golangci analysis over the code. -analyze-go-code: deps ## Run golangci analysis over the code. +## Run golangci analysis over the code +analyze-go-code: deps $(info >>--- RESULTS: GOLANGCI CODE ANALYSIS ---<<) @go get -u github.com/golangci/golangci-lint/cmd/golangci-lint @golangci-lint run .PHONY: format-go-code -# Formats any go file that differs from gofmt's style -format-go-code: prebuild-check ## Formats any go file that differs from gofmt's style +## Formats any go file that does not match formatting defined by gofmt +format-go-code: prebuild-check @gofmt -s -l -w ${GOFORMAT_FILES} # ------------------------------------------------------------------- # Code format/check with golangci-lint # ------------------------------------------------------------------- .PHONY: check-go-code -## Checks the code with golangci-lint (see .golangci.yaml) +## Checks the code with golangci-lint check-go-code: $(GOLANGCI_LINT_BIN) @echo "checking code..." $(GOLANGCI_LINT_BIN) run @@ -257,7 +258,7 @@ clean-tmp: # Keep this "clean" target here after all `clean-*` sub tasks .PHONY: clean -## Runs all clean-* targets. +## Cleans the project, removes all generated code/bins and vendor packages clean: $(CLEAN_TARGETS) # ------------------------------------------------------------------- @@ -265,7 +266,7 @@ clean: $(CLEAN_TARGETS) # ------------------------------------------------------------------- .PHONY: build -## Build the server +## Build the operator build: prebuild-check deps @echo "building $(BINARY_SERVER_BIN)..." go build -v -o $(BINARY_SERVER_BIN) cmd/manager/main.go diff --git a/make/Makefile.lnx b/make/Makefile.lnx deleted file mode 100644 index be34ca0..0000000 --- a/make/Makefile.lnx +++ /dev/null @@ -1,12 +0,0 @@ -BINARY_SERVER_BIN=$(INSTALL_PREFIX)/devconsole-operator -GO_BIN_NAME=go -GIT_BIN_NAME=git -DEP_BIN_NAME=dep -DOCKER_BIN_NAME=docker -CHECK_GOPATH_BIN=$(INSTALL_PREFIX)/check_gopath -UNAME_S=$(shell uname -s) -GOCOV_BIN=$(VENDOR_DIR)/github.com/axw/gocov/gocov/gocov -GOCOVMERGE_BIN=$(VENDOR_DIR)/github.com/wadey/gocovmerge/gocovmerge -GOCYCLO_DIR=$(VENDOR_DIR)/github.com/fzipp/gocyclo -GOCYCLO_BIN=$(GOCYCLO_DIR)/gocyclo -GOLANGCI_LINT_BIN_NAME:=golangci-lint diff --git a/make/Makefile.win b/make/Makefile.win deleted file mode 100644 index 45ab6cf..0000000 --- a/make/Makefile.win +++ /dev/null @@ -1,11 +0,0 @@ -BINARY_SERVER_BIN=$(INSTALL_PREFIX)/devconsole-operator.exe -GO_BIN_NAME=go.exe -GIT_BIN_NAME=git.exe -DEP_BIN_NAME=dep.exe -DOCKER_BIN_NAME=docker.exe -CHECK_GOPATH_BIN= $(INSTALL_PREFIX)/check_gopath.exe -GOCOV_BIN=$(VENDOR_DIR)/github.com/axw/gocov/gocov/gocov.exe -GOCOVMERGE_BIN=$(VENDOR_DIR)/github.com/wadey/gocovmerge/gocovmerge.exe -GOCYCLO_DIR=$(VENDOR_DIR)/github.com/fzipp/gocyclo -GOCYCLO_BIN=$(GOCYCLO_DIR)/gocyclo.exe -GOLANGCI_LINT_BIN_NAME:=golangci-lint.exe diff --git a/make/check_gopath.go b/make/check_gopath.go deleted file mode 100644 index 091c4c2..0000000 --- a/make/check_gopath.go +++ /dev/null @@ -1,46 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "log" - "os" - "path" - "path/filepath" - "runtime" - "strings" -) - -// Checks if the packageName is checked out into one of the GOPATH entries -// under GOPATH[i]/src/packageName. -func main() { - var packageName string - flag.StringVar(&packageName, "packageName", "github.com/redhat-developers/devopsconsole-operator", "Package Name (e.g.)") - flag.Parse() - - wd, err := os.Getwd() - if err != nil { - log.Fatal(err) - } - - for _, p := range strings.Split(os.Getenv("GOPATH"), string(filepath.ListSeparator)) { - // Check if p is a directory - if info, err := os.Stat(p); err == nil && info.IsDir() { - // Make sure we have an absolute path - abs, err := filepath.Abs(p) - if err != nil { - log.Fatal(err) - } - if wd == filepath.Join(abs, "src", packageName) { - os.Exit(0) - } - } - } - - goPathStr := path.Join("$GOPATH", "src", packageName) - if runtime.GOOS == "windows" { - goPathStr = path.Join("%GOPATH%", "src", packageName) - } - log.Fatal(fmt.Errorf("Make sure you've checked out your project in %s", goPathStr)) - -} diff --git a/make/docker.mk b/make/docker.mk index 4696e5a..84e5322 100644 --- a/make/docker.mk +++ b/make/docker.mk @@ -28,13 +28,13 @@ GOPATH_IN_CONTAINER=/tmp/go PACKAGE_PATH=$(GOPATH_IN_CONTAINER)/src/$(PACKAGE_NAME) .PHONY: docker-image-builder -## Builds the docker image used to build the software. +## Builds the docker image used to build the software docker-image-builder: @echo "Building docker image $(DOCKER_IMAGE_CORE)" docker build --build-arg USE_GO_VERSION_FROM_WEBSITE=$(USE_GO_VERSION_FROM_WEBSITE) -t $(DOCKER_IMAGE_CORE) -f $(CUR_DIR)/Dockerfile.builder $(CUR_DIR) .PHONY: docker-image-deploy -## Creates a runnable image using the artifacts from the bin directory. +## Creates a runnable image using the artifacts from the bin directory docker-image-deploy: docker build -t $(DOCKER_IMAGE_DEPLOY) -f $(CUR_DIR)/$(DOCKERFILE_DEPLOY) $(CUR_DIR) diff --git a/make/test.mk b/make/test.mk index 9fae986..98c983d 100644 --- a/make/test.mk +++ b/make/test.mk @@ -14,7 +14,6 @@ # # $ make test-unit # -# # To run all tests, type # # $ make test-all @@ -27,7 +26,6 @@ # # $ make coverage-unit-html # -# # To output all coverage profile information for each function, type # # $ make coverage-all @@ -100,22 +98,22 @@ GOANALYSIS_DIRS=$(shell go list -f {{.Dir}} ./... | grep -v -E $(GOANALYSIS_PKGS #------------------------------------------------------------------------------- .PHONY: test-all -## Runs the test-unit targets. -test-all: prebuild-check test-unit +## Runs the unit tests and e2e tests +test-all: prebuild-check test-unit test-e2e -.PHONY: test-unit-with-coverage # Runs the unit tests and produces coverage files for each package. +.PHONY: test-unit-with-coverage test-unit-with-coverage: prebuild-check clean-coverage-unit $(COV_PATH_UNIT) .PHONY: test-unit -## Runs the unit tests and WITHOUT producing coverage files for each package. +## Runs the unit tests without coverage test-unit: prebuild-check $(SOURCES) $(call log-info,"Running test: $@") $(eval TEST_PACKAGES:=$(shell go list ./... | grep -v $(ALL_PKGS_EXCLUDE_PATTERN))) ADMIN_LOG_LEVEL=$(ADMIN_LOG_LEVEL) go test -vet off $(GO_TEST_VERBOSITY_FLAG) $(TEST_PACKAGES) .PHONY: test-e2e -## Runs the e2e tests and WITHOUT producing coverage files for each package. +## Runs the e2e tests without coverage test-e2e: build build-image e2e-setup $(call log-info,"Running E2E test: $@") go test ./test/e2e/... -root=$(PWD) -kubeconfig=$(HOME)/.kube/config -globalMan deploy/test/global-manifests.yaml -namespacedMan deploy/test/namespace-manifests.yaml -v -parallel=1 -singleNamespace @@ -195,9 +193,10 @@ define cleanup-coverage-file @sed -i '/.*\/confbindata\.go.*/d' $(1) endef -.PHONY: coverage-unit # Output coverage profile information for each function (only based on unit-tests). # Re-runs unit-tests if coverage information is outdated. +.PHONY: coverage-unit +## Runs the unit tests with producing coverage files for each package coverage-unit: prebuild-check $(COV_PATH_UNIT) $(call cleanup-coverage-file,$(COV_PATH_UNIT)) @go tool cover -func=$(COV_PATH_UNIT) @@ -214,9 +213,10 @@ coverage-all: prebuild-check clean-coverage-overall $(COV_PATH_OVERALL) # HTML coverage output: -.PHONY: coverage-unit-html # Generate HTML representation (and show in browser) of coverage profile (based on unit tests). # Re-runs unit tests if coverage information is outdated. +.PHONY: coverage-unit-html +## Runs the unit tests with producing coverage html for each package coverage-unit-html: prebuild-check $(COV_PATH_UNIT) $(call cleanup-coverage-file,$(COV_PATH_UNIT)) @go tool cover -html=$(COV_PATH_UNIT) diff --git a/pkg/controller/envdeployment/envdeployment_controller_test.go b/pkg/controller/envdeployment/envdeployment_controller_test.go index 19da5e7..b7b9943 100644 --- a/pkg/controller/envdeployment/envdeployment_controller_test.go +++ b/pkg/controller/envdeployment/envdeployment_controller_test.go @@ -13,4 +13,4 @@ func TestExample(t *testing.T) { t.Run("subtest example", func(t *testing.T) { require.True(t, true) }) -} \ No newline at end of file +} diff --git a/test/e2e/main_test.go b/test/e2e/main_test.go index 68218e3..35d5c41 100644 --- a/test/e2e/main_test.go +++ b/test/e2e/main_test.go @@ -8,4 +8,4 @@ import ( func TestMain(m *testing.M) { framework.MainEntry(m) -} \ No newline at end of file +} From befe3ef93f1e3f3bc12d563fe7763ca011647787 Mon Sep 17 00:00:00 2001 From: Michael Kleinhenz Date: Fri, 15 Feb 2019 16:43:47 +0100 Subject: [PATCH 3/3] Fixed review comments. --- Dockerfile.deploy | 6 +++--- Makefile | 2 +- deploy/test/global-manifests.yaml | 19 ------------------- make/Makefile.dev | 2 -- make/test.mk | 3 --- test/README.md | 2 -- 6 files changed, 4 insertions(+), 30 deletions(-) diff --git a/Dockerfile.deploy b/Dockerfile.deploy index 7866751..a34ec95 100644 --- a/Dockerfile.deploy +++ b/Dockerfile.deploy @@ -2,17 +2,17 @@ FROM centos:7 LABEL maintainer "Devtools " LABEL author "Devtools " ENV LANG=en_US.utf8 -ENV F8_INSTALL_PREFIX=/usr/local/devconsole-operator +ENV INSTALL_PREFIX=/usr/local/devconsole-operator # Create a non-root user and a group with the same name: "devconsole-operator" ENV F8_USER_NAME=devconsole-operator RUN useradd --no-create-home -s /bin/bash ${F8_USER_NAME} -COPY bin/devconsole-operator ${F8_INSTALL_PREFIX}/bin/devconsole-operator +COPY bin/devconsole-operator ${INSTALL_PREFIX}/bin/devconsole-operator # From here onwards, any RUN, CMD, or ENTRYPOINT will be run under the following user USER ${F8_USER_NAME} -WORKDIR ${F8_INSTALL_PREFIX} +WORKDIR ${INSTALL_PREFIX} ENTRYPOINT [ "bin/devconsole-operator" ] diff --git a/Makefile b/Makefile index 4db17a2..88b6652 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ PROJECT_NAME=devopsconsole-operator -PACKAGE_NAME:=github.com/fabric8-services/$(PROJECT_NAME) +PACKAGE_NAME:=github.com/redhat-developer/$(PROJECT_NAME) CUR_DIR=$(shell pwd) TMP_PATH=$(CUR_DIR)/tmp INSTALL_PREFIX=$(CUR_DIR)/bin diff --git a/deploy/test/global-manifests.yaml b/deploy/test/global-manifests.yaml index 95b384a..27e4e03 100644 --- a/deploy/test/global-manifests.yaml +++ b/deploy/test/global-manifests.yaml @@ -17,25 +17,6 @@ apiVersion: rbac.authorization.k8s.io/v1 metadata: name: devconsole rules: -- apiGroups: - - rbac.authorization.k8s.io - resources: - - clusterrolebindings - verbs: - - '*' -- apiGroups: - - oauth.openshift.io - resources: - - oauthclients - verbs: - - '*' -- apiGroups: - - "" - - project.openshift.io - resources: - - projectrequests - verbs: - - create - apiGroups: - codeready.io resources: diff --git a/make/Makefile.dev b/make/Makefile.dev index 58b7422..51e9731 100644 --- a/make/Makefile.dev +++ b/make/Makefile.dev @@ -74,8 +74,6 @@ clean-resources: @oc delete -f $(DEPLOY_DIR)/namespace.yaml || true @echo "Deleting Custom Resource Definitions..." @oc delete -f $(DEPLOY_DIR)/crds/devconsole_v1alpha1_envdeployment_crd.yaml || true - @echo "Deleting OAuthClient 'codeready-devconsole'" - @oc delete oauthclient codeready-devconsole || true .PHONY: deploy-operator deploy-operator: build build-image deploy-operator-only diff --git a/make/test.mk b/make/test.mk index 98c983d..bd1fc5c 100644 --- a/make/test.mk +++ b/make/test.mk @@ -125,9 +125,6 @@ e2e-setup: e2e-cleanup .PHONY: e2e-cleanup e2e-cleanup: oc login -u system:admin - oc delete oauthclient codeready-devconsole || true - oc delete clusterrolebinding devconsole-enabler || true - oc delete clusterrole devconsole-enabler || true oc delete project devconsole-e2e-test || true #------------------------------------------------------------------------------- diff --git a/test/README.md b/test/README.md index a17d56d..6f48e4e 100644 --- a/test/README.md +++ b/test/README.md @@ -1,7 +1,5 @@ ## E2E Tests -E2E tests are verifying successful deployment of the DevOps Console Operator and creation of self-provisioning service account. - ### How to Run #### TL;DR