Skip to content

Commit

Permalink
Add integration test framework. (#10)
Browse files Browse the repository at this point in the history
* Move logic from cmd/manager to a package for easier testing.

Signed-off-by: Anthony Yeh <[email protected]>

* Add integration test framework.

Signed-off-by: Anthony Yeh <[email protected]>

* Add integration-test workflow.

Signed-off-by: Anthony Yeh <[email protected]>

* integration/framework: Wait for CRDs to be ready.

Signed-off-by: Anthony Yeh <[email protected]>

* Switch to controller-runtime client.

Signed-off-by: Anthony Yeh <[email protected]>
  • Loading branch information
enisoc authored Dec 12, 2019
1 parent 9c7ecb4 commit 87a6e53
Show file tree
Hide file tree
Showing 16 changed files with 801 additions and 124 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/integration-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: integration-test
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
name: Integration Test
runs-on: ubuntu-latest
steps:

- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.12
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: Go module cache
id: go-mod-cache
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: go-mod-cache

- name: Integration Test
run: make integration-test
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
run: go install -v ./...

- name: Unit Test
run: go test ./...
run: make unit-test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Temporary Build Files
build/_output
build/_test
/tools/_bin/

# Created by https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
### Emacs ###
# -*- mode: gitignore; -*-
Expand Down
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build release-build generate push-only push
.PHONY: build release-build unit-test integration-test generate push-only push

IMAGE_REGISTRY:=docker.io
IMAGE_TAG:=latest
Expand All @@ -22,6 +22,16 @@ build:
release-build:
docker build -f build/Dockerfile.release -t $(IMAGE_NAME):$(IMAGE_TAG) .

unit-test:
pkgs="$$(go list ./... | grep -v '/test/integration/')" && \
go test -i $${pkgs} && \
go test $${pkgs}

integration-test:
tools/get-kube-binaries.sh
go test -i ./test/integration/...
PATH="$(PWD)/tools/_bin:$(PATH)" go test -v -timeout 5m ./test/integration/... -args --logtostderr -v=6

generate:
operator-sdk-$(OPERATOR_SDK_VERSION) generate k8s
operator-sdk-$(OPERATOR_SDK_VERSION) generate openapi
Expand Down
115 changes: 6 additions & 109 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,19 @@ import (
goruntime "runtime"
"time"

"k8s.io/klog"

"github.com/spf13/pflag"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
_ "k8s.io/client-go/plugin/pkg/client/auth"

"k8s.io/apimachinery/pkg/runtime"
kubernetesscheme "k8s.io/client-go/kubernetes/scheme"
appsv1defaults "k8s.io/kubernetes/pkg/apis/apps/v1"
batchv1defaults "k8s.io/kubernetes/pkg/apis/batch/v1"
corev1defaults "k8s.io/kubernetes/pkg/apis/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"

"github.com/operator-framework/operator-sdk/pkg/k8sutil"
"github.com/operator-framework/operator-sdk/pkg/leader"
"github.com/operator-framework/operator-sdk/pkg/log/zap"
sdkVersion "github.com/operator-framework/operator-sdk/version"

planetscaleapis "planetscale.dev/vitess-operator/pkg/apis"
"planetscale.dev/vitess-operator/pkg/controller"
vbssubcontroller "planetscale.dev/vitess-operator/pkg/controller/vitessbackupstorage/subcontroller"
"planetscale.dev/vitess-operator/pkg/operator/controllermanager"
"planetscale.dev/vitess-operator/pkg/operator/fork"
)

Expand All @@ -62,30 +50,7 @@ var (
metricsHost = "0.0.0.0"
metricsPort int32 = 8383
)
var log = logf.Log.WithName("cmd")

// schemeAddFuncs are all the things we register into our compiled-in API type system (Scheme).
var schemeAddFuncs = []func(*runtime.Scheme) error{
// This is the types only (no defaulters) for all built-in APIs supported by client-go.
kubernetesscheme.AddToScheme,

/*
These are the defaulters for some built-in APIs that we use.
This code doesn't come with the Kubernetes client library,
so we have to vendor it from the main server repository.
Doing this lets us achieve `kubectl apply`-like semantics while
still using statically-typed Go structs instead of JSON/YAML
to define our objects.
*/
corev1defaults.AddToScheme,
appsv1defaults.AddToScheme,
batchv1defaults.AddToScheme,

// This is our own CRDs.
planetscaleapis.AddToScheme,
}
var log = logf.Log.WithName("manager")

func printVersion() {
log.Info(fmt.Sprintf("Go Version: %s", goruntime.Version()))
Expand All @@ -98,41 +63,7 @@ func main() {
// do something other than run the main operator code.
forkPath := fork.Path()

// Add the zap logger flag set to the CLI. The flag set must
// be added before calling pflag.Parse().
pflag.CommandLine.AddFlagSet(zap.FlagSet())

// Add flags registered by imported packages (e.g. glog and
// controller-runtime)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)

pflag.Parse()

// Initialize flags for klog, which is necessary to configure logging from
// the low-level k8s client libraries. We don't use glog ourselves, but we
// have dependencies that use it, so we have to follow the instructions for
// making klog coexist with glog:
// https://github.com/kubernetes/klog/blob/master/examples/coexist_glog/coexist_glog.go
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(klogFlags)
// Sync the glog and klog flags.
pflag.CommandLine.VisitAll(func(f1 *pflag.Flag) {
f2 := klogFlags.Lookup(f1.Name)
if f2 != nil {
value := f1.Value.String()
f2.Value.Set(value)
}
})

// Use a zap logr.Logger implementation. If none of the zap
// flags are configured (or if the zap flag set is not being
// used), this defaults to a production zap logger.
//
// The logger instantiated here can be changed to any logger
// implementing the logr.Logger interface. This logger will
// be propagated through the whole operator, generating
// uniform and structured logs.
logf.SetLogger(zap.Logger())
controllermanager.InitFlags()

printVersion()

Expand Down Expand Up @@ -161,18 +92,7 @@ func main() {
}
}

// Set up scheme for all resources we depend on.
scheme := runtime.NewScheme()
for _, add := range schemeAddFuncs {
if err := add(scheme); 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{
Scheme: scheme,
mgr, err := controllermanager.New(forkPath, cfg, manager.Options{
Namespace: namespace,
SyncPeriod: cacheInvalidateInterval,
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
Expand All @@ -182,32 +102,9 @@ func main() {
os.Exit(1)
}

log.Info("Registering Components.")

// We use the fork path primarily to decide which controllers to run in this
// manager process. Not all controllers run in the root process, for example.
switch forkPath {
case "":
// Run all root controllers, defined as anything that registers itself
// in the top-level 'pkg/controller' at package init time.
if err := controller.AddToManager(mgr); err != nil {
log.Error(err, "")
os.Exit(1)
}
case vbssubcontroller.ForkPath:
// Run only the vitessbackupstorage subcontroller.
if err := vbssubcontroller.Add(mgr); err != nil {
log.Error(err, "")
os.Exit(1)
}
default:
log.Error(fmt.Errorf("undefined fork path: %v", forkPath), "")
os.Exit(1)
}

log.Info("Starting the Cmd.")
log.Info("Starting the manager.")

// Start the Cmd
// Start the manager
if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
log.Error(err, "Manager exited non-zero")
os.Exit(1)
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.12
require (
contrib.go.opencensus.io/exporter/ocagent v0.4.12 // indirect
github.com/Azure/go-autorest v11.7.1+incompatible // indirect
github.com/ahmetb/gen-crd-api-reference-docs v0.1.5-0.20190629210212-52e137b8d003 // indirect
github.com/ahmetb/gen-crd-api-reference-docs v0.1.5-0.20190629210212-52e137b8d003
github.com/aws/aws-sdk-go v1.20.4 // indirect
github.com/coreos/etcd v3.3.12+incompatible // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
Expand All @@ -27,6 +27,7 @@ require (
github.com/stretchr/testify v1.4.0
gopkg.in/yaml.v2 v2.2.2
k8s.io/api v0.0.0-20190612125737-db0771252981
k8s.io/apiextensions-apiserver v0.0.0-20190228180357-d002e88f6236
k8s.io/apimachinery v0.0.0-20190612125636-6a5db36e93ad
k8s.io/apiserver v0.0.0-20190228174905-79427f02047f // indirect
k8s.io/client-go v11.0.0+incompatible
Expand Down
14 changes: 2 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ github.com/evanphx/json-patch v3.0.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi
github.com/evanphx/json-patch v4.0.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.1.0+incompatible h1:K1MDoo4AZ4wU0GIU/fPmtZg7VpzLjCxu+UwBD1FvwOc=
github.com/evanphx/json-patch v4.1.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M=
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4=
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
Expand Down Expand Up @@ -239,12 +240,10 @@ github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:Fecb
github.com/gregjones/httpcache v0.0.0-20181110185634-c63ab54fda8f/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc h1:f8eY6cV/x1x+HLjOp4r72s/31/V2aTUtg5oKRRPf8/Q=
github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/grpc-ecosystem/go-grpc-middleware v0.0.0-20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:Iju5GlWwrvL6UBg4zJJt3btmonfrMlCDdsejg4CZE7c=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 h1:THDBEeQ9xZ8JEaCLyLQqXMMdRqNr0QAUJTIkQAUtFjg=
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xCzHAvxcr8HZnzsqU6ILg/0NiiE=
github.com/grpc-ecosystem/go-grpc-prometheus v0.0.0-20180418170936-39de4380c2e0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v0.0.0-20161128002007-199c40a060d1/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw=
Expand Down Expand Up @@ -444,8 +443,6 @@ github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7q
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/common v0.0.0-20190104105734-b1c43a6df3ae/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.3.0 h1:taZ4h8Tkxv2kNyoSctBvfXEHmBmxrwmIidZTIaHons4=
github.com/prometheus/common v0.3.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc=
github.com/prometheus/common v0.7.0 h1:L+1lyG48J1zAQXA3RBX/nG/B3gjlHq0zTt2tlbJLyCY=
Expand All @@ -456,8 +453,6 @@ github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R
github.com/prometheus/procfs v0.0.0-20190104112138-b1a0a9a36d74/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190403104016-ea9eea638872/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.0-20190412120340-e22ddced7142 h1:JO6VBMEDSBX/LT4GKwSdvuFigZNwVD4lkPyUE4BDCKE=
github.com/prometheus/procfs v0.0.0-20190412120340-e22ddced7142/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ=
github.com/prometheus/procfs v0.0.5 h1:3+auTFlqw+ZaQYJARz6ArODtkaIwtvBTx3N2NehQlL8=
Expand Down Expand Up @@ -604,8 +599,6 @@ golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM=
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190926025831-c00fd9afed17 h1:qPnAdmjNA41t3QBTx2mFGf/SD1IoslhYu7AmdsVzCcs=
golang.org/x/net v0.0.0-20190926025831-c00fd9afed17/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20170412232759-a6bd8cefa181/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand Down Expand Up @@ -649,8 +642,6 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190830142957-1e83adbbebd0 h1:7z820YPX9pxWR59qM7BE5+fglp4D/mKqAwCvGt11b+8=
golang.org/x/sys v0.0.0-20190830142957-1e83adbbebd0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190926180325-855e68c8590b h1:/8GN4qrAmRZQXgjWZHj9z/UJI5vNqQhPtgcw02z2f+8=
golang.org/x/sys v0.0.0-20190926180325-855e68c8590b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down Expand Up @@ -681,6 +672,7 @@ golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBn
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190830154057-c17b040389b9 h1:5/jaG/gKlo3xxvUn85ReNyTlN7BvlPPsxC6sHZKjGEE=
golang.org/x/tools v0.0.0-20190830154057-c17b040389b9/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
Expand Down Expand Up @@ -804,7 +796,5 @@ sigs.k8s.io/testing_frameworks v0.1.1/go.mod h1:VVBKrHmJ6Ekkfz284YKhQePcdycOzNH9
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
vbom.ml/util v0.0.0-20180919145318-efcd4e0f9787/go.mod h1:so/NYdZXCz+E3ZpW0uAoCj6uzU2+8OWDFv/HxUSs7kI=
vitess.io/vitess v0.0.0-20190910173716-ab425723d591 h1:K6fl8U71PECvq0qNjJpeMelXBEzraWuOBEz5TPEcLOA=
vitess.io/vitess v0.0.0-20190910173716-ab425723d591/go.mod h1:a2W63geOKZ66uYs+/4fCC84TE6ADmQcAqOKMiaNUb4w=
vitess.io/vitess v0.0.0-20191106000153-8de7237f7b75 h1:NsQR+7ALrP7+0AEY7pm3Z0rb7F0tFYRVL2SdOG23M+s=
vitess.io/vitess v0.0.0-20191106000153-8de7237f7b75/go.mod h1:Sk+YyPzRiOS3a6ToCSbno8wUQuxgqsiJat+lyXm5smw=
54 changes: 54 additions & 0 deletions pkg/operator/controllermanager/controller_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package controllermanager

import (
"fmt"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/client-go/rest"

"sigs.k8s.io/controller-runtime/pkg/manager"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"

"planetscale.dev/vitess-operator/pkg/controller"
vbssubcontroller "planetscale.dev/vitess-operator/pkg/controller/vitessbackupstorage/subcontroller"
)

var log = logf.Log.WithName("controller-manager")

func New(forkPath string, cfg *rest.Config, opts manager.Options) (manager.Manager, error) {
// Set up scheme for all resources we depend on.
var err error
opts.Scheme, err = NewScheme()
if err != nil {
return nil, err
}

// Create a new manager to provide shared dependencies and start components
mgr, err := manager.New(cfg, opts)
if err != nil {
return nil, err
}

log.Info("Registering Components.")

// We use the fork path primarily to decide which controllers to run in this
// manager process. Not all controllers run in the root process, for example.
switch forkPath {
case "":
// Run all root controllers, defined as anything that registers itself
// in the top-level 'pkg/controller' at package init time.
if err := controller.AddToManager(mgr); err != nil {
return nil, err
}
case vbssubcontroller.ForkPath:
// Run only the vitessbackupstorage subcontroller.
if err := vbssubcontroller.Add(mgr); err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("undefined fork path: %v", forkPath)
}

return mgr, nil
}
Loading

0 comments on commit 87a6e53

Please sign in to comment.