forked from openstack-k8s-operators/mariadb-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The galera controller creates StatefulSet for the db to run. This adds a StatefulSet pod's label "controller-revision-hash": "<statefulset_name>-<hash>" to the pod. The kubernetes label is restricted under 63 char and the revision hash is an int32, 10 chars + the hyphen. The galera controller also adds a suffix '-galera' to the statefulset name. With this the max name must not exceed 46 chars. Depends-On: openstack-k8s-operators/lib-common#562 Jira: https://issues.redhat.com/browse/OSPRH-8063 Signed-off-by: Martin Schuppert <[email protected]> (cherry picked from commit 4f04456)
- Loading branch information
Showing
10 changed files
with
334 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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,69 @@ | ||
/* | ||
Copyright 2022. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package functional_test | ||
|
||
import ( | ||
"time" | ||
|
||
. "github.com/onsi/gomega" //revive:disable:dot-imports | ||
|
||
"github.com/google/uuid" | ||
|
||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1" | ||
) | ||
|
||
const ( | ||
timeout = 10 * time.Second | ||
interval = timeout / 100 | ||
) | ||
|
||
func CreateGaleraConfig(namespace string, spec map[string]interface{}) client.Object { | ||
name := uuid.New().String() | ||
|
||
raw := map[string]interface{}{ | ||
"apiVersion": "mariadb.openstack.org/v1beta1", | ||
"kind": "Galera", | ||
"metadata": map[string]interface{}{ | ||
"name": name, | ||
"namespace": namespace, | ||
}, | ||
"spec": spec, | ||
} | ||
|
||
return th.CreateUnstructured(raw) | ||
} | ||
|
||
func GetDefaultGaleraSpec() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"replicas": 1, | ||
"logToDisk": false, | ||
"secret": "osp-secret", | ||
"storageClass": "local-storage", | ||
"storageRequest": "500M", | ||
} | ||
} | ||
|
||
func GetGalera(name types.NamespacedName) *mariadbv1.Galera { | ||
instance := &mariadbv1.Galera{} | ||
Eventually(func(g Gomega) { | ||
g.Expect(k8sClient.Get(ctx, name, instance)).Should(Succeed()) | ||
}, timeout, interval).Should(Succeed()) | ||
return instance | ||
} |
This file contains 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,65 @@ | ||
/* | ||
Copyright 2023. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package functional_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" //revive:disable:dot-imports | ||
. "github.com/onsi/gomega" //revive:disable:dot-imports | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
|
||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
var _ = Describe("Galera webhook", func() { | ||
var galeraName types.NamespacedName | ||
|
||
When("a default Galera gets created", func() { | ||
BeforeEach(func() { | ||
galera := CreateGaleraConfig(namespace, GetDefaultGaleraSpec()) | ||
galeraName.Name = galera.GetName() | ||
galeraName.Namespace = galera.GetNamespace() | ||
DeferCleanup(th.DeleteInstance, galera) | ||
}) | ||
|
||
It("should have created a Galera", func() { | ||
Eventually(func(_ Gomega) { | ||
GetGalera(galeraName) | ||
}, timeout, interval).Should(Succeed()) | ||
}) | ||
}) | ||
|
||
When("a Galera gets created with a name longer then 46 chars", func() { | ||
It("gets blocked by the webhook and fail", func() { | ||
|
||
raw := map[string]interface{}{ | ||
"apiVersion": "mariadb.openstack.org/v1beta1", | ||
"kind": "Galera", | ||
"metadata": map[string]interface{}{ | ||
"name": "foo-1234567890-1234567890-1234567890-1234567890", | ||
"namespace": namespace, | ||
}, | ||
"spec": GetDefaultGaleraSpec(), | ||
} | ||
|
||
unstructuredObj := &unstructured.Unstructured{Object: raw} | ||
_, err := controllerutil.CreateOrPatch( | ||
th.Ctx, th.K8sClient, unstructuredObj, func() error { return nil }) | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.