Skip to content

Commit

Permalink
feat: add vector support (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
whg517 authored Oct 23, 2024
1 parent 988fb9a commit a511f5e
Show file tree
Hide file tree
Showing 13 changed files with 692 additions and 536 deletions.
4 changes: 2 additions & 2 deletions .chainsaw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ spec:
# namespace: chainsaw
timeouts:
apply: 300s
assert: 300s
assert: 600s
cleanup: 120s
delete: 120s
error: 180s
exec: 300s
# skipDelete: false
# skipDelete: true
failFast: true
forceTerminationGracePeriod: 10s
parallel: 1
2 changes: 1 addition & 1 deletion api/v1alpha1/master_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type MasterConfigSpec struct {
GracefulShutdownTimeout *string `json:"gracefulShutdownTimeout,omitempty"`

// +kubebuilder:validation:Optional
Logging *commonsv1alpha1.LoggingConfigSpec `json:"logging,omitempty"`
Logging *LoggingSpec `json:"logging,omitempty"`

// +kubebuilder:validation:Optional
Resources *commonsv1alpha1.ResourcesSpec `json:"resources,omitempty"`
Expand Down
10 changes: 10 additions & 0 deletions api/v1alpha1/productlogging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package v1alpha1

import commonsv1alpha1 "github.com/zncdatadev/operator-go/pkg/apis/commons/v1alpha1"

type LoggingSpec struct {
// +kubebuilder:validation:Optional
EnableVectorAgent bool `json:"enableVectorAgent,omitempty"`
// +kubebuilder:validation:Optional
Containers map[string]*commonsv1alpha1.LoggingConfigSpec `json:"containers,omitempty"`
}
2 changes: 1 addition & 1 deletion api/v1alpha1/regionserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type RegionConfigSpec struct {
GracefulShutdownTimeout *string `json:"gracefulShutdownTimeout,omitempty"`

// +kubebuilder:validation:Optional
Logging *commonsv1alpha1.LoggingConfigSpec `json:"logging,omitempty"`
Logging *LoggingSpec `json:"logging,omitempty"`

// +kubebuilder:validation:Optional
Resources *commonsv1alpha1.ResourcesSpec `json:"resources,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/restserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type RestServerConfigSpec struct {
GracefulShutdownTimeout *string `json:"gracefulShutdownTimeout,omitempty"`

// +kubebuilder:validation:Optional
Logging *commonsv1alpha1.LoggingConfigSpec `json:"logging,omitempty"`
Logging *LoggingSpec `json:"logging,omitempty"`

// +kubebuilder:validation:Optional
Resources *commonsv1alpha1.ResourcesSpec `json:"resources,omitempty"`
Expand Down
37 changes: 34 additions & 3 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,028 changes: 535 additions & 493 deletions config/crd/bases/hbase.zncdata.dev_hbaseclusters.yaml

Large diffs are not rendered by default.

81 changes: 53 additions & 28 deletions internal/controller/common/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package common
import (
"context"
"fmt"
"path"
"strings"

corev1 "k8s.io/api/core/v1"
ctrl "sigs.k8s.io/controller-runtime"

commonsv1alpha1 "github.com/zncdatadev/operator-go/pkg/apis/commons/v1alpha1"
"github.com/zncdatadev/operator-go/pkg/builder"
"github.com/zncdatadev/operator-go/pkg/client"
"github.com/zncdatadev/operator-go/pkg/config/xml"
"github.com/zncdatadev/operator-go/pkg/productlogging"
"github.com/zncdatadev/operator-go/pkg/reconciler"
"github.com/zncdatadev/operator-go/pkg/util"

Expand All @@ -35,6 +36,9 @@ var _ builder.ConfigBuilder = &ConfigMapBuilder{}
type ConfigMapBuilder struct {
builder.ConfigMapBuilder

LoggingConfig *commonsv1alpha1.LoggingConfigSpec
VectorConfigMapName string

ClusterName string
RoleName string
RolegroupName string
Expand All @@ -45,6 +49,8 @@ type ConfigMapBuilder struct {
func NewConfigMapBuilder(
client *client.Client,
name string,
loggingConfig *commonsv1alpha1.LoggingConfigSpec,
vectorConfigMapName string,
krb5SecretClass string,
tlsSecretClass string,
options builder.Options,
Expand All @@ -69,10 +75,12 @@ func NewConfigMapBuilder(
options.Labels,
options.Annotations,
),
ClusterName: options.ClusterName,
RoleName: options.RoleName,
RolegroupName: options.RoleGroupName,
krb5Config: krb5Config,
ClusterName: options.ClusterName,
RoleName: options.RoleName,
RolegroupName: options.RoleGroupName,
krb5Config: krb5Config,
LoggingConfig: loggingConfig,
VectorConfigMapName: vectorConfigMapName,
}
}

Expand Down Expand Up @@ -103,26 +111,17 @@ func (b *ConfigMapBuilder) getJVMOPTS() string {
return fmt.Sprintf(`export HBASE_%s_OPTS="$HBASE_OPTS %s"`, b.RoleName, strings.Join(opts, " "))
}

func (b *ConfigMapBuilder) AddLog4jProperties() error {
log4j := `
log4j.rootLogger=INFO, CONSOLE, FILE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=INFO
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %c{2}: %.1000m%n
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.Threshold=INFO
log4j.appender.FILE.File=` + path.Join(HBaseConfigDir, "hbase.log4j.xml") + `
log4j.appender.FILE.MaxFileSize=5MB
log4j.appender.FILE.MaxBackupIndex=1
log4j.appender.FILE.layout=org.apache.log4j.xml.XMLLayout
`
b.AddData(map[string]string{LogKey: util.IndentTab4Spaces(log4j)})
logger.V(15).Info("Log4j", "log4j", log4j, "clusterName", b.ClusterName, "roleName", b.RoleName, "roleGroupName", b.RolegroupName)
return nil
func (b *ConfigMapBuilder) AddLog4jProperties() {
l := productlogging.NewLog4jConfigGenerator(
b.LoggingConfig,
b.RoleName,
"%d{ISO8601} %-5p [%t] %c{2}: %.1000m%n",
nil,
"hbase.log4j.xml",
"",
)
s := l.Generate()
b.AddItem(LogKey, s)
}

func (b *ConfigMapBuilder) AddSSLClientXML() error {
Expand Down Expand Up @@ -191,6 +190,27 @@ func (b *ConfigMapBuilder) AddHbaseSite(znode *ZnodeConfiguration) error {
return nil
}

func (b *ConfigMapBuilder) AddVectorConfig(ctx context.Context) error {
if b.VectorConfigMapName == "" {
return nil
}
s, err := productlogging.MakeVectorYaml(
ctx,
b.Client.Client,
b.Client.GetOwnerNamespace(),
b.ClusterName,
b.RoleName,
b.RolegroupName,
b.VectorConfigMapName,
)
if err != nil {
return err
}

b.AddItem(builder.VectorConfigFile, s)
return nil
}

var _ reconciler.ResourceReconciler[*ConfigMapBuilder] = &ConfigMapReconciler[reconciler.AnySpec]{}

type ConfigMapReconciler[T reconciler.AnySpec] struct {
Expand Down Expand Up @@ -224,9 +244,7 @@ func (r *ConfigMapReconciler[T]) Reconcile(ctx context.Context) (ctrl.Result, er
return ctrl.Result{}, err
}

if err := builder.AddLog4jProperties(); err != nil {
return ctrl.Result{}, err
}
builder.AddLog4jProperties()

if err := builder.AddSSLClientXML(); err != nil {
return ctrl.Result{}, err
Expand All @@ -236,6 +254,10 @@ func (r *ConfigMapReconciler[T]) Reconcile(ctx context.Context) (ctrl.Result, er
return ctrl.Result{}, err
}

if err := builder.AddVectorConfig(ctx); err != nil {
return ctrl.Result{}, err
}

resource, err := builder.Build(ctx)

if err != nil {
Expand All @@ -248,6 +270,7 @@ func (r *ConfigMapReconciler[T]) Reconcile(ctx context.Context) (ctrl.Result, er
func NewConfigMapReconciler[T reconciler.AnySpec](
client *client.Client,
clusterConfig *hbasev1alph1.ClusterConfigSpec,
loggingConfig *commonsv1alpha1.LoggingConfigSpec,
options reconciler.RoleGroupInfo,
spec T,
) *ConfigMapReconciler[T] {
Expand All @@ -261,6 +284,8 @@ func NewConfigMapReconciler[T reconciler.AnySpec](
cmBuilder := NewConfigMapBuilder(
client,
options.GetFullName(),
loggingConfig,
clusterConfig.VectorAggregatorConfigMapName,
krb5SecretClass,
tlsSecretClass,
builder.Options{
Expand Down
23 changes: 22 additions & 1 deletion internal/controller/common/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ var (
HDFSConfigDir = path.Join(constants.KubedoopConfigDir)
HBaseMountConfigDir = path.Join(constants.KubedoopConfigDirMount, "hbase")
HDFSMountConfigDir = path.Join(constants.KubedoopConfigDirMount, "hdfs")

HHbaseConfigVolumeName = "hbase-config"
HbaseLogVolumeName = "log"
)

var _ builder.StatefulSetBuilder = &StatefulSetBuilder{}
Expand Down Expand Up @@ -343,7 +346,25 @@ func (b *StatefulSetBuilder) Build(ctx context.Context) (ctrlclient.Object, erro
b.AddContainer(oidcContainer)
}

return b.GetObject()
obj, err := b.GetObject()
if err != nil {
return nil, err
}

if b.ClusterConfig.VectorAggregatorConfigMapName != "" {
d := builder.NewVectorDecorator(
obj,
b.GetImage(),
HbaseLogVolumeName,
HHbaseConfigVolumeName,
b.ClusterConfig.VectorAggregatorConfigMapName,
)
if err := d.Decorate(); err != nil {
return nil, err
}
}

return obj, nil
}

var _ reconciler.Reconciler = &StatefulSetReconciler{}
Expand Down
12 changes: 10 additions & 2 deletions internal/controller/master/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"context"
"time"

hbasev1alph1 "github.com/zncdatadev/hbase-operator/api/v1alpha1"
"github.com/zncdatadev/hbase-operator/internal/controller/common"
commonsv1alpha1 "github.com/zncdatadev/operator-go/pkg/apis/commons/v1alpha1"
"github.com/zncdatadev/operator-go/pkg/builder"
"github.com/zncdatadev/operator-go/pkg/client"
"github.com/zncdatadev/operator-go/pkg/reconciler"
"github.com/zncdatadev/operator-go/pkg/util"
ctrl "sigs.k8s.io/controller-runtime"

hbasev1alph1 "github.com/zncdatadev/hbase-operator/api/v1alpha1"
"github.com/zncdatadev/hbase-operator/internal/controller/common"
)

var (
Expand Down Expand Up @@ -72,6 +74,11 @@ func (r *Reconciler) RegisterResources(ctx context.Context) error {
func (r *Reconciler) RegisterResourceWithRoleGroup(_ context.Context, info reconciler.RoleGroupInfo, roleGroupSpec any) ([]reconciler.Reconciler, error) {
spec := roleGroupSpec.(*hbasev1alph1.MasterRoleGroupSpec)
var reconcilers []reconciler.Reconciler
var loggingConfig *commonsv1alpha1.LoggingConfigSpec

if spec.Config != nil && spec.Config.Logging != nil {
loggingConfig = spec.Config.Logging.Containers[info.RoleName]
}

options := builder.WorkloadOptions{
Options: builder.Options{
Expand Down Expand Up @@ -137,6 +144,7 @@ func (r *Reconciler) RegisterResourceWithRoleGroup(_ context.Context, info recon
configMapReconciler := common.NewConfigMapReconciler(
r.GetClient(),
r.ClusterConfig,
loggingConfig,
info,
roleGroupSpec.(*hbasev1alph1.MasterRoleGroupSpec),
)
Expand Down
12 changes: 10 additions & 2 deletions internal/controller/regionserver/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"context"
"time"

hbasev1alph1 "github.com/zncdatadev/hbase-operator/api/v1alpha1"
"github.com/zncdatadev/hbase-operator/internal/controller/common"
commonsv1alpha1 "github.com/zncdatadev/operator-go/pkg/apis/commons/v1alpha1"
"github.com/zncdatadev/operator-go/pkg/builder"
"github.com/zncdatadev/operator-go/pkg/client"
"github.com/zncdatadev/operator-go/pkg/reconciler"
"github.com/zncdatadev/operator-go/pkg/util"
ctrl "sigs.k8s.io/controller-runtime"

hbasev1alph1 "github.com/zncdatadev/hbase-operator/api/v1alpha1"
"github.com/zncdatadev/hbase-operator/internal/controller/common"
)

var (
Expand Down Expand Up @@ -73,6 +75,11 @@ func (r *Reconciler) RegisterResources(ctx context.Context) error {
func (r *Reconciler) RegisterResourceWithRoleGroup(_ context.Context, info reconciler.RoleGroupInfo, roleGroupSpec any) ([]reconciler.Reconciler, error) {
spec := roleGroupSpec.(*hbasev1alph1.RegionServerRoleGroupSpec)
var reconcilers []reconciler.Reconciler
var loggingConfig *commonsv1alpha1.LoggingConfigSpec

if spec.Config != nil && spec.Config.Logging != nil {
loggingConfig = spec.Config.Logging.Containers[info.RoleName]
}

options := builder.WorkloadOptions{
Options: builder.Options{
Expand Down Expand Up @@ -138,6 +145,7 @@ func (r *Reconciler) RegisterResourceWithRoleGroup(_ context.Context, info recon
configMapReconciler := common.NewConfigMapReconciler(
r.GetClient(),
r.ClusterConfig,
loggingConfig,
info,
roleGroupSpec.(*hbasev1alph1.RegionServerRoleGroupSpec),
)
Expand Down
Loading

0 comments on commit a511f5e

Please sign in to comment.