Skip to content

Commit

Permalink
feat: Implement delete expired index job (#2702) (#2722)
Browse files Browse the repository at this point in the history
* feat: Implement delete expired index job

* fix: Replace agent Remove RPC to Vald Remove RPC

* fix: service name

* fix: typo

* fix: log method

* fix: variable name

* fix: use internal package

* fix: Change struct field name

Co-authored-by: s-shiraki <s.shiraki.business@gmail.com>
  • Loading branch information
vdaas-ci and highpon authored Oct 27, 2024
1 parent 1dd771f commit 6faa127
Show file tree
Hide file tree
Showing 23 changed files with 1,757 additions and 0 deletions.
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"
["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 <vald@vdaas.org>
#
# 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 <vald@vdaas.org>
#
# 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
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 <vald@vdaas.org>
//
// 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),
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
}),
runner.WithDaemonInitializer(func(cfg any) (runner.Runner, error) {
c, ok := cfg.(*config.Data)
if !ok {
return nil, errors.ErrInvalidConfig
}
return usecase.New(c)
}),
)
})(); err != nil {
log.Fatal(err, info.Get())
return
}
}
Loading

0 comments on commit 6faa127

Please sign in to comment.