diff --git a/api/dataset/v1alpha1/dataset_types.go b/api/dataset/v1alpha1/dataset_types.go index 699b4b0..24ae28c 100644 --- a/api/dataset/v1alpha1/dataset_types.go +++ b/api/dataset/v1alpha1/dataset_types.go @@ -174,6 +174,9 @@ type DatasetStatus struct { // readOnly indicates whether the dataset is mounted as read-only. ReadOnly bool `json:"readOnly,omitempty"` LastSyncTime metav1.Time `json:"lastSyncTime,omitempty"` + // SourceType defaults to spec.source.type, unless it is a REFERENCE, + // in which case it will match the type of the original Dataset. + SourceType DatasetType `json:"sourceType,omitempty"` } // Dataset is the Schema for the datasets API @@ -181,7 +184,7 @@ type DatasetStatus struct { // +kubebuilder:object:root=true // +kubebuilder:subresource:status // +kubebuilder:resource:shortName=data -// +kubebuilder:printcolumn:name="type",type=string,JSONPath=`.spec.source.type` +// +kubebuilder:printcolumn:name="type",type=string,JSONPath=`.status.sourceType` // +kubebuilder:printcolumn:name="uri",type=string,JSONPath=`.spec.source.uri` // +kubebuilder:printcolumn:name="phase",type=string,JSONPath=`.status.phase` type Dataset struct { diff --git a/config/crd/bases/dataset.baizeai.io_datasets.yaml b/config/crd/bases/dataset.baizeai.io_datasets.yaml index 78fb71e..c8a331a 100644 --- a/config/crd/bases/dataset.baizeai.io_datasets.yaml +++ b/config/crd/bases/dataset.baizeai.io_datasets.yaml @@ -17,7 +17,7 @@ spec: scope: Namespaced versions: - additionalPrinterColumns: - - jsonPath: .spec.source.type + - jsonPath: .status.sourceType name: type type: string - jsonPath: .spec.source.uri @@ -695,6 +695,11 @@ spec: description: readOnly indicates whether the dataset is mounted as read-only. type: boolean + sourceType: + description: |- + SourceType defaults to spec.source.type, unless it is a REFERENCE, + in which case it will match the type of the original Dataset. + type: string syncRoundStatuses: description: |- syncRoundStatuses is a list of data sync round statuses. diff --git a/internal/controller/dataset/dataset_controller.go b/internal/controller/dataset/dataset_controller.go index 7233caf..6fcc245 100644 --- a/internal/controller/dataset/dataset_controller.go +++ b/internal/controller/dataset/dataset_controller.go @@ -102,6 +102,7 @@ func (r *DatasetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct {typ: condTypeConfigMap, rec: r.reconcileConfigMap}, {typ: condTypeJob, rec: r.reconcileJob}, {typ: condTypeJobStatus, rec: r.reconcileJobStatus}, + {typ: "", rec: r.reconcileStatusType}, } } @@ -110,7 +111,7 @@ func (r *DatasetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct err := rr.rec(ctx, ds) ds.Status.Conditions = kubeutils.SetCondition(ds.Status.Conditions, rr.typ, err) if err != nil { - log.Errorf("error reconciling dataset for %s/%s: %v", ds.Namespace, ds.Name, err) + log.Errorf("error reconciling dataset(%s) for %s/%s: %v", rr.typ, ds.Namespace, ds.Name, err) break } } @@ -726,6 +727,19 @@ func (r *DatasetReconciler) reconcileJob(ctx context.Context, ds *datasetv1alpha return nil } +func (r *DatasetReconciler) reconcileStatusType(ctx context.Context, ds *datasetv1alpha1.Dataset) error { + if ds.Spec.Source.Type != datasetv1alpha1.DatasetTypeReference { + ds.Status.SourceType = ds.Spec.Source.Type + return nil + } + srcDs, err := r.getSourceDataset(ctx, ds) + if err != nil { + return err + } + ds.Status.SourceType = srcDs.Status.SourceType + return nil +} + func (r *DatasetReconciler) reconcileJobStatus(ctx context.Context, ds *datasetv1alpha1.Dataset) error { if !supportPreload(ds) { ds.Status.LastSyncTime = ds.CreationTimestamp