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

Integration with rafter #56

Merged
merged 7 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The repository has the following structure:
├── internal # Private application and library code
│ ├── addon # Package that provides logic for fetching addons from different remote repositories
│ ├── assetstore # Client for the upload service which allows the Helm Broker to upload documentation
│ ├── rafter # Client for the upload service which allows the Helm Broker to upload documentation
│ ├── bind # Logic that renders the binding data
│ ├── broker # Implementation of the OSB API contract
│ ├── config # Configurations structs for both Controller and Broker
Expand Down
4 changes: 2 additions & 2 deletions charts/helm-broker/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ rules:
- apiGroups: ["servicecatalog.k8s.io"]
resources: ["servicebrokers", "clusterservicebrokers"]
verbs: ["create","delete","list","get","update", "watch"]
- apiGroups: ["cms.kyma-project.io"]
resources: ["clusterdocstopics", "docstopics"]
- apiGroups: ["rafter.kyma-project.io"]
resources: ["clusterassetgroups", "assetgroups"]
verbs: ["get", "create", "update", "delete", "list", "watch"]
- apiGroups: ["addons.kyma-project.io"]
resources: ["addonsconfigurations", "clusteraddonsconfigurations", "addonsconfigurations/status", "clusteraddonsconfigurations/status", "addonsconfigurations/finalizers", "clusteraddonsconfigurations/finalizers"]
Expand Down
4 changes: 2 additions & 2 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"flag"
"fmt"

"github.com/kyma-project/helm-broker/internal/assetstore"
envs "github.com/kyma-project/helm-broker/internal/config"
"github.com/kyma-project/helm-broker/internal/controller"
"github.com/kyma-project/helm-broker/internal/health"
"github.com/kyma-project/helm-broker/internal/platform/logger"
"github.com/kyma-project/helm-broker/internal/rafter"
"github.com/kyma-project/helm-broker/internal/storage"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -36,7 +36,7 @@ func main() {
cfg, err := config.GetConfig()
fatalOnError(err, "while setting up a client")

uploadClient := assetstore.NewClient(ctrCfg.UploadServiceURL, lg)
uploadClient := rafter.NewClient(ctrCfg.UploadServiceURL, lg)
mgr := controller.SetupAndStartController(cfg, ctrCfg, metricsAddr, sFact, uploadClient, lg)

// TODO: switch to native implementation after merge: https://github.com/kubernetes-sigs/controller-runtime/pull/419
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Use the following environment variables to configure the `Controller` container
| **APP_SERVICE_NAME** | Yes | | Specifies the name of the Kubernetes service that exposes the Broker. |
| **APP_CLUSTER_SERVICE_BROKER_NAME** | Yes | | Specifies the name of the ClusterServiceBroker resource which registers the Helm Broker in the Service Catalog. |
| **APP_DEVELOP_MODE** | No | `false` | If set to `true`, you can use unsecured HTTP-based repositories URLs. |
| **APP_DOCUMENTATION_ENABLED** | No | `false` | If set to `true`, the Helm Broker uploads addons documentation to the [Headless CMS](https://kyma-project.io/docs/components/headless-cms/). |
| **APP_DOCUMENTATION_ENABLED** | No | `false` | If set to `true`, the Helm Broker uploads addons documentation to the [Rafter](https://kyma-project.io/docs/components/headless-cms/). |
6 changes: 3 additions & 3 deletions internal/addon/provider/generic_dir_getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

getter "github.com/hashicorp/go-getter"
"github.com/kyma-project/helm-broker/internal"
"github.com/kyma-project/helm-broker/internal/assetstore"
"github.com/kyma-project/helm-broker/internal/rafter"
"github.com/mholt/archiver"
exerr "github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/rand"
Expand All @@ -28,14 +28,14 @@ type ClientModeDirGetter struct {
addonDirPath string
docsURL string

cli assetstore.Client
cli rafter.Client
tmpDir string
protocol string
}

// ClientModeDirGetterCfg holds input parameters for ClientModeDirGetter constructor
type ClientModeDirGetterCfg struct {
Cli assetstore.Client
Cli rafter.Client
TmpDir string
Underlying getter.Getter
Addr string
Expand Down
4 changes: 2 additions & 2 deletions internal/addon/provider/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package provider

import (
getter "github.com/hashicorp/go-getter"
"github.com/kyma-project/helm-broker/internal/assetstore"
"github.com/kyma-project/helm-broker/internal/rafter"
)

// GitGetterCreator provides functionality for loading addon from any Git repository.
type GitGetterCreator struct {
Cli assetstore.Client
Cli rafter.Client
TmpDir string
}

Expand Down
4 changes: 2 additions & 2 deletions internal/addon/provider/hg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package provider

import (
getter "github.com/hashicorp/go-getter"
"github.com/kyma-project/helm-broker/internal/assetstore"
"github.com/kyma-project/helm-broker/internal/rafter"
)

// HgGetterCreator provides functionality for loading addon from any Mercurial repository.
type HgGetterCreator struct {
Cli assetstore.Client
Cli rafter.Client
TmpDir string
}

Expand Down
4 changes: 2 additions & 2 deletions internal/addon/provider/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package provider

import (
getter "github.com/hashicorp/go-getter"
"github.com/kyma-project/helm-broker/internal/assetstore"
"github.com/kyma-project/helm-broker/internal/rafter"
)

// S3GetterCreator provides functionality for loading addon from any S3 repository.
type S3GetterCreator struct {
Cli assetstore.Client
Cli rafter.Client
TmpDir string
}

Expand Down
2 changes: 1 addition & 1 deletion internal/config/controller_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type ControllerConfig struct {
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://rafter-upload-service.kyma-system.svc.cluster.local:3000"`
DocumentationEnabled bool
}

Expand Down
16 changes: 8 additions & 8 deletions internal/controller/addons_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/kyma-project/helm-broker/internal/storage"
"github.com/kyma-project/helm-broker/pkg/apis"
"github.com/kyma-project/helm-broker/pkg/apis/addons/v1alpha1"
cms "github.com/kyma-project/kyma/components/cms-controller-manager/pkg/apis/cms/v1alpha1"
rafter "github.com/kyma-project/helm-broker/pkg/apis/rafter/v1beta1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestReconcileAddonsConfiguration_AddAddonsProcess(t *testing.T) {

ts.addonGetter.On("GetCompleteAddon", e).
Return(completeAddon, nil)
ts.docsProvider.On("EnsureDocsTopic", completeAddon.Addon).Return(nil)
ts.docsProvider.On("EnsureAssetGroup", completeAddon.Addon).Return(nil)
}
}
ts.brokerFacade.On("Exist").Return(false, nil).Once()
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestReconcileAddonsConfiguration_AddAddonsProcess_ErrorIfBrokerExist(t *tes

ts.addonGetter.On("GetCompleteAddon", e).
Return(completeAddon, nil)
ts.docsProvider.On("EnsureDocsTopic", completeAddon.Addon).Return(nil)
ts.docsProvider.On("EnsureAssetGroup", completeAddon.Addon).Return(nil)
}
}
ts.brokerFacade.On("Exist").Return(false, errors.New("")).Once()
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestReconcileAddonsConfiguration_UpdateAddonsProcess(t *testing.T) {

ts.addonGetter.On("GetCompleteAddon", e).
Return(completeAddon, nil)
ts.docsProvider.On("EnsureDocsTopic", completeAddon.Addon).Return(nil)
ts.docsProvider.On("EnsureAssetGroup", completeAddon.Addon).Return(nil)
}
}
ts.brokerFacade.On("Exist").Return(false, nil).Once()
Expand Down Expand Up @@ -570,8 +570,8 @@ func fixAddonWithDocsURL(id, name, url, docsURL string) internal.AddonWithCharts
},
Docs: []internal.AddonDocs{
{
Template: cms.CommonDocsTopicSpec{
Sources: []cms.Source{
Template: rafter.CommonAssetGroupSpec{
Sources: []rafter.Source{
{
URL: docsURL,
},
Expand Down Expand Up @@ -611,8 +611,8 @@ func fixAddonWithEmptyDocs(id, name, url string) internal.AddonWithCharts {
},
Docs: []internal.AddonDocs{
{
Template: cms.CommonDocsTopicSpec{
Sources: []cms.Source{
Template: rafter.CommonAssetGroupSpec{
Sources: []rafter.Source{
{},
},
},
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/automock/docs_provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions internal/controller/cluster_addons_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestReconcileClusterAddonsConfiguration_AddAddonsProcess(t *testing.T) {

ts.addonGetter.On("GetCompleteAddon", e).
Return(completeAddon, nil)
ts.docsProvider.On("EnsureDocsTopic", completeAddon.Addon).Return(nil)
ts.docsProvider.On("EnsureAssetGroup", completeAddon.Addon).Return(nil)

}
}
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestReconcileClusterAddonsConfiguration_AddAddonsProcess_Error(t *testing.T

ts.addonGetter.On("GetCompleteAddon", e).
Return(completeAddon, nil)
ts.docsProvider.On("EnsureDocsTopic", completeAddon.Addon).Return(nil)
ts.docsProvider.On("EnsureAssetGroup", completeAddon.Addon).Return(nil)
}
}
ts.brokerFacade.On("Exist").Return(false, errors.New("")).Once()
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestReconcileClusterAddonsConfiguration_UpdateAddonsProcess(t *testing.T) {
completeAddon := fixAddonWithDocsURL(string(e.Name), string(e.Name), "example.com", "example.com")

ts.addonGetter.On("GetCompleteAddon", e).Return(completeAddon, nil)
ts.docsProvider.On("EnsureDocsTopic", completeAddon.Addon).Return(nil)
ts.docsProvider.On("EnsureAssetGroup", completeAddon.Addon).Return(nil)
}

}
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (c *common) saveAddons(repositories *repository.Collection) bool {

for _, ad := range repositories.ReadyAddons() {
if len(ad.AddonWithCharts.Addon.Docs) == 1 {
if err := c.docsProvider.EnsureDocsTopic(ad.AddonWithCharts.Addon); err != nil {
if err := c.docsProvider.EnsureAssetGroup(ad.AddonWithCharts.Addon); err != nil {
c.log.Errorf("while ensuring documentation for addon %s: %v", ad.ID, err)
}
}
Expand Down Expand Up @@ -372,7 +372,7 @@ func (c *common) removeAddon(ad v1alpha1.Addon) (bool, error) {
return false, err
}
removed = true
if err := c.docsProvider.EnsureDocsTopicRemoved(string(add.ID)); err != nil {
if err := c.docsProvider.EnsureAssetGroupRemoved(string(add.ID)); err != nil {
return removed, errors.Wrapf(err, "while deleting documentation for addon %s", add.ID)
}

Expand Down
42 changes: 21 additions & 21 deletions internal/controller/docs/cluster_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/kyma-project/helm-broker/internal"
"github.com/kyma-project/kyma/components/cms-controller-manager/pkg/apis/cms/v1alpha1"
"github.com/kyma-project/helm-broker/pkg/apis/rafter/v1beta1"
pPrecel marked this conversation as resolved.
Show resolved Hide resolved
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
apiErrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -33,67 +33,67 @@ func NewClusterProvider(dynamicClient client.Client, log logrus.FieldLogger) *Cl
}
}

// EnsureDocsTopic creates ClusterDocsTopic for a given addon or updates it in case it already exists
func (d *ClusterProvider) EnsureDocsTopic(addon *internal.Addon) error {
// EnsureAssetGroup creates ClusterAssetGroup for a given addon or updates it in case it already exists
func (d *ClusterProvider) EnsureAssetGroup(addon *internal.Addon) error {
addon.Docs[0].Template.Sources = defaultDocsSourcesURLs(addon)
cdt := &v1alpha1.ClusterDocsTopic{
cdt := &v1beta1.ClusterAssetGroup{
ObjectMeta: v1.ObjectMeta{
Name: string(addon.ID),
Labels: map[string]string{
cmsLabelKey: "service-catalog",
hbLabelKey: "true",
rafterLabelKey: "service-catalog",
hbLabelKey: "true",
},
},
Spec: v1alpha1.ClusterDocsTopicSpec{CommonDocsTopicSpec: addon.Docs[0].Template},
Spec: v1beta1.ClusterAssetGroupSpec{CommonAssetGroupSpec: addon.Docs[0].Template},
}
d.log.Infof("- ensuring ClusterDocsTopic %s", addon.ID)
d.log.Infof("- ensuring ClusterAssetGroup %s", addon.ID)

return wait.PollImmediate(time.Millisecond*500, time.Second*3, func() (bool, error) {
err := d.dynamicClient.Create(context.Background(), cdt)
switch {
case err == nil:
case apiErrors.IsAlreadyExists(err):
if err := d.updateClusterDocsTopic(addon); err != nil {
d.log.Errorf("while ClusterDocsTopic %s already exists", addon.ID)
if err := d.updateClusterAssetGroup(addon); err != nil {
d.log.Errorf("while ClusterAssetGroup %s already exists", addon.ID)
return false, nil
}
default:
d.log.Errorf("while creating ClusterDocsTopic %s", addon.ID)
d.log.Errorf("while creating ClusterAssetGroup %s", addon.ID)
return false, nil
}
return true, nil
})
}

// EnsureDocsTopicRemoved removes ClusterDocsTopic for a given addon
func (d *ClusterProvider) EnsureDocsTopicRemoved(id string) error {
cdt := &v1alpha1.ClusterDocsTopic{
// EnsureAssetGroupRemoved removes ClusterAssetGroup for a given addon
func (d *ClusterProvider) EnsureAssetGroupRemoved(id string) error {
cdt := &v1beta1.ClusterAssetGroup{
ObjectMeta: v1.ObjectMeta{
Name: id,
},
}
d.log.Infof("- removing ClusterDocsTopic %s", id)
d.log.Infof("- removing ClusterAssetGroup %s", id)

return wait.PollImmediate(time.Millisecond*500, time.Second*3, func() (bool, error) {
err := d.dynamicClient.Delete(context.Background(), cdt)
if err != nil && !apiErrors.IsNotFound(err) {
d.log.Errorf("while deleting ClusterDocsTopic %s", id)
d.log.Errorf("while deleting ClusterAssetGroup %s", id)
return false, nil
}
return true, nil
})
}

func (d *ClusterProvider) updateClusterDocsTopic(addon *internal.Addon) error {
cdt := &v1alpha1.ClusterDocsTopic{}
func (d *ClusterProvider) updateClusterAssetGroup(addon *internal.Addon) error {
cdt := &v1beta1.ClusterAssetGroup{}
return retry.RetryOnConflict(retry.DefaultBackoff, func() error {
if err := d.dynamicClient.Get(context.Background(), types.NamespacedName{Name: string(addon.ID)}, cdt); err != nil {
return errors.Wrapf(err, "while getting ClusterDocsTopic %s", addon.ID)
return errors.Wrapf(err, "while getting ClusterAssetGroup %s", addon.ID)
}
if reflect.DeepEqual(cdt.Spec.CommonDocsTopicSpec, addon.Docs[0].Template) {
if reflect.DeepEqual(cdt.Spec.CommonAssetGroupSpec, addon.Docs[0].Template) {
return nil
}
cdt.Spec = v1alpha1.ClusterDocsTopicSpec{CommonDocsTopicSpec: addon.Docs[0].Template}
cdt.Spec = v1beta1.ClusterAssetGroupSpec{CommonAssetGroupSpec: addon.Docs[0].Template}

if err := d.dynamicClient.Update(context.Background(), cdt); err != nil {
return err
Expand Down
Loading