Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename REB to AB - stage2 #2040

Merged
merged 9 commits into from
Dec 19, 2018
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
19 changes: 16 additions & 3 deletions components/application-broker/Gopkg.lock

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

24 changes: 12 additions & 12 deletions components/application-broker/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Remote Environment Broker
# Application Broker

## Overview

The Remote Environment Broker (REB) provides remote environments in the [Service Catalog](../../docs/service-catalog/docs/001-overview-service-catalog.md).
A remote environment represents the environment connected to the Kyma instance.
The REB implements the [Service Broker API](https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md).
The Application Broker (AB) provides applications in the [Service Catalog](../../docs/service-catalog/docs/001-overview-service-catalog.md).
An Application represents a remote application connected to the Kyma instance.
The AB implements the [Service Broker API](https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md).

The REB fetches all the remote environments' custom resources and exposes their APIs and Events as service classes to the Service Catalog.
When the remote environments list is available in the Service Catalog, you can provision those service classes and enable Kyma services to use them.
The AB fetches all the applications' custom resources and exposes their APIs and Events as service classes to the Service Catalog.
When the applications list is available in the Service Catalog, you can provision those service classes and enable Kyma services to use them.

The REB works as a Namespace-scoped broker which is registered in the specific Namespace when the EnvironmentMapping is created in this Namespace.
The AB works as a Namespace-scoped broker which is registered in the specific Namespace when the ApplicationMapping is created in this Namespace.

For more details about provisioning, deprovisioning, binding, and unbinding, see the [Service Broker API](https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md) documentation.

Expand All @@ -29,15 +29,15 @@ Before each commit, use the `before-commit.sh` script or the `make build` comman
| Name | Required | Default | Description |
|-----|---------|--------|------------|
|**APP_PORT** | NO | `8080` | The port on which the HTTP server listens |
|**APP_BROKER_RELIST_DURATION_WINDOW** | YES | - | Time period after which the REB synchronizes with the Service Catalog if a new Remote Environment is added. In case more than one Remote Environment is added, synchronization is performed only once. |
| **APP_UNIQUE_SELECTOR_LABEL_KEY** | YES | - | Defined label key selector which allows uniquely identify REB pod's |
| **APP_UNIQUE_SELECTOR_LABEL_VALUE** | YES | - | Defined label value selector which allows uniquely identify REB pod's |
| **NAMESPACE** | YES | - | REB working Namespace |
|**APP_BROKER_RELIST_DURATION_WINDOW** | YES | - | Time period after which the AB synchronizes with the Service Catalog if a new Application is added. In case more than one Application is added, synchronization is performed only once. |
| **APP_UNIQUE_SELECTOR_LABEL_KEY** | YES | - | Defined label key selector which allows uniquely identify AB pod's |
| **APP_UNIQUE_SELECTOR_LABEL_VALUE** | YES | - | Defined label value selector which allows uniquely identify AB pod's |
| **NAMESPACE** | YES | - | AB working Namespace |


## Code generation

Structs related to CustomResourceDefinitions are defined in `pkg/apis/remoteenvironment/v1alpha1/types.go` and registered in `pkg/apis/remoteenvironment/v1alpha1/`. After making any changes there, please run:
Structs related to CustomResourceDefinitions are defined in `pkg/apis/application/v1alpha1/types.go` and registered in `pkg/apis/application/v1alpha1/`. After making any changes there, please run:
```bash
./hack/update-codegen.sh
```
39 changes: 25 additions & 14 deletions components/application-broker/cmd/broker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import (
"github.com/kyma-project/kyma/components/application-broker/internal/storage"
"github.com/kyma-project/kyma/components/application-broker/internal/storage/populator"
"github.com/kyma-project/kyma/components/application-broker/internal/syncer"
"github.com/kyma-project/kyma/components/application-broker/pkg/client/clientset/versioned"
"github.com/kyma-project/kyma/components/application-broker/pkg/client/informers/externalversions"
mappingCli "github.com/kyma-project/kyma/components/application-broker/pkg/client/clientset/versioned"
mappingInformer "github.com/kyma-project/kyma/components/application-broker/pkg/client/informers/externalversions"
"github.com/kyma-project/kyma/components/application-broker/platform/logger"
appCli "github.com/kyma-project/kyma/components/application-operator/pkg/client/clientset/versioned"
appInformer "github.com/kyma-project/kyma/components/application-operator/pkg/client/informers/externalversions"
"github.com/sirupsen/logrus"
"k8s.io/client-go/informers/core/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -70,30 +72,37 @@ func main() {
fatalOnError(err)
log.Info("Instance storage populated")

// RemoteEnvironments
reClient, err := versioned.NewForConfig(k8sConfig)
// Applications
appClient, err := appCli.NewForConfig(k8sConfig)
fatalOnError(err)
reInformerFactory := externalversions.NewSharedInformerFactory(reClient, informerResyncPeriod)
reInformersGroup := reInformerFactory.Applicationconnector().V1alpha1()
appInformerFactory := appInformer.NewSharedInformerFactory(appClient, informerResyncPeriod)
appInformersGroup := appInformerFactory.Applicationconnector().V1alpha1()

// Mapping
mClient, err := mappingCli.NewForConfig(k8sConfig)
fatalOnError(err)
mInformerFactory := mappingInformer.NewSharedInformerFactory(mClient, informerResyncPeriod)
mInformersGroup := mInformerFactory.Applicationconnector().V1alpha1()

// internal services
nsBrokerSyncer := syncer.NewServiceBrokerSyncer(scClientSet.ServicecatalogV1beta1())
relistRequester := syncer.NewRelistRequester(nsBrokerSyncer, cfg.BrokerRelistDurationWindow, cfg.UniqueSelectorLabelKey, cfg.UniqueSelectorLabelValue, log)
siFacade := broker.NewServiceInstanceFacade(scInformersGroup.ServiceInstances().Informer())
accessChecker := access.New(sFact.RemoteEnvironment(), reClient.ApplicationconnectorV1alpha1(), sFact.Instance())

reSyncCtrl := syncer.New(reInformersGroup.RemoteEnvironments(), sFact.RemoteEnvironment(), sFact.RemoteEnvironment(), relistRequester, log)
accessChecker := access.New(sFact.Application(), mClient.ApplicationconnectorV1alpha1(), sFact.Instance())

appSyncCtrl := syncer.New(appInformersGroup.Applications(), sFact.Application(), sFact.Application(), relistRequester, log)

brokerService, err := broker.NewNsBrokerService()
fatalOnError(err)

nsBrokerFacade := nsbroker.NewFacade(scClientSet.ServicecatalogV1beta1(), k8sClient.CoreV1(), brokerService, nsBrokerSyncer, cfg.Namespace, cfg.UniqueSelectorLabelKey, cfg.UniqueSelectorLabelValue, int32(cfg.Port), log)

mappingCtrl := mapping.New(reInformersGroup.EnvironmentMappings().Informer(), nsInformer, k8sClient.CoreV1().Namespaces(), sFact.RemoteEnvironment(), nsBrokerFacade, nsBrokerSyncer, log)
mappingCtrl := mapping.New(mInformersGroup.ApplicationMappings().Informer(), nsInformer, k8sClient.CoreV1().Namespaces(), sFact.Application(), nsBrokerFacade, nsBrokerSyncer, log)

// create broker
srv := broker.New(sFact.RemoteEnvironment(), sFact.Instance(), sFact.InstanceOperation(), accessChecker,
reClient.ApplicationconnectorV1alpha1(), siFacade, reInformersGroup.EnvironmentMappings().Lister(), brokerService, log)
srv := broker.New(sFact.Application(), sFact.Instance(), sFact.InstanceOperation(), accessChecker,
mClient.ApplicationconnectorV1alpha1(), siFacade, mInformersGroup.ApplicationMappings().Lister(), brokerService, log)

// setup graceful shutdown signals
ctx, cancelFunc := context.WithCancel(context.Background())
Expand All @@ -104,16 +113,18 @@ func main() {

// start informers
scInformerFactory.Start(stopCh)
reInformerFactory.Start(stopCh)
appInformerFactory.Start(stopCh)
mInformerFactory.Start(stopCh)
go nsInformer.Run(stopCh)

// wait for cache sync
scInformerFactory.WaitForCacheSync(stopCh)
reInformerFactory.WaitForCacheSync(stopCh)
appInformerFactory.WaitForCacheSync(stopCh)
mInformerFactory.WaitForCacheSync(stopCh)
cache.WaitForCacheSync(stopCh, nsInformer.HasSynced)

// start services & ctrl
go reSyncCtrl.Run(stopCh)
go appSyncCtrl.Run(stopCh)
go mappingCtrl.Run(stopCh)
go relistRequester.Run(stopCh)

Expand Down
17 changes: 9 additions & 8 deletions components/application-broker/cmd/poc-events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"path/filepath"
"time"

"github.com/kyma-project/kyma/components/application-broker/pkg/client/clientset/versioned"
"github.com/kyma-project/kyma/components/application-broker/pkg/client/clientset/versioned/scheme"
"github.com/kyma-project/kyma/components/application-operator/pkg/client/clientset/versioned"
"github.com/kyma-project/kyma/components/application-operator/pkg/client/clientset/versioned/scheme"

"github.com/pkg/errors"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -42,7 +43,7 @@ func main() {
panic(err)
}

reClient, err := versioned.NewForConfig(config)
appClient, err := versioned.NewForConfig(config)
if err != nil {
panic(err)
}
Expand All @@ -52,16 +53,16 @@ func main() {
fmt.Printf(format, args...)
})
broadcaster.StartRecordingToSink(&typedV1.EventSinkImpl{Interface: clientset.CoreV1().Events(metav1.NamespaceDefault)})
eventRecorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "Remote-Environment-Broker"})
eventRecorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "Application-Broker"})

re, err := reClient.ApplicationconnectorV1alpha1().RemoteEnvironments().Get("ec-prod", metav1.GetOptions{})
app, err := appClient.ApplicationconnectorV1alpha1().Applications().Get("ec-prod", metav1.GetOptions{})
if err != nil {
panic(errors.Wrap(err, "on getting remote environment"))
panic(errors.Wrap(err, "on getting application"))
}

ref, err := reference.GetReference(scheme.Scheme, re)
ref, err := reference.GetReference(scheme.Scheme, app)
if err != nil {
panic(errors.Wrap(err, "on getting reference for Remote Environment"))
panic(errors.Wrap(err, "on getting reference for Application"))
}

eventRecorder.Event(ref, v1.EventTypeWarning, "SomeReason", "Some additional message")
Expand Down
6 changes: 3 additions & 3 deletions components/application-broker/cmd/poc-events/findings.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Implementation is also merged to master and tagged with version: "v1.10.0-beta.4

So currently we get following error when calling UpdateStatus method.
```text
panic: while updating status: the server could not find the requested resource (put remoteenvironments.remoteenvironment.kyma.io ec-prod)
panic: while updating status: the server could not find the requested resource (put applications.application.kyma.io ec-prod)
```

To add `UpdateStatus` method to Remote Environment client, following actions has to be performed:
- add Status field for type `RemoteEnvironment`
To add `UpdateStatus` method to Application client, following actions has to be performed:
- add Status field for type `Application`
- remove annotation `+genclient:noStatus`

[API Conventions](https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status) contains information how Status should looks like:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: remoteenvironment.kyma.io/v1alpha1
kind: RemoteEnvironment
apiVersion: application.kyma.io/v1alpha1
kind: Application
metadata:
name: ec-prod
spec:
# source identifies remote environment in the cluster
# source identifies application in the cluster
source:
environment: "prod"
type: "commerce"
Expand Down Expand Up @@ -41,7 +41,7 @@ spec:
accessLabel: "access-label-1"
- type: Events

# second service provided by remote environment
# second service provided by application
- id: "48ab05bf-9aa4-4cb7-8999-0d3587265ac3"
displayName: "Orders"
longDescription: "Orders API"
Expand Down
Loading