Skip to content

Commit

Permalink
Update DataSource LastTransitionTime when populated PVC is updated (#…
Browse files Browse the repository at this point in the history
…2381)

* Update DataSource LastTransitionTime when populated source PVC is updated

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>

* Add Source field to DataSourceStatus

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
  • Loading branch information
arnongilboa authored Aug 5, 2022
1 parent 318c55e commit b85cd73
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 2 deletions.
8 changes: 8 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5439,13 +5439,21 @@
"v1beta1.DataSourceStatus": {
"description": "DataSourceStatus provides the most recently observed status of the DataSource",
"type": "object",
"required": [
"source"
],
"properties": {
"conditions": {
"type": "array",
"items": {
"default": {},
"$ref": "#/definitions/v1beta1.DataSourceCondition"
}
},
"source": {
"description": "Source is the current source of the data referenced by the DataSource",
"default": {},
"$ref": "#/definitions/v1beta1.DataSourceSource"
}
}
},
Expand Down
10 changes: 9 additions & 1 deletion pkg/apis/core/v1beta1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/controller/datasource-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func (r *DataSourceReconciler) Reconcile(ctx context.Context, req reconcile.Requ
}

func (r *DataSourceReconciler) update(ctx context.Context, dataSource *cdiv1.DataSource) error {
if !reflect.DeepEqual(dataSource.Status.Source, dataSource.Spec.Source) {
dataSource.Spec.Source.DeepCopyInto(&dataSource.Status.Source)
dataSource.Status.Conditions = nil
}
dataSourceCopy := dataSource.DeepCopy()
sourcePVC := dataSource.Spec.Source.PVC
if sourcePVC != nil {
Expand Down
21 changes: 21 additions & 0 deletions pkg/operator/resources/crds_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -5754,6 +5754,27 @@ spec:
- type
type: object
type: array
source:
description: Source is the current source of the data referenced by
the DataSource
properties:
pvc:
description: DataVolumeSourcePVC provides the parameters to create
a Data Volume from an existing PVC
properties:
name:
description: The name of the source PVC
type: string
namespace:
description: The namespace of the source PVC
type: string
required:
- name
- namespace
type: object
type: object
required:
- source
type: object
required:
- spec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ type DataSourceSource struct {

// DataSourceStatus provides the most recently observed status of the DataSource
type DataSourceStatus struct {
// Source is the current source of the data referenced by the DataSource
Source DataSourceSource `json:"source"`
Conditions []DataSourceCondition `json:"conditions,omitempty" optional:"true"`
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions tests/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,27 @@ var _ = Describe("DataSource", func() {
ds1 = waitForReadyCondition(ds1, corev1.ConditionFalse, "NotFound")
ds2 = waitForReadyCondition(ds2, corev1.ConditionFalse, "NotFound")
})

It("status conditions timestamp should be updated when DataSource referred pvc is updated, although condition status does not change", func() {
createDv(pvc1Name, testUrl())
ds := createDs(ds1Name, pvc1Name)
ds = waitForReadyCondition(ds, corev1.ConditionTrue, "Ready")
cond := controller.FindDataSourceConditionByType(ds, cdiv1.DataSourceReady)
Expect(cond).ToNot(BeNil())
ts := cond.LastTransitionTime

createDv(pvc2Name, testUrl())
err := utils.WaitForDataVolumePhase(f, f.Namespace.Name, cdiv1.Succeeded, pvc2Name)
Expect(err).ToNot(HaveOccurred())
updateDsPvc(ds, pvc2Name)

Eventually(func() metav1.Time {
ds, err = f.CdiClient.CdiV1beta1().DataSources(ds.Namespace).Get(context.TODO(), ds.Name, metav1.GetOptions{})
Expect(ds.Spec.Source.PVC.Name).To(Equal(pvc2Name))
cond = controller.FindDataSourceConditionByType(ds, cdiv1.DataSourceReady)
Expect(cond).ToNot(BeNil())
Expect(cond.Status).To(Equal(corev1.ConditionTrue))
return cond.LastTransitionTime
}, 60*time.Second, pollingInterval).ShouldNot(Equal(ts))
})
})

0 comments on commit b85cd73

Please sign in to comment.