Skip to content

Commit 96f1205

Browse files
authored
Support different Kibana configs based on stack version (#553)
* Test boot up of different stack versions * Reword: default lts 8x * Use STACK_VERSION_VARIANT * Fix: Kibana * Fix * Fix: default * Fix * Another fix * Fix: wrong function * Bug: makefile * Remove deprecated flags * Use 7x instead of lts * Fix: xpack.fleet.agents.elasticsearch.hosts is array
1 parent 4e7ab31 commit 96f1205

File tree

13 files changed

+140
-27
lines changed

13 files changed

+140
-27
lines changed

.ci/Jenkinsfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ pipeline {
9191
dir("${BASE_DIR}") {
9292
script {
9393
parallel([
94-
'stack-command': generateTestCommandStage(command: 'test-stack-command', artifacts: ['build/elastic-stack-dump/stack/logs/*.log', 'build/elastic-stack-dump/stack/logs/fleet-server-internal/*']),
94+
'stack-command-default': generateTestCommandStage(command: 'test-stack-command-default', artifacts: ['build/elastic-stack-dump/stack/*/logs/*.log', 'build/elastic-stack-dump/stack/*/logs/fleet-server-internal/*']),
95+
'stack-command-7x': generateTestCommandStage(command: 'test-stack-command-7x', artifacts: ['build/elastic-stack-dump/stack/*/logs/*.log', 'build/elastic-stack-dump/stack/*/logs/fleet-server-internal/*']),
96+
'stack-command-8x': generateTestCommandStage(command: 'test-stack-command-8x', artifacts: ['build/elastic-stack-dump/stack/*/logs/*.log', 'build/elastic-stack-dump/stack/*/logs/fleet-server-internal/*']),
9597
'check-packages': generateTestCommandStage(command: 'test-check-packages', artifacts: ['build/test-results/*.xml', 'build/kubectl-dump.txt', 'build/elastic-stack-dump/check/logs/*.log', 'build/elastic-stack-dump/check/logs/fleet-server-internal/*'], junitArtifacts: true, publishCoverage: true),
9698
'build-zip': generateTestCommandStage(command: 'test-build-zip', artifacts: ['build/elastic-stack-dump/build-zip/logs/*.log']),
9799
'profiles-command': generateTestCommandStage(command: 'test-profiles-command'),

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,17 @@ test-go-ci:
3838
$(MAKE) test-go | go run github.com/tebeka/go2xunit > "$(PWD)/build/test-results/TEST-unit.xml"
3939
go run github.com/boumenot/gocover-cobertura < $(CODE_COVERAGE_REPORT_NAME_UNIT).out > $(CODE_COVERAGE_REPORT_NAME_UNIT).xml
4040

41-
test-stack-command:
41+
test-stack-command-default:
4242
./scripts/test-stack-command.sh
4343

44+
test-stack-command-7x:
45+
./scripts/test-stack-command.sh 7.16.0-SNAPSHOT
46+
47+
test-stack-command-8x:
48+
./scripts/test-stack-command.sh 8.0.0-SNAPSHOT
49+
50+
test-stack-command: test-stack-command-default test-stack-command-7x test-stack-command-8x
51+
4452
test-check-packages:
4553
./scripts/test-check-packages.sh
4654

internal/install/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func migrateIfNeeded(elasticPackagePath *locations.LocationManager) error {
104104
oldFiles := []string{
105105
filepath.Join(elasticPackagePath.StackDir(), string(profile.SnapshotFile)),
106106
filepath.Join(elasticPackagePath.StackDir(), string(profile.PackageRegistryDockerfileFile)),
107-
filepath.Join(elasticPackagePath.StackDir(), string(profile.KibanaConfigFile)),
107+
filepath.Join(elasticPackagePath.StackDir(), string(profile.KibanaConfigDefaultFile)),
108108
filepath.Join(elasticPackagePath.StackDir(), string(profile.PackageRegistryConfigFile)),
109109
}
110110

internal/profile/_static/docker-compose-stack.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ services:
4343
retries: 600
4444
interval: 1s
4545
volumes:
46-
- ./kibana.config.yml:/usr/share/kibana/config/kibana.yml
47-
- ../../../stack/healthcheck.sh:/usr/share/kibana/healthcheck.sh
46+
- "./kibana.config.${STACK_VERSION_VARIANT}.yml:/usr/share/kibana/config/kibana.yml"
47+
- "../../../stack/healthcheck.sh:/usr/share/kibana/healthcheck.sh"
4848
ports:
4949
- "127.0.0.1:5601:5601"
5050

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
server.name: kibana
2+
server.host: "0.0.0.0"
3+
4+
elasticsearch.hosts: [ "http://elasticsearch:9200" ]
5+
elasticsearch.username: elastic
6+
elasticsearch.password: changeme
7+
8+
monitoring.ui.container.elasticsearch.enabled: true
9+
10+
xpack.fleet.registryUrl: "http://package-registry:8080"
11+
xpack.fleet.agents.enabled: true
12+
xpack.fleet.agents.elasticsearch.hosts: ["http://elasticsearch:9200"]
13+
xpack.fleet.agents.fleet_server.hosts: ["http://fleet-server:8220"]
14+
15+
xpack.encryptedSavedObjects.encryptionKey: "12345678901234567890123456789012"
File renamed without changes.

internal/profile/files.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ type simpleFile struct {
2323

2424
const profileStackPath = "stack"
2525

26-
// configfilesDiffer checks to see if a local configItem differs from the one it knows.
27-
func (cfg simpleFile) configfilesDiffer() (bool, error) {
26+
// configFilesDiffer checks to see if a local configItem differs from the one it knows.
27+
func (cfg simpleFile) configFilesDiffer() (bool, error) {
2828
changes, err := os.ReadFile(cfg.path)
29+
if err != nil && errors.Is(err, os.ErrNotExist) {
30+
return false, nil
31+
}
2932
if err != nil {
30-
return false, errors.Wrapf(err, "error reading %s", KibanaConfigFile)
33+
return false, errors.Wrapf(err, "error reading %s", cfg.path)
3134
}
3235
if string(changes) != cfg.body {
3336
return true, nil

internal/profile/profile.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ type configFile string
3636
// managedProfileFiles is the list of all files managed in a profile
3737
// If you create a new file that's managed by a profile, it needs to go in this list
3838
var managedProfileFiles = map[configFile]NewConfig{
39-
KibanaConfigFile: newKibanaConfig,
39+
KibanaConfigDefaultFile: newKibanaConfigDefault,
40+
KibanaConfig8xFile: newKibanaConfig8x,
4041
PackageRegistryDockerfileFile: newPackageRegistryDockerfile,
4142
PackageRegistryConfigFile: newPackageRegistryConfig,
4243
SnapshotFile: newSnapshotFile,
@@ -240,7 +241,7 @@ func (profile Profile) localFilesChanged() (bool, error) {
240241
if cfgName == PackageProfileMetaFile {
241242
continue
242243
}
243-
changes, err := cfgFile.configfilesDiffer()
244+
changes, err := cfgFile.configFilesDiffer()
244245
if err != nil {
245246
return false, errors.Wrap(err, "error checking config file")
246247
}

internal/profile/static.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,31 @@ func newSnapshotFile(_ string, profilePath string) (*simpleFile, error) {
2525
}, nil
2626
}
2727

28-
// KibanaConfigFile is the main kibana config file
29-
const KibanaConfigFile configFile = "kibana.config.yml"
28+
// KibanaConfigDefaultFile is the default kibana config file
29+
const KibanaConfigDefaultFile configFile = "kibana.config.default.yml"
3030

31-
//go:embed _static/kibana_config.yml
32-
var kibanaConfigYml string
31+
//go:embed _static/kibana_config_default.yml
32+
var kibanaConfigDefaultYml string
3333

34-
// newKibanaConfig returns a Managed Config
35-
func newKibanaConfig(_ string, profilePath string) (*simpleFile, error) {
34+
func newKibanaConfigDefault(_ string, profilePath string) (*simpleFile, error) {
3635
return &simpleFile{
37-
name: string(KibanaConfigFile),
38-
path: filepath.Join(profilePath, profileStackPath, string(KibanaConfigFile)),
39-
body: kibanaConfigYml,
36+
name: string(KibanaConfigDefaultFile),
37+
path: filepath.Join(profilePath, profileStackPath, string(KibanaConfigDefaultFile)),
38+
body: kibanaConfigDefaultYml,
39+
}, nil
40+
}
41+
42+
// KibanaConfig8xFile is the Kibana config file for 8.x stack family
43+
const KibanaConfig8xFile configFile = "kibana.config.8x.yml"
44+
45+
//go:embed _static/kibana_config_8x.yml
46+
var kibanaConfig8xYml string
47+
48+
func newKibanaConfig8x(_ string, profilePath string) (*simpleFile, error) {
49+
return &simpleFile{
50+
name: string(KibanaConfig8xFile),
51+
path: filepath.Join(profilePath, profileStackPath, string(KibanaConfig8xFile)),
52+
body: kibanaConfig8xYml,
4053
}, nil
4154
}
4255

internal/stack/compose.go

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@ import (
1414
"github.com/elastic/elastic-package/internal/profile"
1515
)
1616

17+
type envBuilder struct {
18+
vars []string
19+
}
20+
21+
func newEnvBuilder() *envBuilder {
22+
return new(envBuilder)
23+
}
24+
25+
func (eb *envBuilder) withEnvs(envs []string) *envBuilder {
26+
eb.vars = append(eb.vars, envs...)
27+
return eb
28+
}
29+
30+
func (eb *envBuilder) withEnv(env string) *envBuilder {
31+
eb.vars = append(eb.vars, env)
32+
return eb
33+
}
34+
35+
func (eb *envBuilder) build() []string {
36+
return eb.vars
37+
}
38+
1739
func dockerComposeBuild(options Options) error {
1840
c, err := compose.NewProject(DockerComposeProjectName, options.Profile.FetchPath(profile.SnapshotFile))
1941
if err != nil {
@@ -26,7 +48,11 @@ func dockerComposeBuild(options Options) error {
2648
}
2749

2850
opts := compose.CommandOptions{
29-
Env: append(appConfig.StackImageRefs(options.StackVersion).AsEnv(), options.Profile.ComposeEnvVars()...),
51+
Env: newEnvBuilder().
52+
withEnvs(appConfig.StackImageRefs(options.StackVersion).AsEnv()).
53+
withEnv(stackVariantAsEnv(options.StackVersion)).
54+
withEnvs(options.Profile.ComposeEnvVars()).
55+
build(),
3056
Services: withIsReadyServices(withDependentServices(options.Services)),
3157
}
3258

@@ -48,7 +74,11 @@ func dockerComposePull(options Options) error {
4874
}
4975

5076
opts := compose.CommandOptions{
51-
Env: append(appConfig.StackImageRefs(options.StackVersion).AsEnv(), options.Profile.ComposeEnvVars()...),
77+
Env: newEnvBuilder().
78+
withEnvs(appConfig.StackImageRefs(options.StackVersion).AsEnv()).
79+
withEnv(stackVariantAsEnv(options.StackVersion)).
80+
withEnvs(options.Profile.ComposeEnvVars()).
81+
build(),
5282
Services: withIsReadyServices(withDependentServices(options.Services)),
5383
}
5484

@@ -75,7 +105,11 @@ func dockerComposeUp(options Options) error {
75105
}
76106

77107
opts := compose.CommandOptions{
78-
Env: append(appConfig.StackImageRefs(options.StackVersion).AsEnv(), options.Profile.ComposeEnvVars()...),
108+
Env: newEnvBuilder().
109+
withEnvs(appConfig.StackImageRefs(options.StackVersion).AsEnv()).
110+
withEnv(stackVariantAsEnv(options.StackVersion)).
111+
withEnvs(options.Profile.ComposeEnvVars()).
112+
build(),
79113
ExtraArgs: args,
80114
Services: withIsReadyServices(withDependentServices(options.Services)),
81115
}
@@ -98,7 +132,11 @@ func dockerComposeDown(options Options) error {
98132
}
99133

100134
downOptions := compose.CommandOptions{
101-
Env: append(appConfig.StackImageRefs(options.StackVersion).AsEnv(), options.Profile.ComposeEnvVars()...),
135+
Env: newEnvBuilder().
136+
withEnvs(appConfig.StackImageRefs(options.StackVersion).AsEnv()).
137+
withEnv(stackVariantAsEnv(options.StackVersion)).
138+
withEnvs(options.Profile.ComposeEnvVars()).
139+
build(),
102140
// Remove associated volumes.
103141
ExtraArgs: []string{"--volumes", "--remove-orphans"},
104142
}

0 commit comments

Comments
 (0)