/
in_cluster_application.go
54 lines (45 loc) · 1.93 KB
/
in_cluster_application.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package server
import (
"github.com/codeready-toolchain/registration-service/pkg/application"
"github.com/codeready-toolchain/registration-service/pkg/application/service"
"github.com/codeready-toolchain/registration-service/pkg/application/service/factory"
"github.com/codeready-toolchain/registration-service/pkg/configuration"
"github.com/codeready-toolchain/registration-service/pkg/informers"
"github.com/codeready-toolchain/registration-service/pkg/kubeclient"
"k8s.io/client-go/rest"
)
// NewInClusterApplication creates a new in-cluster application with the specified configuration and options. This
// application type is intended to run inside a Kubernetes cluster, where it makes use of the rest.InClusterConfig()
// function to determine which Kubernetes configuration to use to create the REST client that interacts with the
// Kubernetes service endpoints.
func NewInClusterApplication(informer informers.Informer) (application.Application, error) {
k8sConfig, err := rest.InClusterConfig()
if err != nil {
return nil, err
}
kubeClient, err := kubeclient.NewCRTRESTClient(k8sConfig, informer, configuration.Namespace())
if err != nil {
return nil, err
}
return &InClusterApplication{
serviceFactory: factory.NewServiceFactory(
factory.WithServiceContextOptions(factory.CRTClientOption(kubeClient),
factory.InformerOption(informer),
)),
}, nil
}
type InClusterApplication struct {
serviceFactory *factory.ServiceFactory
}
func (r InClusterApplication) InformerService() service.InformerService {
return r.serviceFactory.InformerService()
}
func (r InClusterApplication) SignupService() service.SignupService {
return r.serviceFactory.SignupService()
}
func (r InClusterApplication) VerificationService() service.VerificationService {
return r.serviceFactory.VerificationService()
}
func (r InClusterApplication) MemberClusterService() service.MemberClusterService {
return r.serviceFactory.MemberClusterService()
}