Skip to content

Commit af2d9eb

Browse files
committed
Feature: set real source type in status
1 parent 7eecfe0 commit af2d9eb

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

api/dataset/v1alpha1/dataset_types.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,17 @@ type DatasetStatus struct {
174174
// readOnly indicates whether the dataset is mounted as read-only.
175175
ReadOnly bool `json:"readOnly,omitempty"`
176176
LastSyncTime metav1.Time `json:"lastSyncTime,omitempty"`
177+
// SourceType defaults to spec.source.type, unless it is a REFERENCE,
178+
// in which case it will match the type of the original Dataset.
179+
SourceType DatasetType `json:"sourceType,omitempty"`
177180
}
178181

179182
// Dataset is the Schema for the datasets API
180183
// +genclient
181184
// +kubebuilder:object:root=true
182185
// +kubebuilder:subresource:status
183186
// +kubebuilder:resource:shortName=data
184-
// +kubebuilder:printcolumn:name="type",type=string,JSONPath=`.spec.source.type`
187+
// +kubebuilder:printcolumn:name="type",type=string,JSONPath=`.status.sourceType`
185188
// +kubebuilder:printcolumn:name="uri",type=string,JSONPath=`.spec.source.uri`
186189
// +kubebuilder:printcolumn:name="phase",type=string,JSONPath=`.status.phase`
187190
type Dataset struct {

config/crd/bases/dataset.baizeai.io_datasets.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ spec:
1717
scope: Namespaced
1818
versions:
1919
- additionalPrinterColumns:
20-
- jsonPath: .spec.source.type
20+
- jsonPath: .status.sourceType
2121
name: type
2222
type: string
2323
- jsonPath: .spec.source.uri
@@ -695,6 +695,11 @@ spec:
695695
description: readOnly indicates whether the dataset is mounted as
696696
read-only.
697697
type: boolean
698+
sourceType:
699+
description: |-
700+
SourceType defaults to spec.source.type, unless it is a REFERENCE,
701+
in which case it will match the type of the original Dataset.
702+
type: string
698703
syncRoundStatuses:
699704
description: |-
700705
syncRoundStatuses is a list of data sync round statuses.

internal/controller/dataset/dataset_controller.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func (r *DatasetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
102102
{typ: condTypeConfigMap, rec: r.reconcileConfigMap},
103103
{typ: condTypeJob, rec: r.reconcileJob},
104104
{typ: condTypeJobStatus, rec: r.reconcileJobStatus},
105+
{typ: "", rec: r.reconcileStatusType},
105106
}
106107
}
107108

@@ -110,7 +111,7 @@ func (r *DatasetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
110111
err := rr.rec(ctx, ds)
111112
ds.Status.Conditions = kubeutils.SetCondition(ds.Status.Conditions, rr.typ, err)
112113
if err != nil {
113-
log.Errorf("error reconciling dataset for %s/%s: %v", ds.Namespace, ds.Name, err)
114+
log.Errorf("error reconciling dataset(%s) for %s/%s: %v", rr.typ, ds.Namespace, ds.Name, err)
114115
break
115116
}
116117
}
@@ -726,6 +727,19 @@ func (r *DatasetReconciler) reconcileJob(ctx context.Context, ds *datasetv1alpha
726727
return nil
727728
}
728729

730+
func (r *DatasetReconciler) reconcileStatusType(ctx context.Context, ds *datasetv1alpha1.Dataset) error {
731+
if ds.Spec.Source.Type != datasetv1alpha1.DatasetTypeReference {
732+
ds.Status.SourceType = ds.Spec.Source.Type
733+
return nil
734+
}
735+
srcDs, err := r.getSourceDataset(ctx, ds)
736+
if err != nil {
737+
return err
738+
}
739+
ds.Status.SourceType = srcDs.Status.SourceType
740+
return nil
741+
}
742+
729743
func (r *DatasetReconciler) reconcileJobStatus(ctx context.Context, ds *datasetv1alpha1.Dataset) error {
730744
if !supportPreload(ds) {
731745
ds.Status.LastSyncTime = ds.CreationTimestamp

0 commit comments

Comments
 (0)