From 0ecdf9b43495f20d8b45ca76f398c059cf82d6f1 Mon Sep 17 00:00:00 2001 From: bananaappletw Date: Tue, 15 Sep 2020 09:42:41 +0800 Subject: [PATCH] Make user-defined InitContainers take the precedence --- Changelog.md | 1 + .../internal/syncer/statefullset.go | 23 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Changelog.md b/Changelog.md index d7b885e51..d1eb85134 100644 --- a/Changelog.md +++ b/Changelog.md @@ -14,6 +14,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). * Add `initBucketURL` and `initBucketSecretName` options to MysqlCluster chart. This bumps the chart version to `0.3.0` ### Changed * Only add `binlog-space-limit` for `percona` image + * Make user-defined InitContainer take the precedence * Set timeout of 15s on connection between the operator and Orchestrator * Bump controller-util dependency to 0.1.18 which fixes some updates on pod spec. * Removed `NO_AUTO_VALUE_ON_ZERO` from `sql-mode` to be inline with MySQL default value diff --git a/pkg/controller/mysqlcluster/internal/syncer/statefullset.go b/pkg/controller/mysqlcluster/internal/syncer/statefullset.go index 1fe050cff..0da0323a6 100644 --- a/pkg/controller/mysqlcluster/internal/syncer/statefullset.go +++ b/pkg/controller/mysqlcluster/internal/syncer/statefullset.go @@ -324,14 +324,20 @@ func (s *sfsSyncer) getEnvFor(name string) []core.EnvVar { } func (s *sfsSyncer) ensureInitContainersSpec() []core.Container { - initCs := []core.Container{ - // clone and init container - s.ensureContainer(containerCloneAndInitName, - s.opt.SidecarImage, - []string{"clone-and-init"}, - ), + initCs := []core.Container{} + + // add user defined init containers + if len(s.cluster.Spec.PodSpec.InitContainers) > 0 { + initCs = append(initCs, s.cluster.Spec.PodSpec.InitContainers...) } + // clone and init container + cloneInit := s.ensureContainer(containerCloneAndInitName, + s.opt.SidecarImage, + []string{"clone-and-init"}, + ) + initCs = append(initCs, cloneInit) + // add init container for MySQL if docker image supports this if s.cluster.ShouldHaveInitContainerForMysql() { mysqlInit := s.ensureContainer(containerMySQLInitName, @@ -341,11 +347,6 @@ func (s *sfsSyncer) ensureInitContainersSpec() []core.Container { initCs = append(initCs, mysqlInit) } - // add user defined init containers - if len(s.cluster.Spec.PodSpec.InitContainers) > 0 { - initCs = append(initCs, s.cluster.Spec.PodSpec.InitContainers...) - } - return initCs }