Skip to content

Commit

Permalink
fix(tiller): allow 3rd party APIs
Browse files Browse the repository at this point in the history
This feature has been disabled in the past because simply enabling the
feature causes the Kubernetes library to make requests to a server.
Thus, running any tests that use the 'pkg/kube' library has required
running a kube API server.

This patch makes it possible to selectively activate 3rdParty API
support, and then disables that support during testing.

Future versions of the Kubernetes library appear to make it easier to
configure and mock this behavior, so this is most likely a stop-gap
measure. (Famous last words.)

Closes #1472
  • Loading branch information
technosophos committed Oct 28, 2016
1 parent 3ba2427 commit f27791c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
18 changes: 12 additions & 6 deletions pkg/kube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,20 @@ import (
// Client represents a client capable of communicating with the Kubernetes API.
type Client struct {
*cmdutil.Factory
// IncludeThirdPartyAPIs indicates whether to load "dynamic" APIs.
//
// This requires additional calls to the Kubernetes API server, and these calls
// are not supported by all versions. Additionally, during testing, initializing
// a client will still attempt to contact a live server. In these situations,
// this flag may need to be disabled.
IncludeThirdPartyAPIs bool
}

// New create a new Client
func New(config clientcmd.ClientConfig) *Client {
return &Client{
Factory: cmdutil.NewFactory(config),
Factory: cmdutil.NewFactory(config),
IncludeThirdPartyAPIs: true,
}
}

Expand Down Expand Up @@ -145,15 +153,15 @@ func (c *Client) Get(namespace string, reader io.Reader) (string, error) {
//
// Namespace will set the namespaces
func (c *Client) Update(namespace string, currentReader, targetReader io.Reader) error {
current := c.NewBuilder(includeThirdPartyAPIs).
current := c.NewBuilder(c.IncludeThirdPartyAPIs).
ContinueOnError().
NamespaceParam(namespace).
DefaultNamespace().
Stream(currentReader, "").
Flatten().
Do()

target := c.NewBuilder(includeThirdPartyAPIs).
target := c.NewBuilder(c.IncludeThirdPartyAPIs).
ContinueOnError().
NamespaceParam(namespace).
DefaultNamespace().
Expand Down Expand Up @@ -275,10 +283,8 @@ func (c *Client) WatchUntilReady(namespace string, reader io.Reader) error {
return perform(c, namespace, reader, watchUntilReady)
}

const includeThirdPartyAPIs = false

func perform(c *Client, namespace string, reader io.Reader, fn ResourceActorFunc) error {
r := c.NewBuilder(includeThirdPartyAPIs).
r := c.NewBuilder(c.IncludeThirdPartyAPIs).
ContinueOnError().
NamespaceParam(namespace).
DefaultNamespace().
Expand Down
8 changes: 6 additions & 2 deletions pkg/kube/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func TestPerform(t *testing.T) {
}

c := New(nil)
c.IncludeThirdPartyAPIs = false
c.ClientForMapping = func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
return &fake.RESTClient{}, nil
}
Expand All @@ -121,12 +122,15 @@ func TestPerform(t *testing.T) {

func TestReal(t *testing.T) {
t.Skip("This is a live test, comment this line to run")
if err := New(nil).Create("test", strings.NewReader(guestbookManifest)); err != nil {
c := New(nil)
c.IncludeThirdPartyAPIs = false
if err := c.Create("test", strings.NewReader(guestbookManifest)); err != nil {
t.Fatal(err)
}

testSvcEndpointManifest := testServiceManifest + "\n---\n" + testEndpointManifest
c := New(nil)
c = New(nil)
c.IncludeThirdPartyAPIs = false
if err := c.Create("test-delete", strings.NewReader(testSvcEndpointManifest)); err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit f27791c

Please sign in to comment.