Skip to content

Commit

Permalink
chore(constants): rename some sensitive literal to kubedoop (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwpk110 authored Aug 28, 2024
1 parent 58c1bbd commit f3e510f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion READNE_zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# operator-go

Operator-go 是 zncdata-stack 中 operator 开发需要用公共类库,主要用于处理 operator 的相关逻辑。
Operator-go 是 Kubedoop 中 operator 开发需要用公共类库,主要用于处理 operator 的相关逻辑。

[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/zncdatadev/operator-go)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/zncdatadev/operator-go)
Expand Down
40 changes: 19 additions & 21 deletions pkg/builder/vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ import (

pkgclient "github.com/zncdatadev/operator-go/pkg/client"
"github.com/zncdatadev/operator-go/pkg/config"
"github.com/zncdatadev/operator-go/pkg/constants"
"github.com/zncdatadev/operator-go/pkg/util"
)

// todo: in future, all operator should config log, config and data to the same dir, like '/zncdata/log', '/zncdata/config'
const (
VectorImage = "timberio/vector:0.38.0-alpine"
VectorContainerName = "vector"
ConfigDir = "/zncdata/config"
LogDir = "/zncdata/log"
VectorConfigFile = "vector.yaml"

VectorConfigVolumeName = "config"
Expand All @@ -32,23 +30,23 @@ func VectorVolumeMount(vectorConfigVolumeName string, vectorLogVolumeName string
return []corev1.VolumeMount{
{
Name: vectorConfigVolumeName,
MountPath: ConfigDir,
MountPath: constants.KubedoopConfigDir,
},
{
Name: vectorLogVolumeName,
MountPath: LogDir,
MountPath: constants.KubedoopLogDir,
},
}
}

func VectorCommandArgs() []string {
arg := `log_dir="/zncdata/log/_vector"
data_dir="/zncdata/vector/var"
arg := `log_dir="/kubedoop/log/_vector"
data_dir="/kubedoop/vector/var"
if [ ! -d "$data_dir" ]; then
mkdir -p "$data_dir"
fi
vector --config /zncdata/config/vector.yaml &
vector --config /kubedoop/config/vector.yaml &
vector_pid=$!
if [ ! -f "$log_dir/shutdown" ]; then
Expand Down Expand Up @@ -97,7 +95,7 @@ func MakeVectorYaml(
vectorAggregatorDiscovery string) (string, error) {
vectorAggregatorDiscoveryURI := vectorAggregatorDiscoveryURI(ctx, client, namespace, vectorAggregatorDiscovery)
data := map[string]interface{}{
"LogDir": LogDir,
"LogDir": constants.KubedoopLogDir,
"Namespace": namespace,
"Cluster": cluster,
"Role": role,
Expand All @@ -110,7 +108,7 @@ func MakeVectorYaml(
func ParseVectorYaml(data map[string]interface{}) (string, error) {
var tmpl = `api:
enabled: true
data_dir: /zncdata/vector/var
data_dir: /kubedoop/vector/var
log_schema:
host_key: "pod"
sources:
Expand All @@ -120,17 +118,17 @@ sources:
files_stdout:
type: file
include:
- {{.LogDir}}/*/*.stdout.log
- {{.LogDir}}*/*.stdout.log
files_stderr:
type: file
include:
- {{.LogDir}}/*/*.stderr.log
- {{.LogDir}}*/*.stderr.log
files_log4j:
type: file
include:
- {{.LogDir}}/*/*.log4j.xml
- {{.LogDir}}*/*.log4j.xml
line_delimiter: "\r\n"
multiline:
mode: halt_before
Expand All @@ -141,13 +139,13 @@ sources:
files_log4j2:
type: file
include:
- {{.LogDir}}/*/*.log4j2.xml
- {{.LogDir}}*/*.log4j2.xml
line_delimiter: "\r\n"
files_airlift:
type: "file"
include:
- "{{.LogDir}}/*/*.airlift.json"
- "{{.LogDir}}*/*.airlift.json"
transforms:
processed_files_stdout:
inputs:
Expand Down Expand Up @@ -381,7 +379,7 @@ transforms:
- processed_files_*
type: remap
source: |
. |= parse_regex!(.file, r'^/zncdata/log/(?P<container>.*?)/(?P<file>.*?)$')
. |= parse_regex!(.file, r'^/kubedoop/log/(?P<container>.*?)/(?P<file>.*?)$')
del(.source_type)
extended_logs:
inputs:
Expand Down Expand Up @@ -468,15 +466,15 @@ wait_for_termination()
set -e
}
rm -f {{ .LogDir }}/_vector/shutdown
rm -f {{ .LogDir }}_vector/shutdown
prepare_signal_handlers
{{ .EntrypointScript }}
wait_for_termination $!
mkdir -p {{ .LogDir }}/_vector && touch {{ .LogDir }}/_vector/shutdown
mkdir -p {{ .LogDir }}_vector && touch {{ .LogDir }}_vector/shutdown
`
data := map[string]interface{}{"LogDir": LogDir, "EntrypointScript": entrypointScript}
data := map[string]interface{}{"LogDir": constants.KubedoopLogDir, "EntrypointScript": entrypointScript}
parser := config.TemplateParser{
Value: data,
Template: template,
Expand Down Expand Up @@ -615,14 +613,14 @@ func (v *VectorDecorator) appendVectorVolumeMounts(container *corev1.Container,
if !v.volumeMountExists(container.VolumeMounts, v.LogVolumeName) { // if log volume mount exists
container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{
Name: v.LogVolumeName,
MountPath: LogDir,
MountPath: constants.KubedoopLogDir,
})
(*containers)[i] = *container
}
if !v.volumeMountExists(container.VolumeMounts, v.VectorConfigVolumeName) { // if vector config volume mount exists
container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{
Name: v.VectorConfigVolumeName,
MountPath: ConfigDir,
MountPath: constants.KubedoopConfigDir,
})
(*containers)[i] = *container
}
Expand Down
21 changes: 11 additions & 10 deletions pkg/builder/vector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/assert"

"github.com/zncdatadev/operator-go/pkg/builder"
"github.com/zncdatadev/operator-go/pkg/constants"
)

func TestLogProviderCommandArgs(t *testing.T) {
Expand Down Expand Up @@ -47,7 +48,7 @@ wait_for_termination()
set -e
}
rm -f /zncdata/log/_vector/shutdown
rm -f /kubedoop/log/_vector/shutdown
prepare_signal_handlers
Expand All @@ -58,7 +59,7 @@ foo() {
wait_for_termination $!
mkdir -p /zncdata/log/_vector && touch /zncdata/log/_vector/shutdown
mkdir -p /kubedoop/log/_vector && touch /kubedoop/log/_vector/shutdown
`,
}

Expand All @@ -69,7 +70,7 @@ mkdir -p /zncdata/log/_vector && touch /zncdata/log/_vector/shutdown

func TestVectorYamlFormatter(t *testing.T) {
actualYaml, err := builder.ParseVectorYaml(map[string]interface{}{
"LogDir": "zncdata/log",
"LogDir": constants.KubedoopLogDir,
"Namespace": "default",
"Cluster": "simple-trino",
"Role": "coordinator",
Expand All @@ -78,7 +79,7 @@ func TestVectorYamlFormatter(t *testing.T) {
})
expectYaml := `api:
enabled: true
data_dir: /zncdata/vector/var
data_dir: /kubedoop/vector/var
log_schema:
host_key: "pod"
sources:
Expand All @@ -88,17 +89,17 @@ sources:
files_stdout:
type: file
include:
- zncdata/log/*/*.stdout.log
- /kubedoop/log/*/*.stdout.log
files_stderr:
type: file
include:
- zncdata/log/*/*.stderr.log
- /kubedoop/log/*/*.stderr.log
files_log4j:
type: file
include:
- zncdata/log/*/*.log4j.xml
- /kubedoop/log/*/*.log4j.xml
line_delimiter: "\r\n"
multiline:
mode: halt_before
Expand All @@ -109,13 +110,13 @@ sources:
files_log4j2:
type: file
include:
- zncdata/log/*/*.log4j2.xml
- /kubedoop/log/*/*.log4j2.xml
line_delimiter: "\r\n"
files_airlift:
type: "file"
include:
- "zncdata/log/*/*.airlift.json"
- "/kubedoop/log/*/*.airlift.json"
transforms:
processed_files_stdout:
inputs:
Expand Down Expand Up @@ -349,7 +350,7 @@ transforms:
- processed_files_*
type: remap
source: |
. |= parse_regex!(.file, r'^/zncdata/log/(?P<container>.*?)/(?P<file>.*?)$')
. |= parse_regex!(.file, r'^/kubedoop/log/(?P<container>.*?)/(?P<file>.*?)$')
del(.source_type)
extended_logs:
inputs:
Expand Down
2 changes: 2 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const (
LabelKubernetesManagedBy = "app.kubernetes.io/managed-by"
LabelKubernetesRoleGroup = "app.kubernetes.io/role-group"
LabelKubernetesVersion = "app.kubernetes.io/version"
)

const (
KubedoopDomain = "zncdata.dev"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/constants/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func ListenerStorageClassPtr() *string {
return &listenersStorageClass
}

// Zncdata defined annotations for PVCTemplate.
// Kubeddoop defined annotations for PVCTemplate.
// Then csi driver can extract annotations from PVC to prepare the listener for pod.
const (
// Specify which network listening rules to use, it is REQUIRED.
Expand Down
4 changes: 2 additions & 2 deletions pkg/constants/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
LabelSecretsService string = secretAPIGroupPrefix + "service"
)

// Zncdata defined annotations for PVCTemplate.
// Kubedoop defined annotations for PVCTemplate.
// Then csi driver can extract annotations from PVC to prepare the secret for pod.
const (
AnnotationSecretsClass string = secretAPIGroupPrefix + "class"
Expand Down Expand Up @@ -53,7 +53,7 @@ const (
AnnotationSecretCertLifeTime string = secretAPIGroupPrefix + "autoTlsCertLifetime"
AnnotationSecretsCertJitterFactor string = secretAPIGroupPrefix + "autoTlsCertJitterFactor"

// Annotation for expiration time of zncdata secret for pod.
// Annotation for expiration time of the secret for pod.
// When the secret is created, the expiration time is set to the current time plus the lifetime.
// Then we can clean up the secret after expiration time
AnnonationSecretExpirationTimeName string = secretAPIGroupPrefix + "expirationTime"
Expand Down

0 comments on commit f3e510f

Please sign in to comment.