Commit Graph

240 Commits

Author SHA1 Message Date
Gareth Smith 2b25091098 Add examples and more detailed docs
- Mostly documenting properties of APIServer (for the most part Etcd has
  the same properties).
- Adding executable examples, some off which run as additional test
  cases.
2017-12-15 16:19:50 +00:00
Gareth Smith 08cb5b2ee7 Give AddressManager responsibility for its host
You no longer have to pass a hostname to initialise the addressmanager.
The DefaultAddressManager always listens on localhost. If you want to
listen on some other interface, you can use a different AddressManager.
2017-12-15 16:07:24 +00:00
k8s-ci-robot 129504ba58
Merge pull request #178 from totherme/control-pane-process-timeouts
Control pane process timeouts
2017-12-14 20:40:29 -08:00
k8s-ci-robot 0e690228fc
Merge pull request #177 from hoegaarden/zero-conf-structs
Zero conf structs
2017-12-14 16:18:29 -08:00
k8s-ci-robot 9afcb2bc07
Merge pull request #176 from totherme/162-apiserver-sane-default-constructor
162 apiserver sane default constructor
2017-12-14 16:03:29 -08:00
k8s-ci-robot 2e18103b69
Merge pull request #168 from totherme/163-fixtures-sane-0-value-default
Finalize the interface of the Fixtures struct
2017-12-14 15:21:28 -08:00
Gareth Smith 57c5c42731 Backfil tests for apiserver and etcd start timeout 2017-12-14 15:22:31 +00:00
Hannes Hörl 0263f2b034 Return error for timeout on process stop
We now return an error when stopping of a process times out, before that
resulted in a panic. Now a caller of `Stop()` can catch an handle this
error.

Also, the timeouts for stopping and starting a process is now
configurable, for example by:
```
etcd := &test.APIServer{
  StartTimeout: 12 * time.Second,
  StopTimeout: 5 * time.Second,
}
```
2017-12-14 13:55:53 +00:00
Hannes Hörl 108b905a06 Update test to work on multiple systems
Our integrationy unit test now works on expecting of multiple, slightly
different errors -- different systems give slightly different errors.
2017-12-14 10:31:42 +00:00
Hannes Hörl 62adb52ec4 Remove dependencies
As separate commit, to make review easier
2017-12-14 10:02:26 +00:00
Hannes Hörl bb7eaaee6c Remove dependeny on govalidator 2017-12-14 10:00:17 +00:00
Hannes Hörl 8953c28b25 Guard against uninitialized AddressManager
In both Etcd and APIServer we return a descriptive Error when the
`URL()` method is called before `Start()` and thus the AddressManager is
not yet initialized.
2017-12-13 15:00:31 +00:00
Hannes Hörl e926d95717 Remove parallel starting of COntrolPlaneProcesses
Right now the ControlPlane is actually just a thin layer around
APIServer, this is the oly process we care for right now. Now that we
only have one process to start, we can remove the parallel starting
logic.

In case we bring in more processes again this commit can just be reverted.
2017-12-13 14:09:22 +00:00
Hannes Hörl 0df12db242 Move logic out of constructors
We can move all of the logic out of the constructors and psuh them into
`ensureInitialized()` of both APIServer and Etcd.
By doing so, the constructors are actually not needed anymore.

We however kept the constructor for the ControlPlane for convinience.
2017-12-13 13:59:09 +00:00
Hannes Hörl 519293f43b Rename "Fixtures" to "ControlPlane"
Updated all comments and other related occurances.
2017-12-13 13:59:08 +00:00
Hannes Hörl fd43bb888a Return an error when stopping a process fails
When an error occours on `Stop()` of either the APIServer or Etcd, that
error is propagated to the caller.
2017-12-13 13:59:06 +00:00
Hannes Hörl a49601db63 Remove PortFinder, use AddressManager
Nothing uses the PortFinder anymore. We can now remove the PortFinder,
and rename the files to make clear AddressManager is now the thing to
use.
2017-12-13 13:59:04 +00:00
Hannes Hörl 0683d7977a Test APIServer's CertDirManager 2017-12-13 13:59:02 +00:00
Hannes Hörl 0aa877d964 Remove EtcdConfig
Using the AddressManager in Etcd removes the need for EtcdConfig.
2017-12-13 13:58:55 +00:00
Hannes Hörl ffa8ee46e5 Give APIServer constructor sane defaults
The APIServer constructor previously required careful configuration. Now
it takes no arguments, and gives you an APIServer that you can
`.Start()`. If you want to configure it, you still can. For example, you
can set the environment variable `TEST_ASSET_KUBE_APISERVER` to the path
to your apiserver binary, or you can override the PathFinder in go code:

```
myAPIServer := test.NewAPIServer()
myAPIServer.PathFinder = func(_ string) string {
  return "/path/to/my/apiserver/binary"
}
```

Previously the responsibility of choosing a port that the APIServer
could listen on was left to the caller. Now APIServer delegates that
responsibility to an AddressManager. By default you get a random unused
port on localhost. If you want to customize that behaviour, you can
overwrite the AddressManager:

```
myAPIServer := test.NewAPIServer()
myAPIServer.AddressManager = myAddressManager
```

If this is a common request, then in future we might provide some common
custom AddressManagers.
2017-12-12 16:50:23 +00:00
Hannes Hörl 657963b319 Make APIServer manage its own port allocations
This means we will no longer need to pass a free port into the APIServer
constructor.
2017-12-12 15:46:53 +00:00
Hannes Hörl d62ff04228 Move APIServer path logic into Start()
Same as in previous commit for Etcd ( d4e9e90d86 )
2017-12-12 11:11:02 +00:00
Hannes Hörl d4e9e90d86 Move etcd path logic from constructor to Start()
This means that if you want to customize the path to your etcd, instead
of doing `etcd.Path = "/my/path"` you should do:

```
etcd.PathFinder = func(_ string) string {
  return "/my/path"
}
```

The advantage of this is that we move logic out of the constructor, so
we need less crazy dependancy injection logic in our tests, and we get
closer to being able to use the 0-value Etcd struct.
2017-12-11 17:18:25 +00:00
Hannes Hörl 85ac9f5969 Expose APIServers coordinates via APIServerURL()
Instead of exposing client configuration via the Fixtures struct, we now
expose the APIServer's coordinates via a method on Fixtures.
2017-12-11 13:54:52 +00:00
Hannes Hörl 1defd3c52e Make Fixtures constructor take 0 args
This is a natural consequence of cleaning up after the "APIServer is
responsible for Etcd" refactor.
2017-12-11 12:09:27 +00:00
Hannes Hörl fe4e62dc59 Remove EtcdURL from APIServer Config 2017-12-11 12:02:07 +00:00
Hannes Hörl b406414c2a Make ApiServer manage Etcd
Everything now works pretty much like before, so we're not yet feeling a
lot of the benefit. Still to do:

- Remove all vestiges of Etcd config etc from the Fixtures struct
- Remove duplicated config
- Make Fixtures and APIServer constructors take 0 params
2017-12-11 11:55:23 +00:00
Antoine Pelisse 588a6ac821
Merge pull request #166 from totherme/161-etcd-sane-0-value-default
Add a sane default constructor for the Etcd and EtcdConfig structs
2017-12-08 10:28:13 -08:00
Hannes Hörl a86b2f83fe Bugfix for BinPathFinder
We now sanitize the binary names from which we construct environment
variables to query for custom binary paths. This means we can now
customize the apiserver binary path with $TEST_ASSET_KUBE_APISERVER
2017-12-08 16:22:46 +00:00
Hannes Hörl ad04fd8972 Make Fixtures use pathless apiserver constructor
This is motivated by #162, but also involves changing the
NewFixtures(...) constructor which is the entry point to the whole
framework. We're removing the amount of config
you need to make it work, in line with #163.
2017-12-08 16:01:19 +00:00
Hannes Hörl e6b042840b Add APIServer constructor with default binary path 2017-12-08 15:59:49 +00:00
Hannes Hörl 3bdc1f4b9b Add a new default constructor for Etcd
- The default constructor for Etcd uses the DefaultBinPathFinder and the
  default EtcdConfig constructor internally
- The Fixtures still use the old constructor, which means it passes in a
  binary path and an EtcdConfig
2017-12-08 14:32:53 +00:00
Hannes Hörl 84e6727884 Add a default constructor for EtcdConfig 2017-12-08 14:13:56 +00:00
Hannes Hörl 08f495a8ee Add a simple Port Finder 2017-12-08 14:08:38 +00:00
Hannes Hörl a4b6e08b30 Add a simple Binary Path Finder 2017-12-08 10:59:29 +00:00
Antoine Pelisse e8f9c7d73a
Merge pull request #157 from hoegaarden/152-no_special_treatment_for_test_framework
No special treatment for test framework
2017-12-07 11:03:08 -08:00
Hannes Hörl 4d9d2ce534 Check errors even in defer blocks 2017-12-07 16:13:30 +00:00
Hannes Hörl 17daebfb1a Add dependencies
As a separate commit, to make review easier.
2017-12-06 14:46:02 +00:00
Hannes Hörl 5afb9ee6cc Validate configs
Brings in github.com/asaskevich/govalidator
2017-12-06 14:46:02 +00:00
Hannes Hörl 819ad8519f Move logic back into fixtures constructor
- Introduce a type for the fixture process configuration
2017-12-06 14:46:02 +00:00
Hannes Hörl 15d507fc83 Change overrides for test fixture paths
One can override the paths to the binaries (etcd, APIServer) to test
against by setting the environment variables
- TEST_ETCD_BIN
- TEST_APISERVER_BIN
2017-12-06 14:46:02 +00:00
Hannes Hörl eee6a20808 Use fakes to get listening URLs for the fixtures 2017-12-06 14:46:02 +00:00
Hannes Hörl de3af899fc Refactor FixtureProcesses
- Remove the logic from the constructors
- Have start take a configuration map for the fixture processes
- Move the testing on open ports closer to the actual start
2017-12-06 14:46:02 +00:00
Hannes Hörl 1513093427 Integrate test framework tests properly
The test framework can now run properly with `go test` and we can remove
- our test wrapper
- special handling of tests for the test framewoek
2017-12-06 14:46:02 +00:00
Hannes Hörl 98faa6a9dc Change handling of default test assets location
If $KUBE_ASSETS_DIR is set, we use that and try to run the binaries from
within that directory.
If it is not set, we try to determine the assets directory as a relative
path to the test suite.
2017-12-06 14:46:02 +00:00
Hannes Hörl 2d275663fe Use the exposed configuration of the fixtures
The fixtures now exposes the URL the API Server is listening on. We can
get this with from `Fixtures.Config.APIServerURL`.

When we start our client program in the test, we pass that API Server
URL in via a command line flag.
2017-12-06 14:46:02 +00:00
Hannes Hörl e8c6a13d49 Configure fixture processes with ports to listen on
- APIServer & Etcd get configured, from the outside, on which ports to
  listen on
- Configuration, the subjects under test might be interested in, is
  exposed by Fixtures.Config

Hint: Before we start any process, we get a random port and check if
that random port is acutally free to bind to. As it takes some time
until we actually start anything, we might run into cases, where another
process binds to that port while we are starting up. Even if we do the
port checking closer to actually binding, we still have the same issue.
For now, however, we take that risk - if we run into problems with that,
we are open to refactor that.
2017-12-06 14:46:02 +00:00
k8s-ci-robot 88e83f4286
Merge pull request #155 from hoegaarden/proper_fake_for_apiserver
Proper fake for apiserver
2017-12-05 13:28:30 -08:00
Antoine Pelisse d56d6ba9a1
Merge pull request #154 from hoegaarden/proper_fake_for_etcd
Proper fake for etcd
2017-12-05 13:23:47 -08:00
Hannes Hörl d9268017e3 Refactor APIServer
- Use a fake certificate directory manager
- Use a simpler CLI Session
2017-12-04 17:43:57 +00:00