Skip to content

Commit

Permalink
*: Modify the podspec.resources field name. radondb#244
Browse files Browse the repository at this point in the history
  • Loading branch information
runkecheng committed Oct 28, 2021
1 parent 607f760 commit b893ebf
Show file tree
Hide file tree
Showing 21 changed files with 146 additions and 140 deletions.
14 changes: 8 additions & 6 deletions api/v1alpha1/mysqlcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ type MysqlClusterSpec struct {

// Pod extra specification.
// +optional
// +kubebuilder:default:={imagePullPolicy: "IfNotPresent", resources: {requests: {cpu: "10m", memory: "32Mi"}}, sidecarImage: "radondb/mysql-sidecar:0.1", busyboxImage: "busybox:1.32"}
PodSpec PodSpec `json:"podSpec,omitempty"`
// +kubebuilder:default:={imagePullPolicy: "IfNotPresent", defaultResources: {requests: {cpu: "10m", memory: "32Mi"}}, sidecarImage: "radondb/mysql-sidecar:0.1", busyboxImage: "busybox:1.32"}
PodPolicy PodPolicy `json:"podPolicy,omitempty"`

// PVC extra specifiaction.
// +optional
Expand Down Expand Up @@ -178,8 +178,9 @@ type MetricsOpts struct {
// string and string.
type MysqlConf map[string]string

// PodSpec defines type for configure cluster pod spec.
type PodSpec struct {
// PodPolicy defines type for configure spec of mysql node.
// A mysql node is a pod, so PodPolicy contains some podspec parameters.
type PodPolicy struct {
// +kubebuilder:validation:Enum=Always;IfNotPresent;Never
// +kubebuilder:default:="IfNotPresent"
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Expand All @@ -191,10 +192,11 @@ type PodSpec struct {
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
SchedulerName string `json:"schedulerName,omitempty"`

// The compute resource requirements.
// DefaultResources defines quotas for containers other than mysql and xenon.
// These containers take up less resources, so quotas are set uniformly.
// +optional
// +kubebuilder:default:={requests: {cpu: "10m", memory: "32Mi"}}
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
DefaultResources corev1.ResourceRequirements `json:"defaultResources,omitempty"`

// To specify the image that will be used for sidecar container.
// +optional
Expand Down
86 changes: 43 additions & 43 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 22 additions & 20 deletions charts/mysql-operator/crds/mysql.radondb.com_mysqlclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@ spec:
More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1'
type: string
type: object
podSpec:
podPolicy:
default:
busyboxImage: busybox:1.32
imagePullPolicy: IfNotPresent
resources:
defaultResources:
requests:
cpu: 10m
memory: 32Mi
imagePullPolicy: IfNotPresent
sidecarImage: radondb/mysql-sidecar:0.1
description: Pod extra specification.
properties:
Expand Down Expand Up @@ -1132,27 +1132,14 @@ spec:
default: busybox:1.32
description: The busybox image.
type: string
imagePullPolicy:
default: IfNotPresent
description: PullPolicy describes a policy for if/when to pull
a container image
enum:
- Always
- IfNotPresent
- Never
type: string
labels:
additionalProperties:
type: string
type: object
priorityClassName:
type: string
resources:
defaultResources:
default:
requests:
cpu: 10m
memory: 32Mi
description: The compute resource requirements.
description: DefaultResources defines quotas for containers other
than mysql and xenon. These containers take up less resources,
so quotas are set uniformly.
properties:
limits:
additionalProperties:
Expand All @@ -1177,6 +1164,21 @@ spec:
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
imagePullPolicy:
default: IfNotPresent
description: PullPolicy describes a policy for if/when to pull
a container image
enum:
- Always
- IfNotPresent
- Never
type: string
labels:
additionalProperties:
type: string
type: object
priorityClassName:
type: string
schedulerName:
type: string
sidecarImage:
Expand Down
42 changes: 22 additions & 20 deletions config/crd/bases/mysql.radondb.com_mysqlclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@ spec:
More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1'
type: string
type: object
podSpec:
podPolicy:
default:
busyboxImage: busybox:1.32
imagePullPolicy: IfNotPresent
resources:
defaultResources:
requests:
cpu: 10m
memory: 32Mi
imagePullPolicy: IfNotPresent
sidecarImage: radondb/mysql-sidecar:0.1
description: Pod extra specification.
properties:
Expand Down Expand Up @@ -1132,27 +1132,14 @@ spec:
default: busybox:1.32
description: The busybox image.
type: string
imagePullPolicy:
default: IfNotPresent
description: PullPolicy describes a policy for if/when to pull
a container image
enum:
- Always
- IfNotPresent
- Never
type: string
labels:
additionalProperties:
type: string
type: object
priorityClassName:
type: string
resources:
defaultResources:
default:
requests:
cpu: 10m
memory: 32Mi
description: The compute resource requirements.
description: DefaultResources defines quotas for containers other
than mysql and xenon. These containers take up less resources,
so quotas are set uniformly.
properties:
limits:
additionalProperties:
Expand All @@ -1177,6 +1164,21 @@ spec:
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
imagePullPolicy:
default: IfNotPresent
description: PullPolicy describes a policy for if/when to pull
a container image
enum:
- Always
- IfNotPresent
- Never
type: string
labels:
additionalProperties:
type: string
type: object
priorityClassName:
type: string
schedulerName:
type: string
sidecarImage:
Expand Down
6 changes: 3 additions & 3 deletions config/samples/mysql_v1alpha1_mysqlcluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ spec:
cpu: 100m
memory: 128Mi

podSpec:
podPolicy:
imagePullPolicy: IfNotPresent
sidecarImage: radondb/mysql-sidecar:latest
busyboxImage: busybox:1.32
Expand All @@ -74,8 +74,8 @@ spec:
priorityClassName: ""
tolerations: []
schedulerName: ""

resources:
# defaultResources defines quotas for containers other than mysql and xenon.
defaultResources:
requests:
cpu: 10m
memory: 32Mi
Expand Down
24 changes: 12 additions & 12 deletions docs/kubernetes/deploy_radondb-mysql_operator_on_k8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,18 @@ kubectl delete customresourcedefinitions.apiextensions.k8s.io mysqlclusters.mysq
| 参数 | 描述 | 默认值 |
|:------------------------- |:-------------------------------------------------- |:------------------------ |
| Replicas | 集群节点数,只允许为0、2、3、5 | 3 |
| PodSpec.ImagePullPolicy | 镜像拉取策略, 只允许为 Always/IfNotPresent/Never | IfNotPresent |
| PodSpec.Labels | 节点 pod [标签](#1-标签) | - |
| PodSpec.Annotations | 节点 pod [注解](#2-注解) | - |
| PodSpec.Affinity | 节点 pod [亲和性](#3-亲和性) | - |
| PodSpec.PriorityClassName | 节点 pod [优先级](#4-优先级)对象名称 | - |
| PodSpec.Tolerations | 节点 pod [污点容忍度](#5-容忍)列表 | - |
| PodSpec.SchedulerName | 节点 pod [调度器](#6-调度器)名称 | - |
| PodSpec.Resources | 节点 pod 配额 | 预留: cpu 10m, 内存 32Mi |
| PodSpec.SidecarImage | Sidecar 镜像 | radondb/mysql-sidecar:0.1 |
| PodSpec.BusyboxImage | Busybox 镜像 | busybox:1.32 |
| PodSpec.SlowLogTail | 是否开启慢日志跟踪 | false |
| PodSpec.AuditLogTail | 是否开启审计日志跟踪 | false |
| PodPolicy.ImagePullPolicy | 镜像拉取策略, 只允许为 Always/IfNotPresent/Never | IfNotPresent |
| PodPolicy.Labels | 节点 pod [标签](#1-标签) | - |
| PodPolicy.Annotations | 节点 pod [注解](#2-注解) | - |
| PodPolicy.Affinity | 节点 pod [亲和性](#3-亲和性) | - |
| PodPolicy.PriorityClassName | 节点 pod [优先级](#4-优先级)对象名称 | - |
| PodPolicy.Tolerations | 节点 pod [污点容忍度](#5-容忍)列表 | - |
| PodPolicy.SchedulerName | 节点 pod [调度器](#6-调度器)名称 | - |
| PodPolicy.Resources | 节点 pod 配额 | 预留: cpu 10m, 内存 32Mi |
| PodPolicy.SidecarImage | Sidecar 镜像 | radondb/mysql-sidecar:0.1 |
| PodPolicy.BusyboxImage | Busybox 镜像 | busybox:1.32 |
| PodPolicy.SlowLogTail | 是否开启慢日志跟踪 | false |
| PodPolicy.AuditLogTail | 是否开启审计日志跟踪 | false |

### 持久化配置

Expand Down
4 changes: 2 additions & 2 deletions mysqlcluster/container/auditlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c *auditLog) getName() string {

// getImage get the container image.
func (c *auditLog) getImage() string {
return c.Spec.PodSpec.BusyboxImage
return c.Spec.PodPolicy.BusyboxImage
}

// getCommand get the container command.
Expand All @@ -58,7 +58,7 @@ func (c *auditLog) getLifecycle() *corev1.Lifecycle {

// getResources get the container resources.
func (c *auditLog) getResources() corev1.ResourceRequirements {
return c.Spec.PodSpec.Resources
return c.Spec.PodPolicy.DefaultResources
}

// getPorts get the container ports.
Expand Down
4 changes: 2 additions & 2 deletions mysqlcluster/container/auditlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (
var (
auditlogMysqlCluster = mysqlv1alpha1.MysqlCluster{
Spec: mysqlv1alpha1.MysqlClusterSpec{
PodSpec: mysqlv1alpha1.PodSpec{
PodPolicy: mysqlv1alpha1.PodPolicy{
BusyboxImage: "busybox",
Resources: corev1.ResourceRequirements{
DefaultResources: corev1.ResourceRequirements{
Limits: nil,
Requests: nil,
},
Expand Down
4 changes: 2 additions & 2 deletions mysqlcluster/container/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (c *backupSidecar) getName() string {
}

func (c *backupSidecar) getImage() string {
return c.Spec.PodSpec.SidecarImage
return c.Spec.PodPolicy.SidecarImage
}

func (c *backupSidecar) getCommand() []string {
Expand Down Expand Up @@ -87,7 +87,7 @@ func (c *backupSidecar) getLifecycle() *corev1.Lifecycle {
}

func (c *backupSidecar) getResources() corev1.ResourceRequirements {
return c.Spec.PodSpec.Resources
return c.Spec.PodPolicy.DefaultResources
}

func (c *backupSidecar) getPorts() []corev1.ContainerPort {
Expand Down
2 changes: 1 addition & 1 deletion mysqlcluster/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func EnsureContainer(name string, c *mysqlcluster.MysqlCluster) corev1.Container
return corev1.Container{
Name: ctr.getName(),
Image: ctr.getImage(),
ImagePullPolicy: c.Spec.PodSpec.ImagePullPolicy,
ImagePullPolicy: c.Spec.PodPolicy.ImagePullPolicy,
Command: ctr.getCommand(),
Env: ctr.getEnvVars(),
Lifecycle: ctr.getLifecycle(),
Expand Down
Loading

0 comments on commit b893ebf

Please sign in to comment.