Skip to content

Commit

Permalink
feature: enable custom bucket clean job (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
guguducken authored Aug 5, 2024
1 parent 96ee3b3 commit d887343
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 14 deletions.
4 changes: 4 additions & 0 deletions charts/matrixone-operator/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
5 changes: 5 additions & 0 deletions charts/matrixone-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ 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"
"github.com/matrixorigin/matrixone-operator/pkg/controllers/cnclaimset"
"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"
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 15 additions & 1 deletion pkg/controllers/bucketclaim/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{}
Expand All @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions pkg/controllers/bucketclaim/jobtpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions pkg/controllers/bucketclaim/options.go
Original file line number Diff line number Diff line change
@@ -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
}
}
}
16 changes: 11 additions & 5 deletions pkg/controllers/common/operatorcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d887343

Please sign in to comment.