Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: edit the csv file should trigger an update of knowledgebase #921

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions apiserver/pkg/common/read_csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ type (
// Do you want to force an update?
ForceUpdate bool `json:"forceUpdate"`

UpdateLines []CSVLine `json:"updateLines"`
NewLines [][]string `json:"newLines,omitempty"`
DelLines []int `json:"delLines"`
UpdateLines []CSVLine `json:"updateLines"`
NewLines [][]string `json:"newLines,omitempty"`
DelLines []int `json:"delLines"`
Knowledgebase string `json:"knowledgebase,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0xff-dev There may have more than one knowledgebases which has this csv

}
)

Expand Down
25 changes: 25 additions & 0 deletions apiserver/service/minio_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/gin-gonic/gin"
"github.com/minio/minio-go/v7"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -1006,6 +1007,30 @@ func (m *minioAPI) EditCSV(ctx *gin.Context) {
return
}
_ = source.Client.PutObjectTagging(ctx.Request.Context(), bucketName, objectName, tags, minio.PutObjectTaggingOptions{})
changed := len(body.DelLines) > 0 || len(body.UpdateLines) > 0 || len(body.NewLines) > 0

if body.Knowledgebase != "" && changed {
go func() {
kb := v1alpha1.KnowledgeBase{}
if err := m.client.Get(context.TODO(), types.NamespacedName{
Namespace: bucketName,
Name: body.Knowledgebase,
}, &kb); err != nil {
klog.Errorf("failed to get knowledgebase %s, error %s", body.Knowledgebase, err)
return
}
if kb.Annotations == nil {
kb.Annotations = make(map[string]string)
}
now := time.Now().Format(time.RFC3339)
kb.Annotations[v1alpha1.UpdateSourceFileAnnotationKey] = now
if err := m.client.Update(context.TODO(), &kb); err != nil {
klog.Errorf("failed to update knowledgebase %s, error %s", body.Knowledgebase, err)
return
}
klog.Infof("successfully update knowledgebase %s", body.Knowledgebase)
}()
}
ctx.JSON(http.StatusOK, "")
}

Expand Down
Loading