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

fix bug for AERAKI_IS_MASTER env #354

Merged
merged 1 commit into from
Jun 13, 2023
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
68 changes: 53 additions & 15 deletions cmd/aeraki/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/aeraki-mesh/aeraki/plugin/thrift"
"github.com/aeraki-mesh/aeraki/plugin/zookeeper"

"istio.io/pkg/env"
"istio.io/pkg/log"
)

Expand All @@ -49,6 +48,8 @@ const (
func main() {
args := bootstrap.NewAerakiArgs()
flag.BoolVar(&args.Master, "master", true, "Run as master")
flag.BoolVar(&args.EnableEnvoyFilterNSScope, "enable-envoy-filter-namespace-scope", false,
"Generate Envoy Filters in the service namespace")
flag.StringVar(&args.AerakiXdsAddr, "aeraki-xds-address", constants.DefaultAerakiXdsAddr, "Aeraki xds server address")
flag.StringVar(&args.AerakiXdsPort, "aeraki-xds-port", constants.DefaultAerakiXdsPort, "Aeraki xds server port")
flag.StringVar(&args.IstiodAddr, "istiod-address", defaultIstiodAddr, "Istiod xds server address")
Expand All @@ -60,29 +61,22 @@ func main() {
flag.StringVar(&args.ElectionID, "election-id", defaultElectionID, "ElectionID to elect master controller")
flag.StringVar(&args.ServerID, "server-id", "", "Aeraki server id")
flag.StringVar(&args.LogLevel, "log-level", defaultLogLevel, "Component log level")
flag.BoolVar(&args.EnableEnvoyFilterNSScope, "enable-envoy-filter-namespace-scope", false,
"Generate Envoy Filters in the service namespace")
flag.StringVar(&args.KubeDomainSuffix, "domain", defaultKubernetesDomain, "Kubernetes DNS domain suffix")
flag.StringVar(&args.HTTPSAddr, "httpsAddr", ":15017", "validation service HTTPS address")
flag.StringVar(&args.HTTPAddr, "httpAddr", ":8080", "Aeraki readiness service HTTP address")

flag.Parse()
if args.ServerID == "" {
args.ServerID = "Aeraki-" + uuid.New().String()
}

args.PodName = env.RegisterStringVar("POD_NAME", args.ServerID, "").Get()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this line?

Copy link
Member Author

@tanjunchen tanjunchen Jun 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the log of aeraki are:

2023-06-09T09:55:00.259687Z	warn	The environment variable POD_NAME was registered multiple times using different metadata: {POD_NAME   false false 0}, {POD_NAME Aeraki-1d13822c-eca8-470f-a828-57938547f5f2  false false 0} 2023-06-09T09:55:00.259743Z	info	Aeraki parameter: aeraki-xds-address: aeraki.istio-system
image

PodName is be registered repeatly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

args.RootNamespace = env.RegisterStringVar("AERAKI_NAMESPACE", args.RootNamespace, "").Get()
args.EnableEnvoyFilterNSScope = env.RegisterBoolVar("AERAKI_ENABLE_ENVOY_FILTER_NS_SCOPE",
args.EnableEnvoyFilterNSScope, "").Get()
args.IstiodAddr = env.RegisterStringVar("AERAKI_ISTIOD_ADDR", args.IstiodAddr, "").Get()
args.AerakiXdsAddr = env.RegisterStringVar("AERAKI_XDS_ADDR", constants.DefaultAerakiXdsAddr, "").Get()
args.AerakiXdsPort = env.RegisterStringVar("AERAKI_XDS_PORT", constants.DefaultAerakiXdsPort, "").Get()

flag.VisitAll(func(flag *flag.Flag) {
log.Infof("Aeraki parameter: %s: %v", flag.Name, flag.Value)
})

if args.ServerID == "" {
args.ServerID = "Aeraki-" + uuid.New().String()
}

initArgsWithEnv(args)
log.Infof("Aeraki bootstrap parameter: %v", args)

setLogLevels(args.LogLevel)
// Create the stop channel for all of the servers.
stopChan := make(chan struct{}, 1)
Expand All @@ -100,6 +94,50 @@ func main() {
stopChan <- struct{}{}
}

func initArgsWithEnv(args *bootstrap.AerakiArgs) {
xdsAddr := os.Getenv("AERAKI_XDS_ADDR")
if xdsAddr != "" {
args.AerakiXdsAddr = xdsAddr
}

xdsPort := os.Getenv("AERAKI_XDS_PORT")
if xdsPort != "" {
args.AerakiXdsPort = xdsPort
}

istiodAddr := os.Getenv("AERAKI_ISTIOD_ADDR")
if istiodAddr != "" {
args.IstiodAddr = istiodAddr
}

namespace := os.Getenv("AERAKI_NAMESPACE")
if namespace != "" {
args.RootNamespace = namespace
}

clusterID := os.Getenv("AERAKI_CLUSTER_ID")
if clusterID != "" {
args.ClusterID = clusterID
}

secret := os.Getenv("AERAKI_ISTIO_CONFIG_STORE_SECRET")
if secret != "" {
args.ConfigStoreSecret = secret
}

logLevel := os.Getenv("AERAKI_LOG_LEVEL")
if logLevel != "" {
args.LogLevel = logLevel
}

podName := os.Getenv("POD_NAME")
if podName != "" {
args.PodName = os.Getenv("POD_NAME")
} else {
args.PodName = args.ServerID
}
}

func initGenerators() map[protocol.Instance]envoyfilter.Generator {
return map[protocol.Instance]envoyfilter.Generator{
protocol.Thrift: thrift.NewGenerator(),
Expand Down
4 changes: 4 additions & 0 deletions k8s/aeraki.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ spec:
containers:
- name: aeraki
image: ${AERAKI_IMAGE}:${AERAKI_TAG}
args:
- /usr/local/bin/aeraki
- --master=true
- --enable-envoy-filter-namespace-scope=false
# imagePullPolicy should be set to Never so Minikube can use local image for e2e testing
imagePullPolicy: ${AERAKI_IMG_PULL_POLICY}
ports:
Expand Down
4 changes: 4 additions & 0 deletions manifests/charts/aeraki/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ spec:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- /usr/local/bin/aeraki
- --master=true
- --enable-envoy-filter-namespace-scope=false
ports:
- containerPort: 8080
protocol: TCP
Expand Down