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

Commit ecbab0f

Browse files
authored
Use k8s api condition type for status.conditions (#851)
Condition type got available in 1.19 API. Hence, we can drop the usage of github.com/openshift/custom-resource-status library. Signed-off-by: Predrag Knezevic <[email protected]>
1 parent 95503bf commit ecbab0f

File tree

16 files changed

+152
-503
lines changed

16 files changed

+152
-503
lines changed

api/v1alpha1/servicebinding_types.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20-
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
2120
corev1 "k8s.io/api/core/v1"
2221
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2322
)
2423

2524
const (
2625
// BindingReady indicates that the overall sbr succeeded
27-
BindingReady conditionsv1.ConditionType = "Ready"
26+
BindingReady string = "Ready"
2827
// CollectionReady indicates readiness for collection and persistance of intermediate manifests
29-
CollectionReady conditionsv1.ConditionType = "CollectionReady"
28+
CollectionReady string = "CollectionReady"
3029
// InjectionReady indicates readiness to change application manifests to use those intermediate manifests
3130
// If status is true, it indicates that the binding succeeded
32-
InjectionReady conditionsv1.ConditionType = "InjectionReady"
31+
InjectionReady string = "InjectionReady"
3332
// EmptyServiceSelectorsReason is used when the ServiceBinding has empty
3433
// services.
3534
EmptyServiceSelectorsReason = "EmptyServiceSelectors"
@@ -40,6 +39,8 @@ const (
4039
ApplicationNotFoundReason = "ApplicationNotFound"
4140
// ServiceNotFoundReason is used when the service is not found.
4241
ServiceNotFoundReason = "ServiceNotFound"
42+
43+
BindingInjectedReason = "BindingInjected"
4344
)
4445

4546
// ServiceBindingSpec defines the desired state of ServiceBinding
@@ -93,7 +94,11 @@ type Mapping struct {
9394
// +k8s:openapi-gen=true
9495
type ServiceBindingStatus struct {
9596
// Conditions describes the state of the operator's reconciliation functionality.
96-
Conditions []conditionsv1.Condition `json:"conditions"`
97+
// +patchMergeKey=type
98+
// +patchStrategy=merge
99+
// +listType=map
100+
// +listMapKey=type
101+
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
97102
// Secret is the name of the intermediate secret
98103
Secret string `json:"secret"`
99104
// Applications contain all the applications filtered by name or label

api/v1alpha1/zz_generated.deepcopy.go

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

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

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,35 +230,80 @@ spec:
230230
description: Conditions describes the state of the operator's reconciliation
231231
functionality.
232232
items:
233-
description: Condition represents the state of the operator's reconciliation
234-
functionality.
233+
description: "Condition contains details for one aspect of the current
234+
state of this API Resource. --- This struct is intended for direct
235+
use as an array at the field path .status.conditions. For example,
236+
type FooStatus struct{ // Represents the observations of a
237+
foo's current state. // Known .status.conditions.type are:
238+
\"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type
239+
\ // +patchStrategy=merge // +listType=map // +listMapKey=type
240+
\ Conditions []metav1.Condition `json:\"conditions,omitempty\"
241+
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`
242+
\n // other fields }"
235243
properties:
236-
lastHeartbeatTime:
237-
format: date-time
238-
type: string
239244
lastTransitionTime:
245+
description: lastTransitionTime is the last time the condition
246+
transitioned from one status to another. This should be when
247+
the underlying condition changed. If that is not known, then
248+
using the time when the API field changed is acceptable.
240249
format: date-time
241250
type: string
242251
message:
252+
description: message is a human readable message indicating
253+
details about the transition. This may be an empty string.
254+
maxLength: 32768
243255
type: string
256+
observedGeneration:
257+
description: observedGeneration represents the .metadata.generation
258+
that the condition was set based upon. For instance, if .metadata.generation
259+
is currently 12, but the .status.conditions[x].observedGeneration
260+
is 9, the condition is out of date with respect to the current
261+
state of the instance.
262+
format: int64
263+
minimum: 0
264+
type: integer
244265
reason:
266+
description: reason contains a programmatic identifier indicating
267+
the reason for the condition's last transition. Producers
268+
of specific condition types may define expected values and
269+
meanings for this field, and whether the values are considered
270+
a guaranteed API. The value should be a CamelCase string.
271+
This field may not be empty.
272+
maxLength: 1024
273+
minLength: 1
274+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
245275
type: string
246276
status:
277+
description: status of the condition, one of True, False, Unknown.
278+
enum:
279+
- "True"
280+
- "False"
281+
- Unknown
247282
type: string
248283
type:
249-
description: ConditionType is the state of the operator's reconciliation
250-
functionality.
284+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
285+
--- Many .condition.type values are consistent across resources
286+
like Available, but because arbitrary conditions can be useful
287+
(see .node.status.conditions), the ability to deconflict is
288+
important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
289+
maxLength: 316
290+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
251291
type: string
252292
required:
293+
- lastTransitionTime
294+
- message
295+
- reason
253296
- status
254297
- type
255298
type: object
256299
type: array
300+
x-kubernetes-list-map-keys:
301+
- type
302+
x-kubernetes-list-type: map
257303
secret:
258304
description: Secret is the name of the intermediate secret
259305
type: string
260306
required:
261-
- conditions
262307
- secret
263308
type: object
264309
required:

controllers/reconciler.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package controllers
33
import (
44
"context"
55
"errors"
6+
"k8s.io/apimachinery/pkg/api/meta"
67

7-
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
8-
corev1 "k8s.io/api/core/v1"
98
k8serrors "k8s.io/apimachinery/pkg/api/errors"
109
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1110
"k8s.io/apimachinery/pkg/runtime"
@@ -87,19 +86,21 @@ func (r *ServiceBindingReconciler) doReconcile(request reconcile.Request) (recon
8786
_, updateErr := updateServiceBindingStatus(
8887
r.dynClient,
8988
sbr,
90-
conditionsv1.Condition{
89+
metav1.Condition{
9190
Type: v1alpha1.CollectionReady,
92-
Status: corev1.ConditionFalse,
91+
Status: metav1.ConditionFalse,
9392
Reason: v1alpha1.EmptyServiceSelectorsReason,
9493
Message: errEmptyServices.Error(),
9594
},
96-
conditionsv1.Condition{
95+
metav1.Condition{
9796
Type: v1alpha1.InjectionReady,
98-
Status: corev1.ConditionFalse,
97+
Reason: v1alpha1.EmptyServiceSelectorsReason,
98+
Status: metav1.ConditionFalse,
9999
},
100-
conditionsv1.Condition{
100+
metav1.Condition{
101101
Type: v1alpha1.BindingReady,
102-
Status: corev1.ConditionFalse,
102+
Reason: v1alpha1.EmptyServiceSelectorsReason,
103+
Status: metav1.ConditionFalse,
103104
},
104105
)
105106
if updateErr == nil {
@@ -125,19 +126,21 @@ func (r *ServiceBindingReconciler) doReconcile(request reconcile.Request) (recon
125126
//handle service not found error
126127
if k8serrors.IsNotFound(err) {
127128
err = updateSBRConditions(r.dynClient, sbr,
128-
conditionsv1.Condition{
129+
metav1.Condition{
129130
Type: v1alpha1.CollectionReady,
130-
Status: corev1.ConditionFalse,
131+
Status: metav1.ConditionFalse,
131132
Reason: v1alpha1.ServiceNotFoundReason,
132133
Message: err.Error(),
133134
},
134-
conditionsv1.Condition{
135+
metav1.Condition{
135136
Type: v1alpha1.InjectionReady,
136-
Status: corev1.ConditionFalse,
137+
Reason: v1alpha1.ServiceNotFoundReason,
138+
Status: metav1.ConditionFalse,
137139
},
138-
conditionsv1.Condition{
140+
metav1.Condition{
139141
Type: v1alpha1.BindingReady,
140-
Status: corev1.ConditionFalse,
142+
Reason: v1alpha1.ServiceNotFoundReason,
143+
Status: metav1.ConditionFalse,
141144
},
142145
)
143146
if err != nil {
@@ -223,9 +226,9 @@ func (r *ServiceBindingReconciler) doReconcile(request reconcile.Request) (recon
223226
return sb.bind()
224227
}
225228

226-
func updateSBRConditions(dynClient dynamic.Interface, sbr *v1alpha1.ServiceBinding, conditions ...conditionsv1.Condition) error {
229+
func updateSBRConditions(dynClient dynamic.Interface, sbr *v1alpha1.ServiceBinding, conditions ...metav1.Condition) error {
227230
for _, v := range conditions {
228-
conditionsv1.SetStatusCondition(&sbr.Status.Conditions, v)
231+
meta.SetStatusCondition(&sbr.Status.Conditions, v)
229232
}
230233
u, err := converter.ToUnstructured(sbr)
231234
if err != nil {

controllers/reconciler_test.go

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
corev1 "k8s.io/api/core/v1"
1414
"k8s.io/apimachinery/pkg/api/meta"
1515
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16-
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1716
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1817
"k8s.io/apimachinery/pkg/runtime"
1918
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -22,8 +21,6 @@ import (
2221
"sigs.k8s.io/controller-runtime/pkg/log/zap"
2322
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2423

25-
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
26-
2724
"github.com/redhat-developer/service-binding-operator/test/mocks"
2825
)
2926

@@ -52,28 +49,28 @@ func reconcileRequest() reconcile.Request {
5249
}
5350
}
5451

55-
func requireConditionPresentAndTrue(t *testing.T, condition conditionsv1.ConditionType, sbrConditions []conditionsv1.Condition) {
52+
func requireConditionPresentAndTrue(t *testing.T, conditionType string, sbrConditions []metav1.Condition) {
5653
require.True(t,
57-
conditionsv1.IsStatusConditionPresentAndEqual(
54+
meta.IsStatusConditionPresentAndEqual(
5855
sbrConditions,
59-
condition,
60-
corev1.ConditionTrue,
56+
conditionType,
57+
metav1.ConditionTrue,
6158
),
6259
"%+v should exist and be true; existing conditions: %+v",
63-
condition,
60+
conditionType,
6461
sbrConditions,
6562
)
6663
}
6764

68-
func requireConditionPresentAndFalse(t *testing.T, condition conditionsv1.ConditionType, sbrConditions []conditionsv1.Condition) {
65+
func requireConditionPresentAndFalse(t *testing.T, conditionType string, sbrConditions []metav1.Condition) {
6966
require.True(t,
70-
conditionsv1.IsStatusConditionPresentAndEqual(
67+
meta.IsStatusConditionPresentAndEqual(
7168
sbrConditions,
72-
condition,
73-
corev1.ConditionFalse,
69+
conditionType,
70+
metav1.ConditionFalse,
7471
),
7572
"%+v should exist and be false; existing conditions: %+v",
76-
condition,
73+
conditionType,
7774
sbrConditions,
7875
)
7976
}
@@ -139,7 +136,7 @@ func TestApplicationByName(t *testing.T) {
139136

140137
require.Equal(t, 1, len(sbrOutput.Status.Applications))
141138
expectedStatus := v1alpha1.BoundApplication{
142-
GroupVersionKind: v1.GroupVersionKind{
139+
GroupVersionKind: metav1.GroupVersionKind{
143140
Group: deploymentsGVR.Group,
144141
Version: deploymentsGVR.Version,
145142
Kind: "Deployment",
@@ -205,7 +202,7 @@ func TestReconcilerReconcileUsingSecret(t *testing.T) {
205202

206203
require.Equal(t, 1, len(sbrOutput.Status.Applications))
207204
expectedStatus := v1alpha1.BoundApplication{
208-
GroupVersionKind: v1.GroupVersionKind{
205+
GroupVersionKind: metav1.GroupVersionKind{
209206
Group: deploymentsGVR.Group,
210207
Version: deploymentsGVR.Version,
211208
Kind: "Deployment",
@@ -468,7 +465,7 @@ func TestReconcilerReconcileWithConflictingAppSelc(t *testing.T) {
468465
require.NoError(t, err)
469466

470467
expectedStatus := v1alpha1.BoundApplication{
471-
GroupVersionKind: v1.GroupVersionKind{
468+
GroupVersionKind: metav1.GroupVersionKind{
472469
Group: deploymentsGVR.Group,
473470
Version: deploymentsGVR.Version,
474471
Kind: "Deployment",
@@ -580,7 +577,7 @@ func TestBindTwoSbrsWithSingleApplication(t *testing.T) {
580577

581578
// expected sbr assertion
582579
expectedStatus := v1alpha1.BoundApplication{
583-
GroupVersionKind: v1.GroupVersionKind{
580+
GroupVersionKind: metav1.GroupVersionKind{
584581
Group: deploymentsGVR.Group,
585582
Version: deploymentsGVR.Version,
586583
Kind: "Deployment",
@@ -618,7 +615,7 @@ func TestBindTwoSbrsWithSingleApplication(t *testing.T) {
618615

619616
// expected sbr assertion
620617
expectedStatus = v1alpha1.BoundApplication{
621-
GroupVersionKind: v1.GroupVersionKind{
618+
GroupVersionKind: metav1.GroupVersionKind{
622619
Group: deploymentsGVR.Group,
623620
Version: deploymentsGVR.Version,
624621
Kind: "Deployment",

0 commit comments

Comments
 (0)