From 46a243dd3f24884bfeb62d84694933fd6c22cd7a Mon Sep 17 00:00:00 2001 From: Matt Moore Date: Thu, 26 Apr 2018 21:38:15 -0700 Subject: [PATCH 1/2] Refactor the repo to support development with "ko". You can read more about `ko` [here](https://github.com/google/go-containerregistry/tree/master/cmd/ko#ko), but the tl;dr is that it is an experimental tool to replicate the current DevX with Bazel without the baggage Bazel comes with (learning curve, BUILD files, Java dependency, ...). I believe the supporting changes are generally useful these include: 1. Moving config files out of the root directory. This is to support the Kubernetes-style of applying an entire directory of configuration, potentially recursively (see below for an example). 1. Naming the image references we substitute around Go import paths. I find that this is a useful convention for expressing image provenance. These changes will support side-by-side development with Bazel and `ko`, until we make a judgement call on whether to remove Bazel. Here's an example of me running this locally: ```shell $ time ko apply -f config/ 2018/04/26 21:35:26 Go building github.com/elafros/eventing/cmd/controller 2018/04/26 21:35:36 Publishing us.gcr.io/convoy-adapter/github.com/elafros/eventing/cmd/controller:latest 2018/04/26 21:35:37 mounted sha256:4fe6b1eadc150125dbdff941f6e199cef0ac6b5c37795bf7cdb263f02a05f955 2018/04/26 21:35:37 mounted sha256:eb05f3dbdb543cc610527248690575bacbbcebabe6ecf665b189cf18b541e3ca 2018/04/26 21:35:37 mounted sha256:a027959537706a82d5fcf8d13f5624b002e39b652c21ec01e787233921434f9a 2018/04/26 21:35:37 pushed us.gcr.io/convoy-adapter/github.com/elafros/eventing/cmd/controller:latest 2018/04/26 21:35:37 Published us.gcr.io/convoy-adapter/github.com/elafros/eventing/cmd/controller@sha256:3afe5f28f3c500f7bf6d2be142cad9b75afcc2a601a3e5709277a91284fd9e15 namespace "bind-system" created customresourcedefinition "binds.eventing.elafros.dev" created clusterrolebinding "bind-controller-admin" created deployment "bind-controller" created customresourcedefinition "eventsources.eventing.elafros.dev" created customresourcedefinition "eventtypes.eventing.elafros.dev" created serviceaccount "bind-controller" created real 0m13.700s user 0m10.976s sys 0m0.864s ``` --- BUILD | 55 +--------------- config/BUILD | 63 +++++++++++++++++++ namespace.yaml => config/a-namespace.yaml | 0 bind.yaml => config/bind.yaml | 0 .../clusterrolebinding.yaml | 0 controller.yaml => config/controller.yaml | 2 +- eventsource.yaml => config/eventsource.yaml | 0 eventtype.yaml => config/eventtype.yaml | 0 .../serviceaccount.yaml | 0 9 files changed, 65 insertions(+), 55 deletions(-) create mode 100644 config/BUILD rename namespace.yaml => config/a-namespace.yaml (100%) rename bind.yaml => config/bind.yaml (100%) rename clusterrolebinding.yaml => config/clusterrolebinding.yaml (100%) rename controller.yaml => config/controller.yaml (94%) rename eventsource.yaml => config/eventsource.yaml (100%) rename eventtype.yaml => config/eventtype.yaml (100%) rename serviceaccount.yaml => config/serviceaccount.yaml (100%) diff --git a/BUILD b/BUILD index 2f429daadff..e58f47c1030 100644 --- a/BUILD +++ b/BUILD @@ -7,64 +7,11 @@ gazelle( external = "vendored", ) -load("@k8s_object//:defaults.bzl", "k8s_object") - -k8s_object( - name = "controller", - images = { - "bind-controller:latest": "//cmd/controller:image", - }, - template = "controller.yaml", -) - -k8s_object( - name = "namespace", - template = "namespace.yaml", -) - -k8s_object( - name = "serviceaccount", - template = "serviceaccount.yaml", -) - -k8s_object( - name = "clusterrolebinding", - template = "clusterrolebinding.yaml", -) - -k8s_object( - name = "bind", - template = "bind.yaml", -) - -k8s_object( - name = "eventtype", - template = "eventtype.yaml", -) - -k8s_object( - name = "eventsource", - template = "eventsource.yaml", -) - load("@io_bazel_rules_k8s//k8s:objects.bzl", "k8s_objects") -k8s_objects( - name = "authz", - objects = [ - ":serviceaccount", - ":clusterrolebinding", - ], -) - k8s_objects( name = "everything", objects = [ - ":namespace", - ":authz", - ":bind", - ":eventtype", - ":eventsource", - ":controller", + "//config:everything", ], ) diff --git a/config/BUILD b/config/BUILD new file mode 100644 index 00000000000..6ed0e5e188b --- /dev/null +++ b/config/BUILD @@ -0,0 +1,63 @@ +package(default_visibility = ["//visibility:public"]) + +load("@k8s_object//:defaults.bzl", "k8s_object") + +k8s_object( + name = "controller", + images = { + "github.com/elafros/eventing/cmd/controller": "//cmd/controller:image", + }, + template = "controller.yaml", +) + +k8s_object( + name = "namespace", + template = "a-namespace.yaml", +) + +k8s_object( + name = "serviceaccount", + template = "serviceaccount.yaml", +) + +k8s_object( + name = "clusterrolebinding", + template = "clusterrolebinding.yaml", +) + +k8s_object( + name = "bind", + template = "bind.yaml", +) + +k8s_object( + name = "eventtype", + template = "eventtype.yaml", +) + +k8s_object( + name = "eventsource", + template = "eventsource.yaml", +) + +load("@io_bazel_rules_k8s//k8s:objects.bzl", "k8s_objects") + +k8s_objects( + name = "authz", + objects = [ + ":serviceaccount", + ":clusterrolebinding", + ], +) + +k8s_objects( + name = "everything", + objects = [ + ":namespace", + ":authz", + ":bind", + ":eventtype", + ":eventsource", + ":controller", + ], +) diff --git a/namespace.yaml b/config/a-namespace.yaml similarity index 100% rename from namespace.yaml rename to config/a-namespace.yaml diff --git a/bind.yaml b/config/bind.yaml similarity index 100% rename from bind.yaml rename to config/bind.yaml diff --git a/clusterrolebinding.yaml b/config/clusterrolebinding.yaml similarity index 100% rename from clusterrolebinding.yaml rename to config/clusterrolebinding.yaml diff --git a/controller.yaml b/config/controller.yaml similarity index 94% rename from controller.yaml rename to config/controller.yaml index 82020a8b654..11396956835 100644 --- a/controller.yaml +++ b/config/controller.yaml @@ -26,7 +26,7 @@ spec: serviceAccountName: bind-controller containers: - name: bind-controller - image: bind-controller:latest + image: github.com/elafros/eventing/cmd/controller args: [ "-logtostderr", "-stderrthreshold", "INFO", diff --git a/eventsource.yaml b/config/eventsource.yaml similarity index 100% rename from eventsource.yaml rename to config/eventsource.yaml diff --git a/eventtype.yaml b/config/eventtype.yaml similarity index 100% rename from eventtype.yaml rename to config/eventtype.yaml diff --git a/serviceaccount.yaml b/config/serviceaccount.yaml similarity index 100% rename from serviceaccount.yaml rename to config/serviceaccount.yaml From e6709d54efbc40acbf2f685bf9ebc525ae98e6c9 Mon Sep 17 00:00:00 2001 From: Matt Moore Date: Sat, 28 Apr 2018 08:14:57 -0700 Subject: [PATCH 2/2] Update the sample as well. --- sample/github/BUILD | 2 +- sample/github/configuration.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sample/github/BUILD b/sample/github/BUILD index f650161ea76..ee759354293 100644 --- a/sample/github/BUILD +++ b/sample/github/BUILD @@ -33,7 +33,7 @@ load("@k8s_object//:defaults.bzl", "k8s_object") k8s_object( name = "configuration", images = { - "git-webhook:latest": ":image", + "github.com/elafros/eventing/sample/github": ":image", }, template = ":configuration.yaml", ) diff --git a/sample/github/configuration.yaml b/sample/github/configuration.yaml index df4f3a955e3..586edf93dd4 100644 --- a/sample/github/configuration.yaml +++ b/sample/github/configuration.yaml @@ -24,7 +24,7 @@ spec: elafros.dev/type: container spec: container: - image: git-webhook:latest + image: github.com/elafros/eventing/sample/github env: - name: GITHUB_SECRET valueFrom: