Skip to content

Commit c03a289

Browse files
authored
Template Readiness Checks (#15)
These last two fields (name & namespace) use the old accessor and string types, by making them plain strings (that may be templated) then we can thrown away yet more legacy code.
1 parent 9cf9809 commit c03a289

File tree

9 files changed

+33
-304
lines changed

9 files changed

+33
-304
lines changed

crds/servicebroker.couchbase.com_servicebrokerconfigs.yaml

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -83,37 +83,11 @@ spec:
8383
type: string
8484
name:
8585
description: Name is the resource name to poll.
86-
properties:
87-
parameter:
88-
description: Parameter, if set, uses the corresponding
89-
request parameter for the parameter source.
90-
type: string
91-
registry:
92-
description: Registry , if set, uses the corresponding
93-
registry value for the parameter source.
94-
pattern: ^[a-zA-Z0-9-]+$
95-
type: string
96-
string:
97-
description: String is a literal string value.
98-
type: string
99-
type: object
86+
type: string
10087
namespace:
10188
description: Namespace is the namespace the resource
10289
resides in.
103-
properties:
104-
parameter:
105-
description: Parameter, if set, uses the corresponding
106-
request parameter for the parameter source.
107-
type: string
108-
registry:
109-
description: Registry , if set, uses the corresponding
110-
registry value for the parameter source.
111-
pattern: ^[a-zA-Z0-9-]+$
112-
type: string
113-
string:
114-
description: String is a literal string value.
115-
type: string
116-
type: object
90+
type: string
11791
status:
11892
description: Status is the status of the condition
11993
that must match e.g. "True"
@@ -193,37 +167,11 @@ spec:
193167
type: string
194168
name:
195169
description: Name is the resource name to poll.
196-
properties:
197-
parameter:
198-
description: Parameter, if set, uses the corresponding
199-
request parameter for the parameter source.
200-
type: string
201-
registry:
202-
description: Registry , if set, uses the corresponding
203-
registry value for the parameter source.
204-
pattern: ^[a-zA-Z0-9-]+$
205-
type: string
206-
string:
207-
description: String is a literal string value.
208-
type: string
209-
type: object
170+
type: string
210171
namespace:
211172
description: Namespace is the namespace the resource
212173
resides in.
213-
properties:
214-
parameter:
215-
description: Parameter, if set, uses the corresponding
216-
request parameter for the parameter source.
217-
type: string
218-
registry:
219-
description: Registry , if set, uses the corresponding
220-
registry value for the parameter source.
221-
pattern: ^[a-zA-Z0-9-]+$
222-
type: string
223-
string:
224-
description: String is a literal string value.
225-
type: string
226-
type: object
174+
type: string
227175
status:
228176
description: Status is the status of the condition
229177
that must match e.g. "True"

documentation/modules/ROOT/pages/concepts/dynamic-attributes.adoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ Service Broker defined functions are divided into categories based on their beha
6565
* Generators--these generate data items.
6666
* Assertions--these perform error checking.
6767

68-
[#accessors]
6968
=== Accessors
7069

7170
Accessors do a simple lookup of a value from available data sources.
@@ -167,7 +166,7 @@ metadata:
167166

168167
=== Mutators
169168

170-
Mutators build upon accessors and allow data to be modified.
169+
Mutators allow data to be modified.
171170

172171
==== Default
173172

documentation/modules/ROOT/pages/reference/servicebrokerconfigs.adoc

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@ readinessChecks:
499499
- condition:
500500
apiVersion: apps/v1
501501
kind: Deployment
502-
namespace: {}
503-
name: {}
502+
namespace: '{{ registry "namespace" | json }}'
503+
name: '{{ registry "instance-name" | json }}'
504504
type: Available
505505
status: "True"
506506
----
@@ -521,16 +521,16 @@ This attribute defines the resource kind of the desired resource.
521521
==== readinessChecks.condition.namespace
522522

523523
This attribute defines the namespace the desired resource exists in.
524+
This attribute may be templated as per dynamic attributes.
524525

525-
* This attribute is required and must be an object.
526-
* This attribute is described in more detail in the <<string,string>> reference.
526+
* This attribute is required and must be a string.
527527

528528
==== readinessChecks.condition.name
529529

530530
This attribute defines the name the desired resource has.
531+
This attribute may be templated as per dynamic attributes.
531532

532-
* This attribute is required and must be an object.
533-
* This attribute is described in more detail in the <<string,string>> reference.
533+
* This attribute is required and must be a string.
534534

535535
==== readinessChecks.condition.type
536536

@@ -543,59 +543,3 @@ This attribute defines the condition type to match.
543543
This attribute defines the condition status to match.
544544

545545
* This attribute is required and must be a string.
546-
547-
[#accessor]
548-
=== Accessor
549-
550-
This object is used by parameter sources to read configuration data dynamically from one of the available data sources.
551-
Only one of `registry` or `parameter` should be specified, the result is undefined otherwise.
552-
553-
[source,yaml]
554-
----
555-
registry: my-key
556-
parameter: /path/to/my/value
557-
----
558-
559-
==== registry
560-
561-
This attribute causes the Service Broker to source a value from the registry associated with the service instance or service binding.
562-
563-
* This attribute is optional and must be a string.
564-
565-
==== parameter
566-
567-
This attribute causes the Service Broker to source a value from the user-specified service instance or service binding request parameters.
568-
569-
* This attribute is optional and must be a string.
570-
571-
[#string]
572-
=== String
573-
574-
This object is a specialization of the <<accessor,accessor>> type that enforces type.
575-
It also allows a literal string value to be specified.
576-
Only one of `registry`, `parameter` or `string` can be specified, the result is undefined otherwise.
577-
578-
[source,yaml]
579-
----
580-
registry: my-key
581-
parameter: /path/to/my/value
582-
string: my-string
583-
----
584-
585-
==== registry
586-
587-
This attribute causes the Service Broker to source a value from the registry associated with the service instance or service binding.
588-
589-
* This attribute is optional and must be a string.
590-
591-
==== parameter
592-
593-
This attribute causes the Service Broker to source a value from the user-specified service instance or service binding request parameters.
594-
595-
* This attribute is optional and must be a string.
596-
597-
==== string
598-
599-
This attribute provides a literal string value.
600-
601-
* This attribute is optional and must be a string.

examples/configurations/couchbase-server/broker.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,8 @@ spec:
453453
condition:
454454
apiVersion: couchbase.com/v2
455455
kind: CouchbaseCluster
456-
namespace:
457-
registry: namespace
458-
name:
459-
registry: instance-name
456+
namespace: '{{ registry "namespace" | json }}'
457+
name: '{{ registry "instance-name" | json }}'
460458
type: Available
461459
status: "True"
462460
serviceBinding:

pkg/apis/servicebroker/v1alpha1/types.go

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,10 @@ type ConfigurationReadinessCheckCondition struct {
308308
Kind string `json:"kind"`
309309

310310
// Namespace is the namespace the resource resides in.
311-
Namespace String `json:"namespace"`
311+
Namespace string `json:"namespace"`
312312

313313
// Name is the resource name to poll.
314-
Name String `json:"name"`
314+
Name string `json:"name"`
315315

316316
// Type is the type of the condition to look for e.g. "Available"
317317
Type string `json:"type"`
@@ -320,29 +320,6 @@ type ConfigurationReadinessCheckCondition struct {
320320
Status string `json:"status"`
321321
}
322322

323-
// Accessor is an argument that references data from either parameters or
324-
// the registry.
325-
type Accessor struct {
326-
// Registry , if set, uses the corresponding registry value for the
327-
// parameter source.
328-
// +kubebuilder:validation:Pattern="^[a-zA-Z0-9-]+$"
329-
Registry *string `json:"registry,omitempty"`
330-
331-
// Parameter, if set, uses the corresponding request parameter for the
332-
// parameter source.
333-
Parameter *string `json:"parameter,omitempty"`
334-
}
335-
336-
// String allows the specification of a string value from either a literal source
337-
// or an accessor.
338-
type String struct {
339-
// Accessor allows the string to be read from the registry or parameters.
340-
Accessor `json:",inline"`
341-
342-
// String is a literal string value.
343-
String *string `json:"string,omitempty"`
344-
}
345-
346323
// ServiceBrokerConfigStatus records status information about a configuration
347324
// as the Service Broker processes it.
348325
type ServiceBrokerConfigStatus struct {

pkg/apis/servicebroker/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/provisioners/readiness.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
v1 "github.com/couchbase/service-broker/pkg/apis/servicebroker/v1alpha1"
2121
"github.com/couchbase/service-broker/pkg/config"
22+
"github.com/couchbase/service-broker/pkg/errors"
2223
"github.com/couchbase/service-broker/pkg/operation"
2324
"github.com/couchbase/service-broker/pkg/registry"
2425

@@ -55,16 +56,26 @@ func (e *conditionUnreadyError) Error() string {
5556
// conditionReady waits for a condition on a resource to report as ready. Returns nil on success and
5657
// an error otherwise.
5758
func conditionReady(entry *registry.Entry, condition *v1.ConfigurationReadinessCheckCondition) error {
58-
namespace, err := resolveString(&condition.Namespace, entry)
59+
namespaceRaw, err := renderTemplateString(condition.Namespace, entry)
5960
if err != nil {
6061
return err
6162
}
6263

63-
name, err := resolveString(&condition.Name, entry)
64+
namespace, ok := namespaceRaw.(string)
65+
if !ok {
66+
return errors.NewConfigurationError("condition resource namespace not a string %v", namespaceRaw)
67+
}
68+
69+
nameRaw, err := renderTemplateString(condition.Name, entry)
6470
if err != nil {
6571
return err
6672
}
6773

74+
name, ok := nameRaw.(string)
75+
if !ok {
76+
return errors.NewConfigurationError("condition resource name not a string %v", nameRaw)
77+
}
78+
6879
gv, err := schema.ParseGroupVersion(condition.APIVersion)
6980
if err != nil {
7081
return err

0 commit comments

Comments
 (0)