Skip to content

Commit

Permalink
*: v3.0.0 backup convert do not work when use helm install it. #793
Browse files Browse the repository at this point in the history
  • Loading branch information
acekingke committed Jun 7, 2023
1 parent 174b801 commit 12e464e
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 16 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases

update-crd: ## Synchronize the generated YAML files to operator Chart after make manifests.
make manifests
cp config/crd/bases/* charts/mysql-operator/crds/
##make manifests
@echo "should modify by manaual for mysqlclster and mysqlbackup"
cp config/crd/bases/mysql.radondb.com_mysqlusers.yaml charts/mysql-operator/crds/

generate: controller-gen generate-go-conversions ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
Expand Down
3 changes: 3 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ resources:
kind: Backup
path: github.com/radondb/radondb-mysql-kubernetes/api/v1beta1
version: v1beta1
webhooks:
conversion: true
webhookVersion: v1
version: "3"
47 changes: 47 additions & 0 deletions api/v1beta1/mysqlcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ package v1beta1
import (
"fmt"
"strings"
"time"
"unsafe"

"github.com/radondb/radondb-mysql-kubernetes/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apiconversion "k8s.io/apimachinery/pkg/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)
Expand Down Expand Up @@ -183,13 +185,58 @@ func Convert_v1beta1_BackupStatus_To_v1alpha1_BackupStatus(in *BackupStatus, out
if err := autoConvert_v1beta1_BackupStatus_To_v1alpha1_BackupStatus(in, out, s); err != nil {
return err
}
out.BackupDate = in.CompletionTime.Format("2006-01-02 15:04:05")
switch in.State {
case BackupFailed:
out.Conditions = append(out.Conditions, v1alpha1.BackupCondition{
Type: v1alpha1.BackupStart,
Status: corev1.ConditionTrue,
Reason: "",
}, v1alpha1.BackupCondition{
Type: v1alpha1.BackupFailed,
Status: corev1.ConditionTrue,
Reason: "",
})
out.Completed = true
case BackupSucceeded:
out.Conditions = append(out.Conditions, v1alpha1.BackupCondition{
Type: v1alpha1.BackupStart,
Status: corev1.ConditionTrue,
Reason: "",
}, v1alpha1.BackupCondition{
Type: v1alpha1.BackupComplete,
Status: corev1.ConditionTrue,
Reason: "",
})
out.Completed = true
}
return nil
}

func Convert_v1alpha1_BackupStatus_To_v1beta1_BackupStatus(in *v1alpha1.BackupStatus, out *BackupStatus, s apiconversion.Scope) error {
if err := autoConvert_v1alpha1_BackupStatus_To_v1beta1_BackupStatus(in, out, s); err != nil {
return err
}
if t, err := time.Parse("2006-01-02 15:04:05", in.BackupDate); err != nil {
return err
} else {
completeTime := metav1.NewTime(t)
out.CompletionTime = &completeTime
}
if in.Completed {
out.State = BackupFailed
for _, cond := range in.Conditions {

if cond.Type == v1alpha1.BackupStart && cond.Status == corev1.ConditionTrue &&
out.State != BackupSucceeded {
out.State = BackupStart
}
if cond.Type == v1alpha1.BackupComplete && cond.Status == corev1.ConditionTrue {
out.State = BackupSucceeded
break
}
}
}
return nil
}

Expand Down
5 changes: 0 additions & 5 deletions api/v1beta1/zz_generated.conversion.go

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

4 changes: 2 additions & 2 deletions charts/mysql-operator/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ Create MySQLCluster:
> Create MySQLCluster:
{{- end }}

kubectl apply -f https://github.com/radondb/radondb-mysql-kubernetes/releases/latest/download/mysql_v1alpha1_mysqlcluster.yaml
kubectl apply -f https://github.com/radondb/radondb-mysql-kubernetes/releases/latest/download/mysql_v1beta1_mysqlcluster.yaml

Create Users:

kubectl apply -f https://github.com/radondb/radondb-mysql-kubernetes/releases/latest/download/mysql_v1alpha1_mysqluser.yaml
kubectl apply -f https://github.com/radondb/radondb-mysql-kubernetes/releases/latest/download/mysql_v1beta1_mysqluser.yaml

{{- if .Values.mysqlcluster.install }}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@

---
{{- $certManagerEnabled := .Values.webhook.certManager.enabled -}}
{{- $caCertPEM := include "webhook.caBundleCertPEM" . -}}
{{- $tlsCertPEM := include "webhook.certPEM" . -}}
{{- $tlsKeyPEM := include "webhook.keyPEM" . -}}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
{{- if $certManagerEnabled }}
cert-manager.io/inject-ca-from: "{{ .Release.Namespace }}/{{ template "certificate.name" . }}"
{{- end }}
creationTimestamp: null
name: backups.mysql.radondb.com
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
{{- if not $certManagerEnabled }}
caBundle: {{ ternary (b64enc $caCertPEM) (b64enc (trim $tlsCertPEM)) (empty $tlsKeyPEM) }}
{{- end }}
service:
name: radondb-mysql-webhook
namespace: default
path: /convert
conversionReviewVersions:
- v1
group: mysql.radondb.com
names:
kind: Backup
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@

---
{{- $certManagerEnabled := .Values.webhook.certManager.enabled -}}
{{- $caCertPEM := include "webhook.caBundleCertPEM" . -}}
{{- $tlsCertPEM := include "webhook.certPEM" . -}}
{{- $tlsKeyPEM := include "webhook.keyPEM" . -}}
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
cert-manager.io/inject-ca-from: default/radondb-mysql-certificate
{{- if $certManagerEnabled }}
cert-manager.io/inject-ca-from: "{{ .Release.Namespace }}/{{ template "certificate.name" . }}"
{{- end }}
creationTimestamp: null
name: mysqlclusters.mysql.radondb.com
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
caBundle: Cg==
{{- if not $certManagerEnabled }}
caBundle: {{ ternary (b64enc $caCertPEM) (b64enc (trim $tlsCertPEM)) (empty $tlsKeyPEM) }}
{{- end }}
service:
name: radondb-mysql-webhook
namespace: default
Expand Down
2 changes: 1 addition & 1 deletion config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ patchesStrategicMerge:
# patches here are for enabling the conversion webhook for each CRD
- patches/webhook_in_mysqlclusters.yaml
#- patches/webhook_in_mysqlclusters.yaml
#- patches/webhook_in_backups.yaml
- patches/webhook_in_backups.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
Expand Down
16 changes: 16 additions & 0 deletions config/crd/patches/webhook_in_backups.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: backups.mysql.radondb.com
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: radondb-mysql-webhook
path: /convert
conversionReviewVersions:
- v1

0 comments on commit 12e464e

Please sign in to comment.