Skip to content

Commit

Permalink
fix: edit the csv file should trigger an update of knowledgebase
Browse files Browse the repository at this point in the history
  • Loading branch information
0xff-dev committed Apr 7, 2024
1 parent f259628 commit 6978fb2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
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"`
}
)

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

0 comments on commit 6978fb2

Please sign in to comment.