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

Get Binding Endpoint #1262

Merged
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
6a4bc24
Initial Test and Implementation
ralikio Oct 4, 2024
a7fb391
Merge branch 'main' into features/get-and-delete-bindings
ralikio Oct 7, 2024
4ab4bae
Added Missing Instance ID in Get Binding Method
ralikio Oct 7, 2024
a01e2f8
Removed Unnecessary Field
ralikio Oct 7, 2024
a1dea6e
Added Missing Instance ID in Get Binding Method
ralikio Oct 7, 2024
f1ae37d
Get Binding Implementation Correction
ralikio Oct 7, 2024
5a1c1de
Insert Binding in Bind Create Endpoint
ralikio Oct 7, 2024
360f8b5
Removed Unnecessary Field
ralikio Oct 7, 2024
000d44a
Added Missing Instance ID in Get Binding Method
ralikio Oct 7, 2024
2b8ccd9
Added Missing Instance ID in Get Binding Method
ralikio Oct 7, 2024
a7e007b
Get Binding Memory Implementation
ralikio Oct 7, 2024
7fb16c5
Missing Not Found Response
ralikio Oct 7, 2024
2d96154
Get Endpoint Test
ralikio Oct 7, 2024
78c7d45
Linter and Missing Error Check
ralikio Oct 8, 2024
d1b5399
Reverted Invalid Test Change
ralikio Oct 8, 2024
a83b769
Corrected Kubeconfig Assignment & Test Correction
ralikio Oct 8, 2024
6913554
Removed TODO
ralikio Oct 8, 2024
56a6dfd
Linter
ralikio Oct 8, 2024
24f69fb
Review Correction
ralikio Oct 9, 2024
f5b8f82
Review Corrections
ralikio Oct 9, 2024
07e50fa
Code Review
ralikio Oct 9, 2024
98387c6
Update internal/broker/bind_create.go
ralikio Oct 9, 2024
52020f4
Review Remarks
ralikio Oct 9, 2024
2532880
Review Remarks
ralikio Oct 9, 2024
949c6ea
Review Remarks
ralikio Oct 9, 2024
1154562
Review Remarks
ralikio Oct 9, 2024
3ea8737
Review Remarks
ralikio Oct 9, 2024
c12a739
Review Remarks
ralikio Oct 9, 2024
c19ef09
Review Remarks
ralikio Oct 9, 2024
bba7001
Review Remarks
ralikio Oct 9, 2024
33f13c2
Mock DB Correction
ralikio Oct 9, 2024
7eef843
Review Remarks - Additional Test Case
ralikio Oct 9, 2024
ecce43b
Linter
ralikio Oct 9, 2024
f340000
Merge branch 'main' into features/get-and-delete-bindings
ralikio Oct 9, 2024
0b7c3e1
Review Remarks
ralikio Oct 10, 2024
75b65f0
Linter
ralikio Oct 10, 2024
179c885
Review Remarks
ralikio Oct 10, 2024
d3147f6
Linter
ralikio Oct 10, 2024
34669fd
Merge branch 'main' into features/get-and-delete-bindings
ralikio Oct 10, 2024
462c175
Assertions Corrections
ralikio Oct 10, 2024
8f2a0a6
Assertions Corrections
ralikio Oct 10, 2024
eff2678
Assertion Corrections
ralikio Oct 10, 2024
83998f6
Merge branch 'main' into features/get-and-delete-bindings
ralikio Oct 10, 2024
e185ad5
Review Remarks
ralikio Oct 10, 2024
62d98dc
Merge branch 'main' into features/get-and-delete-bindings
ralikio Oct 10, 2024
1987267
Incorporate DB in Binding Selection E2E Test
ralikio Oct 10, 2024
e0885ca
Merge branch 'main' into features/get-and-delete-bindings
ralikio Oct 10, 2024
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
4 changes: 2 additions & 2 deletions cmd/broker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,9 @@ func createAPI(router *mux.Router, servicesConfig broker.ServicesConfig, planVal
planDefaults, logs, cfg.KymaDashboardConfig, kcBuilder, convergedCloudRegionProvider, kcpK8sClient),
GetInstanceEndpoint: broker.NewGetInstance(cfg.Broker, db.Instances(), db.Operations(), kcBuilder, logs),
LastOperationEndpoint: broker.NewLastOperation(db.Operations(), db.InstancesArchived(), logs),
BindEndpoint: broker.NewBind(cfg.Broker.Binding, db.Instances(), logs, clientProvider, kubeconfigProvider, gardenerClient),
BindEndpoint: broker.NewBind(cfg.Broker.Binding, db.Instances(), db.Bindings(), logs, clientProvider, kubeconfigProvider, gardenerClient),
UnbindEndpoint: broker.NewUnbind(logs),
GetBindingEndpoint: broker.NewGetBinding(logs),
GetBindingEndpoint: broker.NewGetBinding(logs, db.Bindings()),
LastBindingOperationEndpoint: broker.NewLastBindingOperation(logs),
}

Expand Down
34 changes: 30 additions & 4 deletions internal/broker/bind_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"fmt"
"net/http"
"strings"
"time"

"github.com/kyma-project/kyma-environment-broker/internal"
broker "github.com/kyma-project/kyma-environment-broker/internal/broker/bindings"
"github.com/kyma-project/kyma-environment-broker/internal/storage"
"github.com/kyma-project/kyma-environment-broker/internal/storage/dberr"
Expand All @@ -29,6 +31,7 @@ type BindingConfig struct {
type BindEndpoint struct {
config BindingConfig
instancesStorage storage.Instances
bindingsStorage storage.Bindings

serviceAccountBindingManager broker.BindingsManager
gardenerBindingsManager broker.BindingsManager
Expand All @@ -45,8 +48,11 @@ type Credentials struct {
Kubeconfig string `json:"kubeconfig"`
}

func NewBind(cfg BindingConfig, instanceStorage storage.Instances, log logrus.FieldLogger, clientProvider broker.ClientProvider, kubeconfigProvider broker.KubeconfigProvider, gardenerClient client.Client) *BindEndpoint {
return &BindEndpoint{config: cfg, instancesStorage: instanceStorage, log: log.WithField("service", "BindEndpoint"),
func NewBind(cfg BindingConfig, instanceStorage storage.Instances, bindingsStorage storage.Bindings, log logrus.FieldLogger, clientProvider broker.ClientProvider, kubeconfigProvider broker.KubeconfigProvider, gardenerClient client.Client) *BindEndpoint {
jaroslaw-pieszka marked this conversation as resolved.
Show resolved Hide resolved
return &BindEndpoint{config: cfg,
instancesStorage: instanceStorage,
bindingsStorage: bindingsStorage,
log: log.WithField("service", "BindEndpoint"),
jaroslaw-pieszka marked this conversation as resolved.
Show resolved Hide resolved
serviceAccountBindingManager: broker.NewServiceAccountBindingsManager(clientProvider, kubeconfigProvider),
gardenerBindingsManager: broker.NewGardenerBindingManager(gardenerClient),
}
Expand Down Expand Up @@ -112,19 +118,39 @@ func (b *BindEndpoint) Bind(ctx context.Context, instanceID, bindingID string, d
}

var kubeconfig string
binding := &internal.Binding{
ID: bindingID,
InstanceID: instanceID,

CreatedAt: time.Now(),
UpdatedAt: time.Now(),

ExpirationSeconds: int64(expirationSeconds),
}
if parameters.ServiceAccount {
// get kubeconfig for the instance
kubeconfig, err = b.serviceAccountBindingManager.Create(ctx, instance, bindingID, expirationSeconds)
if err != nil {
message := fmt.Sprintf("failed to create kyma binding for service account using token request: %s", err)
message := fmt.Sprintf("failed to create a Kyma binding using service account's kubeconfig: %s", err)
return domain.Binding{}, apiresponses.NewFailureResponse(fmt.Errorf(message), http.StatusBadRequest, message)
}
binding.BindingType = internal.BINDING_TYPE_SERVICE_ACCOUNT
} else {
kubeconfig, err = b.gardenerBindingsManager.Create(ctx, instance, bindingID, expirationSeconds)
if err != nil {
message := fmt.Sprintf("failed to create kyma binding using adminkubeconfig gardener subresource: %s", err)
message := fmt.Sprintf("failed to create a Kyma binding using adminkubeconfig gardener subresource: %s", err)
return domain.Binding{}, apiresponses.NewFailureResponse(fmt.Errorf(message), http.StatusBadRequest, message)
}
binding.BindingType = internal.BINDING_TYPE_ADMIN_KUBECONFIG
}

binding.Kubeconfig = kubeconfig

err = b.bindingsStorage.Insert(binding)
if err != nil {
message := fmt.Sprintf("failed to insert Kyma binding into storage: %s", err)
return domain.Binding{}, apiresponses.NewFailureResponse(fmt.Errorf(message), http.StatusInternalServerError, message)
jaroslaw-pieszka marked this conversation as resolved.
Show resolved Hide resolved

}

return domain.Binding{
Expand Down
Loading
Loading