Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
8719b4a8
Commit
8719b4a8
authored
Aug 15, 2017
by
xiangpengzhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove deprecated init-container in annotations
parent
74f4fda7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
158 additions
and
527 deletions
+158
-527
conversion.go
pkg/api/v1/conversion.go
+1
-232
defaults_test.go
pkg/api/v1/defaults_test.go
+95
-104
util.go
pkg/api/v1/pod/util.go
+0
-62
util_test.go
pkg/api/v1/pod/util_test.go
+0
-50
zz_generated.conversion.go
pkg/api/v1/zz_generated.conversion.go
+20
-0
BUILD
pkg/kubelet/config/BUILD
+0
-1
config.go
pkg/kubelet/config/config.go
+0
-12
status_manager.go
pkg/kubelet/status/status_manager.go
+0
-3
types.go
staging/src/k8s.io/api/core/v1/types.go
+0
-21
init_container.go
test/e2e/common/init_container.go
+0
-0
statefulset.yaml
...ting-manifests/statefulset/mysql-upgrade/statefulset.yaml
+42
-42
No files found.
pkg/api/v1/conversion.go
View file @
8719b4a8
This diff is collapsed.
Click to expand it.
pkg/api/v1/defaults_test.go
View file @
8719b4a8
...
...
@@ -350,7 +350,7 @@ func TestSetDefaultReplicationControllerInitContainers(t *testing.T) {
return
nil
}
cpu
,
_
:=
resource
.
ParseQuantity
(
"100
Gi
"
)
cpu
,
_
:=
resource
.
ParseQuantity
(
"100
m
"
)
mem
,
_
:=
resource
.
ParseQuantity
(
"100Mi"
)
tests
:=
[]
struct
{
...
...
@@ -364,15 +364,12 @@ func TestSetDefaultReplicationControllerInitContainers(t *testing.T) {
rc
:
v1
.
ReplicationController
{
Spec
:
v1
.
ReplicationControllerSpec
{
Template
:
&
v1
.
PodTemplateSpec
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
"pod.beta.kubernetes.io/init-containers"
:
`
[
{
"name": "install",
"image": "busybox"
}
]`
,
Spec
:
v1
.
PodSpec
{
InitContainers
:
[]
v1
.
Container
{
{
Name
:
"install"
,
Image
:
"busybox"
,
},
},
},
},
...
...
@@ -390,26 +387,23 @@ func TestSetDefaultReplicationControllerInitContainers(t *testing.T) {
rc
:
v1
.
ReplicationController
{
Spec
:
v1
.
ReplicationControllerSpec
{
Template
:
&
v1
.
PodTemplateSpec
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
"pod.beta.kubernetes.io/init-containers"
:
`
[
{
"name": "fun",
"image": "alpine",
"env": [
{
"name": "MY_POD_IP",
"valueFrom": {
"fieldRef": {
"apiVersion": "",
"fieldPath": "status.podIP"
}
}
}
]
}
]`
,
Spec
:
v1
.
PodSpec
{
InitContainers
:
[]
v1
.
Container
{
{
Name
:
"fun"
,
Image
:
"alpine"
,
Env
:
[]
v1
.
EnvVar
{
{
Name
:
"MY_POD_IP"
,
ValueFrom
:
&
v1
.
EnvVarSource
{
FieldRef
:
&
v1
.
ObjectFieldSelector
{
APIVersion
:
""
,
FieldPath
:
"status.podIP"
,
},
},
},
},
},
},
},
},
...
...
@@ -437,20 +431,17 @@ func TestSetDefaultReplicationControllerInitContainers(t *testing.T) {
rc
:
v1
.
ReplicationController
{
Spec
:
v1
.
ReplicationControllerSpec
{
Template
:
&
v1
.
PodTemplateSpec
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
"pod.beta.kubernetes.io/init-containers"
:
`
[
{
"name": "fun",
"image": "alpine",
"ports": [
{
"name": "default"
}
]
}
]`
,
Spec
:
v1
.
PodSpec
{
InitContainers
:
[]
v1
.
Container
{
{
Name
:
"fun"
,
Image
:
"alpine"
,
Ports
:
[]
v1
.
ContainerPort
{
{
Name
:
"default"
,
},
},
},
},
},
},
...
...
@@ -473,25 +464,22 @@ func TestSetDefaultReplicationControllerInitContainers(t *testing.T) {
rc
:
v1
.
ReplicationController
{
Spec
:
v1
.
ReplicationControllerSpec
{
Template
:
&
v1
.
PodTemplateSpec
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
"pod.beta.kubernetes.io/init-containers"
:
`
[
{
"name": "fun",
"image": "alpine",
"resources": {
"limits": {
"cpu": "100Gi",
"memory": "100Mi"
},
"requests": {
"cpu": "100Gi",
"memory": "100Mi"
}
}
}
]`
,
Spec
:
v1
.
PodSpec
{
InitContainers
:
[]
v1
.
Container
{
{
Name
:
"fun"
,
Image
:
"alpine"
,
Resources
:
v1
.
ResourceRequirements
{
Limits
:
v1
.
ResourceList
{
v1
.
ResourceCPU
:
resource
.
MustParse
(
"100m"
),
v1
.
ResourceMemory
:
resource
.
MustParse
(
"100Mi"
),
},
Requests
:
v1
.
ResourceList
{
v1
.
ResourceCPU
:
resource
.
MustParse
(
"100m"
),
v1
.
ResourceMemory
:
resource
.
MustParse
(
"100Mi"
),
},
},
},
},
},
},
...
...
@@ -514,29 +502,30 @@ func TestSetDefaultReplicationControllerInitContainers(t *testing.T) {
validators
:
[]
InitContainerValidator
{
assertResource
},
},
{
name
:
"Prob"
,
name
:
"Prob
e
"
,
rc
:
v1
.
ReplicationController
{
Spec
:
v1
.
ReplicationControllerSpec
{
Template
:
&
v1
.
PodTemplateSpec
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
"pod.beta.kubernetes.io/init-containers"
:
`
[
{
"name": "fun",
"image": "alpine",
"livenessProbe": {
"httpGet": {
"host": "localhost"
}
},
"readinessProbe": {
"httpGet": {
"host": "localhost"
}
}
}
]`
,
Spec
:
v1
.
PodSpec
{
InitContainers
:
[]
v1
.
Container
{
{
Name
:
"fun"
,
Image
:
"alpine"
,
LivenessProbe
:
&
v1
.
Probe
{
Handler
:
v1
.
Handler
{
HTTPGet
:
&
v1
.
HTTPGetAction
{
Host
:
"localhost"
,
},
},
},
ReadinessProbe
:
&
v1
.
Probe
{
Handler
:
v1
.
Handler
{
HTTPGet
:
&
v1
.
HTTPGetAction
{
Host
:
"localhost"
,
},
},
},
},
},
},
},
...
...
@@ -577,27 +566,29 @@ func TestSetDefaultReplicationControllerInitContainers(t *testing.T) {
rc
:
v1
.
ReplicationController
{
Spec
:
v1
.
ReplicationControllerSpec
{
Template
:
&
v1
.
PodTemplateSpec
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
"pod.beta.kubernetes.io/init-containers"
:
`
[
{
"name": "fun",
"image": "alpine",
"lifecycle": {
"postStart": {
"httpGet": {
"host": "localhost"
}
},
"preStop": {
"httpGet": {
"host": "localhost"
}
}
}
}
]`
,
Spec
:
v1
.
PodSpec
{
InitContainers
:
[]
v1
.
Container
{
{
Name
:
"fun"
,
Image
:
"alpine"
,
Ports
:
[]
v1
.
ContainerPort
{
{
Name
:
"default"
,
},
},
Lifecycle
:
&
v1
.
Lifecycle
{
PostStart
:
&
v1
.
Handler
{
HTTPGet
:
&
v1
.
HTTPGetAction
{
Host
:
"localhost"
,
},
},
PreStop
:
&
v1
.
Handler
{
HTTPGet
:
&
v1
.
HTTPGetAction
{
Host
:
"localhost"
,
},
},
},
},
},
},
},
...
...
pkg/api/v1/pod/util.go
View file @
8719b4a8
...
...
@@ -17,7 +17,6 @@ limitations under the License.
package
pod
import
(
"encoding/json"
"fmt"
"time"
...
...
@@ -49,67 +48,6 @@ func FindPort(pod *v1.Pod, svcPort *v1.ServicePort) (int, error) {
return
0
,
fmt
.
Errorf
(
"no suitable port for manifest: %s"
,
pod
.
UID
)
}
// TODO: remove this function when init containers becomes a stable feature
func
SetInitContainersAndStatuses
(
pod
*
v1
.
Pod
)
error
{
var
initContainersAnnotation
string
initContainersAnnotation
=
pod
.
Annotations
[
v1
.
PodInitContainersAnnotationKey
]
initContainersAnnotation
=
pod
.
Annotations
[
v1
.
PodInitContainersBetaAnnotationKey
]
if
len
(
initContainersAnnotation
)
>
0
{
var
values
[]
v1
.
Container
if
err
:=
json
.
Unmarshal
([]
byte
(
initContainersAnnotation
),
&
values
);
err
!=
nil
{
return
err
}
pod
.
Spec
.
InitContainers
=
values
}
var
initContainerStatusesAnnotation
string
initContainerStatusesAnnotation
=
pod
.
Annotations
[
v1
.
PodInitContainerStatusesAnnotationKey
]
initContainerStatusesAnnotation
=
pod
.
Annotations
[
v1
.
PodInitContainerStatusesBetaAnnotationKey
]
if
len
(
initContainerStatusesAnnotation
)
>
0
{
var
values
[]
v1
.
ContainerStatus
if
err
:=
json
.
Unmarshal
([]
byte
(
initContainerStatusesAnnotation
),
&
values
);
err
!=
nil
{
return
err
}
pod
.
Status
.
InitContainerStatuses
=
values
}
return
nil
}
// TODO: remove this function when init containers becomes a stable feature
func
SetInitContainersAnnotations
(
pod
*
v1
.
Pod
)
error
{
if
len
(
pod
.
Spec
.
InitContainers
)
>
0
{
value
,
err
:=
json
.
Marshal
(
pod
.
Spec
.
InitContainers
)
if
err
!=
nil
{
return
err
}
if
pod
.
Annotations
==
nil
{
pod
.
Annotations
=
make
(
map
[
string
]
string
)
}
pod
.
Annotations
[
v1
.
PodInitContainersAnnotationKey
]
=
string
(
value
)
pod
.
Annotations
[
v1
.
PodInitContainersBetaAnnotationKey
]
=
string
(
value
)
}
return
nil
}
// TODO: remove this function when init containers becomes a stable feature
func
SetInitContainersStatusesAnnotations
(
pod
*
v1
.
Pod
)
error
{
if
len
(
pod
.
Status
.
InitContainerStatuses
)
>
0
{
value
,
err
:=
json
.
Marshal
(
pod
.
Status
.
InitContainerStatuses
)
if
err
!=
nil
{
return
err
}
if
pod
.
Annotations
==
nil
{
pod
.
Annotations
=
make
(
map
[
string
]
string
)
}
pod
.
Annotations
[
v1
.
PodInitContainerStatusesAnnotationKey
]
=
string
(
value
)
pod
.
Annotations
[
v1
.
PodInitContainerStatusesBetaAnnotationKey
]
=
string
(
value
)
}
else
{
delete
(
pod
.
Annotations
,
v1
.
PodInitContainerStatusesAnnotationKey
)
delete
(
pod
.
Annotations
,
v1
.
PodInitContainerStatusesBetaAnnotationKey
)
}
return
nil
}
// Visitor is called with each object name, and returns true if visiting should continue
type
Visitor
func
(
name
string
)
(
shouldContinue
bool
)
...
...
pkg/api/v1/pod/util_test.go
View file @
8719b4a8
...
...
@@ -17,7 +17,6 @@ limitations under the License.
package
pod
import
(
"encoding/json"
"reflect"
"strings"
"testing"
...
...
@@ -405,52 +404,3 @@ func TestIsPodAvailable(t *testing.T) {
}
}
}
func
TestSetInitContainersStatusesAnnotations
(
t
*
testing
.
T
)
{
testStatuses
:=
[]
v1
.
ContainerStatus
{
{
Name
:
"test"
,
},
}
value
,
_
:=
json
.
Marshal
(
testStatuses
)
testAnnotation
:=
string
(
value
)
tests
:=
[]
struct
{
name
string
pod
*
v1
.
Pod
annotations
map
[
string
]
string
}{
{
name
:
"Populate annotations from status"
,
pod
:
&
v1
.
Pod
{
Status
:
v1
.
PodStatus
{
InitContainerStatuses
:
testStatuses
,
},
},
annotations
:
map
[
string
]
string
{
v1
.
PodInitContainerStatusesAnnotationKey
:
testAnnotation
,
v1
.
PodInitContainerStatusesBetaAnnotationKey
:
testAnnotation
,
},
},
{
name
:
"Clear annotations if no status"
,
pod
:
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{
v1
.
PodInitContainerStatusesAnnotationKey
:
testAnnotation
,
v1
.
PodInitContainerStatusesBetaAnnotationKey
:
testAnnotation
,
},
},
Status
:
v1
.
PodStatus
{
InitContainerStatuses
:
[]
v1
.
ContainerStatus
{},
},
},
annotations
:
map
[
string
]
string
{},
},
}
for
_
,
test
:=
range
tests
{
SetInitContainersStatusesAnnotations
(
test
.
pod
)
if
!
reflect
.
DeepEqual
(
test
.
pod
.
Annotations
,
test
.
annotations
)
{
t
.
Errorf
(
"%v, actual = %v, expected = %v"
,
test
.
name
,
test
.
pod
.
Annotations
,
test
.
annotations
)
}
}
}
pkg/api/v1/zz_generated.conversion.go
View file @
8719b4a8
...
...
@@ -3232,6 +3232,11 @@ func autoConvert_v1_Pod_To_api_Pod(in *v1.Pod, out *api.Pod, s conversion.Scope)
return
nil
}
// Convert_v1_Pod_To_api_Pod is an autogenerated conversion function.
func
Convert_v1_Pod_To_api_Pod
(
in
*
v1
.
Pod
,
out
*
api
.
Pod
,
s
conversion
.
Scope
)
error
{
return
autoConvert_v1_Pod_To_api_Pod
(
in
,
out
,
s
)
}
func
autoConvert_api_Pod_To_v1_Pod
(
in
*
api
.
Pod
,
out
*
v1
.
Pod
,
s
conversion
.
Scope
)
error
{
out
.
ObjectMeta
=
in
.
ObjectMeta
if
err
:=
Convert_api_PodSpec_To_v1_PodSpec
(
&
in
.
Spec
,
&
out
.
Spec
,
s
);
err
!=
nil
{
...
...
@@ -3243,6 +3248,11 @@ func autoConvert_api_Pod_To_v1_Pod(in *api.Pod, out *v1.Pod, s conversion.Scope)
return
nil
}
// Convert_api_Pod_To_v1_Pod is an autogenerated conversion function.
func
Convert_api_Pod_To_v1_Pod
(
in
*
api
.
Pod
,
out
*
v1
.
Pod
,
s
conversion
.
Scope
)
error
{
return
autoConvert_api_Pod_To_v1_Pod
(
in
,
out
,
s
)
}
func
autoConvert_v1_PodAffinity_To_api_PodAffinity
(
in
*
v1
.
PodAffinity
,
out
*
api
.
PodAffinity
,
s
conversion
.
Scope
)
error
{
out
.
RequiredDuringSchedulingIgnoredDuringExecution
=
*
(
*
[]
api
.
PodAffinityTerm
)(
unsafe
.
Pointer
(
&
in
.
RequiredDuringSchedulingIgnoredDuringExecution
))
out
.
PreferredDuringSchedulingIgnoredDuringExecution
=
*
(
*
[]
api
.
WeightedPodAffinityTerm
)(
unsafe
.
Pointer
(
&
in
.
PreferredDuringSchedulingIgnoredDuringExecution
))
...
...
@@ -3736,6 +3746,11 @@ func autoConvert_v1_PodStatusResult_To_api_PodStatusResult(in *v1.PodStatusResul
return
nil
}
// Convert_v1_PodStatusResult_To_api_PodStatusResult is an autogenerated conversion function.
func
Convert_v1_PodStatusResult_To_api_PodStatusResult
(
in
*
v1
.
PodStatusResult
,
out
*
api
.
PodStatusResult
,
s
conversion
.
Scope
)
error
{
return
autoConvert_v1_PodStatusResult_To_api_PodStatusResult
(
in
,
out
,
s
)
}
func
autoConvert_api_PodStatusResult_To_v1_PodStatusResult
(
in
*
api
.
PodStatusResult
,
out
*
v1
.
PodStatusResult
,
s
conversion
.
Scope
)
error
{
out
.
ObjectMeta
=
in
.
ObjectMeta
if
err
:=
Convert_api_PodStatus_To_v1_PodStatus
(
&
in
.
Status
,
&
out
.
Status
,
s
);
err
!=
nil
{
...
...
@@ -3744,6 +3759,11 @@ func autoConvert_api_PodStatusResult_To_v1_PodStatusResult(in *api.PodStatusResu
return
nil
}
// Convert_api_PodStatusResult_To_v1_PodStatusResult is an autogenerated conversion function.
func
Convert_api_PodStatusResult_To_v1_PodStatusResult
(
in
*
api
.
PodStatusResult
,
out
*
v1
.
PodStatusResult
,
s
conversion
.
Scope
)
error
{
return
autoConvert_api_PodStatusResult_To_v1_PodStatusResult
(
in
,
out
,
s
)
}
func
autoConvert_v1_PodTemplate_To_api_PodTemplate
(
in
*
v1
.
PodTemplate
,
out
*
api
.
PodTemplate
,
s
conversion
.
Scope
)
error
{
out
.
ObjectMeta
=
in
.
ObjectMeta
if
err
:=
Convert_v1_PodTemplateSpec_To_api_PodTemplateSpec
(
&
in
.
Template
,
&
out
.
Template
,
s
);
err
!=
nil
{
...
...
pkg/kubelet/config/BUILD
View file @
8719b4a8
...
...
@@ -28,7 +28,6 @@ go_library(
"//pkg/api/helper:go_default_library",
"//pkg/api/install:go_default_library",
"//pkg/api/v1:go_default_library",
"//pkg/api/v1/pod:go_default_library",
"//pkg/api/validation:go_default_library",
"//pkg/kubelet/container:go_default_library",
"//pkg/kubelet/events:go_default_library",
...
...
pkg/kubelet/config/config.go
View file @
8719b4a8
...
...
@@ -29,7 +29,6 @@ import (
"k8s.io/client-go/tools/record"
"k8s.io/kubernetes/pkg/api"
k8s_api_v1
"k8s.io/kubernetes/pkg/api/v1"
podutil
"k8s.io/kubernetes/pkg/api/v1/pod"
"k8s.io/kubernetes/pkg/api/validation"
kubecontainer
"k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/events"
...
...
@@ -256,17 +255,6 @@ func (s *podStorage) merge(source string, change interface{}) (adds, updates, de
}
update
:=
change
.
(
kubetypes
.
PodUpdate
)
// The InitContainers and InitContainerStatuses fields are lost during
// serialization and deserialization. They are conveyed via Annotations.
// Setting these fields here so that kubelet doesn't have to check for
// annotations.
if
source
==
kubetypes
.
ApiserverSource
{
for
_
,
pod
:=
range
update
.
Pods
{
if
err
:=
podutil
.
SetInitContainersAndStatuses
(
pod
);
err
!=
nil
{
glog
.
Error
(
err
)
}
}
}
switch
update
.
Op
{
case
kubetypes
.
ADD
,
kubetypes
.
UPDATE
,
kubetypes
.
DELETE
:
if
update
.
Op
==
kubetypes
.
ADD
{
...
...
pkg/kubelet/status/status_manager.go
View file @
8719b4a8
...
...
@@ -440,9 +440,6 @@ func (m *manager) syncPod(uid types.UID, status versionedPodStatus) {
return
}
pod
.
Status
=
status
.
status
if
err
:=
podutil
.
SetInitContainersStatusesAnnotations
(
pod
);
err
!=
nil
{
glog
.
Error
(
err
)
}
// TODO: handle conflict as a retry, make that easier too.
newPod
,
err
:=
m
.
kubeClient
.
Core
()
.
Pods
(
pod
.
Namespace
)
.
UpdateStatus
(
pod
)
if
err
!=
nil
{
...
...
staging/src/k8s.io/api/core/v1/types.go
View file @
8719b4a8
...
...
@@ -2423,27 +2423,6 @@ const (
TolerationOpEqual
TolerationOperator
=
"Equal"
)
const
(
// This annotation key will be used to contain an array of v1 JSON encoded Containers
// for init containers. The annotation will be placed into the internal type and cleared.
// This key is only recognized by version >= 1.4.
PodInitContainersBetaAnnotationKey
=
"pod.beta.kubernetes.io/init-containers"
// This annotation key will be used to contain an array of v1 JSON encoded Containers
// for init containers. The annotation will be placed into the internal type and cleared.
// This key is recognized by version >= 1.3. For version 1.4 code, this key
// will have its value copied to the beta key.
PodInitContainersAnnotationKey
=
"pod.alpha.kubernetes.io/init-containers"
// This annotation key will be used to contain an array of v1 JSON encoded
// ContainerStatuses for init containers. The annotation will be placed into the internal
// type and cleared. This key is only recognized by version >= 1.4.
PodInitContainerStatusesBetaAnnotationKey
=
"pod.beta.kubernetes.io/init-container-statuses"
// This annotation key will be used to contain an array of v1 JSON encoded
// ContainerStatuses for init containers. The annotation will be placed into the internal
// type and cleared. This key is recognized by version >= 1.3. For version 1.4 code,
// this key will have its value copied to the beta key.
PodInitContainerStatusesAnnotationKey
=
"pod.alpha.kubernetes.io/init-container-statuses"
)
// PodSpec is a description of a pod.
type
PodSpec
struct
{
// List of volumes that can be mounted by containers belonging to the pod.
...
...
test/e2e/common/init_container.go
View file @
8719b4a8
This diff is collapsed.
Click to expand it.
test/e2e/testing-manifests/statefulset/mysql-upgrade/statefulset.yaml
View file @
8719b4a8
...
...
@@ -9,47 +9,48 @@ spec:
metadata
:
labels
:
app
:
mysql
annotations
:
pod.beta.kubernetes.io/init-containers
:
'
[
{
"name":
"init-mysql",
"image":
"mysql:5.7",
"command":
["bash",
"-c",
"
set
-ex\n
[[
`hostname`
=~
-([0-9]+)$
]]
||
exit
1\n
ordinal=${BASH_REMATCH[1]}\n
echo
[mysqld]
>
/mnt/conf.d/server-id.cnf\n
echo
server-id=$((100
+
$ordinal))
>>
/mnt/conf.d/server-id.cnf\n
if
[[
$ordinal
-eq
0
]];
then\n
cp
/mnt/config-map/master.cnf
/mnt/conf.d/\n
else\n
cp
/mnt/config-map/slave.cnf
/mnt/conf.d/\n
fi\n
"],
"volumeMounts":
[
{"name":
"conf",
"mountPath":
"/mnt/conf.d"},
{"name":
"config-map",
"mountPath":
"/mnt/config-map"}
]
},
{
"name":
"clone-mysql",
"image":
"gcr.io/google-samples/xtrabackup:1.0",
"command":
["bash",
"-c",
"
set
-ex\n
[[
-d
/var/lib/mysql/mysql
]]
&&
exit
0\n
[[
`hostname`
=~
-([0-9]+)$
]]
||
exit
1\n
ordinal=${BASH_REMATCH[1]}\n
[[
$ordinal
-eq
0
]]
&&
exit
0\n
ncat
--recv-only
mysql-$(($ordinal-1)).mysql
3307
|
xbstream
-x
-C
/var/lib/mysql\n
xtrabackup
--prepare
--target-dir=/var/lib/mysql\n
"],
"volumeMounts":
[
{"name":
"data",
"mountPath":
"/var/lib/mysql",
"subPath":
"mysql"},
{"name":
"conf",
"mountPath":
"/etc/mysql/conf.d"}
]
}
]'
spec
:
initContainers
:
-
name
:
init-mysql
image
:
mysql:5.7
command
:
-
bash
-
"
-c"
-
|
set -ex
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
ordinal=${BASH_REMATCH[1]}
echo [mysqld] > /mnt/conf.d/server-id.cnf
echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf
if [[ $ordinal -eq 0 ]]; then
cp /mnt/config-map/master.cnf /mnt/conf.d/
else
cp /mnt/config-map/slave.cnf /mnt/conf.d/
fi
volumeMounts
:
-
name
:
conf
mountPath
:
/mnt/conf.d
-
name
:
config-map
mountPath
:
/mnt/config-map
-
name
:
clone-mysql
image
:
gcr.io/google-samples/xtrabackup:1.0
command
:
-
bash
-
"
-c"
-
|
set -ex
[[ -d /var/lib/mysql/mysql ]] && exit 0
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
ordinal=${BASH_REMATCH[1]}
[[ $ordinal -eq 0 ]] && exit 0
ncat --recv-only mysql-$(($ordinal-1)).mysql 3307 | xbstream -x -C /var/lib/mysql
xtrabackup --prepare --target-dir=/var/lib/mysql
volumeMounts
:
-
name
:
data
mountPath
:
/var/lib/mysql
subPath
:
mysql
-
name
:
conf
mountPath
:
/etc/mysql/conf.d
containers
:
-
name
:
mysql
image
:
mysql:5.7.15
...
...
@@ -138,10 +139,9 @@ spec:
volumeClaimTemplates
:
-
metadata
:
name
:
data
annotations
:
volume.alpha.kubernetes.io/storage-class
:
default
spec
:
accessModes
:
[
"
ReadWriteOnce"
]
storageClassName
:
default
resources
:
requests
:
storage
:
10Gi
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment