-
Notifications
You must be signed in to change notification settings - Fork 35
Add MySQLCluster v1beta2 #350
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
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
273702f
Add MySQLCluster v1beta2
d-kuro 0db2d21
Generate manifests
d-kuro a53e138
Set maxDescLen=30
d-kuro 7ae9b8b
Set maxDescLen=0
d-kuro 1c274d9
Use MySQLCluster v1beta2
d-kuro eb0e306
Generate conversion codes
d-kuro d8bb804
Add replicaServiceTemplate tests
d-kuro 1e2c6f2
Support conversion webhook in Helm chart
d-kuro a9fb411
Add Helm chart update note
d-kuro 7a4a056
Update PROJECT
d-kuro 63c1df5
Fix kubebulder comments.
d-kuro a94e04a
Move conversion logic form v1beta2 -> v1beta1
d-kuro 2733404
Add comment for generate manifests.
d-kuro 9253b81
Fix linter Warnings
d-kuro 4b44ff8
Generate docs
d-kuro 42da610
Add admisson webhook for MySQLCluster v1beta2
d-kuro c7988e3
Remove validate and mutate webhooks from v1beta1 MySQLCluster.
d-kuro e6e44e6
Add comments
d-kuro 4f5c0ae
Convert jobConfig.
d-kuro 6e11466
Fix Makefile format.
d-kuro d0fa6af
Add BackupPolicy v1beta2
d-kuro 7c02683
Use BackupPolicy v1beta2
d-kuro 4cc80be
Add conversion webhook for BackupPolicy
d-kuro e2400d9
Add BackupPolicy v1beta2 docs
d-kuro 3a55e6b
Remove old api docs
d-kuro 05700b9
Fix testing package name
d-kuro fcbc2a5
Upgrade apiVersion for example and docs.
d-kuro 6625785
Update serviceTemplate usage docs.
d-kuro e354449
Update docs/reconcile.md
ymmt2005 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| package v1beta1 | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "unsafe" | ||
|
|
||
| "github.com/cybozu-go/moco/api/v1beta2" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| apiconversion "k8s.io/apimachinery/pkg/conversion" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/conversion" | ||
| ) | ||
|
|
||
| const ( | ||
| SpecReplicaServiceTemplateAnnotation = "mysqlcluster.v1beta2.moco.cybozu.com/spec.replicaServiceTemplate" | ||
| ) | ||
|
|
||
| var _ conversion.Convertible = &MySQLCluster{} | ||
|
|
||
| // ConvertTo converts this MySQLCluster to the Hub version (v1beta2). | ||
| func (src *MySQLCluster) ConvertTo(dstRaw conversion.Hub) error { | ||
| dst := dstRaw.(*v1beta2.MySQLCluster) | ||
|
|
||
| return Convert__MySQLCluster_To_v1beta2_MySQLCluster(src, dst, nil) | ||
| } | ||
|
|
||
| // ConvertFrom converts from the Hub version (v1beta2) to this version. | ||
| func (dst *MySQLCluster) ConvertFrom(srcRaw conversion.Hub) error { | ||
| src := srcRaw.(*v1beta2.MySQLCluster) | ||
|
|
||
| return Convert_v1beta2_MySQLCluster_To__MySQLCluster(src, dst, nil) | ||
| } | ||
|
|
||
| // ConvertTo converts this MySQLCluster to the Hub version (v1beta2). | ||
| func (src *BackupPolicy) ConvertTo(dstRaw conversion.Hub) error { | ||
| dst := dstRaw.(*v1beta2.BackupPolicy) | ||
|
|
||
| return Convert__BackupPolicy_To_v1beta2_BackupPolicy(src, dst, nil) | ||
| } | ||
|
|
||
| // ConvertFrom converts from the Hub version (v1beta2) to this version. | ||
| func (dst *BackupPolicy) ConvertFrom(srcRaw conversion.Hub) error { | ||
| src := srcRaw.(*v1beta2.BackupPolicy) | ||
|
|
||
| return Convert_v1beta2_BackupPolicy_To__BackupPolicy(src, dst, nil) | ||
| } | ||
|
|
||
| // Convert__MySQLCluster_To_v1beta2_MySQLCluster is an autogenerated conversion function. | ||
| func Convert__MySQLCluster_To_v1beta2_MySQLCluster(in *MySQLCluster, out *v1beta2.MySQLCluster, s apiconversion.Scope) error { | ||
| if err := autoConvert__MySQLCluster_To_v1beta2_MySQLCluster(in, out, s); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if _, err := unmarshalReplicaServiceTemplate(in, out); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Convert_v1beta2_MySQLCluster_To__MySQLCluster is an autogenerated conversion function. | ||
| func Convert_v1beta2_MySQLCluster_To__MySQLCluster(in *v1beta2.MySQLCluster, out *MySQLCluster, s apiconversion.Scope) error { | ||
| if err := autoConvert_v1beta2_MySQLCluster_To__MySQLCluster(in, out, s); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := marshalReplicaServiceTemplate(&in.Spec, out); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func Convert__MySQLClusterSpec_To_v1beta2_MySQLClusterSpec(in *MySQLClusterSpec, out *v1beta2.MySQLClusterSpec, s apiconversion.Scope) error { | ||
| if err := autoConvert__MySQLClusterSpec_To_v1beta2_MySQLClusterSpec(in, out, s); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| out.PrimaryServiceTemplate = (*v1beta2.ServiceTemplate)(unsafe.Pointer(in.ServiceTemplate)) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func Convert_v1beta2_MySQLClusterSpec_To__MySQLClusterSpec(in *v1beta2.MySQLClusterSpec, out *MySQLClusterSpec, s apiconversion.Scope) error { | ||
| if err := autoConvert_v1beta2_MySQLClusterSpec_To__MySQLClusterSpec(in, out, s); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| out.ServiceTemplate = (*ServiceTemplate)(unsafe.Pointer(in.PrimaryServiceTemplate)) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // marshalReplicaServiceTemplate stores the service template as json data in the destination object annotations. | ||
| func marshalReplicaServiceTemplate(spec *v1beta2.MySQLClusterSpec, dst metav1.Object) error { | ||
| if spec.ReplicaServiceTemplate == nil { | ||
| return nil | ||
| } | ||
|
|
||
| u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(spec.ReplicaServiceTemplate) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| data, err := json.Marshal(u) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| annotations := dst.GetAnnotations() | ||
| if annotations == nil { | ||
| annotations = map[string]string{} | ||
| } | ||
|
|
||
| annotations[SpecReplicaServiceTemplateAnnotation] = string(data) | ||
| dst.SetAnnotations(annotations) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // unmarshalReplicaServiceTemplate tries to retrieve the data from the annotation and unmarshal it into the service template passed as input. | ||
| func unmarshalReplicaServiceTemplate(src metav1.Object, dst *v1beta2.MySQLCluster) (bool, error) { | ||
| data, ok := src.GetAnnotations()[SpecReplicaServiceTemplateAnnotation] | ||
| if !ok { | ||
| return false, nil | ||
| } | ||
|
|
||
| var s *v1beta2.ServiceTemplate | ||
|
|
||
| if err := json.Unmarshal([]byte(data), &s); err != nil { | ||
| return false, err | ||
| } | ||
|
|
||
| dst.Spec.ReplicaServiceTemplate = s | ||
|
|
||
| dstAnnotation := dst.GetAnnotations() | ||
|
|
||
| delete(dstAnnotation, SpecReplicaServiceTemplateAnnotation) | ||
|
|
||
| if len(dstAnnotation) == 0 { | ||
| dst.SetAnnotations(nil) | ||
| } | ||
|
|
||
| return true, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package v1beta1 | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| mocov1beta2 "github.com/cybozu-go/moco/api/v1beta2" | ||
| "github.com/google/go-cmp/cmp" | ||
| "github.com/google/go-cmp/cmp/cmpopts" | ||
| "k8s.io/apimachinery/pkg/api/apitesting/roundtrip" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| ) | ||
|
|
||
| func TestCompatibility(t *testing.T) { | ||
| scheme := runtime.NewScheme() | ||
| _ = AddToScheme(scheme) | ||
| _ = mocov1beta2.AddToScheme(scheme) | ||
|
|
||
| f := roundtrip.CompatibilityTestFuzzer(scheme, nil) | ||
| f.NilChance(0.5).NumElements(0, 3) | ||
|
|
||
| t.Run("MySQLCluster v1beta1 => v1beta2 => v1beta1", func(t *testing.T) { | ||
| for i := 0; i < 10000; i++ { | ||
| var oldCluster1, oldCluster2 MySQLCluster | ||
| var cluster mocov1beta2.MySQLCluster | ||
| f.Fuzz(&oldCluster1) | ||
|
|
||
| var tmp1, tmp2 mocov1beta2.MySQLCluster | ||
|
|
||
| if err := scheme.Convert(oldCluster1.DeepCopy(), &tmp1, nil); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if err := scheme.Convert(&tmp1, &cluster, nil); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if err := scheme.Convert(&cluster, &tmp2, nil); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if err := scheme.Convert(&tmp2, &oldCluster2, nil); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| if diff := cmp.Diff(oldCluster1, oldCluster2, cmpopts.EquateEmpty()); diff != "" { | ||
| t.Fatalf("compatibility error case #%d (-want +got):\n%s", i, diff) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| t.Run("BackupPolicy v1beta1 => v1beta2 => v1beta1", func(t *testing.T) { | ||
| for i := 0; i < 10000; i++ { | ||
| var oldPolicy1, oldPolicy2 BackupPolicy | ||
| var policy mocov1beta2.BackupPolicy | ||
| f.Fuzz(&oldPolicy1) | ||
|
|
||
| var tmp1, tmp2 mocov1beta2.BackupPolicy | ||
|
|
||
| if err := scheme.Convert(oldPolicy1.DeepCopy(), &tmp1, nil); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if err := scheme.Convert(&tmp1, &policy, nil); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if err := scheme.Convert(&policy, &tmp2, nil); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if err := scheme.Convert(&tmp2, &oldPolicy2, nil); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| if diff := cmp.Diff(oldPolicy1, oldPolicy2, cmpopts.EquateEmpty()); diff != "" { | ||
| t.Fatalf("compatibility error case #%d (-want +got):\n%s", i, diff) | ||
| } | ||
| } | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // Package v1beta1 contains the v1beta1 API implementation. | ||
| // +k8s:conversion-gen=github.com/cybozu-go/moco/api/v1beta2 | ||
| package v1beta1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.