Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

Commit

Permalink
Add DocsEnabled flag
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmiskiewicz committed Aug 8, 2019
1 parent d4e0a3b commit e7aa7db
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 195 deletions.
5 changes: 3 additions & 2 deletions internal/config/controller_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ import (
type ControllerConfig struct {
TmpDir string
Logger logger.Config
KubeconfigPath string `envconfig:"optional"`
KubeconfigPath string `envconfig:"optional"`
Namespace string
ServiceName string
ClusterServiceBrokerName string
Storage []storage.Config `valid:"required"`
DevelopMode bool
UploadServiceURL string `default:"http://assetstore-asset-upload-service.kyma-system.svc.cluster.local:3000"`
UploadServiceURL string `default:"http://assetstore-asset-upload-service.kyma-system.svc.cluster.local:3000"`
DocumentationEnabled bool
}

// LoadControllerConfig method has following strategy:
Expand Down
22 changes: 22 additions & 0 deletions internal/controller/dummy_docs_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package controller

import "github.com/kyma-project/helm-broker/internal"

type dummyDocsProvider struct {
}

func (s *dummyDocsProvider) EnsureDocsTopic(addon *internal.Addon, namespace string) error {
return nil
}

func (*dummyDocsProvider) EnsureDocsTopicRemoved(id string, namespace string) error {
return nil
}

func (*dummyDocsProvider) EnsureClusterDocsTopic(addon *internal.Addon) error {
return nil
}

func (*dummyDocsProvider) EnsureClusterDocsTopicRemoved(id string) error {
return nil
}
13 changes: 12 additions & 1 deletion internal/controller/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
)

type docsFacade interface {
clusterDocsProvider
docsProvider
}

// SetupAndStartController creates and starts the controller
func SetupAndStartController(cfg *rest.Config, ctrCfg *config.ControllerConfig, metricsAddr string, sFact storage.Factory, uploadClient assetstore.Client, lg *logrus.Entry) manager.Manager {
// Create a new Cmd to provide shared dependencies and start components
Expand All @@ -41,7 +46,13 @@ func SetupAndStartController(cfg *rest.Config, ctrCfg *config.ControllerConfig,
fatalOnError(v1alpha1.AddToScheme(mgr.GetScheme()), "while adding CMS scheme")

// Setup dependencies
docsProvider := NewDocsProvider(mgr.GetClient())

var docsProvider docsFacade
docsProvider = NewDocsProvider(mgr.GetClient())
if !ctrCfg.DocumentationEnabled {
docsProvider = &dummyDocsProvider{}
}

brokerSyncer := broker.NewServiceBrokerSyncer(mgr.GetClient(), ctrCfg.ClusterServiceBrokerName, lg)
sbFacade := broker.NewBrokersFacade(mgr.GetClient(), brokerSyncer, ctrCfg.Namespace, ctrCfg.ServiceName, lg)
csbFacade := broker.NewClusterBrokersFacade(mgr.GetClient(), brokerSyncer, ctrCfg.Namespace, ctrCfg.ServiceName, ctrCfg.ClusterServiceBrokerName, lg)
Expand Down
File renamed without changes.
File renamed without changes.
137 changes: 46 additions & 91 deletions test/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import (
"testing"

"github.com/kyma-project/helm-broker/pkg/apis/addons/v1alpha1"
"github.com/stretchr/testify/assert"
)

func TestGetCatalogHappyPath(t *testing.T) {
// given
suite := newTestSuite(t)
suite := newTestSuite(t, true)
defer suite.tearDown()

for name, c := range map[string]struct {
Expand All @@ -34,20 +33,10 @@ func TestGetCatalogHappyPath(t *testing.T) {
},
} {
t.Run(name, func(t *testing.T) {
var repository *gitRepo
if c.kind == sourceGit {
repo, err := newGitRepository(t, addonSource)
assert.NoError(t, err)

defer repo.removeTmpDir()
repository = repo
}

suite.assertNoServicesInCatalogEndpoint("ns/stage")

// when
source := newSource(c.kind, suite, repository, []string{redisAndAccTestRepo})
suite.createAddonsConfiguration("stage", c.addonName, source)
suite.createAddonsConfiguration("stage", c.addonName, []string{redisAndAccTestRepo}, c.kind)

// then
suite.waitForAddonsConfigurationPhase("stage", c.addonName, v1alpha1.AddonsConfigurationReady)
Expand All @@ -56,14 +45,13 @@ func TestGetCatalogHappyPath(t *testing.T) {
suite.assertNoServicesInCatalogEndpoint("cluster")

// when
suite.createAddonsConfiguration("prod", c.addonName, source)
suite.createAddonsConfiguration("prod", c.addonName, []string{redisAndAccTestRepo}, c.kind)
suite.waitForAddonsConfigurationPhase("prod", c.addonName, v1alpha1.AddonsConfigurationReady)
suite.waitForServicesInCatalogEndpoint("ns/prod", []string{c.redisID, c.testID})

// when
source.removeURL(redisAndAccTestRepo)
suite.updateAddonsConfigurationRepositories("stage", c.addonName, source)
suite.updateAddonsConfigurationRepositories("prod", c.addonName, source)
suite.updateAddonsConfigurationRepositories("stage", c.addonName, []string{}, c.kind)
suite.updateAddonsConfigurationRepositories("prod", c.addonName, []string{}, c.kind)

// then
suite.waitForEmptyCatalogResponse("ns/stage")
Expand All @@ -89,28 +77,17 @@ func TestGetCatalogHappyPath(t *testing.T) {
},
} {
t.Run(name, func(t *testing.T) {
var repository *gitRepo
if c.kind == sourceGit {
repo, err := newGitRepository(t, addonSource)
assert.NoError(t, err)

defer repo.removeTmpDir()
repository = repo
}

suite.assertNoServicesInCatalogEndpoint("cluster")

// when
source := newSource(c.kind, suite, repository, []string{redisRepo})
suite.createClusterAddonsConfiguration(c.addonName, source)
suite.createClusterAddonsConfiguration(c.addonName, []string{redisRepo}, c.kind)

// then
suite.waitForClusterAddonsConfigurationPhase(c.addonName, v1alpha1.AddonsConfigurationReady)
suite.waitForServicesInCatalogEndpoint("cluster", []string{c.redisID})

// when
source.removeURL(redisRepo)
suite.updateClusterAddonsConfigurationRepositories(c.addonName, source)
suite.updateClusterAddonsConfigurationRepositories(c.addonName, []string{}, c.kind)

// then
suite.waitForEmptyCatalogResponse("cluster")
Expand All @@ -120,7 +97,7 @@ func TestGetCatalogHappyPath(t *testing.T) {

func TestAddonsConflicts(t *testing.T) {
// given
suite := newTestSuite(t)
suite := newTestSuite(t, true)
defer suite.tearDown()

for name, c := range map[string]struct {
Expand All @@ -140,22 +117,13 @@ func TestAddonsConflicts(t *testing.T) {
},
} {
t.Run(name, func(t *testing.T) {
var repository *gitRepo
if c.kind == sourceGit {
repo, err := newGitRepository(t, addonSource)
assert.NoError(t, err)

defer repo.removeTmpDir()
repository = repo
}
first := "first-" + c.kind
second := "second-" + c.kind
third := "third-" + c.kind

// when
// - create an addons configuration with repo with redis addon
source := newSource(c.kind, suite, repository, []string{redisRepo})
suite.createAddonsConfiguration("stage", first, source)
suite.createAddonsConfiguration("stage", first, []string{redisRepo}, c.kind)

// then
// - wait for readiness and wait for service redis at the catalog endpoint
Expand All @@ -164,8 +132,7 @@ func TestAddonsConflicts(t *testing.T) {

// when
// - create second addons configuration with a repo with redis and acc-test addons
sourceFull := newSource(c.kind, suite, repository, []string{redisAndAccTestRepo})
suite.createAddonsConfiguration("stage", second, sourceFull)
suite.createAddonsConfiguration("stage", second, []string{redisAndAccTestRepo}, c.kind)

// then
// - expect phase "failed", still redis service at the catalog endpoint
Expand All @@ -174,8 +141,7 @@ func TestAddonsConflicts(t *testing.T) {

// when
// - remove repo with redis from the first (cluster) addon
source.removeURL(redisRepo)
suite.updateAddonsConfigurationRepositories("stage", first, source)
suite.updateAddonsConfigurationRepositories("stage", first, []string{}, c.kind)

// then
// - expect for readiness and 2 services at the catalog endpoint
Expand All @@ -184,8 +150,7 @@ func TestAddonsConflicts(t *testing.T) {

// when
// - create third addons configuration with a repo with acc-test addons
sourceTesting := newSource(c.kind, suite, repository, []string{accTestRepo})
suite.createAddonsConfiguration("stage", third, sourceTesting)
suite.createAddonsConfiguration("stage", third, []string{accTestRepo}, c.kind)

// then
// - expect failed (because of the conflict)
Expand Down Expand Up @@ -219,22 +184,13 @@ func TestAddonsConflicts(t *testing.T) {
},
} {
t.Run(name, func(t *testing.T) {
var repository *gitRepo
if c.kind == sourceGit {
repo, err := newGitRepository(t, addonSource)
assert.NoError(t, err)

defer repo.removeTmpDir()
repository = repo
}
first := "first-" + c.kind
second := "second-" + c.kind
third := "third-" + c.kind

// when
// - create an cluster addons configuration with repo with redis addon
source := newSource(c.kind, suite, repository, []string{redisRepo})
suite.createClusterAddonsConfiguration(first, source)
suite.createClusterAddonsConfiguration(first, []string{redisRepo}, c.kind)

// then
// - wait for readiness and wait for service redis at the catalog endpoint
Expand All @@ -243,8 +199,7 @@ func TestAddonsConflicts(t *testing.T) {

// when
// - create second cluster addons configuration with a repo with redis and acc-test addons
sourceFull := newSource(c.kind, suite, repository, []string{redisAndAccTestRepo})
suite.createClusterAddonsConfiguration(second, sourceFull)
suite.createClusterAddonsConfiguration(second, []string{redisAndAccTestRepo}, c.kind)

// then
// - expect phase "failed", still redis service at the catalog endpoint
Expand All @@ -253,8 +208,7 @@ func TestAddonsConflicts(t *testing.T) {

// when
// - remove repo with redis from the first (cluster) addon
source.removeURL(redisRepo)
suite.updateClusterAddonsConfigurationRepositories(first, source)
suite.updateClusterAddonsConfigurationRepositories(first, []string{}, c.kind)

// then
// - expect for readiness and 2 services at the catalog endpoint
Expand All @@ -263,8 +217,7 @@ func TestAddonsConflicts(t *testing.T) {

// when
// - create third cluster addons configuration with a repo with acc-test addons
sourceTesting := newSource(c.kind, suite, repository, []string{accTestRepo})
suite.createClusterAddonsConfiguration(third, sourceTesting)
suite.createClusterAddonsConfiguration(third, []string{accTestRepo}, c.kind)

// then
// - expect failed (because of the conflict)
Expand All @@ -284,7 +237,7 @@ func TestAddonsConflicts(t *testing.T) {

func TestDocsTopic(t *testing.T) {
// given
suite := newTestSuite(t)
suite := newTestSuite(t, true)
defer suite.tearDown()

for name, c := range map[string]struct {
Expand All @@ -304,26 +257,15 @@ func TestDocsTopic(t *testing.T) {
},
} {
t.Run(name, func(t *testing.T) {
var repository *gitRepo
if c.kind == sourceGit {
repo, err := newGitRepository(t, addonSource)
assert.NoError(t, err)

defer repo.removeTmpDir()
repository = repo
}

// when
source := newSource(c.kind, suite, repository, []string{redisAndAccTestRepo})
suite.createAddonsConfiguration("stage", c.addonName, source)
suite.createAddonsConfiguration("stage", c.addonName, []string{redisAndAccTestRepo}, c.kind)

// then
suite.waitForAddonsConfigurationPhase("stage", c.addonName, v1alpha1.AddonsConfigurationReady)
suite.assertDocsTopicExist("stage", c.docsTopicID)

// when
source.replaceURL(redisRepo)
suite.updateAddonsConfigurationRepositories("stage", c.addonName, source)
suite.updateAddonsConfigurationRepositories("stage", c.addonName, []string{redisRepo}, c.kind)

// then
suite.assertDocsTopicListIsEmpty()
Expand All @@ -347,29 +289,42 @@ func TestDocsTopic(t *testing.T) {
},
} {
t.Run(name, func(t *testing.T) {
var repository *gitRepo
if c.kind == sourceGit {
repo, err := newGitRepository(t, addonSource)
assert.NoError(t, err)

defer repo.removeTmpDir()
repository = repo
}

// when
source := newSource(c.kind, suite, repository, []string{redisAndAccTestRepo})
suite.createClusterAddonsConfiguration(c.addonName, source)
suite.createClusterAddonsConfiguration(c.addonName, []string{redisAndAccTestRepo}, c.kind)

// then
suite.waitForClusterAddonsConfigurationPhase(c.addonName, v1alpha1.AddonsConfigurationReady)
suite.assertClusterDocsTopicExist(c.docsTopicID)

// when
source.replaceURL(redisRepo)
suite.updateClusterAddonsConfigurationRepositories(c.addonName, source)
suite.updateClusterAddonsConfigurationRepositories(c.addonName, []string{redisRepo}, c.kind)

// then
suite.assertClusterDocsTopicListIsEmpty()
})
}
}

func TestDisabledDocs(t *testing.T) {
suite := newTestSuite(t, false)
defer suite.tearDown()

t.Run("namespaced", func(t *testing.T) {
suite.assertNoServicesInCatalogEndpoint("ns/stage")

// when
suite.createAddonsConfiguration("stage", "addon1", []string{accTestRepo}, sourceHTTP)

// then
suite.waitForAddonsConfigurationPhase("stage", "addon1", v1alpha1.AddonsConfigurationReady)
})

t.Run("cluster", func(t *testing.T) {
suite.assertNoServicesInCatalogEndpoint("cluster")

// when
suite.createClusterAddonsConfiguration("addon1", []string{accTestRepo}, sourceHTTP)

// then
suite.waitForClusterAddonsConfigurationPhase("addon1", v1alpha1.AddonsConfigurationReady)
})
}
Loading

0 comments on commit e7aa7db

Please sign in to comment.