-
Notifications
You must be signed in to change notification settings - Fork 210
K8SPXC-1683: add validation for PiTR fields #2398
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
Open
nmarukovich
wants to merge
11
commits into
main
Choose a base branch
from
K8SPXC-1683_add_validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
94b28ac
K8SPXC-1683 add validation
nmarukovich 9fee392
fix
nmarukovich 5816420
fix
nmarukovich f6ec32f
fix PR comments
nmarukovich 84d3f7a
Merge branch 'main' of github.com:percona/percona-xtradb-cluster-oper…
nmarukovich ac952d7
Merge branch 'main' of github.com:percona/percona-xtradb-cluster-oper…
nmarukovich 47d82f2
fix PR
nmarukovich fc8b174
rewrite tests
nmarukovich d92188d
fix test
nmarukovich 3c3b93a
Merge branch 'main' into K8SPXC-1683_add_validation
nmarukovich fa6f4d5
Merge branch 'main' into K8SPXC-1683_add_validation
nmarukovich 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
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,111 @@ | ||
| package pxcrestore | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/client-go/kubernetes/scheme" | ||
| "k8s.io/client-go/rest" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/envtest" | ||
| logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
| "sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
|
|
||
| "github.com/percona/percona-xtradb-cluster-operator/pkg/apis" | ||
| pxcv1 "github.com/percona/percona-xtradb-cluster-operator/pkg/apis/pxc/v1" | ||
| ) | ||
|
|
||
| var ( | ||
| cfg *rest.Config | ||
| k8sClient client.Client | ||
| testEnv *envtest.Environment | ||
| ) | ||
|
|
||
| func TestPxcrestore(t *testing.T) { | ||
| RegisterFailHandler(Fail) | ||
| RunSpecs(t, "PerconaXtraDBClusterRestore Suite") | ||
| } | ||
|
|
||
| var _ = BeforeSuite(func() { | ||
| logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) | ||
|
|
||
| Expect(os.Setenv("WATCH_NAMESPACE", "default")).NotTo(HaveOccurred()) | ||
|
|
||
| By("bootstrapping test environment") | ||
| testEnv = &envtest.Environment{ | ||
| CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, | ||
| ErrorIfCRDPathMissing: true, | ||
| } | ||
|
|
||
| var err error | ||
| cfg, err = testEnv.Start() | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(cfg).NotTo(BeNil()) | ||
|
|
||
| err = apis.AddToScheme(scheme.Scheme) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(k8sClient).NotTo(BeNil()) | ||
| }) | ||
|
|
||
| var _ = AfterSuite(func() { | ||
| By("tearing down the test environment") | ||
| Expect(os.Unsetenv("WATCH_NAMESPACE")).NotTo(HaveOccurred()) | ||
| Expect(testEnv.Stop()).NotTo(HaveOccurred()) | ||
| }) | ||
|
|
||
| var _ = Describe("PerconaXtraDBClusterRestore PITR CRD validation", Ordered, func() { | ||
| ctx := context.Background() | ||
| const ns = "pitr-validation" | ||
|
|
||
| BeforeAll(func() { | ||
| Expect(k8sClient.Create(ctx, &corev1.Namespace{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: ns}, | ||
| })).To(Succeed()) | ||
| }) | ||
|
|
||
| AfterAll(func() { | ||
| _ = k8sClient.Delete(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: ns}}) | ||
| }) | ||
|
|
||
| newRestore := func(name string, pitr *pxcv1.PITR) *pxcv1.PerconaXtraDBClusterRestore { | ||
| return &pxcv1.PerconaXtraDBClusterRestore{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: ns}, | ||
| Spec: pxcv1.PerconaXtraDBClusterRestoreSpec{ | ||
| PXCCluster: "cluster1", | ||
| BackupName: "backup1", | ||
| PITR: pitr, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| DescribeTable("valid PITR configurations", | ||
| func(name string, pitr *pxcv1.PITR) { | ||
| Expect(k8sClient.Create(ctx, newRestore(name, pitr))).To(Succeed()) | ||
| }, | ||
| Entry("type latest", "valid-latest", &pxcv1.PITR{Type: "latest"}), | ||
| Entry("type date with valid format", "valid-date", &pxcv1.PITR{Type: "date", Date: "2024-01-15 12:30:00"}), | ||
| Entry("type transaction with gtid", "valid-transaction", &pxcv1.PITR{Type: "transaction", GTID: "abc123:1-10"}), | ||
| ) | ||
|
|
||
| DescribeTable("invalid PITR configurations", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. til DescribeTable nice |
||
| func(name string, pitr *pxcv1.PITR, errMsg string) { | ||
| err := k8sClient.Create(ctx, newRestore(name, pitr)) | ||
| Expect(err).To(HaveOccurred()) | ||
| Expect(err.Error()).To(ContainSubstring(errMsg)) | ||
| }, | ||
| Entry("type date with empty date", "invalid-date-empty", &pxcv1.PITR{Type: "date"}, "Date is required"), | ||
| Entry("type date with wrong format", "invalid-date-format", &pxcv1.PITR{Type: "date", Date: "15-01-2024 12:30:00"}, "format YYYY-MM-DD"), | ||
| Entry("type latest with date set", "invalid-latest-date", &pxcv1.PITR{Type: "latest", Date: "2024-01-15 12:30:00"}, "Date and GTID should not be set"), | ||
| Entry("type transaction without gtid", "invalid-transaction-no-gtid", &pxcv1.PITR{Type: "transaction"}, "GTID is required"), | ||
| Entry("unknown type", "invalid-unknown-type", &pxcv1.PITR{Type: "unknown"}, "Unsupported value"), | ||
| ) | ||
| }) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we discussed the kubebuilder validation testing through envtest, are we going to update that test in this PR?