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

feat: Implement delete expired index job #2702

Merged
merged 8 commits into from
Oct 26, 2024
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"
["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/**
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),
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