Skip to content
This repository was archived by the owner on Jun 26, 2024. It is now read-only.

Commit d4799a6

Browse files
authored
Remove 'mountPath' support (#1035)
Reportedly, mountPath hasn't seen a lot of use, and it doesn't make sense to support it for GA. Therefore, unless we want to commit to it for GA, we should remove it now. Signed-off-by: Andy Sadler <[email protected]>
1 parent fe3abe1 commit d4799a6

File tree

11 files changed

+40
-272
lines changed

11 files changed

+40
-272
lines changed

apis/binding/v1alpha1/servicebinding_types.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ var templates = map[string]string{
3030

3131
// ServiceBindingSpec defines the desired state of ServiceBinding.
3232
type ServiceBindingSpec struct {
33-
// MountPath specifies the path inside the app container where bindings
34-
// will be mounted. The environment variable `SERVICE_BINDING_ROOT`
35-
// has higher precedence than this option, and setting it within an
36-
// application to be bound will cause MountPath to be ignored and will
37-
// always mount resources as files. If it isn't set, then it is
38-
// automatically set to the value of MountPath. If neither MountPath
39-
// nor `SERVICE_BINDING_ROOT` are set, this field defaults to
40-
// `/bindings`, and `SERVICE_BINDING_ROOT` is also set. This results
41-
// in the file being mounted under the directory specified.
42-
// +optional
43-
MountPath string `json:"mountPath,omitempty"`
44-
4533
// NamingStrategy defines custom string template for preparing binding
4634
// names. It can be set to pre-defined strategies: `none`,
4735
// `lowercase`, or `uppercase`. Otherwise, it is treated as a custom
@@ -70,8 +58,9 @@ type ServiceBindingSpec struct {
7058
DetectBindingResources bool `json:"detectBindingResources,omitempty"`
7159

7260
// BindAsFiles makes the binding values available as files in the
73-
// application's container. See the MountPath attribute description
74-
// for more details.
61+
// application's container. By default, values are mounted under the path
62+
// "/bindings"; this can be changed by setting the SERVICE_BINDING_ROOT
63+
// environment variable.
7564
// +optional
7665
// +kubebuilder:default:=true
7766
BindAsFiles bool `json:"bindAsFiles"`

config/crd/bases/binding.operators.coreos.com_servicebindings.yaml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ spec:
133133
bindAsFiles:
134134
default: true
135135
description: BindAsFiles makes the binding values available as files
136-
in the application's container. See the MountPath attribute description
137-
for more details.
136+
in the application's container. By default, values are mounted
137+
under the path "/bindings"; this can be changed by setting the SERVICE_BINDING_ROOT
138+
environment variable.
138139
type: boolean
139140
detectBindingResources:
140141
description: DetectBindingResources is a flag that, when set to true,
@@ -160,17 +161,6 @@ spec:
160161
- value
161162
type: object
162163
type: array
163-
mountPath:
164-
description: MountPath specifies the path inside the app container
165-
where bindings will be mounted. The environment variable `SERVICE_BINDING_ROOT`
166-
has higher precedence than this option, and setting it within an
167-
application to be bound will cause MountPath to be ignored and will
168-
always mount resources as files. If it isn't set, then it is automatically
169-
set to the value of MountPath. If neither MountPath nor `SERVICE_BINDING_ROOT`
170-
are set, this field defaults to `/bindings`, and `SERVICE_BINDING_ROOT`
171-
is also set. This results in the file being mounted under the directory
172-
specified.
173-
type: string
174164
namingStrategy:
175165
description: 'NamingStrategy defines custom string template for preparing
176166
binding names. It can be set to pre-defined strategies: `none`,

docs/User_Guide.md

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -283,51 +283,9 @@ bindings
283283
│ ├── COCKROACHDB_CONF_PORT
284284
```
285285

286-
Instead of `/bindings`, you can specify a custom binding root path by specifying the same in `spec.mountPath`, example,
286+
Setting `spec.bindAsFiles` to `false` (default: `true`) enables injecting gathered bindings as environment variables into the application/workload instead of injecting this data as files.
287287

288-
``` yaml
289-
apiVersion: binding.operators.coreos.com/v1alpha1
290-
kind: ServiceBinding
291-
metadata:
292-
name: binding-request
293-
namespace: service-binding-demo
294-
spec:
295-
bindAsFiles: true
296-
application:
297-
name: java-app
298-
group: apps
299-
version: v1
300-
resource: deployments
301-
services:
302-
- group: charts.helm.k8s.io
303-
version: v1alpha1
304-
kind: Cockroachdb
305-
name: db-demo
306-
id: db_1
307-
mounthPath: '/bindings/accounts-db' # User configurable binding root
308-
```
309-
310-
Here's how the mount paths would look like, where applicable:
311-
312-
```
313-
bindings
314-
├── accounts-db
315-
│ ├── COCKROACHDB_CLUSTERIP
316-
│ ├── COCKROACHDB_CONF_PORT
317-
```
318-
319-
Setting `spec.bindAsFiles` to `false` (default: `true`) enables injecting gathered bindings as env variables into the application/workload.
320-
321-
For determining the folder where bindings should be injected, we can specify the destination using `spec.mountPath` or we can use `SERVICE_BINDING_ROOT` environment variable. If both are set then the `SERVICE_BINDING_ROOT` environment variable takes the higher precedence.
322-
323-
The following table summarizes how the final bind path is computed:
324-
325-
| spec.mountPath | SERVICE_BINDING_ROOT | Final Bind Path |
326-
| --------------- | ---------------------| -------------------------------------|
327-
| nil | non-existent | /bindings/ServiceBinding_Name |
328-
| nil | /some/path/root | /some/path/root/ServiceBinding_Name |
329-
| /home/foo | non-existent | /home/foo |
330-
| /home/foo | /some/path/root | /some/path/root/ServiceBinding_Name |
288+
For determining the folder where bindings should be injected, we can use the `SERVICE_BINDING_ROOT` environment variable. This provides a method for overriding the path that injected configuration data will be exposed.
331289

332290
## Custom naming strategy
333291
Binding names declared through annotations or CSV descriptors are processed before injected into the application according to the following strategy

pkg/reconcile/pipeline/api.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ type Context interface {
110110
// Return true if bindings should be projected as files inside application containers
111111
BindAsFiles() bool
112112

113-
// Path where bindings should be mounted inside application containers
114-
MountPath() string
115-
116113
// Template that should be applied on collected binding names, prior projection
117114
NamingTemplate() string
118115

pkg/reconcile/pipeline/context/impl.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ func (i *bindingImpl) EnvBindings() []*pipeline.EnvBinding {
135135
return make([]*pipeline.EnvBinding, 0)
136136
}
137137

138-
func (i *bindingImpl) MountPath() string {
139-
return i.serviceBinding.Spec.MountPath
140-
}
141-
142138
func (i *bindingImpl) Mappings() map[string]string {
143139
result := make(map[string]string)
144140
for _, m := range i.serviceBinding.Spec.Mappings {

pkg/reconcile/pipeline/context/spec_binding_impl.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,6 @@ func (s *specImpl) BindAsFiles() bool {
185185
return true
186186
}
187187

188-
func (s *specImpl) MountPath() string {
189-
return ""
190-
}
191-
192188
func (s *specImpl) NamingTemplate() string {
193189
return ""
194190
}

pkg/reconcile/pipeline/handler/project/impl.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,8 @@ func mountPath(container map[string]interface{}, ctx pipeline.Context) (string,
374374
}
375375
}
376376

377-
mp := ctx.MountPath()
378-
if mp == "" {
379-
bindingRoot = "/bindings"
380-
mp = path.Join(bindingRoot, ctx.BindingName())
381-
} else {
382-
return mp, nil
383-
}
377+
bindingRoot = "/bindings"
378+
mp := path.Join(bindingRoot, ctx.BindingName())
384379

385380
u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&corev1.EnvVar{
386381
Name: bindingRootEnvVar,

pkg/reconcile/pipeline/handler/project/impl_test.go

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,26 +474,31 @@ var _ = Describe("Inject bindings as files", func() {
474474
}
475475

476476
ctx.EXPECT().Applications().Return(apps, nil)
477-
ctx.EXPECT().MountPath().Return("/bla").AnyTimes()
478477
ctx.EXPECT().BindingName().Return(bindingName).AnyTimes()
479478
})
480479
It("should mount binding secret as volume", func() {
481480
project.BindingsAsFiles(ctx)
482481
for i, old := range deploymentsUnstructuredOld {
483482
Expect(deploymentsUnstructured[i]).NotTo(Equal(old))
484483
}
485-
exoectedD1 := deployment("d1", []corev1.Container{
484+
expectedD1 := deployment("d1", []corev1.Container{
486485
{
487486
Image: "foo",
487+
Env: []corev1.EnvVar{
488+
{
489+
Name: "SERVICE_BINDING_ROOT",
490+
Value: "/bindings",
491+
},
492+
},
488493
VolumeMounts: []corev1.VolumeMount{
489494
{
490495
Name: bindingName,
491-
MountPath: "/bla",
496+
MountPath: "/bindings/sb1",
492497
},
493498
},
494499
},
495500
})
496-
exoectedD1.Spec.Template.Spec.Volumes = []corev1.Volume{
501+
expectedD1.Spec.Template.Spec.Volumes = []corev1.Volume{
497502
{
498503
Name: bindingName,
499504
VolumeSource: corev1.VolumeSource{
@@ -565,10 +570,16 @@ var _ = Describe("Inject bindings as files", func() {
565570
expectedD4 := deployment("d4", []corev1.Container{
566571
{
567572
Image: "foo",
573+
Env: []corev1.EnvVar{
574+
{
575+
Name: "SERVICE_BINDING_ROOT",
576+
Value: "/bindings",
577+
},
578+
},
568579
VolumeMounts: []corev1.VolumeMount{
569580
{
570581
Name: bindingName,
571-
MountPath: "/bla",
582+
MountPath: "/bindings/sb1",
572583
},
573584
},
574585
},
@@ -599,11 +610,15 @@ var _ = Describe("Inject bindings as files", func() {
599610
Name: "SOME_ENV",
600611
Value: "val1",
601612
},
613+
{
614+
Name: "SERVICE_BINDING_ROOT",
615+
Value: "/bindings",
616+
},
602617
},
603618
VolumeMounts: []corev1.VolumeMount{
604619
{
605620
Name: bindingName,
606-
MountPath: "/bla",
621+
MountPath: "/bindings/sb1",
607622
},
608623
},
609624
},
@@ -621,10 +636,16 @@ var _ = Describe("Inject bindings as files", func() {
621636
expectedD6 := deployment("d6", []corev1.Container{
622637
{
623638
Image: "foo",
639+
Env: []corev1.EnvVar{
640+
{
641+
Name: "SERVICE_BINDING_ROOT",
642+
Value: "/bindings",
643+
},
644+
},
624645
VolumeMounts: []corev1.VolumeMount{
625646
{
626647
Name: bindingName,
627-
MountPath: "/bla",
648+
MountPath: "/bindings/sb1",
628649
},
629650
},
630651
},
@@ -639,7 +660,7 @@ var _ = Describe("Inject bindings as files", func() {
639660
},
640661
},
641662
}
642-
for i, expectedDeployment := range []*appsv1.Deployment{exoectedD1, expectedD2, expectedD3, expectedD4, expectedD5, expectedD6, expectedD6, expectedD6, expectedD6} {
663+
for i, expectedDeployment := range []*appsv1.Deployment{expectedD1, expectedD2, expectedD3, expectedD4, expectedD5, expectedD6, expectedD6, expectedD6, expectedD6} {
643664
d := &appsv1.Deployment{}
644665
err := runtime.DefaultUnstructuredConverter.FromUnstructured(deploymentsUnstructured[i].Object, d)
645666
Expect(err).NotTo(HaveOccurred())

pkg/reconcile/pipeline/mocks/mocks_pipeline.go

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/acceptance/features/bindWithCustomNamingStrategies.feature

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ Feature: Bind an application to a service using custom naming strategies
175175
name: binding-request-custom-file-naming
176176
spec:
177177
namingStrategy: "PREFIX_{{ .service.kind | upper }}_{{ .name | upper }}_SUFFIX"
178-
mountPath: "/foo/bar"
179178
bindAsFiles: true
180179
application:
181180
name: myapp-custom-file-naming
@@ -189,7 +188,7 @@ Feature: Bind an application to a service using custom naming strategies
189188
name: backend-custom-file-naming
190189
"""
191190
Then Service Binding "binding-request-custom-file-naming" is ready
192-
And Content of file "/foo/bar/PREFIX_BACKEND_HOST_CROSS_NS_SERVICE_SUFFIX" in application pod is
191+
And Content of file "/bindings/binding-request-custom-file-naming/PREFIX_BACKEND_HOST_CROSS_NS_SERVICE_SUFFIX" in application pod is
193192
"""
194193
cross.ns.service.stable.example.com
195194
"""

0 commit comments

Comments
 (0)