diff --git a/charts/matrixone-operator/templates/configmap.yaml b/charts/matrixone-operator/templates/configmap.yaml index b11f4dc7..cdef29f6 100644 --- a/charts/matrixone-operator/templates/configmap.yaml +++ b/charts/matrixone-operator/templates/configmap.yaml @@ -11,6 +11,10 @@ data: {{.name | nindent 4 }}: {{- toYaml .values | nindent 4 }} {{- end }} + {{- with .Values.bucketCleanJob }} + bucketCleanJob: | + image: {{ .image | default "amazon/aws-cli:latest" | quote }} + {{- end }} featureGates: | {{- range $key, $value := .Values.featureGates }} diff --git a/charts/matrixone-operator/values.yaml b/charts/matrixone-operator/values.yaml index 7fbc0f03..04687a19 100644 --- a/charts/matrixone-operator/values.yaml +++ b/charts/matrixone-operator/values.yaml @@ -86,6 +86,11 @@ defaultArgs: values: - -debug-http=:6060 +# Currently only public repository are accepted +# If you are in China, you can use our public repository: ccr.ccs.tencentyun.com/mo-infra/aws-cli:latest +#bucketCleanJob: +# image: amazon/aws-cli:latest + featureGates: s3Reclaim: true proxySupport: true diff --git a/cmd/operator/main.go b/cmd/operator/main.go index d055314a..ffbf4439 100644 --- a/cmd/operator/main.go +++ b/cmd/operator/main.go @@ -17,6 +17,8 @@ package main import ( "flag" "fmt" + "os" + "github.com/go-logr/zapr" "github.com/matrixorigin/matrixone-operator/pkg/controllers/br" "github.com/matrixorigin/matrixone-operator/pkg/controllers/cnclaim" @@ -24,7 +26,6 @@ import ( "github.com/matrixorigin/matrixone-operator/pkg/controllers/cnpool" "github.com/matrixorigin/matrixone-operator/pkg/mocli" "github.com/matrixorigin/matrixone-operator/pkg/querycli" - "os" "sigs.k8s.io/controller-runtime/pkg/client" "github.com/matrixorigin/controller-runtime/pkg/metrics" @@ -61,7 +62,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" "github.com/matrixorigin/matrixone-operator/api/core/v1alpha1" - //+kubebuilder:scaffold:imports + // +kubebuilder:scaffold:imports ) var ( @@ -210,7 +211,9 @@ func main() { } if features.DefaultFeatureGate.Enabled(features.S3Reclaim) { - bucketActor := bucketclaim.Actor{} + bucketActor := bucketclaim.New( + bucketclaim.WithImage(operatorCfg.BucketCleanJob.Image), + ) err = bucketActor.Reconcile(mgr) exitIf(err, "unable to set up bucketclaim cluster controller") } else { diff --git a/pkg/controllers/bucketclaim/controller.go b/pkg/controllers/bucketclaim/controller.go index b41d18b8..5c5ec4b9 100644 --- a/pkg/controllers/bucketclaim/controller.go +++ b/pkg/controllers/bucketclaim/controller.go @@ -16,6 +16,8 @@ package bucketclaim import ( "fmt" + "sync" + recon "github.com/matrixorigin/controller-runtime/pkg/reconciler" "github.com/matrixorigin/matrixone-operator/api/core/v1alpha1" batchv1 "k8s.io/api/batch/v1" @@ -26,7 +28,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/manager" - "sync" ) var _ recon.Actor[*v1alpha1.BucketClaim] = &Actor{} @@ -35,6 +36,19 @@ type Actor struct { mutex sync.Mutex tasks chan task client client.Client + + // image related config + image string +} + +func New(options ...Option) *Actor { + a := &Actor{ + image: defaultImage, + } + for _, opt := range options { + opt(a) + } + return a } type task struct { diff --git a/pkg/controllers/bucketclaim/jobtpl.go b/pkg/controllers/bucketclaim/jobtpl.go index dda8b3b7..c189cd48 100644 --- a/pkg/controllers/bucketclaim/jobtpl.go +++ b/pkg/controllers/bucketclaim/jobtpl.go @@ -17,19 +17,20 @@ package bucketclaim import ( "bytes" "fmt" + "path/filepath" + "strings" + "text/template" + "github.com/matrixorigin/controller-runtime/pkg/util" "github.com/matrixorigin/matrixone-operator/api/core/v1alpha1" "github.com/matrixorigin/matrixone-operator/pkg/utils" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "path/filepath" - "strings" - "text/template" ) const ( - awsCliImage = "amazon/aws-cli" + defaultImage = "amazon/aws-cli" // entrypoint of job pod entrypoint = "start.sh" @@ -120,7 +121,7 @@ func (bca *Actor) NewJobTpl(bucket *v1alpha1.BucketClaim, cm *corev1.ConfigMap) mainContainer := util.FindFirst(podTpl.Spec.Containers, func(c corev1.Container) bool { return c.Name == v1alpha1.ContainerMain }) - mainContainer.Image = awsCliImage + mainContainer.Image = bca.image mainContainer.Command = []string{"/bin/sh", filepath.Join(cmMountPath, entrypoint)} mainContainer.Args = []string{} podTpl.Spec.RestartPolicy = corev1.RestartPolicyOnFailure diff --git a/pkg/controllers/bucketclaim/options.go b/pkg/controllers/bucketclaim/options.go new file mode 100644 index 00000000..2eb3a5c7 --- /dev/null +++ b/pkg/controllers/bucketclaim/options.go @@ -0,0 +1,25 @@ +// Copyright 2024 Matrix Origin +// +// 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 +// +// http://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 bucketclaim + +type Option func(actor *Actor) + +func WithImage(image string) Option { + return func(actor *Actor) { + if image != "" { + actor.image = image + } + } +} diff --git a/pkg/controllers/common/operatorcfg.go b/pkg/controllers/common/operatorcfg.go index 7456dfdb..91ee9260 100644 --- a/pkg/controllers/common/operatorcfg.go +++ b/pkg/controllers/common/operatorcfg.go @@ -15,24 +15,30 @@ package common import ( - "github.com/matrixorigin/matrixone-operator/api/core/v1alpha1" - "k8s.io/apimachinery/pkg/util/yaml" "os" "path" "strings" + + "github.com/matrixorigin/matrixone-operator/api/core/v1alpha1" + "k8s.io/apimachinery/pkg/util/yaml" ) // OperatorConfig includes configurations for this operator process type OperatorConfig struct { - DefaultArgs *v1alpha1.DefaultArgs `json:"defaultArgs,omitempty" yaml:"defaultArgs,omitempty"` - FeatureGates map[string]bool `json:"featureGates,omitempty" yaml:"featureGates,omitempty"` - BRConfig BrConfig `json:"brConfig,omitempty" yaml:"brConfig,omitempty"` + DefaultArgs *v1alpha1.DefaultArgs `json:"defaultArgs,omitempty" yaml:"defaultArgs,omitempty"` + FeatureGates map[string]bool `json:"featureGates,omitempty" yaml:"featureGates,omitempty"` + BRConfig BrConfig `json:"brConfig,omitempty" yaml:"brConfig,omitempty"` + BucketCleanJob BucketCleanJob `json:"bucketCleanJob,omitempty" yaml:"bucketCleanJob,omitempty"` } type BrConfig struct { Image string `json:"image,omitempty" yaml:"image,omitempty"` } +type BucketCleanJob struct { + Image string `json:"image,omitempty" yaml:"image,omitempty"` +} + // LoadOperatorConfig read all operator configurations from configmap mount path, and load it into OperatorConfig struct func LoadOperatorConfig(cfgPath string, config *OperatorConfig) error { entries, err := os.ReadDir(cfgPath)