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

Backport PR #2702 to release/v1.7 for feat: Implement delete expired index job #2722

Merged
Merged
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
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"**/cmd/gateway/mirror/mirror",
"**/cmd/index/job/correction/index-correction",
"**/cmd/index/job/creation/index-creation",
"**/cmd/index/job/deletion/index-deletion",
"**/cmd/index/job/readreplica/rotate/readreplica-rotate",
"**/cmd/index/job/save/index-save",
"**/cmd/index/operator/index-operator",
Expand Down
1 change: 1 addition & 0 deletions .gitfiles
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
.github/workflows/dockers-image-scan.yaml
.github/workflows/dockers-index-correction-image.yaml
.github/workflows/dockers-index-creation-image.yaml
.github/workflows/dockers-index-deletion-image.yaml
.github/workflows/dockers-index-operator-image.yaml
.github/workflows/dockers-index-save-image.yaml
.github/workflows/dockers-loadtest-image.yaml
Expand Down
1 change: 1 addition & 0 deletions .github/actions/detect-docker-image-tags/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ runs:
["vdaas/vald-mirror-gateway"]="gateway.mirror.image.tag"
["vdaas/vald-manager-index"]="manager.index.image.tag"
["vdaas/vald-index-creation"]="manager.index.creator.image.tag"
["vdaas/vald-index-deletion"]="manager.index.delete.image.tag"
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

The image tag mapping needs corresponding Helm chart configuration

The verification reveals that while the Docker image and K8s manifests for the index deletion feature exist, there's no corresponding Helm chart configuration to support the image tag mapping. This needs to be addressed for the feature to work properly with Helm deployments.

  • Missing Helm chart template at charts/vald/templates/index/job/deletion/
  • Missing image configuration in charts/vald/values.yaml for the index deletion job
  • The image tag mapping in the action won't work without these Helm configurations
🔗 Analysis chain

LGTM! Verify related workflow configurations.

The new entry for the index deletion image follows the established pattern and naming conventions.

Let's verify that this image is properly referenced in related workflow files:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the consistency of image references across workflow files
# Expected: Find corresponding workflow configurations for the index deletion image

# Test 1: Check for workflow files referencing the index deletion image
echo "Checking for workflow files containing vald-index-deletion:"
rg -l "vald-index-deletion" .github/workflows/

# Test 2: Verify the image tag parameter in Helm chart values
echo -e "\nChecking for Helm chart parameter usage:"
rg "manager\.index\.delete\.image\.tag" helm/

Length of output: 366


Script:

#!/bin/bash
# Let's try a different approach to verify the image and configuration consistency

# Check for any references to the index deletion across the codebase
echo "Checking for index deletion references:"
rg -l "index.?delet(e|ion)" --type yaml

# Check for Docker-related files that might reference this image
echo -e "\nChecking Docker-related files:"
fd Dockerfile
rg -l "vdaas/vald-index" --type dockerfile

# Check for chart or values files in any location
echo -e "\nChecking for Helm chart files:"
fd -e yaml -e yml . | grep -i "values\|chart"

Length of output: 8292


Script:

#!/bin/bash
# Let's examine the specific files related to index deletion

# Check the Dockerfile for the index deletion job
echo "Checking index deletion Dockerfile:"
cat dockers/index/job/deletion/Dockerfile

# Check the k8s manifests for the index deletion job
echo -e "\nChecking k8s manifests:"
cat k8s/index/job/deletion/cronjob.yaml
cat k8s/index/job/deletion/configmap.yaml

# Check if there's a corresponding Helm chart template
echo -e "\nChecking for Helm chart template for index deletion:"
fd -e yaml . charts/vald/templates/index/job/deletion/

# Check values.yaml for the image configuration
echo -e "\nChecking values.yaml for image configuration:"
rg "index.*delete.*image" charts/vald/values.yaml

Length of output: 22222

["vdaas/vald-index-save"]="manager.index.saver.image.tag"
["vdaas/vald-readreplica-rotate"]="manager.index.readreplica.rotator.image.tag"
["vdaas/vald-helm-operator"]="image.tag"
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/dockers-image-scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ jobs:
uses: ./.github/workflows/_docker-image-scan.yaml
with:
target: index-creation
index-deletion:
uses: ./.github/workflows/_docker-image-scan.yaml
with:
target: index-deletion
index-save:
uses: ./.github/workflows/_docker-image-scan.yaml
with:
Expand Down
80 changes: 80 additions & 0 deletions .github/workflows/dockers-index-deletion-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#
# Copyright (C) 2019-2024 vdaas.org vald team <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# DO_NOT_EDIT this workflow file is generated by https://github.com/vdaas/vald/blob/main/hack/actions/gen/main.go

name: 'Build docker image: index-deletion'
on:
push:
branches:
- main
- release/v*.*
- '!release/v*.*.*'
tags:
- '*.*.*'
- v*.*.*
- '*.*.*-*'
- v*.*.*-*
pull_request:
paths:
- hack/docker/gen/main.go
- dockers/index/job/deletion/Dockerfile
- hack/actions/gen/main.go
- .github/workflows/dockers-index-deletion-image.yaml
- .github/actions/docker-build/action.yaml
- .github/workflows/_docker-image.yaml
- cmd/index/job/deletion/**
- pkg/index/job/deletion/**
- apis/grpc/**
- apis/proto/**
- go.mod
- go.sum
- versions/GO_VERSION
- internal/**
- '!internal/**/*_test.go'
- '!internal/**/*_mock.go'
- '!internal/db/**'
- '!internal/k8s/**'
- Makefile
- Makefile.d/**
pull_request_target:
paths:
- hack/docker/gen/main.go
- dockers/index/job/deletion/Dockerfile
- hack/actions/gen/main.go
- .github/workflows/dockers-index-deletion-image.yaml
- .github/actions/docker-build/action.yaml
- .github/workflows/_docker-image.yaml
- cmd/index/job/deletion/**
- pkg/index/job/deletion/**
- apis/grpc/**
- apis/proto/**
- go.mod
- go.sum
- versions/GO_VERSION
- internal/**
- '!internal/**/*_test.go'
- '!internal/**/*_mock.go'
- '!internal/db/**'
- '!internal/k8s/**'
- Makefile
- Makefile.d/**
jobs:
build:
uses: ./.github/workflows/_docker-image.yaml
with:
target: index-deletion
secrets: inherit
80 changes: 80 additions & 0 deletions .github/workflows/dockers-index-deletion.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#
# Copyright (C) 2019-2024 vdaas.org vald team <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# DO_NOT_EDIT this workflow file is generated by https://github.com/vdaas/vald/blob/main/hack/actions/gen/main.go

name: "Build docker image: index-deletion"
on:
push:
branches:
- main
- release/v*.*
- "!release/v*.*.*"
tags:
- "*.*.*"
- v*.*.*
- "*.*.*-*"
- v*.*.*-*
pull_request:
paths:
- hack/docker/gen/main.go
- dockers/index/job/deletion/Dockerfile
- hack/actions/gen/main.go
- .github/workflows/dockers-index-deletion-image.yaml
- .github/actions/docker-build/action.yaml
- .github/workflows/_docker-image.yaml
- cmd/index/job/deletion/**
- pkg/index/job/deletion/**
- apis/grpc/**
- apis/proto/**
- go.mod
- go.sum
- versions/GO_VERSION
- internal/**
- "!internal/**/*_test.go"
- "!internal/**/*_mock.go"
- "!internal/db/**"
- "!internal/k8s/**"
- Makefile
- Makefile.d/**
pull_request_target:
paths:
- hack/docker/gen/main.go
- dockers/index/job/deletion/Dockerfile
- hack/actions/gen/main.go
- .github/workflows/dockers-index-deletion-image.yaml
- .github/actions/docker-build/action.yaml
- .github/workflows/_docker-image.yaml
- cmd/index/job/deletion/**
- pkg/index/job/deletion/**
- apis/grpc/**
- apis/proto/**
- go.mod
- go.sum
- versions/GO_VERSION
- internal/**
- "!internal/**/*_test.go"
- "!internal/**/*_mock.go"
- "!internal/db/**"
- "!internal/k8s/**"
- Makefile
- Makefile.d/**
Comment on lines +32 to +74
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider optimizing path filters for better maintainability.

The current path filters are quite broad and might trigger unnecessary builds. Consider:

  1. Explicitly listing required internal/** paths instead of excluding patterns
  2. Limiting dependency file triggers to when deletion-related packages change
  3. Scoping API changes to relevant services

Example optimization:

  pull_request:
    paths:
      - hack/docker/gen/main.go
      - dockers/index/job/deletion/Dockerfile
      - hack/actions/gen/main.go
      - .github/workflows/dockers-index-deletion-image.yaml
      - .github/actions/docker-build/action.yaml
      - .github/workflows/_docker-image.yaml
      - cmd/index/job/deletion/**
      - pkg/index/job/deletion/**
-     - apis/grpc/**
-     - apis/proto/**
+     - apis/grpc/v*/agent/**
+     - apis/proto/v*/agent/**
-     - go.mod
-     - go.sum
+     # Only trigger on dependency changes affecting deletion packages
+     - 'go.{mod,sum} if:@@ pkg/index/job/deletion'
-     - internal/**
-     - "!internal/**/*_test.go"
-     - "!internal/**/*_mock.go"
-     - "!internal/db/**"
-     - "!internal/k8s/**"
+     - internal/core/algorithm/**
+     - internal/core/alogrithm/ngt/**
      - Makefile
      - Makefile.d/**

Committable suggestion was skipped due to low confidence.

Comment on lines +53 to +74
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Security: Restrict pull_request_target usage.

The current configuration using pull_request_target with inherited secrets poses security risks for PRs from forks. Consider:

  1. Adding explicit checks for trusted contributors
  2. Limiting secret access based on PR source
  3. Using environment protection rules

Example implementation:

  pull_request_target:
+   # Only run on trusted PRs
+   if: |
+     github.event.pull_request.user.login == 'dependabot[bot]' ||
+     contains(github.event.pull_request.labels.*.name, 'safe-to-test')
    paths:
      # ... existing paths ...
  jobs:
    build:
      uses: ./.github/workflows/_docker-image.yaml
+     # Define environment with protection rules
+     environment: docker-build
      with:
        target: index-deletion
-     secrets: inherit
+     secrets:
+       # Explicitly list required secrets
+       DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
+       DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}

Committable suggestion was skipped due to low confidence.

jobs:
build:
uses: ./.github/workflows/_docker-image.yaml
with:
target: index-deletion
secrets: inherit
6 changes: 6 additions & 0 deletions .github/workflows/dockers-release-branch-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ jobs:
with:
target: index-creation
secrets: inherit
index-deletion:
needs: [dump-contexts-to-log]
uses: ./.github/workflows/_docker-image.yaml
with:
target: index-deletion
secrets: inherit
index-save:
needs: [dump-contexts-to-log]
uses: ./.github/workflows/_docker-image.yaml
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ FILTER_GATEWAY_IMAGE = $(NAME)-filter-gateway
HELM_OPERATOR_IMAGE = $(NAME)-helm-operator
INDEX_CORRECTION_IMAGE = $(NAME)-index-correction
INDEX_CREATION_IMAGE = $(NAME)-index-creation
INDEX_DELETION_IMAGE = $(NAME)-index-deletion
INDEX_OPERATOR_IMAGE = $(NAME)-index-operator
INDEX_SAVE_IMAGE = $(NAME)-index-save
LB_GATEWAY_IMAGE = $(NAME)-lb-gateway
Expand Down
10 changes: 10 additions & 0 deletions Makefile.d/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ binary/build: \
cmd/gateway/mirror/mirror \
cmd/index/job/correction/index-correction \
cmd/index/job/creation/index-creation \
cmd/index/job/deletion/index-deletion \
cmd/index/job/readreplica/rotate/readreplica-rotate \
cmd/index/job/save/index-save \
cmd/index/operator/index-operator \
Expand Down Expand Up @@ -80,6 +81,10 @@ cmd/index/job/creation/index-creation:
$(eval CGO_ENABLED = 0)
$(call go-build,index/job/creation,,-static,,,$@)

cmd/index/job/deletion/index-deletion:
$(eval CGO_ENABLED = 0)
$(call go-build,index/job/deletion,,-static,,,$@)

cmd/index/job/save/index-save:
$(eval CGO_ENABLED = 0)
$(call go-build,index/job/save,,-static,,,$@)
Expand Down Expand Up @@ -128,6 +133,7 @@ binary/build/zip: \
artifacts/vald-filter-gateway-$(GOOS)-$(GOARCH).zip \
artifacts/vald-index-correction-$(GOOS)-$(GOARCH).zip \
artifacts/vald-index-creation-$(GOOS)-$(GOARCH).zip \
artifacts/vald-index-deletion-$(GOOS)-$(GOARCH).zip \
artifacts/vald-index-operator-$(GOOS)-$(GOARCH).zip \
artifacts/vald-index-save-$(GOOS)-$(GOARCH).zip \
artifacts/vald-lb-gateway-$(GOOS)-$(GOARCH).zip \
Expand Down Expand Up @@ -187,6 +193,10 @@ artifacts/vald-index-creation-$(GOOS)-$(GOARCH).zip: cmd/index/job/creation/inde
$(call mkdir, $(dir $@))
zip --junk-paths $@ $<

artifacts/vald-index-deletion-$(GOOS)-$(GOARCH).zip: cmd/index/job/deletion/index-deletion
$(call mkdir, $(dir $@))
zip --junk-paths $@ $<

artifacts/vald-index-save-$(GOOS)-$(GOARCH).zip: cmd/index/job/save/index-save
$(call mkdir, $(dir $@))
zip --junk-paths $@ $<
Expand Down
13 changes: 13 additions & 0 deletions Makefile.d/docker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ docker/build: \
docker/build/helm-operator \
docker/build/index-correction \
docker/build/index-creation \
docker/build/index-deletion \
docker/build/index-operator \
docker/build/index-save \
docker/build/loadtest \
Expand Down Expand Up @@ -63,6 +64,7 @@ docker/xpanes/build:
docker/build/gateway-mirror \
docker/build/index-correction \
docker/build/index-creation \
docker/build/index-deletion \
docker/build/index-operator \
docker/build/index-save \
docker/build/loadtest \
Expand Down Expand Up @@ -341,6 +343,17 @@ docker/build/index-save:
IMAGE=$(INDEX_SAVE_IMAGE) \
docker/build/image

.PHONY: docker/name/index-deletion
docker/name/index-deletion:
@echo "$(ORG)/$(INDEX_DELETION_IMAGE)"

.PHONY: docker/build/index-deletion
## build index-deletion image
docker/build/index-deletion:
@make DOCKERFILE="$(ROOTDIR)/dockers/index/job/deletion/Dockerfile" \
IMAGE=$(INDEX_DELETION_IMAGE) \
docker/build/image

.PHONY: docker/name/index-operator
docker/name/index-operator:
@echo "$(ORG)/$(INDEX_OPERATOR_IMAGE)"
Expand Down
59 changes: 59 additions & 0 deletions cmd/index/job/deletion/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (C) 2019-2024 vdaas.org vald team <[email protected]>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main

import (
"context"

"github.com/vdaas/vald/internal/errors"
"github.com/vdaas/vald/internal/info"
"github.com/vdaas/vald/internal/log"
"github.com/vdaas/vald/internal/runner"
"github.com/vdaas/vald/internal/safety"
"github.com/vdaas/vald/pkg/index/job/deletion/config"
"github.com/vdaas/vald/pkg/index/job/deletion/usecase"
)

const (
maxVersion = "v0.0.10"
minVersion = "v0.0.0"
name = "index deletion job"
)

func main() {
if err := safety.RecoverFunc(func() error {
return runner.Do(
context.Background(),
runner.WithName(name),
Comment on lines +37 to +38
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding a context timeout.

Using context.Background() without a timeout could potentially allow the deletion job to run indefinitely. Consider adding a reasonable timeout to ensure the job completes within expected boundaries.

-		return runner.Do(
-			context.Background(),
+		ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
+		defer cancel()
+		return runner.Do(
+			ctx,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
context.Background(),
runner.WithName(name),
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
defer cancel()
return runner.Do(
ctx,
runner.WithName(name),

runner.WithVersion(info.Version, maxVersion, minVersion),
runner.WithConfigLoader(func(path string) (any, *config.GlobalConfig, error) {
cfg, err := config.NewConfig(path)
if err != nil {
return nil, nil, errors.Wrap(err, "failed to load "+name+"'s configuration")
}
return cfg, &cfg.GlobalConfig, nil

Check warning on line 45 in cmd/index/job/deletion/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/index/job/deletion/main.go#L34-L45

Added lines #L34 - L45 were not covered by tests
}),
runner.WithDaemonInitializer(func(cfg any) (runner.Runner, error) {
c, ok := cfg.(*config.Data)
if !ok {
return nil, errors.ErrInvalidConfig
}
return usecase.New(c)

Check warning on line 52 in cmd/index/job/deletion/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/index/job/deletion/main.go#L47-L52

Added lines #L47 - L52 were not covered by tests
}),
)
})(); err != nil {
log.Fatal(err, info.Get())
return
}

Check warning on line 58 in cmd/index/job/deletion/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/index/job/deletion/main.go#L55-L58

Added lines #L55 - L58 were not covered by tests
}
Loading
Loading