Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Kubernetes 1.27 #525

Merged
merged 10 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
strategy:
matrix:
mysql-version: ["8.0.32"]
k8s-version: ["1.24.7", "1.25.3", "1.26.0"]
k8s-version: ["1.25.9", "1.26.4", "1.27.1"]
uses: ./.github/workflows/e2e.yaml
with:
k8s-version: ${{ matrix.k8s-version }}
Expand All @@ -43,7 +43,7 @@ jobs:
strategy:
matrix:
mysql-version: ["8.0.28", "8.0.31", "8.0.32"]
k8s-version: ["1.26.0"]
k8s-version: ["1.27.1"]
uses: ./.github/workflows/e2e.yaml
with:
k8s-version: ${{ matrix.k8s-version }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/helm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ jobs:
uses: helm/[email protected]
if: steps.list-changed.outputs.changed == 'true'
with:
version: v0.17.0
node_image: kindest/node:v1.26.0
kubectl_version: v1.26.0
version: v0.19.0
node_image: kindest/node:v1.27.1
kubectl_version: v1.27.1

- name: Apply cert-manager
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/weekly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
strategy:
matrix:
mysql-version: ["8.0.32"]
k8s-version: ["1.24.7", "1.25.3", "1.26.0"]
k8s-version: ["1.25.9", "1.26.4", "1.27.1"]
uses: ./.github/workflows/e2e.yaml
with:
k8s-version: ${{ matrix.k8s-version }}
Expand All @@ -38,7 +38,7 @@ jobs:
strategy:
matrix:
mysql-version: ["8.0.18", "8.0.25", "8.0.26", "8.0.27", "8.0.28", "8.0.30", "8.0.31", "8.0.32"]
k8s-version: ["1.26.0"]
k8s-version: ["1.27.1"]
uses: ./.github/workflows/e2e.yaml
with:
k8s-version: ${{ matrix.k8s-version }}
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Tool versions
CTRL_TOOLS_VERSION=0.11.1
CTRL_TOOLS_VERSION=0.12.0
CTRL_RUNTIME_VERSION := $(shell awk '/sigs.k8s.io\/controller-runtime/ {print substr($$2, 2)}' go.mod)
CODE_GENERATOR_VERSION := $(shell awk '/k8s.io\/client-go/ {print substr($$2, 2)}' go.mod)
KUSTOMIZE_VERSION = 4.5.6
HELM_VERSION = 3.10.2
KUSTOMIZE_VERSION = 5.0.3
HELM_VERSION = 3.12.0
CRD_TO_MARKDOWN_VERSION = 0.0.3
MYSQLSH_VERSION = 8.0.31-1
MDBOOK_VERSION = 0.4.21
GORELEASER_VERSION = 1.13.0
YQ_VERSION = 4.30.4
MDBOOK_VERSION = 0.4.20
GORELEASER_VERSION = 1.18.2
YQ_VERSION = 4.34.1
OS_VERSION := $(shell . /etc/os-release; echo $$VERSION_ID)

# Test tools
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Blog article: [Introducing MOCO, a modern MySQL operator on Kubernetes](https://
## Supported software

- MySQL: 8.0.18, 8.0.25, 8.0.26, 8.0.27, 8.0.28, 8.0.30, 8.0.31, 8.0.32
- Kubernetes: 1.24, 1.25, 1.26
- Kubernetes: 1.25, 1.26, 1.27

Other MySQL 8 releases would probably work. They are simply not tested in our CI.

Expand Down
8 changes: 4 additions & 4 deletions api/v1beta1/zz_generated.conversion.go

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

5 changes: 3 additions & 2 deletions api/v1beta2/backuppolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
batchv1 "k8s.io/api/batch/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation/field"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand Down Expand Up @@ -84,15 +85,15 @@ type BackupPolicySpec struct {
FailedJobsHistoryLimit *int32 `json:"failedJobsHistoryLimit,omitempty"`
}

func (s *BackupPolicySpec) validate() field.ErrorList {
func (s *BackupPolicySpec) validate() (admission.Warnings, field.ErrorList) {
var allErrs field.ErrorList
p := field.NewPath("spec")

if _, err := cron.ParseStandard(s.Schedule); err != nil {
allErrs = append(allErrs, field.Invalid(p.Child("schedule"), s.Schedule, err.Error()))
}

return allErrs
return nil, allErrs
}

//+kubebuilder:object:root=true
Expand Down
19 changes: 10 additions & 9 deletions api/v1beta2/backuppolicy_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

func (r *BackupPolicy) SetupWebhookWithManager(mgr ctrl.Manager) error {
Expand All @@ -29,27 +30,27 @@ type backupPolicyAdmission struct {

var _ webhook.CustomValidator = &backupPolicyAdmission{}

func (a *backupPolicyAdmission) ValidateCreate(ctx context.Context, obj runtime.Object) error {
func (a *backupPolicyAdmission) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ValidateCreate(), ValidateUpdate() and ValidateDelete() need to retern (warnings Warnings, err error)

ref: kubernetes-sigs/controller-runtime#2014

policy := obj.(*BackupPolicy)

errs := policy.Spec.validate()
warns, errs := policy.Spec.validate()
if len(errs) == 0 {
return nil
return warns, nil
}

return apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "BackupPolicy"}, policy.Name, errs)
return warns, apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "BackupPolicy"}, policy.Name, errs)
}

func (a *backupPolicyAdmission) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) error {
func (a *backupPolicyAdmission) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
return a.ValidateCreate(ctx, newObj)
}

func (a *backupPolicyAdmission) ValidateDelete(ctx context.Context, obj runtime.Object) error {
func (a *backupPolicyAdmission) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
policy := obj.(*BackupPolicy)

clusters := &MySQLClusterList{}
if err := a.client.List(context.Background(), clusters, client.InNamespace(policy.Namespace)); err != nil {
return err
return nil, err
}

for _, cluster := range clusters.Items {
Expand All @@ -58,8 +59,8 @@ func (a *backupPolicyAdmission) ValidateDelete(ctx context.Context, obj runtime.
}

if *cluster.Spec.BackupPolicyName == policy.Name {
return fmt.Errorf("MySQLCluster %s/%s has a reference to this policy", cluster.Namespace, cluster.Name)
return nil, fmt.Errorf("MySQLCluster %s/%s has a reference to this policy", cluster.Namespace, cluster.Name)
}
}
return nil
return nil, nil
}
10 changes: 6 additions & 4 deletions api/v1beta2/mysqlcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"
corev1ac "k8s.io/client-go/applyconfigurations/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand Down Expand Up @@ -118,7 +119,7 @@ type MySQLClusterSpec struct {
DisableSlowQueryLogContainer bool `json:"disableSlowQueryLogContainer,omitempty"`
}

func (s MySQLClusterSpec) validateCreate() field.ErrorList {
func (s MySQLClusterSpec) validateCreate() (admission.Warnings, field.ErrorList) {
var allErrs field.ErrorList
p := field.NewPath("spec")
pp := p.Child("volumeClaimTemplates")
Expand Down Expand Up @@ -232,10 +233,10 @@ func (s MySQLClusterSpec) validateCreate() field.ErrorList {
}
}

return allErrs
return nil, allErrs
}

func (s MySQLClusterSpec) validateUpdate(ctx context.Context, apiReader client.Reader, old MySQLClusterSpec) field.ErrorList {
func (s MySQLClusterSpec) validateUpdate(ctx context.Context, apiReader client.Reader, old MySQLClusterSpec) (admission.Warnings, field.ErrorList) {
var allErrs field.ErrorList
p := field.NewPath("spec")

Expand Down Expand Up @@ -285,7 +286,8 @@ func (s MySQLClusterSpec) validateUpdate(ctx context.Context, apiReader client.R
allErrs = append(allErrs, s.validateVolumeExpansionSupported(ctx, apiReader, volumeExpansionTargetIndices)...)
}

return append(allErrs, s.validateCreate()...)
warns, errs := s.validateCreate()
return warns, append(allErrs, errs...)
}

func (s MySQLClusterSpec) validateVolumeExpansionSupported(ctx context.Context, apiReader client.Reader, targetIndices []int) field.ErrorList {
Expand Down
21 changes: 11 additions & 10 deletions api/v1beta2/mysqlcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

func (r *MySQLCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
Expand Down Expand Up @@ -56,29 +57,29 @@ func (a *mySQLClusterAdmission) Default(ctx context.Context, obj runtime.Object)

var _ webhook.CustomValidator = &mySQLClusterAdmission{}

func (a *mySQLClusterAdmission) ValidateCreate(ctx context.Context, obj runtime.Object) error {
func (a *mySQLClusterAdmission) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
cluster := obj.(*MySQLCluster)

errs := cluster.Spec.validateCreate()
warns, errs := cluster.Spec.validateCreate()
if len(errs) == 0 {
return nil
return warns, nil
}

return apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "MySQLCluster"}, cluster.Name, errs)
return warns, apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "MySQLCluster"}, cluster.Name, errs)
}

func (a *mySQLClusterAdmission) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) error {
func (a *mySQLClusterAdmission) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
oldCluster := oldObj.(*MySQLCluster)
newCluster := newObj.(*MySQLCluster)

errs := newCluster.Spec.validateUpdate(ctx, a.client, oldCluster.Spec)
warns, errs := newCluster.Spec.validateUpdate(ctx, a.client, oldCluster.Spec)
if len(errs) == 0 {
return nil
return warns, nil
}

return apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "MySQLCluster"}, newCluster.Name, errs)
return warns, apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "MySQLCluster"}, newCluster.Name, errs)
}

func (a *mySQLClusterAdmission) ValidateDelete(ctx context.Context, obj runtime.Object) error {
return nil
func (a *mySQLClusterAdmission) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
return nil, nil
}
Loading