Skip to content

Commit 1f9ad5f

Browse files
pooknullhors
andauthored
K8SPS-413: replace initImage with initContainer (#996)
* K8SPS-413: replace initImage with initContainer https://perconadev.atlassian.net/browse/K8SPS-413 * fix test * add test * make generate * replace all initImage fields with initContainer * add version checks * fix unit-test * add nolint comments * update controller-gen to v0.18.0 * improve Jenkinsfile * improve Jenkinsfile --------- Co-authored-by: Viacheslav Sarzhan <[email protected]>
1 parent 550a4bd commit 1f9ad5f

25 files changed

+3550
-218
lines changed

Jenkinsfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,10 @@ void runTest(Integer TEST_ID) {
248248

249249
void prepareNode() {
250250
sh """
251-
sudo curl -s -L -o /usr/local/bin/kubectl https://dl.k8s.io/release/\$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl && sudo chmod +x /usr/local/bin/kubectl
251+
if [ ! -f /usr/local/bin/kubectl ]; then
252+
sudo curl -s -L -o /usr/local/bin/kubectl https://dl.k8s.io/release/\$(curl -L -s https://api.github.com/repos/kubernetes/kubernetes/releases/latest | jq -r .tag_name)/bin/linux/amd64/kubectl && sudo chmod +x /usr/local/bin/kubectl
253+
fi
254+
252255
kubectl version --client --output=yaml
253256
254257
curl -fsSL https://get.helm.sh/helm-v3.18.0-linux-amd64.tar.gz | sudo tar -C /usr/local/bin --strip-components 1 -xzf - linux-amd64/helm

api/v1alpha1/perconaservermysql_types.go

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ type PerconaServerMySQLSpec struct {
6363
SecretsName string `json:"secretsName,omitempty"`
6464
SSLSecretName string `json:"sslSecretName,omitempty"`
6565
Unsafe UnsafeFlags `json:"unsafeFlags,omitempty"`
66-
InitImage string `json:"initImage,omitempty"`
6766
IgnoreAnnotations []string `json:"ignoreAnnotations,omitempty"`
6867
IgnoreLabels []string `json:"ignoreLabels,omitempty"`
6968
MySQL MySQLSpec `json:"mysql,omitempty"`
@@ -75,6 +74,16 @@ type PerconaServerMySQLSpec struct {
7574
Toolkit *ToolkitSpec `json:"toolkit,omitempty"`
7675
UpgradeOptions UpgradeOptions `json:"upgradeOptions,omitempty"`
7776
UpdateStrategy appsv1.StatefulSetUpdateStrategyType `json:"updateStrategy,omitempty"`
77+
78+
// Deprecated: not supported since v0.12.0. Use initContainer instead
79+
InitImage string `json:"initImage,omitempty"`
80+
InitContainer InitContainerSpec `json:"initContainer,omitempty"`
81+
}
82+
83+
type InitContainerSpec struct {
84+
Image string `json:"image,omitempty"`
85+
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
86+
ContainerSecurityContext *corev1.SecurityContext `json:"containerSecurityContext,omitempty"`
7887
}
7988

8089
type UnsafeFlags struct {
@@ -178,7 +187,10 @@ type PodSpec struct {
178187
Annotations map[string]string `json:"annotations,omitempty"`
179188
Labels map[string]string `json:"labels,omitempty"`
180189
VolumeSpec *VolumeSpec `json:"volumeSpec,omitempty"`
181-
InitImage string `json:"initImage,omitempty"`
190+
191+
// Deprecated: not supported since v0.12.0. Use initContainer instead
192+
InitImage string `json:"initImage,omitempty"`
193+
InitContainer *InitContainerSpec `json:"initContainer,omitempty"`
182194

183195
Affinity *PodAffinity `json:"affinity,omitempty"`
184196
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
@@ -208,9 +220,16 @@ func (s PodSpec) GetTerminationGracePeriodSeconds() *int64 {
208220
return &gp
209221
}
210222

211-
// Retrieves the initialization image for the pod.
212-
func (s *PodSpec) GetInitImage() string {
213-
return s.InitImage
223+
func (s *PodSpec) GetInitSpec(cr *PerconaServerMySQL) InitContainerSpec {
224+
if s.InitContainer == nil {
225+
if cr.CompareVersion("0.12.0") < 0 {
226+
return InitContainerSpec{
227+
Image: s.InitImage,
228+
}
229+
}
230+
return InitContainerSpec{}
231+
}
232+
return *s.InitContainer
214233
}
215234

216235
type PMMSpec struct {
@@ -226,7 +245,6 @@ type PMMSpec struct {
226245
type BackupSpec struct {
227246
Enabled bool `json:"enabled,omitempty"`
228247
Image string `json:"image"`
229-
InitImage string `json:"initImage,omitempty"`
230248
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
231249
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
232250
ServiceAccountName string `json:"serviceAccountName,omitempty"`
@@ -236,6 +254,10 @@ type BackupSpec struct {
236254
BackoffLimit *int32 `json:"backoffLimit,omitempty"`
237255
PiTR PiTRSpec `json:"pitr,omitempty"`
238256
Schedule []BackupSchedule `json:"schedule,omitempty"`
257+
258+
// Deprecated: not supported since v0.12.0. Use initContainer instead
259+
InitImage string `json:"initImage,omitempty"`
260+
InitContainer *InitContainerSpec `json:"initContainer,omitempty"`
239261
}
240262

241263
type BackupSchedule struct {
@@ -248,9 +270,16 @@ type BackupSchedule struct {
248270
StorageName string `json:"storageName,omitempty"`
249271
}
250272

251-
// Retrieves the initialization image for the backup.
252-
func (s *BackupSpec) GetInitImage() string {
253-
return s.InitImage
273+
func (s *BackupSpec) GetInitSpec(cr *PerconaServerMySQL) InitContainerSpec {
274+
if s.InitContainer == nil {
275+
if cr.CompareVersion("0.12.0") < 0 {
276+
return InitContainerSpec{
277+
Image: s.InitImage,
278+
}
279+
}
280+
return InitContainerSpec{}
281+
}
282+
return *s.InitContainer
254283
}
255284

256285
type BackupStorageType string

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 64 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)